1
0
Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

Aidan Follestad 10 жил өмнө
parent
commit
8156873887

+ 8 - 12
README.md

@@ -62,7 +62,7 @@ new MaterialDialog.Builder(this)
         .show();
 ```
 
-On Lollipop (API 21) or if you use AppCompat, the Material dialog will automatically match the `positiveColor`
+On Lollipop (API 21+) or if you use AppCompat, the Material dialog will automatically match the `positiveColor`
 (which is used on the positive action button) to the `colorAccent` attribute of your styles.xml theme.
 
 If the content is long enough, it will become scrollable and a divider will be displayed above the action buttons.
@@ -245,7 +245,7 @@ unless auto dismiss is turned off.
 If you make a call to `alwaysCallSingleChoiceCallback()`, the single choice callback will be called
 every time the user selects an item.
 
-## Coloring Radio Buttons (API 22+)
+## Coloring Radio Buttons
 
 Like action buttons and many other elements of the Material dialog, you can customize the color of a 
  dialog's radio buttons. The `Builder` class contains a `widgetColor()`, `widgetColorRes()`,
@@ -255,8 +255,6 @@ Like action buttons and many other elements of the Material dialog, you can cust
  
 There's also a global theming attribute as shown in the Global Theming section of this README: `md_widget_color`.
 
-Due to limitations, this only works correctly on API 22 (Android 5.1 Lollipop) and above.
-
 ---
 
 # Multi Choice List Dialogs
@@ -295,7 +293,7 @@ unless auto dismiss is turned off.
 If you make a call to `alwaysCallMultiChoiceCallback()`, the multi choice callback will be called
 every time the user selects an item.
 
-## Coloring Check Boxes (API 22+)
+## Coloring Check Boxes
 
 Like action buttons and many other elements of the Material dialog, you can customize the color of a 
  dialog's check boxes. The `Builder` class contains a `widgetColor()`, `widgetColorRes()`,
@@ -305,8 +303,6 @@ Like action buttons and many other elements of the Material dialog, you can cust
  
 There's also a global theming attribute as shown in the Global Theming section of this README: `md_widget_color`.
 
-Due to limitations, this only works correctly on API 22 (Android 5.1 Lollipop) and above.
-
 ---
 
 # Custom List Dialogs
@@ -459,10 +455,10 @@ new MaterialDialog.Builder(this)
         .show();
 ```
 
-The names are self explanatory for the most part. The `widgetColor` method is discussed in a few other
-sections of this tutorial, it applies to progress bars on all API levels, along check boxes and radio 
-buttons (on API 22 and above due to limitations). Also note that each of these methods have 3 variations 
-for setting a color directly, using color resources, and using color attributes.
+The names are self explanatory for the most part. The `widgetColor` method, discussed in a few other
+sections of this tutorial, applies to progress bars, check boxes, and radio buttons. Also note that 
+each of these methods have 3 variations for setting a color directly, using color resources, and using 
+color attributes.
 
 ## Selectors
 
@@ -485,7 +481,7 @@ or because you used `forceStacked(true)` on the `Builder`. `listSelector` is use
 you are NOT using a custom adapter.
 
 ***An important note related to using custom action button selectors***: make sure your selector drawable references
-inset drawables like the default ones do, this is important for correct action button padding.
+inset drawables like the default ones do - this is important for correct action button padding.
 
 ## Gravity
 

+ 15 - 0
library/src/main/java/com/afollestad/materialdialogs/prefs/MaterialEditTextPreference.java

@@ -5,6 +5,7 @@ import android.content.Context;
 import android.os.Build;
 import android.os.Bundle;
 import android.preference.EditTextPreference;
+import android.preference.PreferenceManager;
 import android.support.annotation.NonNull;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
@@ -24,6 +25,9 @@ import com.afollestad.materialdialogs.R;
 import com.afollestad.materialdialogs.internal.MDTintHelper;
 import com.afollestad.materialdialogs.util.DialogUtils;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 /**
  * @author Aidan Follestad (afollestad)
  */
@@ -95,6 +99,17 @@ public class MaterialEditTextPreference extends EditTextPreference {
         }
         mBuilder.customView(layout, false);
 
+        PreferenceManager pm = getPreferenceManager();
+        try {
+            Method method = pm.getClass().getDeclaredMethod(
+                    "registerOnActivityDestroyListener",
+                    PreferenceManager.OnActivityDestroyListener.class);
+            method.setAccessible(true);
+            method.invoke(pm, this);
+        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+            e.printStackTrace();
+        }
+
         mDialog = mBuilder.build();
         if (state != null)
             mDialog.onRestoreInstanceState(state);

+ 19 - 1
library/src/main/java/com/afollestad/materialdialogs/prefs/MaterialListPreference.java

@@ -6,12 +6,16 @@ import android.content.DialogInterface;
 import android.os.Build;
 import android.os.Bundle;
 import android.preference.ListPreference;
+import android.preference.PreferenceManager;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.View;
 
 import com.afollestad.materialdialogs.MaterialDialog;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 /**
  * @author Marc Holder Kluver (marchold), Aidan Follestad (afollestad)
  */
@@ -84,7 +88,21 @@ public class MaterialListPreference extends ListPreference {
             builder.content(getDialogMessage());
         }
 
-        mDialog = builder.show();
+        PreferenceManager pm = getPreferenceManager();
+        try {
+            Method method = pm.getClass().getDeclaredMethod(
+                    "registerOnActivityDestroyListener",
+                    PreferenceManager.OnActivityDestroyListener.class);
+            method.setAccessible(true);
+            method.invoke(pm, this);
+        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+            e.printStackTrace();
+        }
+
+        mDialog = builder.build();
+        if (state != null)
+            mDialog.onRestoreInstanceState(state);
+        mDialog.show();
     }
 
     @Override

+ 18 - 1
library/src/main/java/com/afollestad/materialdialogs/prefs/MaterialMultiSelectListPreference.java

@@ -7,11 +7,14 @@ import android.content.DialogInterface;
 import android.os.Build;
 import android.os.Bundle;
 import android.preference.MultiSelectListPreference;
+import android.preference.PreferenceManager;
 import android.util.AttributeSet;
 import android.view.View;
 
 import com.afollestad.materialdialogs.MaterialDialog;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -94,6 +97,20 @@ public class MaterialMultiSelectListPreference extends MultiSelectListPreference
             builder.content(getDialogMessage());
         }
 
-        mDialog = builder.show();
+        PreferenceManager pm = getPreferenceManager();
+        try {
+            Method method = pm.getClass().getDeclaredMethod(
+                    "registerOnActivityDestroyListener",
+                    PreferenceManager.OnActivityDestroyListener.class);
+            method.setAccessible(true);
+            method.invoke(pm, this);
+        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+            e.printStackTrace();
+        }
+
+        mDialog = builder.build();
+        if (state != null)
+            mDialog.onRestoreInstanceState(state);
+        mDialog.show();
     }
 }