B4A Library afollestad material-dialogs

Firstly, this is a work in progress but I thought I would share to get some feedback from the B4A community. Not all dialogs types are implemented yet.

This is a B4A wrapper library of Aidan Follestads Material Dialogs library on GitHub

mdshowcase.png


His library supports material style dialogs all the way back to API level 8. If you would like to see examples of the library Aidan has an app on the Play Store (well worth downloading). The library is updated frequently.

Secondly this is similar to thedesolatesoul's MSMaterialDialogs library. He has provided great advice on the road to getting this library working. So thanks thedesolatesoul!

Thirdly, as with thedesolatesoul's MSMaterialDialogs library these dialogs are not modal and use callbacks (see the example project).

To get this running you need;

1) The wrapper library (download from here)
2) android-support-v4.jar (must be version 22.1 or later, use Android SDK-Manager to update your copy)
3) android-support-v7-appcompat.jar
4) android-support-v7-recyclerview.jar
5) The android.support.v7.appcompat additional resources
6) The afollestad_material-dialogs additional resources
7) All additional libraries must be in your B4A additional libraries folder
8) See note 1 below regarding dialog text colours (and themes).
9) Make sure that you reference a android.jar with platform version 21 or above in the IDE under the "Tools/Configure Paths" menu. (Thanks to corwin42)

Please refer to the sample project to see where to place the additional resources. The sample project uses a menu to initiate the dialogs.

NOTE 1: When using the library in your own app the dialog colours may not be the correct "Material" colours. The example app defines the correct colours via a theme under ..\MDTest\Objects\res\values\theme.xml (this file must be made read only otherwise it will be overwritten). Read this forum post for more info on themes.
NOTE 2: Please, please, please make sure you have version 22.1 or later of the support libraries and that the 3 libraries are copied to your additional libraries folder for B4A.

B4X:
<resources>
    <!-- http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">#3F51B5</item>
        <item name="colorPrimaryDark">#3949AB</item>
        <item name="colorAccent">#E91E63</item>
    </style>
</resources>

Whats New?

06/05/2015
  • Updated to 0.7.3.1 of afollestad material-dialogs library
  • Split out dialogs into seperate objects (all have MD_ prefix)
  • Added/tidied up documentation (including events)
  • Included progress dialogs and folder selection dialog
15/05/2015
  • Updated to 0.7.4.1 of afollestad material-dialogs library

Documentation

MaterialDialogs
Comment:
This is a B4A wrapper library of Aidan Follestads Material Dialogs library on GitHub

MD_BasicDialog is a basic dialog
MD_InputDialog is an input dialog
MD_ListDialog is a list dialog showing items
MD_MultiChoiceDialog is a choice dialog showing items and allowing multiple selections
MD_SingleChoiceDialog is a choice dialog showing items and allowing a single selections
MD_FolderSelectorDialog is a folder selection dialog
MD_ProgressDialog is a progress dialog

Author: Trevor Hart
Version: 0.731
  • MD_BasicDialog
    Events:
    • ButtonPress (Result As Int)
    • Cancel
    • Dismiss
    • Show
    Methods:
    • Initialize (EventName As String)
    • Show (title As String, content As String, positiveText As String, negativeText As String, neutralText As String, icon As Bitmap, limitIconToDefaultSize As Boolean, forceStacking As Boolean)
    Permissions:
    • android.permission.READ_EXTERNAL_STORAGE
  • MD_FolderSelectorDialog
    Events:
    • ButtonPress (Result As Int)
    • Cancel
    • Dismiss
    • FolderSelection (Result As String)
    • Show
    Methods:
    • Initialize (EventName As String)
    • Show (InitialFolder As String)
  • MD_InputDialog
    Events:
    • ButtonPress (Result As Int)
    • Cancel
    • Dismiss
    • Input (Result As String)
    • Show
    Methods:
    • Initialize (EventName As String)
    • Show (title As String, content As String, hint As String, prefill As String, allowEmptyInput As Boolean, inputMaxLength As Int, positiveText As String, negativeText As String, neutralText As String, icon As Bitmap, limitIconToDefaultSize As Boolean, forceStacking As Boolean)
  • MD_ListDialog
    Events:
    • ButtonPress (Result As Int)
    • Cancel
    • Dismiss
    • ItemSelected (Index As Int, Text As String)
    • Show
    Methods:
    • Initialize (EventName As String)
    • Show (title As String, items As List, positiveText As String, negativeText As String)
  • MD_MultiChoiceDialog
    Events:
    • ButtonPress (Result As Int)
    • Cancel
    • Dismiss
    • MultiChoice (Result As Map)
    • Show
    Methods:
    • Initialize (EventName As String)
    • Show (title As String, items As Map, positiveText As String, negativeText As String)
  • MD_ProgressDialog
    Events:
    • ButtonPress (Result As Int)
    • Cancel
    • Dismiss
    • Show
    Methods:
    • CurrentProgress As Int
    • Dismiss
    • IncrementProgress (Increment As Int)
    • Initialize (EventName As String)
    • Show (title As String, content As String, negativeText As String, Indeterminate As Boolean, Max As Int, showMinMax As Boolean)
  • MD_SingleChoiceDialog
    Events:
    • ButtonPress (Result As Int)
    • Cancel
    • Dismiss
    • Show
    • SingleChoice (Index As Int, Text As String)
    Methods:
    • Initialize (EventName As String)
    • Show (title As String, items As List, selectedIndex As Int, positiveText As String, negativeText As String)
 
Last edited:

Ian Garton

Member
Licensed User
Longtime User
Thanks for this great work. Have you any plans to implement support for custom views?
Also wondering if/how the existing input dialog can be used for password entry?
 

mshafiee110

Active Member
Licensed User
Longtime User
@tchart
Thanks a lot,for this lib.
:)
Please add another view (color picker,custom view,... )of material-dialog to your lib.tnx
 
Last edited:

Scantech

Well-Known Member
Licensed User
Longtime User
Hey, thanks for this nice library. It appears to be non modal just what I am looking for. However, can we make an option to pass the value to a variable like this

B4X:
dim Ret as string
Ret = ld1.Show("Social Networks",items,"","Cancel")

or

Ret = ld1.ValueSelected
Index or String value passed to Ret will be helpful. I prefer index for my situation.

I am trying to replace all of my inputlist and dialogs with this wonderful library, but using the event procedure can complicate things in my source. I will donate if you can add this option.
 

joneden

Active Member
Licensed User
Longtime User
Hi Trevor,

This lib looks great, thank you.

I am seeing some odd colours but haven't played with the themeing yet so hope a couple of tweaks will have it matching my theme, first job tomorrow morning.

Couple of questions for you.
1) I see on the github that Aidan has his version up to 0.8.5.0 now and that that includes things like custom dialogs. Are you going to update the lib to atch his one at somepoint? If not any chance of postinng the source of it so far so that i can have a try at getting it working?
2) Has anyone managed to get a decent date dialog and time dialog working based off this lib? The original dialog lib fails to work properly with material colours and there doesn't appear to be any other decent material date or time dialog libs. I have seen a few on github but haven't tried making a wrapper from scratch yet!

Cheers

Jon
 

BarryW

Active Member
Licensed User
Longtime User
This lib is very nice...

Is it possible to do custom dialog with this library?

Tnx...
 

tchart

Well-Known Member
Licensed User
Longtime User
No not yet. The latest version has a dependency on another library so I am unable to compile it at the moment.
 

bermooda

Member
Licensed User
Longtime User
thank you for your great job.
i have a strange problem with input dialog. in your sample project input dialog is ok but in my own project it shows input dialog without edit text field and i have no clue why?!
there is no error message and i use sdk and support lib 23.
also i have not problem with other dialogs.
can you suggest any fix?
 

BarryW

Active Member
Licensed User
Longtime User
how to set the progressdialog as cancellable touch outside... Tnx
 

Prosg

Active Member
Licensed User
Longtime User
thank you for your great job.
i have a strange problem with input dialog. in your sample project input dialog is ok but in my own project it shows input dialog without edit text field and i have no clue why?!
there is no error message and i use sdk and support lib 23.
also i have not problem with other dialogs.
can you suggest any fix?

Hello i had the same problem that you describe and i fix it this way :

In reality their is not bug... it's only if the event is not on the activity it's bugging

Example :
I had this to my activity

B4X:
sd1.Initialize("sd1")

    Dim items As List
    items.Initialize
    items.Add("Twitter")
    items.Add("Google+")
    items.Add("Instagram")
    items.Add("Facebook")

    sd1.Show("Social Networks",items,-1,"OK","Cancel")

It's bugging their is no radiobutton in the dialogs

if i add the event of the activity it's working
B4X:
Sub....
sd1.Initialize("sd1")

    Dim items As List
    items.Initialize
    items.Add("Twitter")
    items.Add("Google+")
    items.Add("Instagram")
    items.Add("Facebook")

    sd1.Show("Social Networks",items,-1,"OK","Cancel")

End sub


Sub sd1_SingleChoice(Index As Int,Text As String)
    ToastMessageShow(Index & " : " & Text,False)
End Sub


Hope your understand my explanation

Regards
 

bermooda

Member
Licensed User
Longtime User
Hello i had the same problem that you describe and i fix it this way :

In reality their is not bug... it's only if the event is not on the activity it's bugging

Example :
I had this to my activity

B4X:
sd1.Initialize("sd1")

    Dim items As List
    items.Initialize
    items.Add("Twitter")
    items.Add("Google+")
    items.Add("Instagram")
    items.Add("Facebook")

    sd1.Show("Social Networks",items,-1,"OK","Cancel")

It's bugging their is no radiobutton in the dialogs

if i add the event of the activity it's working
B4X:
Sub....
sd1.Initialize("sd1")

    Dim items As List
    items.Initialize
    items.Add("Twitter")
    items.Add("Google+")
    items.Add("Instagram")
    items.Add("Facebook")

    sd1.Show("Social Networks",items,-1,"OK","Cancel")

End sub


Sub sd1_SingleChoice(Index As Int,Text As String)
    ToastMessageShow(Index & " : " & Text,False)
End Sub


Hope your understand my explanation

Regards

Thank you for answering my question.
i have tried this but there was no difference on the result. i think this occurs when i have multiple dialogs of same type (Ex. 2 inputDialog) and separate event handler for each one of them. because if i use just one input dialog in my app every thing works fine.
 

tchart

Well-Known Member
Licensed User
Longtime User
I have compiled the latest version but have not yet tested it or wrapped any of the new features. Hopefully I will get time to do that soon.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Thanks, this does indeed resolve the problem. However, now I get this:
B4X:
java.lang.NoClassDefFoundError: android.support.graphics.drawable.VectorDrawableCompat
I've noticed this is (also!) a known bug, referenced here: https://github.com/afollestad/material-dialogs/issues/1013

However, the original library has not been updated yet, so I'm afraid there is not much you can do at the moment. A fix is listed in the issue details but is not yet checked in on github.
 

tchart

Well-Known Member
Licensed User
Longtime User
Ok thanks for letting me know. I'll keep an eye out for the next update.
 
Top