Sfoglia il codice sorgente

Merge pull request #146 from hzsweers/master

Some misc tweaks
Aidan Follestad 10 anni fa
parent
commit
1de068927e

+ 20 - 17
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -154,7 +154,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         if (builder.contentAlignment == Alignment.CENTER) {
             content.setGravity(Gravity.CENTER_HORIZONTAL);
         } else if (builder.contentAlignment == Alignment.RIGHT) {
-            content.setGravity(Gravity.RIGHT);
+            content.setGravity(Gravity.END);
         }
 
         if (builder.contentColor != -1) {
@@ -246,7 +246,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
             if (builder.titleAlignment == Alignment.CENTER) {
                 title.setGravity(Gravity.CENTER_HORIZONTAL);
             } else if (builder.titleAlignment == Alignment.RIGHT) {
-                title.setGravity(Gravity.RIGHT);
+                title.setGravity(Gravity.END);
             }
         }
 
@@ -259,6 +259,16 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
             title.setTextColor(Color.BLACK);
             content.setTextColor(Color.BLACK);
         }
+
+        if (builder.showListener != null) {
+            setOnShowListener(builder.showListener);
+        }
+        if (builder.cancelListener != null) {
+            setOnCancelListener(builder.cancelListener);
+        }
+        if (builder.dismissListener != null) {
+            setOnDismissListener(builder.dismissListener);
+        }
     }
 
     @Override
@@ -553,7 +563,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     }
 
     private void sendMultichoiceCallback() {
-        List<CharSequence> selectedTitles = new ArrayList<CharSequence>();
+        List<CharSequence> selectedTitles = new ArrayList<>();
         for (Integer i : selectedIndicesList) {
             selectedTitles.add(items[i]);
         }
@@ -661,9 +671,9 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         protected Typeface mediumFont;
         protected Drawable icon;
         protected ListAdapter adapter;
-        private OnDismissListener dismissListener;
-        private OnCancelListener cancelListener;
-        private OnShowListener showListener;
+        protected OnDismissListener dismissListener;
+        protected OnCancelListener cancelListener;
+        protected OnShowListener showListener;
         protected boolean forceStacking;
 
         public Builder(@NonNull Context context) {
@@ -965,17 +975,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         }
 
         public MaterialDialog build() {
-            MaterialDialog dialog = new MaterialDialog(this);
-            if (this.showListener != null) {
-                dialog.setOnShowListener(this.showListener);
-            }
-            if (this.cancelListener != null) {
-                dialog.setOnCancelListener(this.cancelListener);
-            }
-            if (this.dismissListener != null) {
-                dialog.setOnDismissListener(this.dismissListener);
-            }
-            return dialog;
+            return new MaterialDialog(this);
         }
 
         public MaterialDialog show() {
@@ -1272,6 +1272,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     /**
      * @deprecated Use the new {@link com.afollestad.materialdialogs.MaterialDialog.ButtonCallback}
      */
+    @Deprecated
     public abstract static class SimpleCallback extends ButtonCallback {
         @Override
         public abstract void onPositive(MaterialDialog dialog);
@@ -1280,6 +1281,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     /**
      * @deprecated Use the new {@link com.afollestad.materialdialogs.MaterialDialog.ButtonCallback}
      */
+    @Deprecated
     public abstract static class Callback extends SimpleCallback {
         @Override
         public abstract void onNegative(MaterialDialog dialog);
@@ -1288,6 +1290,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     /**
      * @deprecated Use the new {@link com.afollestad.materialdialogs.MaterialDialog.ButtonCallback}
      */
+    @Deprecated
     public abstract static class FullCallback extends Callback {
         @Override
         public abstract void onNeutral(MaterialDialog dialog);

+ 19 - 4
library/src/main/res/layout/md_dialog.xml

@@ -13,7 +13,9 @@
         android:layout_marginTop="@dimen/md_dialog_frame_margin"
         android:layout_marginBottom="@dimen/md_main_frame_margin"
         android:layout_marginLeft="@dimen/md_dialog_frame_margin"
+        android:layout_marginStart="@dimen/md_dialog_frame_margin"
         android:layout_marginRight="@dimen/md_dialog_frame_margin"
+        android:layout_marginEnd="@dimen/md_dialog_frame_margin"
         android:layout_weight="1">
 
         <LinearLayout
@@ -22,6 +24,7 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center_vertical"
+            android:layoutDirection="locale"
             android:layout_marginBottom="@dimen/md_main_frame_margin">
 
             <ImageView
@@ -29,7 +32,9 @@
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:scaleType="fitXY"
-                android:layout_marginRight="@dimen/md_icon_margin" />
+                android:layout_marginRight="@dimen/md_icon_margin"
+                android:layout_marginEnd="@dimen/md_icon_margin"
+                />
 
             <TextView
                 android:id="@+id/title"
@@ -79,6 +84,7 @@
                 android:paddingTop="@dimen/md_dialog_frame_margin"
                 android:paddingBottom="@dimen/md_dialog_frame_margin"
                 android:layout_marginLeft="@dimen/md_dialog_frame_margin"
+                android:layout_marginStart="@dimen/md_dialog_frame_margin"
                 android:layout_marginRight="@dimen/md_dialog_frame_margin">
 
                 <LinearLayout
@@ -87,6 +93,7 @@
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:gravity="center_vertical"
+                    android:layoutDirection="locale"
                     android:layout_marginBottom="@dimen/md_main_frame_margin">
 
                     <ImageView
@@ -94,7 +101,9 @@
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:scaleType="fitXY"
-                        android:layout_marginRight="@dimen/md_icon_margin" />
+                        android:layout_marginRight="@dimen/md_icon_margin"
+                        android:layout_marginEnd="@dimen/md_icon_margin"
+                        />
 
                     <TextView
                         android:id="@+id/titleCustomView"
@@ -140,13 +149,17 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginRight="@dimen/md_button_padding_frame_side"
+        android:layout_marginEnd="@dimen/md_button_padding_frame_side"
         android:layout_marginBottom="@dimen/md_button_padding_frame_bottom">
 
         <Button
             android:id="@+id/buttonDefaultNeutral"
             style="@style/MD_ActionButton"
             android:layout_alignParentLeft="true"
-            android:layout_marginLeft="@dimen/md_neutral_button_margin" />
+            android:layout_alignParentStart="true"
+            android:layout_marginLeft="@dimen/md_neutral_button_margin"
+            android:layout_marginStart="@dimen/md_neutral_button_margin"
+            />
 
         <!-- toLeftOf rule added from invalidateActions() -->
         <Button
@@ -156,7 +169,9 @@
         <Button
             android:id="@+id/buttonDefaultPositive"
             style="@style/MD_ActionButton"
-            android:layout_alignParentRight="true" />
+            android:layout_alignParentRight="true"
+            android:layout_alignParentEnd="true"
+            />
 
     </RelativeLayout>
 

+ 4 - 1
library/src/main/res/layout/md_listitem.xml

@@ -15,6 +15,9 @@
         android:textSize="@dimen/md_listitem_textsize"
         android:gravity="center_vertical"
         android:layout_marginLeft="@dimen/md_listitem_margin_left"
-        android:layout_marginRight="@dimen/md_dialog_frame_margin" />
+        android:layout_marginStart="@dimen/md_listitem_margin_left"
+        android:layout_marginRight="@dimen/md_dialog_frame_margin"
+        android:layout_marginEnd="@dimen/md_dialog_frame_margin"
+        />
 
 </LinearLayout>

+ 5 - 1
library/src/main/res/layout/md_listitem_multichoice.xml

@@ -15,7 +15,9 @@
         android:clickable="false"
         android:gravity="center_vertical"
         android:layout_marginLeft="@dimen/md_dialog_frame_margin"
+        android:layout_marginStart="@dimen/md_dialog_frame_margin"
         android:layout_marginRight="@dimen/md_listitem_control_margin"
+        android:layout_marginEnd="@dimen/md_listitem_control_margin"
         android:focusable="false"
         android:focusableInTouchMode="false" />
 
@@ -27,6 +29,8 @@
         tools:text="Item"
         android:textSize="@dimen/md_listitem_textsize"
         android:gravity="center_vertical"
-        android:layout_marginRight="@dimen/md_dialog_frame_margin" />
+        android:layout_marginRight="@dimen/md_dialog_frame_margin"
+        android:layout_marginEnd="@dimen/md_dialog_frame_margin"
+        />
 
 </LinearLayout>

+ 5 - 1
library/src/main/res/layout/md_listitem_singlechoice.xml

@@ -15,7 +15,9 @@
         android:clickable="false"
         android:gravity="center_vertical"
         android:layout_marginLeft="@dimen/md_dialog_frame_margin"
+        android:layout_marginStart="@dimen/md_dialog_frame_margin"
         android:layout_marginRight="@dimen/md_listitem_control_margin"
+        android:layout_marginEnd="@dimen/md_listitem_control_margin"
         android:focusable="false"
         android:focusableInTouchMode="false" />
 
@@ -27,6 +29,8 @@
         tools:text="Item"
         android:textSize="@dimen/md_listitem_textsize"
         android:gravity="center_vertical"
-        android:layout_marginRight="@dimen/md_dialog_frame_margin" />
+        android:layout_marginRight="@dimen/md_dialog_frame_margin"
+        android:layout_marginEnd="@dimen/md_dialog_frame_margin"
+        />
 
 </LinearLayout>

+ 6 - 3
library/src/main/res/values/styles.xml

@@ -19,12 +19,15 @@
 
     <style name="MD_ActionButtonStacked" parent="@style/MD_ActionButton">
         <item name="android:layout_width">match_parent</item>
-        <item name="android:gravity">right|center_vertical</item>
+        <item name="android:gravity">end|center_vertical</item>
 
         <item name="android:paddingLeft">@dimen/md_button_padding_horizontal_internalexternal</item>
-        <item name="android:paddingRight">@dimen/md_button_padding_horizontal_internalexternal
-        </item>
+        <item name="android:paddingStart">@dimen/md_button_padding_horizontal_internalexternal</item>
+        <item name="android:paddingRight">@dimen/md_button_padding_horizontal_internalexternal</item>
+        <item name="android:paddingEnd">@dimen/md_button_padding_horizontal_internalexternal</item>
+
         <item name="android:layout_marginLeft">0dp</item>
+        <item name="android:layout_marginStart">0dp</item>
     </style>
 
     <style name="MD_ActionButton">

+ 5 - 0
sample/src/main/res/layout/dialog_customlistitem.xml

@@ -11,8 +11,11 @@
         android:layout_height="wrap_content"
         android:textSize="@dimen/md_listitem_textsize"
         android:layout_marginLeft="@dimen/md_listitem_margin_left"
+        android:layout_marginStart="@dimen/md_listitem_margin_left"
         android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true"
         android:layout_toLeftOf="@+id/button"
+        android:layout_toStartOf="@+id/button"
         android:layout_centerVertical="true" />
 
     <Button
@@ -20,8 +23,10 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginRight="@dimen/md_dialog_frame_margin"
+        android:layout_marginEnd="@dimen/md_dialog_frame_margin"
         android:text="@string/custom_listitem_button"
         android:layout_alignParentRight="true"
+        android:layout_alignParentEnd="true"
         android:layout_centerVertical="true"
         android:layout_marginTop="4dp"
         android:layout_marginBottom="4dp" />