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:

lomosami

Member
Licensed User
Longtime User
Very beautiful library. I have a question. When a dialog appear it can be close tapping outside the dialog. Is it possible to prevent this feature? I would like close the dialog only when pressing button on the dialog and not outside it.
Thanks
 

tchart

Well-Known Member
Licensed User
Longtime User
Will this work for custom dialogs?

trueboss323, the actual library does support custom dialogs but the B4A wrapper does not implement this. I have not had much time to work on the library and also my B4A version is not up to date.
 

trueboss323

Active Member
Licensed User
Longtime User
I tried using your library as a test sample and I wanted to display a simple message box. But I keep getting a android.content.res.Resources$NotFoundException: Resource ID #0x0 error. And my code looks like this:
B4X:
Dim MD As MD_BasicDialog
    MD.Initialize("MD")
    MD.Show("Test","test","ok","ok","",Null ,False,False)

So what is the correct way to use it?
 

tchart

Well-Known Member
Licensed User
Longtime User
I tried using your library as a test sample and I wanted to display a simple message box. But I keep getting a android.content.res.Resources$NotFoundException: Resource ID #0x0 error. And my code looks like this:
B4X:
Dim MD As MD_BasicDialog
    MD.Initialize("MD")
    MD.Show("Test","test","ok","ok","",Null ,False,False)

So what is the correct way to use it?

Have you included the additional resources?

B4X:
    #AdditionalRes: D:\Apps\B4A\AdditionalRes\afollestad_material-dialogs\core\res, com.afollestad.materialdialogs
    #AdditionalRes: D:\Apps\B4A\AdditionalRes\afollestad_material-dialogs\commons\res, com.afollestad.materialdialogs
    #AdditionalRes: D:\Apps\B4A\AdditionalRes\me.zhanghai.android.materialprogressbar\res, me.zhanghai.android.materialprogressbar   
    #AdditionalRes: D:\Apps\Android\android-sdk\extras\android\support\v7\appcompat\res, android.support.v7.appcompat   
    #Extends: android.support.v7.app.AppCompatActivity
 

trueboss323

Active Member
Licensed User
Longtime User
One thing, I'd like to use this library on older Android versions. And on Android versions 5+ it should let it use the native material dialog, is it possible?
 
Top