浏览代码

Progress modifiers don't need to be posted to the UI thread, progress bar does that automatically. Removed thrown exception for not being on the UI thread too.

Aidan Follestad 10 年之前
父节点
当前提交
12b8f1d9ca
共有 1 个文件被更改,包括 5 次插入16 次删除
  1. 5 16
      library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

+ 5 - 16
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -1314,26 +1314,17 @@ public class MaterialDialog extends DialogBase implements
     }
 
     public final void incrementProgress(final int by) {
-        if (mBuilder.progress <= -2)
-            throw new IllegalStateException("Cannot use incrementProgress() on this dialog.");
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                setProgress(getCurrentProgress() + by);
-            }
-        });
+        setProgress(getCurrentProgress() + by);
     }
 
     public final void setProgress(final 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.progress <= -2)
+        if (mBuilder.progress <= -2)
             throw new IllegalStateException("Cannot use setProgress() on this dialog.");
+        mProgress.setProgress(progress);
         mHandler.post(new Runnable() {
             @Override
             public void run() {
-                mProgress.setProgress(progress);
-                int percentage = (int) (((float) getCurrentProgress() / (float) getMaxProgress()) * 100f);
+                final int percentage = (int) (((float) getCurrentProgress() / (float) getMaxProgress()) * 100f);
                 mProgressLabel.setText(percentage + "%");
                 if (mProgressMinMax != null)
                     mProgressMinMax.setText(getCurrentProgress() + "/" + getMaxProgress());
@@ -1342,9 +1333,7 @@ public class MaterialDialog extends DialogBase implements
     }
 
     public final void setMaxProgress(final int max) {
-        if (Looper.myLooper() != Looper.getMainLooper())
-            throw new IllegalStateException("You can only set the dialog's progress from the UI thread.");
-        else if (mBuilder.progress <= -2)
+        if (mBuilder.progress <= -2)
             throw new IllegalStateException("Cannot use setMaxProgress() on this dialog.");
         mHandler.post(new Runnable() {
             @Override