OSDN Git Service

CMFM: Don't show the cancel button if action is non-cancellable
authorEthan Chen <intervigil@gmail.com>
Tue, 10 Dec 2013 00:54:14 +0000 (16:54 -0800)
committerEthan Chen <intervigil@gmail.com>
Tue, 10 Dec 2013 20:53:09 +0000 (12:53 -0800)
Change-Id: Ic8078d75aa8c5e77f37f3110cdd8cbf5e65fe790

src/com/cyanogenmod/filemanager/ui/dialogs/MessageProgressDialog.java

index 3b64a89..ab4f8ec 100644 (file)
@@ -21,6 +21,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.text.Spanned;
 import android.view.LayoutInflater;
+import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -117,36 +118,27 @@ public class MessageProgressDialog implements DialogInterface.OnClickListener {
                                         iconResourceId,
                                         titleResourceId,
                                         layout);
-        this.mDialog.setButton(
-                DialogInterface.BUTTON_NEUTRAL, context.getString(android.R.string.cancel), this);
-        this.mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
-            @Override
-            public void onCancel(DialogInterface dialog) {
-                // Disable cancel button
-                MessageProgressDialog.this.mDialog.getButton(
+        this.mDialog.setCancelable(cancellable);
+        if (cancellable) {
+            this.mDialog.setButton(
+                    DialogInterface.BUTTON_NEUTRAL, context.getString(android.R.string.cancel), this);
+            this.mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
+                @Override
+                public void onCancel(DialogInterface dialog) {
+                    // Disable cancel button
+                    MessageProgressDialog.this.mDialog.getButton(
                         DialogInterface.BUTTON_NEUTRAL).setEnabled(false);
 
-                // Wait for cancellation
-                if (MessageProgressDialog.this.mOnCancelListener != null) {
-                    if (!MessageProgressDialog.this.mOnCancelListener.onCancel()) {
-                        //The operation couldn't be cancelled
-                        DialogHelper.showToast(
+                    // Wait for cancellation
+                    if (MessageProgressDialog.this.mOnCancelListener != null) {
+                        if (!MessageProgressDialog.this.mOnCancelListener.onCancel()) {
+                            //The operation couldn't be cancelled
+                            DialogHelper.showToast(
                                 MessageProgressDialog.this.mContext,
                                 R.string.msgs_operation_can_not_be_cancelled, Toast.LENGTH_SHORT);
+                        }
                     }
                 }
-            }
-        });
-
-        // Is cancellable
-        this.mDialog.setCancelable(cancellable);
-        if (!cancellable) {
-            this.mProgress.post(new Runnable() {
-                @Override
-                public void run() {
-                    MessageProgressDialog.this.mDialog.getButton(
-                            DialogInterface.BUTTON_NEUTRAL).setEnabled(false);
-                }
             });
         }