Explorar o código

Stack algorithm should work perfectly now

Aidan Follestad %!s(int64=10) %!d(string=hai) anos
pai
achega
c938ac4f61

+ 11 - 4
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -3,6 +3,7 @@ package com.afollestad.materialdialogs;
 import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.res.ColorStateList;
 import android.content.res.TypedArray;
 import android.graphics.Paint;
@@ -138,11 +139,17 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         }
 
         invalidateList();
-        if (invalidateActions())
-            checkIfStackingNeeded();
+        invalidateActions();
+        setOnShowListenerInternal();
         setViewInternal(view);
     }
 
+    @Override
+    public void onShow(DialogInterface dialog) {
+        super.onShow(dialog); // calls any external show listeners
+        checkIfStackingNeeded();
+    }
+
     /**
      * Invalidates visibility of views for the presence of a custom view or list content
      */
@@ -250,10 +257,10 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
      * From: http://www.google.com/design/spec/components/dialogs.html#dialogs-specs
      */
     private int calculateMaxButtonWidth() {
-        final int dialogWidthDp = (int) mContext.getResources().getDimension(R.dimen.dialog_width);
+        final int dialogWidth = getWindow().getDecorView().getMeasuredWidth();
         final int eightDp = (int) mContext.getResources().getDimension(R.dimen.button_padding_horizontal_external);
         final int sixteenDp = (int) mContext.getResources().getDimension(R.dimen.button_padding_frame_side);
-        return (dialogWidthDp - sixteenDp - sixteenDp - eightDp) / 2;
+        return (dialogWidth - sixteenDp - sixteenDp - eightDp) / 2;
     }
 
     /**

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

@@ -2,6 +2,7 @@ package com.afollestad.materialdialogs.base;
 
 import android.app.AlertDialog;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.graphics.drawable.Drawable;
 import android.os.Message;
 import android.view.View;
@@ -12,11 +13,12 @@ import android.widget.ListView;
 /**
  * @author Aidan Follestad (afollestad)
  */
-public class DialogBase extends AlertDialog {
+public class DialogBase extends AlertDialog implements DialogInterface.OnShowListener {
 
     protected final static String POSITIVE = "POSITIVE";
     protected final static String NEGATIVE = "NEGATIVE";
     protected final static String NEUTRAL = "NEUTRAL";
+    private OnShowListener mShowListener;
 
     protected DialogBase(Context context) {
         super(context);
@@ -135,4 +137,19 @@ public class DialogBase extends AlertDialog {
     public ListView getListView() {
         throw new RuntimeException("This method is not supported by the MaterialDialog.");
     }
+
+    @Override
+    public final void setOnShowListener(OnShowListener listener) {
+        mShowListener = listener;
+    }
+
+    protected final void setOnShowListenerInternal() {
+        super.setOnShowListener(this);
+    }
+
+    @Override
+    public void onShow(DialogInterface dialog) {
+        if (mShowListener != null)
+            mShowListener.onShow(dialog);
+    }
 }

+ 0 - 1
library/src/main/res/values/dimens.xml

@@ -22,6 +22,5 @@
     <dimen name="listitem_textsize">16sp</dimen>
     <dimen name="listitem_height">48dp</dimen>
     <dimen name="listitem_control_margin">16dp</dimen>
-    <dimen name="dialog_width">280dp</dimen>
 
 </resources>

+ 1 - 0
library/src/main/res/values/styles.xml

@@ -35,6 +35,7 @@
         <item name="android:textSize">@dimen/button_textsize</item>
         <item name="android:textAllCaps">true</item>
         <item name="android:gravity">center</item>
+        <item name="android:singleLine">true</item>
 
         <item name="android:layout_height">@dimen/button_height</item>
         <item name="android:minWidth">@dimen/button_min_width</item>

+ 1 - 1
sample/src/main/res/values/strings.xml

@@ -25,7 +25,7 @@
     <string name="useGoogleLocationServicesPrompt">Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.</string>
     <string name="socialNetworks">Social Networks</string>
     <string name="choose">Choose</string>
-    <string name="speedBoost">Turn on speed boost</string>
+    <string name="speedBoost">Turn on speed boost now!</string>
     <string name="noThanks">No thanks</string>
     <string name="googleWifi">Google Wifi</string>
     <string name="connect">Connect</string>