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,389
  • Java source - BetterDialogs.zip
    8.5 KB · Views: 765
Last edited:

Informatix

Expert
Licensed User
Longtime User
Really I'm not so familiar with Java but I've worked a little with it (fixed/rearranged a java PDF library with B4A and made some BlackBerry support to programmers), so I should have a chance.
As now, I will reconvert to form (with timer, because I don't know how stop keyboard but having the cursor visible), when I'll have some time I will try it (and I will report to you).

Many thanks for your support.
In fact, in Java, I don't see any other solution than adding some specific code to the function. From the outside, even by extending the class, you won't be able to do what you want. Feel free to decompile my code and do your own function.
 

bluedude

Well-Known Member
Licensed User
Longtime User
I tested the keyboard hiding and I noticed it isn't always working. It does not generate any error.

After extensive testing I just found the cause of the problem. When the dialog is initiated from a click event (button) al works fine. However, i'm calling ShowDialog (which contains code for betterdialogs) from another sub which is not in a click event. I check an URL and in the sub handling the http request i'm calling the dialog. When that happens the keyboard does not get closed and i'm actually also not able to close it by hidekeyboard.

Any suggestions?

Tried to call a click event handler of a button to see if that helps (with requestfocus) but even then it does not work.

Even when I use a click event of a button sometimes it fails. This is a pretty big showstopper from an app. i'm developing, the better dialogs make my life easier.

Cheers.
 

Informatix

Expert
Licensed User
Longtime User
I tested the keyboard hiding and I noticed it isn't always working. It does not generate any error.

After extensive testing I just found the cause of the problem. When the dialog is initiated from a click event (button) al works fine. However, i'm calling ShowDialog (which contains code for betterdialogs) from another sub which is not in a click event. I check an URL and in the sub handling the http request i'm calling the dialog. When that happens the keyboard does not get closed and i'm actually also not able to close it by hidekeyboard.

Any suggestions?

Tried to call a click event handler of a button to see if that helps (with requestfocus) but even then it does not work.

Even when I use a click event of a button sometimes it fails. This is a pretty big showstopper from an app. i'm developing, the better dialogs make my life easier.

Cheers.
In the demo, the dialogs are not called when you click on a button and I can ensure you that you can call the dialogs from any sub without issue with the keyboard. Maybe it's a problem with HttpUtils2 but I'm not familiar at all with this library. Without a case to reproduce the issue, I cannot help.
 

Kevin

Well-Known Member
Licensed User
Longtime User
bluedude: I had problems hiding the keyboard after the dialog dismisses as well and this seems to have solved it for me (albeit with a slight delay sometimes):

B4X:
' After finished with dialog and you want to close keyboard.......

CallSubDelayed (Me, "HideKeyboard")

' ----------------------------------------------------------------

'ph is of course declared as Phone

Sub HideKeyboard
    DoEvents: ph.HideKeyboard (Activity): DoEvents
End Sub
 

Informatix

Expert
Licensed User
Longtime User
bluedude: I had problems hiding the keyboard after the dialog dismisses as well and this seems to have solved it for me (albeit with a slight delay sometimes):

B4X:
' After finished with dialog and you want to close keyboard.......

CallSubDelayed (Me, "HideKeyboard")

' ----------------------------------------------------------------

'ph is of course declared as Phone

Sub HideKeyboard
    DoEvents: ph.HideKeyboard (Activity): DoEvents
End Sub
I'd like to understand why the keyboard is not closed but I need a simple example to reproduce the case. On my side, everything works fine.
 

Kevin

Well-Known Member
Licensed User
Longtime User
I'm not really sure why this is happening and there are probably lots of factors, at least in my case. I am using AHViewPager, with your ULV. When an item is pressed, an AHQuickAction menu pops up, then your dialog depending on what the user chooses. Maybe it is just too much stuff happening after the dialog is closed? I have no idea, but putting the 'keyboard hide' command in a delayed sub seems to have worked for me.
 

Informatix

Expert
Licensed User
Longtime User
Just to be sure, I clarify the behavior of the lib:
The BetterDialogs lib opens and closes automatically the keyboard for an InputBox, but for a CustomDialog, the keyboard is open and closed ONLY when the OpenKeyboard parameter = True and the dialog contains an editable view. If you open the keyboard yourself by entering an EditText, then BD won't hide the keyboard.
 

Kevin

Well-Known Member
Licensed User
Longtime User
In my case I am using a custom message box with an EditText and I do use the OpenKeyboard parameter, but the keyboard did not hide itself when closing the dialog which is when I eventually came up with the delayed sub workaround. It may also be worth mentioning that I use your custom message box in a class.

I would guess that it probably works as expected in most circumstances and it is something peculiar about my (and bluedude's) situation.
 

TheMightySwe

Active Member
Licensed User
Longtime User
If your hardware is recognized as an input hardware, it wouldn't be surprising that the virtual keyboard is disabled. The BD library does not do anything special to open the keyboard, it just sets the mode of the virtual keyboard to SOFT_INPUT_STATE_ALWAYS_VISIBLE with setSoftInputMode.


Is there some way to force the soft keyboard to be shown and connected to the dialog?
 

Informatix

Expert
Licensed User
Longtime User
It seem to be impossible on Sony Xperia Z2 tablet, they don't have an option in the settings to keep the softkeyboard on even if a "hardware keyboard" is present.
I don't know this setting. That would not be surprising if this behavior is the default behavior on all Android devices. Why do you need the virtual keyboard when a hardware keyboard is connected?
 

TheMightySwe

Active Member
Licensed User
Longtime User
I don't know this setting. That would not be surprising if this behavior is the default behavior on all Android devices. Why do you need the virtual keyboard when a hardware keyboard is connected?

Because the "hardware keyboard" is a barcodescanner.
 

TheMightySwe

Active Member
Licensed User
Longtime User
I remember now that you already asked the question. I have no answer for you, sorry, except that you cannot open the keyboard programmatically with another method AFAIK.

Many units have an option in the settings to "open soft keyboard even if hardware keyboard is present", of the 8 units I have infront of me now 5 has that option. But ofcourse the unit that the customer has lack that option. Grrrrrrrrrrrrrrrrrrr!

But anyway, I just make them buy one hardware keyboard so can I relax.
 

TheMightySwe

Active Member
Licensed User
Longtime User
Hi,

Regarding my soft keyboard problem, i have made a Keyboard on a BD, but the click event on the buttons dont seem to fire.

I don't know if we I have asked this before in the context of BD, but is it possible to update an edittext on a BD with buttons on a BD?
 

Informatix

Expert
Licensed User
Longtime User
Hi,

Regarding my soft keyboard problem, i have made a Keyboard on a BD, but the click event on the buttons dont seem to fire.

I don't know if we I have asked this before in the context of BD, but is it possible to update an edittext on a BD with buttons on a BD?
I think there's an error in your code or your event name.
In my app on the Play store, I made a small keyboard with BD (a Masked EditText + 10 buttons) to enter and display a password. The Click event works fine.
 

TheMightySwe

Active Member
Licensed User
Longtime User
I think there's an error in your code or your event name.
In my app on the Play store, I made a small keyboard with BD (a Masked EditText + 10 buttons) to enter and display a password. The Click event works fine.


I think so to, I initialize in in Main, I have the sub in Main. I put the buttons on the panel in a CodeFile, is that the problem?

The Buttons are Globals, The Panel is global.
 

TheMightySwe

Active Member
Licensed User
Longtime User
Yes I know, but i initialized everything in Main. Now I moved out the rest of the code and it does not work anyway.
 
Top