Przeglądaj źródła

Crash fix for Huawei devices

Aidan Follestad 10 lat temu
rodzic
commit
3e8ed207a6

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

@@ -26,6 +26,7 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
+import android.widget.Button;
 import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
@@ -995,29 +996,46 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
      * @param which The action button of which to get the view for.
      * @return The view from the dialog's layout representing this action button.
      */
-    public final View getActionButton(DialogAction which) {
+    public final Button getActionButton(DialogAction which) {
         if (view == null) return null;
         if (isStacked) {
             switch (which) {
                 default:
-                    return view.findViewById(R.id.buttonStackedPositive);
+                    return (Button) view.findViewById(R.id.buttonStackedPositive);
                 case NEUTRAL:
-                    return view.findViewById(R.id.buttonStackedNeutral);
+                    return (Button) view.findViewById(R.id.buttonStackedNeutral);
                 case NEGATIVE:
-                    return view.findViewById(R.id.buttonStackedNegative);
+                    return (Button) view.findViewById(R.id.buttonStackedNegative);
             }
         } else {
             switch (which) {
                 default:
-                    return view.findViewById(R.id.buttonDefaultPositive);
+                    return (Button) view.findViewById(R.id.buttonDefaultPositive);
                 case NEUTRAL:
-                    return view.findViewById(R.id.buttonDefaultNeutral);
+                    return (Button) view.findViewById(R.id.buttonDefaultNeutral);
                 case NEGATIVE:
-                    return view.findViewById(R.id.buttonDefaultNegative);
+                    return (Button) view.findViewById(R.id.buttonDefaultNegative);
             }
         }
     }
 
+    /**
+     * @deprecated Use getActionButton(com.afollestad.materialdialogs.DialogAction)} instead.
+     */
+    @Override
+    public Button getButton(int whichButton) {
+        switch (whichButton) {
+            case BUTTON_POSITIVE:
+                return getActionButton(DialogAction.POSITIVE);
+            case BUTTON_NEUTRAL:
+                return getActionButton(DialogAction.NEUTRAL);
+            case BUTTON_NEGATIVE:
+                return getActionButton(DialogAction.NEGATIVE);
+            default:
+                return null;
+        }
+    }
+
     /**
      * Retrieves the frame view containing the title and icon. You can manually change visibility and retrieve children.
      */

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

@@ -10,7 +10,6 @@ import android.os.Build;
 import android.os.Message;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.Button;
 import android.widget.TextView;
 
 /**
@@ -41,14 +40,6 @@ public class DialogBase extends AlertDialog implements DialogInterface.OnShowLis
         view.setLayoutParams(params);
     }
 
-    /**
-     * @deprecated Use getActionButton(com.afollestad.materialdialogs.DialogAction)} instead.
-     */
-    @Override
-    public Button getButton(int whichButton) {
-        throw new RuntimeException("Use getActionButton(MaterialDialog.Button) instead.");
-    }
-
     /**
      * @deprecated Not supported by the Material dialog.
      */

+ 6 - 6
library/src/main/res/layout/md_dialog.xml

@@ -143,18 +143,18 @@
         android:layout_marginRight="@dimen/md_button_padding_frame_side"
         android:layout_marginBottom="@dimen/md_button_padding_frame_bottom">
 
-        <TextView
+        <Button
             android:id="@+id/buttonDefaultNeutral"
             style="@style/MD_ActionButton"
             android:layout_alignParentLeft="true"
             android:layout_marginLeft="@dimen/md_neutral_button_margin" />
 
         <!-- toLeftOf rule added from invalidateActions() -->
-        <TextView
+        <Button
             android:id="@+id/buttonDefaultNegative"
             style="@style/MD_ActionButton" />
 
-        <TextView
+        <Button
             android:id="@+id/buttonDefaultPositive"
             style="@style/MD_ActionButton"
             android:layout_alignParentRight="true" />
@@ -168,15 +168,15 @@
         android:layout_height="wrap_content"
         android:layout_marginBottom="@dimen/md_button_padding_frame_bottom">
 
-        <TextView
+        <Button
             android:id="@+id/buttonStackedPositive"
             style="@style/MD_ActionButtonStacked" />
 
-        <TextView
+        <Button
             android:id="@+id/buttonStackedNegative"
             style="@style/MD_ActionButtonStacked" />
 
-        <TextView
+        <Button
             android:id="@+id/buttonStackedNeutral"
             style="@style/MD_ActionButtonStacked" />