Browse Source

Release 0.6.3.0. Too much stuff to list here. See the release page when it's there. Also updated the art.

Aidan Follestad 10 years ago
parent
commit
72b4219b4e

+ 54 - 2
README.md

@@ -64,10 +64,10 @@ If the content is long enough, it will become scrollable and a divider will be d
 
 ### Migration from AlertDialogs
 
-If you're migrating old dialogs you could use ```MaterialDialogCompat```. You need change imports and replace ```AlertDialog.Builder``` with ```MaterialDialogCompat.Builder```:
+If you're migrating old dialogs you could use ```AlertDialogWrapper```. You need change imports and replace ```AlertDialog.Builder``` with ```AlertDialogWrapper.Builder```:
 
 ```java
-MaterialDialogCompat.Builder dialogBuilder = new MaterialDialogCompat.Builder(context);
+AlertDialogWrapper.Builder dialogBuilder = new AlertDialogWrapper.Builder(context);
 dialogBuilder.setMessage(messageId);
 dialogBuilder.setTitle(titleId);
 dialogBuilder.setNegativeButton(R.string.OK, new DialogInterface.OnClickListener() {
@@ -507,6 +507,58 @@ new MaterialDialog.Builder(this)
 
 ---
 
+### Progress Dialogs
+
+This library allows you to display progress dialogs with Material design that even use your app's
+accent color to color the progress bars (if you use AppCompat to theme your app, or the Material theme on Lollipop).
+
+###### Indeterminate Progress Dialogs
+
+This will display the classic progress dialog with a spinning circle, see the sample project to see it in action:
+
+```java
+new MaterialDialog.Builder(this)
+    .title(R.string.progress_dialog)
+    .content(R.string.please_wait)
+    .progress(true, 0)
+    .show();
+```
+
+###### Seeker Progress Dialogs
+
+If a dialog is not indeterminate, it displays a horizontal progress bar that increases up until a max value.
+The comments in the code explain what this does.
+
+```java
+// Create and show a non-indeterminate dialog with a max value of 150
+MaterialDialog dialog = new MaterialDialog.Builder(this)
+    .title(R.string.progress_dialog)
+    .content(R.string.please_wait)
+    .progress(false, 150)
+    .show();
+
+// Loop until the dialog's progress value reaches the max (150)
+while (dialog.getCurrentProgress() != dialog.getMaxProgress()) {
+    // If the progress dialog is cancelled (the user closes it before it's done), break the loop
+    if (dialog.isCancelled()) break;
+    // Wait 50 milliseconds to simulate doing work that requires progress
+    try {
+        Thread.sleep(50);
+    } catch (InterruptedException e) {
+        break;
+    }
+    // Increment the dialog's progress by 1 after sleeping for 50ms
+    dialog.incrementProgress(1);
+}
+
+// When the loop exits, set the dialog content to a string that equals "Done"
+dialog.setContent(getString(R.string.done));
+```
+
+See the sample project for this dialog in action, with the addition of threading.
+
+---
+
 ### Preference Dialogs
 
 Android's `EditTextPreference` and `ListPreference` allow you to associate a preference activity's settings

BIN
art/screenshots.png


+ 2 - 2
library/build.gradle

@@ -9,7 +9,7 @@ android {
         minSdkVersion 8
         targetSdkVersion 21
         versionCode 1
-        versionName "0.6.2.4"
+        versionName "0.6.3.0"
     }
     lintOptions {
         abortOnError false
@@ -27,7 +27,7 @@ publish {
     userOrg = 'drummer-aidan'
     groupId = 'com.afollestad'
     artifactId = 'material-dialogs'
-    version = '0.6.2.4'
+    version = '0.6.3.0'
     description = 'A library for implementing Material design styled dialogs across all versions of Android.'
     website = 'https://github.com/afollestad/material-dialogs'
     issueTracker = "${website}/issues"

+ 3 - 1
library/src/main/java/com/afollestad/materialdialogs/MaterialDialogCompat.java → library/src/main/java/com/afollestad/materialdialogs/AlertDialogWrapper.java

@@ -13,6 +13,8 @@ import android.support.annotation.StringRes;
 import android.view.View;
 import android.widget.ListAdapter;
 
+import com.afollestad.materialdialogs.MaterialDialog;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -20,7 +22,7 @@ import java.util.List;
 /**
  * Convenience class for migrating old dialogs code. Not all methods are implemented yet. Using MaterialDialog.Builder directly is recommended.
  */
-public class MaterialDialogCompat {
+public class AlertDialogWrapper {
 
     public static class Builder {
 

+ 83 - 7
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -40,6 +40,7 @@ import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.ListAdapter;
 import android.widget.ListView;
+import android.widget.ProgressBar;
 import android.widget.RadioButton;
 import android.widget.RelativeLayout;
 import android.widget.ScrollView;
@@ -66,6 +67,9 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
     protected TextView title;
     protected View titleFrame;
     protected FrameLayout customViewFrame;
+    protected ProgressBar mProgress;
+    protected TextView mProgressLabel;
+    protected TextView content;
 
     protected View positiveButton;
     protected View neutralButton;
@@ -101,7 +105,8 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
                 mBuilder.regularFont = TypefaceHelper.get(getContext(), "Roboto-Regular");
         }
 
-        this.view = LayoutInflater.from(getContext()).inflate(R.layout.md_dialog, null);
+        final LayoutInflater inflater = LayoutInflater.from(mBuilder.context);
+        this.view = inflater.inflate(R.layout.md_dialog, null);
         this.setCancelable(builder.cancelable);
 
         if (mBuilder.backgroundColor == 0)
@@ -116,7 +121,27 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         title = (TextView) view.findViewById(R.id.title);
         icon = (ImageView) view.findViewById(R.id.icon);
         titleFrame = view.findViewById(R.id.titleFrame);
-        final TextView content = (TextView) view.findViewById(R.id.content);
+        content = (TextView) view.findViewById(R.id.content);
+
+        if (mBuilder.mIndeterminateProgress || mBuilder.mProgress > -2) {
+            mBuilder.customView = inflater.inflate(mBuilder.mIndeterminateProgress ? R.layout.md_progress_dialog_indeterminate
+                    : R.layout.md_progress_dialog, (ViewGroup) this.view, false);
+            mProgress = (ProgressBar) mBuilder.customView.findViewById(android.R.id.progress);
+            content = (TextView) mBuilder.customView.findViewById(android.R.id.message);
+            if (!mBuilder.mIndeterminateProgress) {
+                mProgress.setProgress(0);
+                mProgress.setMax(mBuilder.mProgressMax);
+                mProgressLabel = (TextView) mBuilder.customView.findViewById(R.id.label);
+                mProgressLabel.setText("0%");
+            }
+            int bottomPadding = (int) getContext().getResources().getDimension(R.dimen.md_dialog_frame_margin);
+            int topPadding = builder.title == null ? bottomPadding
+                    : (int) getContext().getResources().getDimension(R.dimen.md_progressdialog_paddingwithtitle);
+            mBuilder.customView.setPadding(mBuilder.customView.getPaddingLeft(),
+                    topPadding,
+                    mBuilder.customView.getPaddingRight(),
+                    bottomPadding);
+        }
 
         content.setText(builder.content);
         content.setMovementMethod(new LinkMovementMethod());
@@ -232,7 +257,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             }
         }
 
-        if (builder.title == null || builder.title.toString().trim().length() == 0) {
+        if (builder.title == null) {
             titleFrame.setVisibility(View.GONE);
         } else {
             title.setText(builder.title);
@@ -358,7 +383,6 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             return;
         }
         View contentScrollView = view.findViewById(R.id.contentScrollView);
-        TextView content = (TextView) view.findViewById(R.id.content);
         final int contentHorizontalPadding = (int) mBuilder.context.getResources()
                 .getDimension(R.dimen.md_dialog_frame_margin);
         content.setPadding(contentHorizontalPadding, 0, contentHorizontalPadding, 0);
@@ -608,7 +632,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
      */
     private boolean canContentScroll() {
         final ScrollView scrollView = (ScrollView) view.findViewById(R.id.contentScrollView);
-        final int childHeight = view.findViewById(R.id.content).getMeasuredHeight();
+        final int childHeight = content.getMeasuredHeight();
         return scrollView.getMeasuredHeight() < childHeight;
     }
 
@@ -914,6 +938,9 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         protected int dividerColor;
         protected int backgroundColor;
         protected int itemColor;
+        protected boolean mIndeterminateProgress;
+        protected int mProgress = -2;
+        protected int mProgressMax = 0;
 
         // Since 0 is black and -1 is white, no default value is good for indicating if a color was set.
         // So this is a decent solution to this problem.
@@ -1300,6 +1327,25 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             return this;
         }
 
+        /**
+         * Makes this dialog a progress dialog.
+         *
+         * @param 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.
+         * @param max           When indeterminate is false, the max value the horizontal progress bar can get to.
+         * @return An instance of the Builder so calls can be chained.
+         */
+        public Builder progress(boolean indeterminate, int max) {
+            if (indeterminate) {
+                this.mIndeterminateProgress = true;
+                this.mProgress = -2;
+            } else {
+                this.mIndeterminateProgress = false;
+                this.mProgress = -1;
+                this.mProgressMax = max;
+            }
+            return this;
+        }
+
         public Builder positiveColor(int color) {
             this.positiveColor = color;
             return this;
@@ -1624,7 +1670,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
     }
 
     public final void setContent(CharSequence content) {
-        ((TextView) view.findViewById(R.id.content)).setText(content);
+        this.content.setText(content);
         invalidateCustomViewAssociations(); // invalidates padding in content area scroll (if needed)
     }
 
@@ -1642,6 +1688,36 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         invalidateCustomViewAssociations();
     }
 
+    public final int getCurrentProgress() {
+        if (mProgress == null) return -1;
+        return mProgress.getProgress();
+    }
+
+    public final void incrementProgress(int by) {
+        if (mBuilder.mProgress <= -2)
+            throw new IllegalStateException("Cannot use incrementProgress() on this dialog.");
+        setProgress(getCurrentProgress() + by);
+    }
+
+    public final void setProgress(int progress) {
+        if (Looper.myLooper() != Looper.getMainLooper())
+            throw new IllegalStateException("You can only set the dialog's progress from the UI thread.");
+        else if (mBuilder.mProgress <= -2)
+            throw new IllegalStateException("Cannot use setProgress() on this dialog.");
+        mProgress.setProgress(progress);
+        int percentage = (int) (((float) getCurrentProgress() / (float) getMaxProgress()) * 100f);
+        mProgressLabel.setText(percentage + "%");
+    }
+
+    public final int getMaxProgress() {
+        if (mProgress == null) return -1;
+        return mProgress.getMax();
+    }
+
+    public final boolean isCancelled() {
+        return !isShowing();
+    }
+
     /**
      * Use this to customize any list-specific logic for this dialog (OnItemClickListener, OnLongItemClickListener, etc.)
      *
@@ -1826,4 +1902,4 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             return super.toString();
         }
     }
-}
+}

+ 0 - 87
library/src/main/java/com/afollestad/materialdialogs/MaterialEditTextPreference.java

@@ -1,87 +0,0 @@
-package com.afollestad.materialdialogs;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.preference.EditTextPreference;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.EditText;
-import android.widget.FrameLayout;
-
-/**
- * @author Marc Holder Kluver (marchold)
- */
-public class MaterialEditTextPreference extends EditTextPreference {
-
-    private final Context context;
-    private EditText editText;
-
-    public MaterialEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
-        super(context, attrs, defStyleAttr);
-        this.context = context;
-        editText = new EditText(context, attrs);
-    }
-
-    public MaterialEditTextPreference(Context context, AttributeSet attrs) {
-        this(context, attrs, 0);
-    }
-
-    public MaterialEditTextPreference(Context context) {
-        this(context, null, 0);
-    }
-
-    @Override
-    protected void showDialog(Bundle state) {
-        final FrameLayout layout = new FrameLayout(context);
-        int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getContext().getResources().getDisplayMetrics());
-        layout.setPadding(margin, 0, margin, 0);
-        editText.setText(getText());
-        editText.setId(android.R.id.edit);
-        if (editText.getParent() != null)
-            ((ViewGroup) editText.getParent()).removeView(editText);
-        layout.addView(editText);
-        MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(context)
-                .title(getTitle())
-                .icon(getDialogIcon())
-                .positiveText(android.R.string.ok)
-                .customView(layout, false)
-                .negativeText(getNegativeButtonText())
-                .callback(new MaterialDialog.ButtonCallback() {
-                    @Override
-                    public void onPositive(MaterialDialog dialog) {
-                        super.onPositive(dialog);
-                        layout.removeView(editText);
-                        String value = editText.getText().toString();
-                        if (callChangeListener(value)) {
-                            setText(value);
-                        }
-                    }
-
-                    public void onNegative(MaterialDialog dialog) {
-                        layout.removeView(editText);
-                    }
-
-                    public void onNeutral(MaterialDialog dialog) {
-                        layout.removeView(editText);
-                    }
-
-
-                });
-
-        final View contentView = onCreateDialogView();
-        if (contentView != null) {
-            onBindDialogView(contentView);
-            mBuilder.customView(contentView, false);
-        } else {
-            mBuilder.content(getDialogMessage());
-        }
-
-        mBuilder.show();
-    }
-
-    public EditText getEditText() {
-        return editText;
-    }
-}

+ 1 - 1
library/src/main/java/com/afollestad/materialdialogs/base/DialogBase.java

@@ -129,4 +129,4 @@ public class DialogBase extends AlertDialog implements DialogInterface.OnShowLis
         text.setPaintFlags(flags);
         text.setTypeface(t);
     }
-}
+}

+ 60 - 0
library/src/main/java/com/afollestad/materialdialogs/prefs/MaterialEditTextPreference.java

@@ -0,0 +1,60 @@
+package com.afollestad.materialdialogs.prefs;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.preference.EditTextPreference;
+import android.util.AttributeSet;
+import android.view.ViewGroup;
+import android.widget.EditText;
+
+import com.afollestad.materialdialogs.MaterialDialog;
+import com.afollestad.materialdialogs.R;
+
+/**
+ * @author Marc Holder Kluver (marchold)
+ */
+public class MaterialEditTextPreference extends EditTextPreference {
+
+    private EditText editText;
+
+    public MaterialEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    public MaterialEditTextPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public MaterialEditTextPreference(Context context) {
+        super(context);
+    }
+
+    @Override
+    protected void showDialog(Bundle state) {
+        MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext())
+                .title(getTitle())
+                .icon(getDialogIcon())
+                .positiveText(getPositiveButtonText())
+                .negativeText(getNegativeButtonText())
+                .customView(R.layout.md_input_dialog, false)
+                .callback(new MaterialDialog.ButtonCallback() {
+                    @Override
+                    public void onPositive(MaterialDialog dialog) {
+                        super.onPositive(dialog);
+                        String value = editText.getText().toString();
+                        if (callChangeListener(value) && isPersistent())
+                            setText(value);
+                    }
+                });
+
+        mBuilder.content(getDialogMessage());
+        MaterialDialog dialog = mBuilder.build();
+        editText = (EditText) ((ViewGroup) dialog.getCustomView()).getChildAt(0);
+        editText.setText(getText());
+        dialog.show();
+    }
+
+    public final EditText getEditText() {
+        return editText;
+    }
+}

+ 15 - 4
library/src/main/java/com/afollestad/materialdialogs/MaterialListPreference.java → library/src/main/java/com/afollestad/materialdialogs/prefs/MaterialListPreference.java

@@ -1,4 +1,4 @@
-package com.afollestad.materialdialogs;
+package com.afollestad.materialdialogs.prefs;
 
 import android.content.Context;
 import android.content.DialogInterface;
@@ -7,6 +7,8 @@ import android.preference.ListPreference;
 import android.util.AttributeSet;
 import android.view.View;
 
+import com.afollestad.materialdialogs.MaterialDialog;
+
 /**
  * Adapted from http://stackoverflow.com/a/27429926/1247248
  *
@@ -29,21 +31,30 @@ public class MaterialListPreference extends ListPreference {
 
     @Override
     protected void showDialog(Bundle state) {
+        int preselect = -1;
+        if (getEntryValues() != null) {
+            for (int i = 0; i < getEntryValues().length; i++) {
+                if (getValue() != null && getValue().equals(getEntryValues()[i])) {
+                    preselect = i;
+                    break;
+                }
+            }
+        }
+
         mBuilder = new MaterialDialog.Builder(context)
                 .title(getTitle())
                 .icon(getDialogIcon())
                 .positiveText(getPositiveButtonText())
                 .negativeText(getNegativeButtonText())
                 .items(getEntries())
-                .itemsCallback(new MaterialDialog.ListCallback() {
+                .itemsCallbackSingleChoice(preselect, new MaterialDialog.ListCallback() {
                     @Override
                     public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                         onClick(null, DialogInterface.BUTTON_POSITIVE);
                         dialog.dismiss();
-
                         if (which >= 0 && getEntryValues() != null) {
                             String value = getEntryValues()[which].toString();
-                            if (callChangeListener(value))
+                            if (callChangeListener(value) && isPersistent())
                                 setValue(value);
                         }
                     }

+ 3 - 1
library/src/main/res/layout/md_dialog.xml

@@ -29,7 +29,8 @@
                 android:layout_height="wrap_content"
                 android:scaleType="fitXY"
                 android:layout_marginRight="@dimen/md_icon_margin"
-                android:layout_marginEnd="@dimen/md_icon_margin" />
+                android:layout_marginEnd="@dimen/md_icon_margin"
+                tools:ignore="ContentDescription" />
 
             <TextView
                 android:id="@+id/title"
@@ -37,6 +38,7 @@
                 android:layout_height="wrap_content"
                 android:textSize="@dimen/md_title_textsize"
                 tools:text="Title" />
+
         </LinearLayout>
 
         <View

+ 17 - 0
library/src/main/res/layout/md_input_dialog.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:gravity="start"
+    android:paddingLeft="@dimen/md_dialog_frame_margin"
+    android:paddingRight="@dimen/md_dialog_frame_margin">
+
+    <EditText
+        android:id="@android:id/edit"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:inputType="text"
+        android:singleLine="true" />
+
+</FrameLayout>

+ 55 - 0
library/src/main/res/layout/md_progress_dialog.xml

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    tools:ignore="NewApi,RtlSymmetry,UnusedAttribute">
+
+    <TextView
+        android:id="@android:id/message"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:fontFamily="sans-serif"
+        android:textSize="@dimen/md_content_textsize"
+        android:layout_marginTop="8dp"
+        android:layout_marginBottom="8dp"
+        tools:text="Message"
+        android:layout_gravity="center_horizontal" />
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <ProgressBar
+            android:id="@android:id/progress"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            style="?android:progressBarStyleHorizontal"
+            android:layout_marginLeft="@dimen/md_dialog_frame_margin"
+            android:layout_marginStart="@dimen/md_dialog_frame_margin"
+            android:layout_marginBottom="@dimen/md_dialog_frame_margin"
+            android:layout_toLeftOf="@+id/label"
+            android:layout_toStartOf="@+id/label"
+            android:layout_centerVertical="true" />
+
+        <TextView
+            android:id="@+id/label"
+            android:layout_width="wrap_content"
+            android:minWidth="36dp"
+            android:layout_height="wrap_content"
+            tools:text="100%"
+            android:textSize="14sp"
+            android:layout_marginLeft="12dp"
+            android:layout_marginStart="12dp"
+            android:layout_marginRight="12dp"
+            android:layout_marginEnd="12dp"
+            android:gravity="end"
+            android:textAlignment="viewEnd"
+            android:layout_alignParentRight="true"
+            android:layout_alignParentEnd="true"
+            android:layout_centerVertical="true" />
+
+    </RelativeLayout>
+
+</LinearLayout>

+ 25 - 0
library/src/main/res/layout/md_progress_dialog_indeterminate.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:orientation="horizontal"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="start|center_vertical">
+
+    <ProgressBar
+        android:id="@android:id/progress"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="@dimen/md_dialog_frame_margin"
+        android:layout_marginStart="@dimen/md_dialog_frame_margin" />
+
+    <TextView
+        android:id="@android:id/message"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:fontFamily="sans-serif"
+        android:textSize="16sp"
+        tools:text="Message"
+        tools:ignore="UnusedAttribute" />
+
+</LinearLayout>

+ 6 - 2
library/src/main/res/values/dimens.xml

@@ -15,13 +15,14 @@
     <!-- 16dp - 4dp (inset) -->
     <dimen name="md_button_padding_frame_side">12dp</dimen>
     <dimen name="md_neutral_button_margin">12dp</dimen>
-    <!-- Applied to content scrollview/listview and customview, the spec calls for 16dp between the
+    <!--
+            Applied to content scrollview/listview and customview, the spec calls for 16dp between the
              bottom of the content and the top of the button bar, we split this between the two for
              ease of layouts and adjustments. Likewise the spec implies 16dp between the title and
              content and we split that as well.
 
              Splitting makes it easier to have consistent padding against the dividers.
-             -->
+    -->
     <dimen name="md_content_vertical_padding">8dp</dimen>
     <dimen name="md_button_frame_vertical_padding">8dp</dimen>
     <dimen name="md_button_height">48dp</dimen>
@@ -34,4 +35,7 @@
     <dimen name="md_icon_margin">16dp</dimen>
     <dimen name="md_listitem_margin_left">24dp</dimen>
     <dimen name="md_action_corner_radius">2dp</dimen>
+
+    <dimen name="md_progressdialog_paddingwithtitle">4dp</dimen>
+
 </resources>

+ 2 - 2
sample/build.gradle

@@ -8,8 +8,8 @@ android {
         applicationId "com.afollestad.materialdialogssample"
         minSdkVersion 14
         targetSdkVersion 21
-        versionCode 76
-        versionName "0.6.2.4"
+        versionCode 77
+        versionName "0.6.3.0"
     }
     lintOptions {
         abortOnError false

BIN
sample/sample.apk


+ 62 - 1
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.java

@@ -174,10 +174,24 @@ public class MainActivity extends ActionBarActivity implements FolderSelectorDia
             }
         });
 
+        findViewById(R.id.progress1).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                showProgressDialog(false);
+            }
+        });
+
+        findViewById(R.id.progress2).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                showProgressDialog(true);
+            }
+        });
+
         findViewById(R.id.preference_dialogs).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                startActivity(new Intent(getApplicationContext(),PreferenceActivity.class));
+                startActivity(new Intent(getApplicationContext(), PreferenceActivity.class));
             }
         });
     }
@@ -484,6 +498,53 @@ public class MainActivity extends ActionBarActivity implements FolderSelectorDia
                 .show();
     }
 
+    public void showProgressDialog(boolean indeterminate) {
+        if (indeterminate) {
+            new MaterialDialog.Builder(this)
+                    .title(R.string.progress_dialog)
+                    .content(R.string.please_wait)
+                    .progress(true, 0)
+                    .show();
+        } else {
+            new MaterialDialog.Builder(this)
+                    .title(R.string.progress_dialog)
+                    .content(R.string.please_wait)
+                    .progress(false, 150)
+                    .showListener(new DialogInterface.OnShowListener() {
+                        @Override
+                        public void onShow(DialogInterface dialogInterface) {
+                            final MaterialDialog dialog = (MaterialDialog) dialogInterface;
+                            new Thread(new Runnable() {
+                                @Override
+                                public void run() {
+                                    while (dialog.getCurrentProgress() != dialog.getMaxProgress()) {
+                                        if (dialog.isCancelled())
+                                            break;
+                                        try {
+                                            Thread.sleep(50);
+                                        } catch (InterruptedException e) {
+                                            break;
+                                        }
+                                        runOnUiThread(new Runnable() {
+                                            @Override
+                                            public void run() {
+                                                dialog.incrementProgress(1);
+                                            }
+                                        });
+                                    }
+                                    runOnUiThread(new Runnable() {
+                                        @Override
+                                        public void run() {
+                                            dialog.setContent(getString(R.string.done));
+                                        }
+                                    });
+                                }
+                            }).start();
+                        }
+                    }).show();
+        }
+    }
+
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         getMenuInflater().inflate(R.menu.main, menu);

+ 14 - 0
sample/src/main/res/layout/activity_main.xml

@@ -142,6 +142,20 @@
             android:text="@string/folder_chooser"
             android:layout_marginTop="@dimen/sample_button_spacing" />
 
+        <Button
+            android:id="@+id/progress1"
+            android:layout_width="match_parent"
+            android:layout_height="56dp"
+            android:text="@string/progress_dialog"
+            android:layout_marginTop="@dimen/sample_button_spacing" />
+
+        <Button
+            android:id="@+id/progress2"
+            android:layout_width="match_parent"
+            android:layout_height="56dp"
+            android:text="@string/progress_dialog_indeterminate"
+            android:layout_marginTop="@dimen/sample_button_spacing" />
+
         <Button
             android:id="@+id/preference_dialogs"
             android:layout_width="match_parent"

+ 2 - 1
sample/src/main/res/layout/dialog_color_chooser.xml

@@ -3,7 +3,8 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical"
-    android:gravity="center_horizontal">
+    android:gravity="center_horizontal"
+    tools:ignore="ContentDescription">
 
     <GridLayout
         android:id="@+id/grid"

+ 4 - 0
sample/src/main/res/values/strings.xml

@@ -131,5 +131,9 @@
     <string name="edittext_pref_title">Material EditText Preference</string>
     <string name="edittext_pref_desc">This is an example of an EditText preference that automatically uses Material Dialogs to show the input dialog.</string>
     <string name="edittext_pref_dialogtitle">Enter a Name</string>
+    <string name="progress_dialog_indeterminate">Progress Dialog (Indeterminate)</string>
+    <string name="progress_dialog">Progress Dialog</string>
+    <string name="please_wait">Please wait…</string>
+    <string name="done">Done!</string>
 
 </resources>

+ 4 - 4
sample/src/main/res/xml/preferences.xml

@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 
-    <com.afollestad.materialdialogs.MaterialListPreference
+    <com.afollestad.materialdialogs.prefs.MaterialListPreference
         android:key="unused_key1"
         android:entries="@array/preference_values"
         android:entryValues="@array/preference_values"
         android:title="@string/list_pref_title"
         android:summary="@string/list_pref_desc"
-        android:persistent="false"
+        android:persistent="true"
         android:layout="@layout/preference_custom" />
 
-    <com.afollestad.materialdialogs.MaterialEditTextPreference
+    <com.afollestad.materialdialogs.prefs.MaterialEditTextPreference
         android:key="unused_key2"
         android:title="@string/edittext_pref_title"
         android:summary="@string/edittext_pref_desc"
         android:inputType="textPersonName"
         android:dialogTitle="@string/edittext_pref_dialogtitle"
-        android:persistent="false"
+        android:persistent="true"
         android:layout="@layout/preference_custom" />
 
 </PreferenceScreen>