afollestad MaterialDialogs reborn

DonManfred

Expert
Licensed User
Longtime User
This is a wrap for this github project. It is a completely new written wrap and it is similar to this library written by @tchart

The advantage of this wrap is that you, the developer, now have much less work to implement the material dialogs into your app.

Additional this wrap is more up-to-date and includes CustomView too.

Requirements:
- B4A 6+
- You app must be setup for AppCompat

MaterialDialogs
Author:
DonManfred (wrapper)
Version: 1.13
  • MaterialDialog
    Events:
    • onAny (action As String)
    • onCancel ( As )
    • onDismiss ( As )
    • onInput (text As String)
    • onItemsCB (v As View, index As Int, text As String)
    • onKey (key As Int, event As String)
    • onNegative (action As String)
    • onNeutral (action As String)
    • onPositive (action As String)
    • onSelection (selected() As Integer, strings() As CharSequence)
    • onShow ( As )
    • onSingleChoiceSelect (v As View, index As Int, text As String)
    Methods:
    • Initialize (EventName As String)
    • IsInitialized As Boolean
    • adapter (adapter As ListAdapter, callback As ListCallback) As MaterialDialogBuilder
      Sets a custom {@link android.widget.ListAdapter} for the dialog's list
      adapter: The adapter to set to the list.
      callback: The callback invoked when an item in the list is selected.
      Return type: @return:This Builder object to allow for chaining of calls to set methods
    • alwaysCallInputCallback As MaterialDialogBuilder
    • alwaysCallMultiChoiceCallback As MaterialDialogBuilder
      By default, the multi choice callback is only called when the user clicks the positive button
      or if there are no buttons. Call this to force it to always call on item clicks even if the
      positive button exists.
      Return type: @return:The Builder instance so you can chain calls to it.
    • alwaysCallSingleChoiceCallback As MaterialDialogBuilder
      By default, the single choice callback is only called when the user clicks the positive button
      or if there are no buttons. Call this to force it to always call on item clicks even if the
      positive button exists.
      Return type: @return:The Builder instance so you can chain calls to it.
    • autoDismiss (dismiss As Boolean) As MaterialDialogBuilder
      This defaults to true. If set to false, the dialog will not automatically be dismissed
      when an action button is pressed, and not automatically dismissed when the user selects
      a list item.
      dismiss: Whether or not to dismiss the dialog automatically.
      Return type: @return:The Builder instance so you can chain calls to it.
    • backgroundColor (color As Int) As MaterialDialogBuilder
    • backgroundColorRes (colorRes As String) As MaterialDialogBuilder
    • btnSelector (selectorRes As String) As MaterialDialogBuilder
    • btnSelectorStacked (selectorRes As String) As MaterialDialogBuilder
    • btnStackedGravity (gravity As GravityEnum) As MaterialDialogBuilder
      Sets the gravity used for the text in stacked action buttons. By default, it's #{@link GravityEnum#END}.
      gravity: The gravity to use.
      Return type: @return:The Builder instance so calls can be chained.
    • build As MaterialDialog
    • buttonRippleColor (color As Int) As MaterialDialogBuilder
    • buttonRippleColorAttr (colorAttr As Int) As MaterialDialogBuilder
    • buttonRippleColorRes (colorRes As String) As MaterialDialogBuilder
    • buttonsGravity (gravity As GravityEnum) As MaterialDialogBuilder
    • cancelable (cancelable As Boolean) As MaterialDialogBuilder
    • canceledOnTouchOutside (canceledOnTouchOutside As Boolean) As MaterialDialogBuilder
    • content (content As CharSequence) As MaterialDialogBuilder
    • contentColor (color As Int) As MaterialDialogBuilder
    • contentColorAttr (colorAttr As Int) As MaterialDialogBuilder
    • contentColorRes (colorRes As String) As MaterialDialogBuilder
    • contentGravity (gravity As GravityEnum) As MaterialDialogBuilder
    • contentLineSpacing (multiplier As Float) As MaterialDialogBuilder
    • contentRes (contentRes As String) As MaterialDialogBuilder
    • customView (view As View, wrapInScrollView As Boolean) As MaterialDialogBuilder
    • dividerColor (color As Int) As MaterialDialogBuilder
    • dividerColorRes (colorRes As String) As MaterialDialogBuilder
    • forceStacking (stacked As Boolean) As MaterialDialogBuilder
    • icon (icon As Drawable) As MaterialDialogBuilder
    • iconAttr (iconAttr As Int) As MaterialDialogBuilder
    • iconRes (icon As String) As MaterialDialogBuilder
    • input (hint As CharSequence, prefill As CharSequence) As MaterialDialogBuilder
    • input2 (hint As CharSequence, prefill As CharSequence, allowEmptyInput As Boolean) As MaterialDialogBuilder
    • inputMaxLength (maxLength As Int) As MaterialDialogBuilder
    • inputMaxLengthRes (maxLength As Int, errorColor As String) As MaterialDialogBuilder
    • inputRange (minLength As Int, maxLength As Int) As MaterialDialogBuilder
    • inputRangeRes (minLength As Int, maxLength As Int, errorColor As String) As MaterialDialogBuilder
      Same as #{@link #inputRange(int, int, int)}, but it takes a color resource ID for the error color.
    • inputType (type As Int) As MaterialDialogBuilder
    • itemColor (color As Int) As MaterialDialogBuilder
      Renamed to {@link #itemsColor(int)} for consistency.
    • itemColorAttr (colorAttr As Int) As MaterialDialogBuilder
      Renamed to {@link #itemsColorAttr(int)} for consistency.
    • itemColorRes (colorRes As String) As MaterialDialogBuilder
      Renamed to {@link #itemsColorRes(int)} for consistency.
    • items (collection() As String) As MaterialDialogBuilder
    • itemsCallback As MaterialDialogBuilder
    • itemsCallbackMultiChoice (selectedIndices() As Integer) As MaterialDialogBuilder
      Pass null for the selected indices to leave all options unselected initially. Otherwise pass
      an array of indices that will be selected initially.
      selectedIndices: The radio button indices that will be selected initially.
      callback: The callback that will be called when the presses the positive button.
      Return type: @return:The Builder instance so you can chain calls to it.
    • itemsCallbackSingleChoice (selectedIndex As Int) As MaterialDialogBuilder
      Pass anything below 0 (such as -1) for the selected index to leave all options unselected initially.
      Otherwise pass the index of an item that will be selected initially.
      selectedIndex: The checkbox index that will be selected initially.
      callback: The callback that will be called when the presses the positive button.
      Return type: @return:The Builder instance so you can chain calls to it.
    • itemsColor (color As Int) As MaterialDialogBuilder
    • itemsColorAttr (colorAttr As Int) As MaterialDialogBuilder
    • itemsColorRes (colorRes As String) As MaterialDialogBuilder
    • itemsGravity (gravity As GravityEnum) As MaterialDialogBuilder
    • itemsIds (idsArray() As Int) As MaterialDialogBuilder
    • itemsRes (itemsRes As String) As MaterialDialogBuilder
    • limitIconToDefaultSize As MaterialDialogBuilder
      Limits the display size of a set icon to 48dp.
    • linkColor (color As Int) As MaterialDialogBuilder
    • linkColor2 (colorStateList As ColorStateList) As MaterialDialogBuilder
    • listSelector (selectorRes As String) As MaterialDialogBuilder
    • maxIconSize (maxIconSize As Int) As MaterialDialogBuilder
    • negativeColor (color As Int) As MaterialDialogBuilder
    • negativeColorRes (colorRes As String) As MaterialDialogBuilder
    • negativeText (message As CharSequence) As MaterialDialogBuilder
    • negativeTextRes (negativeRes As String) As MaterialDialogBuilder
    • neutralColor (color As Int) As MaterialDialogBuilder
    • neutralColor2 (colorStateList As ColorStateList) As MaterialDialogBuilder
    • neutralColorRes (colorRes As String) As MaterialDialogBuilder
    • neutralText (message As CharSequence) As MaterialDialogBuilder
    • neutralTextRes (neutralRes As String) As MaterialDialogBuilder
    • positiveColor (color As Int) As MaterialDialogBuilder
    • positiveColor2 (colorStateList As ColorStateList) As MaterialDialogBuilder
    • positiveText (message As CharSequence) As MaterialDialogBuilder
    • positiveTextRes (positiveRes As String) As MaterialDialogBuilder
    • progress (indeterminate As Boolean, max As Int) As MaterialDialogBuilder
      Makes this dialog a progress dialog.
      indeterminate: If true, an infinite circular spinner is shown. If false, a horizontal progress bar is shown that is incremented or set via the built MaterialDialog instance.
      max: When indeterminate is false, the max value the horizontal progress bar can get to.
      Return type: @return:An instance of the Builder so calls can be chained.
    • progress2 (indeterminate As Boolean, max As Int, showMinMax As Boolean) As MaterialDialogBuilder
      Makes this dialog a progress dialog.
      indeterminate: If true, an infinite circular spinner is shown. If false, a horizontal progress bar is shown that is incremented or set via the built MaterialDialog instance.
      max: When indeterminate is false, the max value the horizontal progress bar can get to.
      showMinMax: For determinate dialogs, the min and max will be displayed to the left (start) of the progress bar, e.g. 50/100.
      Return type: @return:An instance of the Builder so calls can be chained.
    • progressIndeterminateStyle (horizontal As Boolean) As MaterialDialogBuilder
      By default, indeterminate progress dialogs will use a circular indicator. You
      can change it to use a horizontal progress indicator.
    • progressNumberFormat (format As String) As MaterialDialogBuilder
      hange the format of the small text showing current and maximum units of progress.
      The default is "%1d/%2d".
    • progressPercentFormat (format As NumberFormat) As MaterialDialogBuilder
      Change the format of the small text showing the percentage of progress.
      The default is NumberFormat.getPercentageInstance().
    • show As MaterialDialog
    • theme (theme As Theme) As MaterialDialogBuilder
    • title (title As CharSequence) As MaterialDialogBuilder
    • titleColor (color As Int) As MaterialDialogBuilder
    • titleColorAttr (colorAttr As Int) As MaterialDialogBuilder
    • titleColorRes (colorRes As String) As MaterialDialogBuilder
    • titleGravity (gravity As GravityEnum) As MaterialDialogBuilder
    • typeface (medium As Typeface, regular As Typeface) As MaterialDialogBuilder
      Sets the fonts used in the dialog. It's recommended that you use {@link #typeface(String, String)} instead,
      to avoid duplicate Typeface allocations and high memory usage.
      medium: The font used on titles and action buttons. Null uses device default.
      regular: The font used everywhere else, like on the content and list items. Null uses device default.
      Return type: @return:The Builder instance so you can chain calls to it.
    • typefacebyString (medium As String, regular As String) As MaterialDialogBuilder
      Sets the fonts used in the dialog, by file names. This also uses TypefaceHelper in order
      to avoid any un-needed allocations (it recycles typefaces for you).
      medium: The name of font in assets/fonts used on titles and action buttons (null uses device default). E.g. [your-project]/app/main/assets/fonts/[medium]
      regular: The name of font in assets/fonts used everywhere else, like content and list items (null uses device default). E.g. [your-project]/app/main/assets/fonts/[regular]
      Return type: @return:The Builder instance so you can chain calls to it.
    • widgetColor (color As Int) As MaterialDialogBuilder
    • widgetColorRes (colorRes As String) As MaterialDialogBuilder

As there is not much to say there is no example.

But basically the use of this lib is

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim dialog As MaterialDialog
End sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    dialog.Initialize("Dialog")
End Sub
Sub Button_Click
    Log("Button_Click")
    dialog.positiveText("Cool!").negativeText("Oh nooo").neutralText("I dont care").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).title("DonManfred presents").content("afollestad´s MaterialDialogs").iconRes("donmanfred").dividerColor(Colors.Cyan).autoDismiss(False).buttonRippleColor(Colors.Gray).show
End Sub

Install:
- Copy the lib files to your additional libraries folder
- Copy the content of MaterialDialogsRES.zip to your projects root folder so that the folder are at the same place as the files folder of your project.
- Add these lines to your project
B4X:
#AdditionalRes: ..\res.core
#AdditionalRes: ..\res.MaterialProgressBar

Note that you should start with Initialization on each to setup the defaults...

Some Examples:
B4X:
    If dialog.isShowing Then
        dialog.hide
    End If
    Dim items(3) As String
    items(0) = "Hallo"
    items(1) = "B4X"
    items(2) = "World!"
    dialog.Initialize("Dialog")
    dialog.tag = CreateMap("action":"MultiSelect")
  
    dialog.positiveText("Yo").negativeText("Oh nooo").neutralText("I dont care").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).content("test").contentLineSpacing(1).items(Array As String("Apple ", "Orange", "Grapes","Pineapple","Mango" )).itemColor(Colors.Blue).itemsCallbackMultiChoice(Array As Int(1,2)).alwaysCallMultiChoiceCallback.build.show

SingleSelect:
B4X:
    If dialog.isShowing Then
        dialog.hide
    End If
    dialog.Initialize("Dialog")
    dialog.tag = CreateMap("action":"SingleSelect")
    dialog.content("Test 5").items(Array As String("Apple ", "Orange", "Grapes","Pineapple","Mango" )).itemColor(Colors.Yellow).negativeText("Oh nooo").positiveText("OK").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).itemsCallbackSingleChoice(1).build.show

Using the "Items" as Content:
B4X:
    If dialog.isShowing Then
        dialog.hide
    End If
    dialog.Initialize("Dialog")
    dialog.tag = CreateMap("action":"SingleSelect")
    dialog.content("Test 5").items(Array As String("1. Do this", "2. and this", "3. yo, this too","4. one again","Last but not least" )).itemColor(Colors.Yellow).negativeText("Oh nooo").positiveText("OK").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).title("Hallo B4X-World :-)").titleGravity(2).itemsGravity(2).build.show


Different Gravity for title and content
B4X:
    If dialog.isShowing Then
        dialog.hide
    End If
    dialog.Initialize("Dialog")
    dialog.tag = CreateMap("action":"SingleSelect")
    dialog.content("Test 5").items(Array As String("1. Do this", "2. and this", "3. yo, this too","4. one again","Last but not least" )).itemColor(Colors.Yellow).negativeText("Oh nooo").positiveText("OK").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).title("Hallo B4X-World :-)")).titleGravity(2).contentGravity(0).itemsGravity(1).build.show
 

Attachments

  • MaterialDialogsEx.zip
    8.9 KB · Views: 675
  • MaterialDialogsRES.zip
    29.9 KB · Views: 671
  • MaterialDialogsV1.13.zip
    197.9 KB · Views: 814
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Oppss.... I had missed :confused:
Anyway, you're always the FIRST ( 1° ) to have made of the libs for B4A 6.X :D
 

JNG

Member
Licensed User
Hi
I am getting this error Pl. suggest

B4A version: 6.00 BETA #1
Parsing code. (0.00s)
Compiling code. (0.12s)
Compiling layouts code. (0.00s)
Generating R file. Error
invalid resource directory name: D:\DownLoad 26thMay2016-onward\materialDialog\Objects\bin\extra\res2\res/drawable-anydpi-v21


regards
jng
 

tchart

Well-Known Member
Licensed User
Longtime User
Nice job DonManfred. Things will be so much easier with B4A 6 supporting Maven/AAR.
 

tchart

Well-Known Member
Licensed User
Longtime User
DonManfred are you going to implement the file/folder dialogs and also the colour picker? I was planning on adding those next but your implementation is much nicer.
 

JNG

Member
Licensed User
But I am getting similar error May be unable to detect pl. let me know where I am wrong.
B4A version: 6.00 BETA #1
Parsing code. (0.00s)
Compiling code. (0.04s)
Compiling layouts code. (0.00s)
Generating R file. Error
invalid resource directory name: D:\DownLoad26thMay2016onward\materialDialog\Objects\bin\extra\res2\res/drawable-anydpi-v21


B4X:
#Region  Project Attributes
    #ApplicationLabel: materialDialog
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalRes : ..\resource
    #AdditionalRes: C:\libres\b4a_appcompat, de.amberhome.objects.appcompat
    #AdditionalRes: C:\Android\sdk\extras\android\support\v7\appcompat\res, android.support.v7.appcompat   
   
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
    #Extends: android.support.v7.app.ActionBarActivity
#End Region


Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim dialog As MaterialDialog
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    dialog.Initialize("Dialog")
End Sub
Sub Button_Click
    Log("Button_Click")
    dialog.positiveText("Cool!").negativeText("Oh nooo").neutralText("I dont care").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).title("DonManfred presents").content("afollestad´s MaterialDialogs").iconRes("donmanfred").dividerColor(Colors.Cyan).autoDismiss(False).buttonRippleColor(Colors.Gray).show
End Sub
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub



Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Regards
Jng
 

DonManfred

Expert
Licensed User
Longtime User
DonManfred are you going to implement the file/folder dialogs and also the colour picker?
is there a file and color picker dialog too in this library? I didn´t saw any other object than the dialog itself while writing the wrap
 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
is there a file and color picker dialog too in this library? I didn´t saw any other object than the dialog itself while writing the wrap

Yes there are a couple of utility dialogs. Download the afollestad sample app off the app store to see them all.

Look under the commons part of the library there is a file selector, folder selector, colour picker and preference dialog.
 

DonManfred

Expert
Licensed User
Longtime User
DonManfred are you going to implement the file/folder dialogs and also the colour picker?
they are in my most recent version inplemented but i did not get it to run as (talking about colorpicker) it depends on android.support.v7.app.AppCompatActivity.getSupportFragmentManager()

I never got a library working which depends on a SupportFragmentManager()
It is not the same as the fragmentmanager used in googlemaps library...

As long as there no one writes a wrapper for SupportFragmentManager() it will not work.

I for myself tried it hundred times. And failed hundred times :-(

So; if i encounter to see a getSupportFragmentManager() in the library i want to wrap i´m 100% dure i can stop developing as i dont get it to work. :-(
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Unfortunately, I'm getting the invalid resource directory name as well (and I don't have spaces inside the directory names).

B4X:
invalid resource directory name: C:\myprojects\newproject\Objects\bin\extra\res2\res/drawable-anydpi-v21
 

wimpie3

Well-Known Member
Licensed User
Longtime User
I managed to get the library working, however, using a customView still causes a crash:

B4X:
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/RecyclerView;
    at com.afollestad.materialdialogs.internal.MDRootLayout.setUpDividersVisibility(MDRootLayout.java:424)
    at com.afollestad.materialdialogs.internal.MDRootLayout.onLayout(MDRootLayout.java:343)
    at android.view.View.layout(View.java:15715)
    at android.view.ViewGroup.layout(ViewGroup.java:5046)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
    at android.view.View.layout(View.java:15715)
    at android.view.ViewGroup.layout(ViewGroup.java:5046)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
    at android.view.View.layout(View.java:15715)
    at android.view.ViewGroup.layout(ViewGroup.java:5046)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
    at android.view.View.layout(View.java:15715)
    at android.view.ViewGroup.layout(ViewGroup.java:5046)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2097)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1069)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5915)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
    at android.view.Choreographer.doCallbacks(Choreographer.java:580)
    at android.view.Choreographer.doFrame(Choreographer.java:550)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:139)
    at android.app.ActivityThread.main(ActivityThread.java:5298)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/de.amberhome.appcompat.basicexample-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 33 more
    Suppressed: java.lang.ClassNotFoundException: android.support.v7.widget.RecyclerView
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 34 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
 

wimpie3

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Button1_Click
    Dim p As Panel
    p.Initialize("")
    p.Color=Colors.red
    dialog.Initialize("Dialog")
    dialog.positiveText("Cool!")
    dialog.negativeText("Oh nooo")
    dialog.neutralText("I dont care")
    dialog.positiveColor(Colors.Green)
    dialog.neutralColor(Colors.Magenta)
    dialog.negativeColor(Colors.Red)
    dialog.title("DonManfred presents")
    dialog.dividerColor(Colors.Cyan)
    dialog.autoDismiss(False)
    dialog.buttonRippleColor(Colors.Gray)
    dialog.customView(p,False)
    dialog.show
End Sub
 
Top