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

GMan

Well-Known Member
Licensed User
Longtime User
TOP - so you may gimme a virtual hug ;)
 

pesquera

Active Member
Licensed User
Longtime User
is there a way to drag the windows from this class like the floating windows?
 

pesquera

Active Member
Licensed User
Longtime User
hello, after closing the custom dialog the soft keyboard remains opened.. I've tried with both HideKeyboard (Phone and IME) without luck.. what I'm doing wrong? thanks

B4X:
Dim loc_Resultado As Int
loc_Resultado =  BDialog.CustomDialog(loc_Titulo, -1, -1, loc_PanelCuerpo, 310dip, loc_H_PanelCuerpo, loc_X, Colors.Black, "Ok", "Cancelar", "", True, "rtn_Form_Manual_Cancelado")
'        Dim loc_Phone As Phone
'        loc_Phone.HideKeyboard(Activity)
'      Dim loc_IME As IME
'      loc_IME.Initialize("")
'      loc_IME.HideKeyboard
 

Informatix

Expert
Licensed User
Longtime User
hello, after closing the custom dialog the soft keyboard remains opened.. I've tried with both HideKeyboard (Phone and IME) without luck.. what I'm doing wrong? thanks

B4X:
Dim loc_Resultado As Int
loc_Resultado =  BDialog.CustomDialog(loc_Titulo, -1, -1, loc_PanelCuerpo, 310dip, loc_H_PanelCuerpo, loc_X, Colors.Black, "Ok", "Cancelar", "", True, "rtn_Form_Manual_Cancelado")
'        Dim loc_Phone As Phone
'        loc_Phone.HideKeyboard(Activity)
'      Dim loc_IME As IME
'      loc_IME.Initialize("")
'      loc_IME.HideKeyboard
Do you have the same problem in the demo, or just in your application?
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I am using BetterDialogs to show a dialog box.

On my Samsung S3 phone it is chopping off the sides but on my Samsung Tab-3 (7") it looks the way I want it to.

I can increase the border size (20dip) but then it has a lot of "white space" (See: Samsung Tab3 - Larger Border - I marked the white space with yellow rectangles)

This seems to be happening with ALL the screens I am using with BetterDialogs.

I feel like BetterDialogs is not using dip on all it's numbers??? Because this dialog should fit on the Samsung S3 in Portrait mode but as you can see by the Samsung S3 - Portrait image that it is being clipped?

Can you provide any help with this?

Thanks

BobVal


B4X:
    mPlayerScore_Dialog.CustomDialog(Null, 0dip, 0dip, PlayerScorePanel, sPlayerScore_Main.Width, sPlayerScore_Main.Height, 10dip, Colors.Transparent, Null, Null, Null, False, "")


Samsung S3 - Landscape.png Samsung S3 - Portrait.png Samsung Tab3 - Landscape.png Samsung Tab3 - Portrait.png Samsung Tab3 - Larger Border.png
 

Informatix

Expert
Licensed User
Longtime User
I am using BetterDialogs to show a dialog box.

On my Samsung S3 phone it is chopping off the sides but on my Samsung Tab-3 (7") it looks the way I want it to.

The exact width of the dialog window is not exactly the same on different devices and OS versions (it's not due to my code), so you have to set a margin to have no bad surprise.

PS: IMHO your dialog would look better with some white space around the radio selector.
 
Last edited:

RVP

Active Member
Licensed User
Longtime User
Did you set WithSuggestions to False?

Well I finally tried this( left it the other way as it was easier when testing) and the Suggestions line is still showing.

This is my code

B4X:
Dim BD As BetterDialogs
Dim PwI As Int
Dim IP As  BD_InputBoxParams
                IP.Initialize
                IP.Question = "<I>Password ? </I>"
                IP.QuestionTextSize = 18
                IP.SpaceBetween = 4dip
                IP.InputTextSize = 24
                IP.InputType = IP.INPUT_TYPE_TEXT
                IP.WithSuggestions = False
                IP.PasswordMode = True   
                IP.Gravity = Gravity.CENTER_VERTICAL + Gravity.CENTER_HORIZONTAL
                IP.ValidationCallback = ""
                PwI = BD.InputBox("Enter Password",IP,"OK","Cancel","",Null)
 

Informatix

Expert
Licensed User
Longtime User
Well I finally tried this( left it the other way as it was easier when testing) and the Suggestions line is still showing.

This is my code

B4X:
Dim BD As BetterDialogs
Dim PwI As Int
Dim IP As  BD_InputBoxParams
                IP.Initialize
                IP.Question = "<I>Password ? </I>"
                IP.QuestionTextSize = 18
                IP.SpaceBetween = 4dip
                IP.InputTextSize = 24
                IP.InputType = IP.INPUT_TYPE_TEXT
                IP.WithSuggestions = False
                IP.PasswordMode = True
                IP.Gravity = Gravity.CENTER_VERTICAL + Gravity.CENTER_HORIZONTAL
                IP.ValidationCallback = ""
                PwI = BD.InputBox("Enter Password",IP,"OK","Cancel","",Null)
I tried this code with different versions of Android, from 2.3.6 to 4.4.2, on real devices. None showed the suggestions and the input was hidden behind dots, as expected.
Example:
result.png
 

RVP

Active Member
Licensed User
Longtime User
I tried this code with different versions of Android, from 2.3.6 to 4.4.2, on real devices. None showed the suggestions and the input was hidden behind dots, as expected.
Example:
View attachment 26421

Well I definitely have suggestions showing, although the input is hidden. I am running this on a Samsung Note 3, and it's keyboard has a bunch more options for input, ie handwriting, voice. I wonder if maybe it is ignoring the option.
 

Informatix

Expert
Licensed User
Longtime User
Well I definitely have suggestions showing, although the input is hidden. I am running this on a Samsung Note 3, and it's keyboard has a bunch more options for input, ie handwriting, voice. I wonder if maybe it is ignoring the option.
Maybe. I cannot say. I didn't see any report on Internet by other users, but that would not surprise me on a Samsung device.
I suppose that you have this issue with my Masked EditText too.

EDIT: This morning I tried with a Samsung S4 and I was able to reproduce the problem. So it's due to changes made by Samsung. I'm looking for a fix.
 
Last edited:

deltacode

Member
Licensed User
Longtime User
Hi,

How can i change the size of the button and text size of the OK and CANCEL buttons on a customdialog ?
i have tried setting the size for the button without success

B4X:
Dim btnOK As Button
    btnOK.Initialize("")
    btnOK.Background = CreateStateListDrawableRed
    btnOK.Text = "<Font Color='Yellow' size='10'>O</Font>K"
    btnOK.TextSize = 10
    btnOK.TextColor = Colors.White

    'Custom list with radio buttons
    Dim pnlList As Panel
    pnlList.Initialize("")
    pnlList.LoadLayout("main")

    DR = BD.CustomDialog(pnlTitle, 100%x, 30dip, pnlList, 265dip, 220dip, 0, Colors.White, btnOK, "", Null, False, "dd")
 

Informatix

Expert
Licensed User
Longtime User
Hi,

How can i change the size of the button and text size of the OK and CANCEL buttons on a customdialog ?
i have tried setting the size for the button without success

B4X:
Dim btnOK As Button
    btnOK.Initialize("")
    btnOK.Background = CreateStateListDrawableRed
    btnOK.Text = "<Font Color='Yellow' size='10'>O</Font>K"
    btnOK.TextSize = 10
    btnOK.TextColor = Colors.White

    'Custom list with radio buttons
    Dim pnlList As Panel
    pnlList.Initialize("")
    pnlList.LoadLayout("main")

    DR = BD.CustomDialog(pnlTitle, 100%x, 30dip, pnlList, 265dip, 220dip, 0, Colors.White, btnOK, "", Null, False, "dd")
Put your buttons into the dialog layout and don't set the parameters of CustomDialog for the buttons.
 

deltacode

Member
Licensed User
Longtime User
Hi informatix,

Thanks for the quick reply.

If i have understood you correctly i have declared the button as:

B4X:
Dim btnOK As Button
btnOK.Initialize("")
btnOK.Text = "OK"
btnOK.TextColor = Colors.White

Now the button is still the same size without the coloring, i was hoping for it to be approx 30dip to match the title size..

Also why does this title not center horizontally correctly when i have defined the width of the label to be the same as the width as the dialog box:

B4X:
'Custom dialog
    Dim pnlTitle As Panel
    pnlTitle.Initialize("")
    pnlTitle.Color = Colors.Red

    Dim lblTitle As Label
    lbltitle.Initialize("")
    lblTitle.Color = Colors.Transparent
    lblTitle.Text = "Hello World"
    lblTitle.TextColor = Colors.White
    lblTitle.TextSize=14
    lblTitle.Gravity = Gravity.CENTER_VERTICAL + Gravity.CENTER_HORIZONTAL
    pnlTitle.AddView(lblTitle,0,0,265dip,30dip)

I need to decrease the label to be around 240dip instead for it to center.

All of this is being tested on a Nexus 5
 

Informatix

Expert
Licensed User
Longtime User
Hi informatix,

Thanks for the quick reply.

If i have understood you correctly i have declared the button as:

B4X:
Dim btnOK As Button
btnOK.Initialize("")
btnOK.Text = "OK"
btnOK.TextColor = Colors.White

Now the button is still the same size without the coloring, i was hoping for it to be approx 30dip to match the title size..

Also why does this title not center horizontally correctly when i have defined the width of the label to be the same as the width as the dialog box:

B4X:
'Custom dialog
    Dim pnlTitle As Panel
    pnlTitle.Initialize("")
    pnlTitle.Color = Colors.Red

    Dim lblTitle As Label
    lbltitle.Initialize("")
    lblTitle.Color = Colors.Transparent
    lblTitle.Text = "Hello World"
    lblTitle.TextColor = Colors.White
    lblTitle.TextSize=14
    lblTitle.Gravity = Gravity.CENTER_VERTICAL + Gravity.CENTER_HORIZONTAL
    pnlTitle.AddView(lblTitle,0,0,265dip,30dip)

I need to decrease the label to be around 240dip instead for it to center.

All of this is being tested on a Nexus 5
Put your OK button at the bottom of your layout. Don't use the PositiveButton parameter. This way, you can place it and size it exactly like you want.
To be sure to center your title properly, set the title width to -1 (this value means "Fill parent"). The reason is that the OS adds margins to dialogs (and that's why there's a Margin parameter).
 

deltacode

Member
Licensed User
Longtime User
Thanks Informatix,

If i just pass text in for the button it displays at the height i want but i loose my formatting, this is something i can live with for now.

For the title, i tried doing both 100%x and -1 for the size, yet it seemed to be picking up the layout size and not the size of the actual dialog box i defined.

This is also the reason i did not put a button my layout as again it would not center correctly.
 

ilan

Expert
Licensed User
Longtime User
very nice informatix

what i am missing is to load the inputbox with a text allready typed
i want to give the user the possibility to change/edit a text for a control and would like to put the text in the inputdialog inside so if he want to make a small correction he dont need to add all text again

like he typed: Work Nr10 instead of Work Nr1 so if i could start the inputbox with the text from the label the user dont need to enter everything again

is this possible? or its not icluded?


thank you very much for this lib

EDIT: got it, IP.Default = "text" :oops:
 
Last edited:
Top