B4A Library [Lib] BetterDialogs

I tried to improve the most useful dialogs of the Dialogs library. In my version, HTML tags are interpreted (even in the text of buttons), the InputBox uses a Masked EditText and has more options, you can check if the input is valid before closing the dialog, and the CustomDialog is fully customizable. I also solved an issue with the virtual keyboard.

MsgBox (under Gingerbread and JellyBean):

msgbox.png


InputBox (under Gingerbread and JellyBean):

inputbox.png


CustomDialog (under Gingerbread and JellyBean):

cd1.jpg


Another CustomDialog (under Gingerbread and JellyBean):

cd2.png


v1.1:
- I added a CloseDialog function;
- I added a margin parameter to the custom dialog.

v1.2:
- I fixed a bug in InputBox when there's a default value;
- I added the BackKeyPressed event for custom dialogs.

v1.3:
- I added a PasswordMode option to the InputBox;
- I added a CancelOnTouchOutside option.

v1.4:
- I added a CursorPosition option to the InputBox.

v2.0:
- I moved the CustomDialog parameters to the BD_CustomDlgParams class.
- I added two new parameters: Duration and DialogGravity.
- I removed the Margin parameter and added the MarginHeight parameter (to be used when Gravity is set to TOP).
- The BodyWidth and BodyHeight parameters defines now accurately the size of the dialog body.

v2.1:
- I added a "closing" event raised just before a custom dialog is dismissed. You can cancel the closure by returning False.

v2.11:
- I added the "DlgResponse" parameter to the Closing event.

This library does not work with Android versions < 2.
It requires another library: Masked EditText
 

Attachments

  • BetterDialogs v2.11.zip
    55.6 KB · Views: 2,241
  • Java source - BetterDialogs.zip
    8.5 KB · Views: 670
Last edited:

Kevin

Well-Known Member
Licensed User
Longtime User
Forgive me if this is evident in a demo or something, but is it possible to combine the features of a custom dialog (specifically a custom title bar and custom buttons) with your built-in dialogs? I like the custom dialog in that I can use custom buttons but then they do not size or internally scroll automatically. I am referring to just a simple text-only dialog, without any extra controls.
 

Informatix

Expert
Licensed User
Longtime User
Forgive me if this is evident in a demo or something, but is it possible to combine the features of a custom dialog (specifically a custom title bar and custom buttons) with your built-in dialogs? I like the custom dialog in that I can use custom buttons but then they do not size or internally scroll automatically. I am referring to just a simple text-only dialog, without any extra controls.
I'm not sure to understand.
 

MMORETTI964

Member
Licensed User
Longtime User
Hi @Informatix

I tried it but seems doesn't work.
Give me an exception even I only declared the BD variable.
I need some other updated library than MaskedEditText (1.30)?

java.lang.ClassNotFoundException: flm$b4a$betterdialogs$BetterDialogs
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:544)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:516)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:320)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at flm.b4a.testdialogs.main.initializeGlobals(main.java:264)
at flm.b4a.testdialogs.main.afterFirstLayout(main.java:95)
at flm.b4a.testdialogs.main.access$100(main.java:16)
at flm.b4a.testdialogs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Hi @Informatix

I tried it but seems doesn't work.
Give me an exception even I only declared the BD variable.
I need some other updated library than MaskedEditText (1.30)?

java.lang.ClassNotFoundException: flm$b4a$betterdialogs$BetterDialogs
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:544)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:516)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:320)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at flm.b4a.testdialogs.main.initializeGlobals(main.java:264)
at flm.b4a.testdialogs.main.afterFirstLayout(main.java:95)
at flm.b4a.testdialogs.main.access$100(main.java:16)
at flm.b4a.testdialogs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Sorry but I don't know why you get this error. I tested my library with at least 6 different devices and OS (from Gingerbread to Lollypop). Did you try the demo or your own app?
 

MMORETTI964

Member
Licensed User
Longtime User
Sorry but I don't know why you get this error. I tested my library with at least 6 different devices and OS (from Gingerbread to Lollypop). Did you try the demo or your own app?

Even in my code and in your example, too.
In my libs I see:
BetterDialogs (2.00)
Core (3.80)
Reflection (2.40)

Even in rapid and legacy mode
 

MMORETTI964

Member
Licensed User
Longtime User
I've tried on another PC of my colleague with another device (SAMSUNG 7 with KitKat), mine is attached to SAMSUNG NOTE 3 with kitkat, the error is the same.

RAPID:
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


java.lang.ClassNotFoundException: flm$b4a$betterdialogs$BetterDialogs


at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:544)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:516)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:320)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at flm.b4a.testdialogs.main.initializeGlobals(main.java:264)
at flm.b4a.testdialogs.main.afterFirstLayout(main.java:95)
at flm.b4a.testdialogs.main.access$100(main.java:16)
at flm.b4a.testdialogs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)




LEGACY:
main_globals (java line: 651)


java.lang.NoClassDefFoundError: flm.b4a.betterdialogs.BetterDialogs


at flm.b4a.testdialogs.main._globals(main.java:651)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at flm.b4a.testdialogs.main.initializeGlobals(main.java:264)
at flm.b4a.testdialogs.main.afterFirstLayout(main.java:95)
at flm.b4a.testdialogs.main.access$100(main.java:16)
at flm.b4a.testdialogs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
 

Informatix

Expert
Licensed User
Longtime User
I've tried on another PC of my colleague with another device (SAMSUNG 7 with KitKat), mine is attached to SAMSUNG NOTE 3 with kitkat, the error is the same.

RAPID:
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


java.lang.ClassNotFoundException: flm$b4a$betterdialogs$BetterDialogs


at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:544)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:516)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:320)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at flm.b4a.testdialogs.main.initializeGlobals(main.java:264)
at flm.b4a.testdialogs.main.afterFirstLayout(main.java:95)
at flm.b4a.testdialogs.main.access$100(main.java:16)
at flm.b4a.testdialogs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)




LEGACY:
main_globals (java line: 651)


java.lang.NoClassDefFoundError: flm.b4a.betterdialogs.BetterDialogs


at flm.b4a.testdialogs.main._globals(main.java:651)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at flm.b4a.testdialogs.main.initializeGlobals(main.java:264)
at flm.b4a.testdialogs.main.afterFirstLayout(main.java:95)
at flm.b4a.testdialogs.main.access$100(main.java:16)
at flm.b4a.testdialogs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
I just tried on a Samsung S4 under Jellybean (in case it is related to Samsung devices) and got no issue, whatever mode I used.
I don't have Samsung devices running under KitKat.
 

MMORETTI964

Member
Licensed User
Longtime User
I just tried on a Samsung S4 (in case it is related to Samsung devices) and got no issue, whatever mode I used.

In the second PC I've tried, I redownload your library, peraphs Erel could solve the mistery.

RELEASE
LogCat connected to: 1af4b817
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


main_globals (java line: 486)


java.lang.NoClassDefFoundError: flm.b4a.betterdialogs.BetterDialogs
at flm.b4a.testdialogs.main._globals(main.java:486)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at flm.b4a.testdialogs.main.initializeGlobals(main.java:264)
at flm.b4a.testdialogs.main.afterFirstLayout(main.java:95)
at flm.b4a.testdialogs.main.access$100(main.java:16)
at flm.b4a.testdialogs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

...
How about give us a dialog timer? Having B4A Timer not working, should a java timer work with Dialog?
(as usual) Thank you.
 

Informatix

Expert
Licensed User
Longtime User
In the second PC I've tried, I redownload your library, peraphs Erel could solve the mistery.

RELEASE
LogCat connected to: 1af4b817
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


main_globals (java line: 486)


java.lang.NoClassDefFoundError: flm.b4a.betterdialogs.BetterDialogs
at flm.b4a.testdialogs.main._globals(main.java:486)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at flm.b4a.testdialogs.main.initializeGlobals(main.java:264)
at flm.b4a.testdialogs.main.afterFirstLayout(main.java:95)
at flm.b4a.testdialogs.main.access$100(main.java:16)
at flm.b4a.testdialogs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

...
How about give us a dialog timer? Having B4A Timer not working, should a java timer work with Dialog?
(as usual) Thank you.
The new version includes a parameter (Duration) to dismiss the dialog after the given time is elapsed.
 

MMORETTI964

Member
Licensed User
Longtime User
In some circumstances (after a touch on my customedit) it appears a keyboard. I would like to hide that keyboard (my keyboard is the dialog). Something like that:

Sub customedit2_FocusChanged (HasFocus As Boolean)
If HasFocus Then
'CallSubDelayed(Me,"timerkeyboard_tick")
TimerKeyboard.interval=1
TimerKeyboard.Enabled = True
End If
End Sub

Sub customedit2_Click
TimerKeyboard_tick
'CallSubDelayed(Me,"timerkeyboard_tick")
'TimerKeyboard.Interval=1
'TimerKeyboard.Enabled = True
End Sub

Sub TimerKeyboard_tick
TimerKeyboard.Enabled = False
Dim p As Phone
p.HideKeyboard(ActivityLib)
End Sub
 

Informatix

Expert
Licensed User
Longtime User
In some circumstances (after a touch on my customedit) it appears a keyboard. I would like to hide that keyboard (my keyboard is the dialog). Something like that:

Sub customedit2_FocusChanged (HasFocus As Boolean)
If HasFocus Then
'CallSubDelayed(Me,"timerkeyboard_tick")
TimerKeyboard.interval=1
TimerKeyboard.Enabled = True
End If
End Sub

Sub customedit2_Click
TimerKeyboard_tick
'CallSubDelayed(Me,"timerkeyboard_tick")
'TimerKeyboard.Interval=1
'TimerKeyboard.Enabled = True
End Sub

Sub TimerKeyboard_tick
TimerKeyboard.Enabled = False
Dim p As Phone
p.HideKeyboard(ActivityLib)
End Sub
It is quite normal that a keyboard opens when you enter an EditText. If you want that your text cannot be edited with the keyboard (and thus avoid opening it), use my MaskedEditText lib and set ReadOnly to true. You will only be able to set a new text programmatically.
 

Informatix

Expert
Licensed User
Longtime User
If the library was compiled with Java 7 then you need to:
- Reference Java 7 under Tools - Configure Paths.
- Use B4A v3.82+.
Indeed.
The path with the latest version is: C:\Program Files\Java\jdk1.7.0_71\bin\javac.exe

Android is compatible with Java 7 since October 2013, so I thought everybody was already compiling with Java 7 and that I was one of the last to keep Java 6 until this week. From now on, I will always compile with Java 7. Java 6 is no longer on my HD.
 

MMORETTI964

Member
Licensed User
Longtime User
If the library was compiled with Java 7 then you need to:
- Reference Java 7 under Tools - Configure Paths.
- Use B4A v3.82+.

I have the following path:
C:\Program Files (x86)\Java\jdk1.7.0_03\bin\javac.exe

But... I should change / update it?
 
Top