Aidan Follestad 10 年之前
父節點
當前提交
fd0e2b0169

+ 1 - 2
library/src/main/java/com/afollestad/materialdialogs/internal/MDButton.java

@@ -65,7 +65,6 @@ public class MDButton extends TextView {
             if (stacked) {
                 setPadding(mStackedEndPadding, getPaddingTop(), mStackedEndPadding, getPaddingBottom());
             } /* Else the padding was properly reset by the drawable */
-
         }
     }
 
@@ -96,4 +95,4 @@ public class MDButton extends TextView {
             }
         }
     }
-}
+}

+ 15 - 28
library/src/main/java/com/afollestad/materialdialogs/internal/MDRootLayout.java

@@ -95,7 +95,6 @@ public class MDRootLayout extends ViewGroup {
     @Override
     public void onFinishInflate() {
         super.onFinishInflate();
-
         for (int i = 0; i < getChildCount(); i++) {
             View v = getChildAt(i);
             if (v.getId() == R.id.titleFrame) {
@@ -123,8 +122,7 @@ public class MDRootLayout extends ViewGroup {
         final boolean stacked;
         if (!mForceStack) {
             int buttonsWidth = 0;
-            for (int i = 0; i < mButtons.length; i++) {
-                MDButton button = mButtons[i];
+            for (MDButton button : mButtons) {
                 if (button != null && button.getVisibility() != View.GONE) {
                     button.setStacked(false, false);
                     measureChild(button, widthMeasureSpec, heightMeasureSpec);
@@ -139,14 +137,13 @@ public class MDRootLayout extends ViewGroup {
             final int buttonFrameWidth = width - 2 * buttonBarPadding;
             stacked = buttonsWidth > buttonFrameWidth;
         } else {
-            stacked = mForceStack;
+            stacked = true;
         }
 
         int stackedHeight = 0;
         mIsStacked = stacked;
         if (stacked) {
-            for (int i = 0; i < mButtons.length; i++) {
-                MDButton button = mButtons[i];
+            for (MDButton button : mButtons) {
                 if (button != null && button.getVisibility() != View.GONE) {
                     button.setStacked(true, false);
                     measureChild(button, widthMeasureSpec, heightMeasureSpec);
@@ -229,24 +226,22 @@ public class MDRootLayout extends ViewGroup {
             t += mNoTitlePaddingFull;
         }
 
-        if (mContent != null && mContent.getVisibility() != View.GONE) {
+        if (mContent != null && mContent.getVisibility() != View.GONE)
             mContent.layout(l, t, r, t + mContent.getMeasuredHeight());
-        }
 
         if (mIsStacked) {
             b -= mButtonPaddingFull;
-            for (int i = 0; i < mButtons.length; i++) {
-                if (mButtons[i] != null && mButtons[i].getVisibility() != View.GONE) {
-                    mButtons[i].layout(l, b - mButtons[i].getMeasuredHeight(), r, b);
-                    b -= mButtons[i].getMeasuredHeight();
+            for (MDButton mButton : mButtons) {
+                if (mButton != null && mButton.getVisibility() != View.GONE) {
+                    mButton.layout(l, b - mButton.getMeasuredHeight(), r, b);
+                    b -= mButton.getMeasuredHeight();
                 }
             }
         } else {
             int barTop;
             int barBottom = b;
-            if (mUseFullPadding) {
+            if (mUseFullPadding)
                 barBottom -= mButtonPaddingFull;
-            }
             barTop = barBottom - mButtonBarHeight;
             /* START:
                Neutral   Negative  Positive
@@ -267,7 +262,6 @@ public class MDRootLayout extends ViewGroup {
 
             if (mButtons[INDEX_POSITIVE] != null && mButtons[INDEX_POSITIVE].getVisibility() != View.GONE) {
                 int bl, br;
-
                 if (mButtonGravity == GravityEnum.END) {
                     bl = l + offset;
                     br = bl + mButtons[INDEX_POSITIVE].getMeasuredWidth();
@@ -276,16 +270,12 @@ public class MDRootLayout extends ViewGroup {
                     bl = br - mButtons[INDEX_POSITIVE].getMeasuredWidth();
                     neutralRight = bl;
                 }
-
                 mButtons[INDEX_POSITIVE].layout(bl, barTop, br, barBottom);
-
                 offset += mButtons[INDEX_POSITIVE].getMeasuredWidth();
             }
 
             if (mButtons[INDEX_NEGATIVE] != null && mButtons[INDEX_NEGATIVE].getVisibility() != View.GONE) {
-
                 int bl, br;
-
                 if (mButtonGravity == GravityEnum.END) {
                     bl = l + offset;
                     br = bl + mButtons[INDEX_NEGATIVE].getMeasuredWidth();
@@ -297,7 +287,6 @@ public class MDRootLayout extends ViewGroup {
                     br = bl + mButtons[INDEX_NEGATIVE].getMeasuredWidth();
                     neutralLeft = br;
                 }
-
                 mButtons[INDEX_NEGATIVE].layout(bl, barTop, br, barBottom);
             }
 
@@ -314,7 +303,7 @@ public class MDRootLayout extends ViewGroup {
                         neutralLeft = neutralRight - mButtons[INDEX_NEUTRAL].getMeasuredWidth();
                     } else if (neutralRight == -1 && neutralLeft != -1) {
                         neutralRight = neutralLeft + mButtons[INDEX_NEUTRAL].getMeasuredWidth();
-                    } else if (neutralRight == -1 && neutralLeft == -1) {
+                    } else if (neutralRight == -1) {
                         neutralLeft = (r - l) / 2 - mButtons[INDEX_NEUTRAL].getMeasuredWidth() / 2;
                         neutralRight = neutralLeft + mButtons[INDEX_NEUTRAL].getMeasuredWidth();
                     }
@@ -342,9 +331,9 @@ public class MDRootLayout extends ViewGroup {
     }
 
     public void setButtonStackedGravity(GravityEnum gravity) {
-        for (int i = 0; i < mButtons.length; i++) {
-            if (mButtons[i] != null)
-                mButtons[i].setStackedGravity(gravity);
+        for (MDButton mButton : mButtons) {
+            if (mButton != null)
+                mButton.setStackedGravity(gravity);
         }
     }
 
@@ -394,7 +383,6 @@ public class MDRootLayout extends ViewGroup {
             /* Or the first item's top is above or own top */
             if (lv.getChildAt(0).getTop() < lv.getPaddingTop())
                 return true;
-
             /* or the last item's bottom is beyond our own bottom */
             return lv.getChildAt(lv.getChildCount() - 1).getBottom() >
                     lv.getHeight() - lv.getPaddingBottom();
@@ -412,8 +400,7 @@ public class MDRootLayout extends ViewGroup {
      */
     @Nullable
     private static View getBottomView(ViewGroup viewGroup) {
-        if (viewGroup == null)
-            return null;
+        if (viewGroup == null) return null;
         View bottomView = null;
         for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
             View child = viewGroup.getChildAt(i);
@@ -439,4 +426,4 @@ public class MDRootLayout extends ViewGroup {
         }
         return topView;
     }
-}
+}