+ * + * @param context The context of the shared preferences. + * @param resId The resource ID of the preference XML file. + * @param readAgain Whether to re-read the default values. + * If false, this method sets the default values only if this + * method has never been called in the past (or if the + * {@link #KEY_HAS_SET_DEFAULT_VALUES} in the default value shared + * preferences file is false). To attempt to set the default values again + * bypassing this check, set {@code readAgain} to true. + *
+ * Note: this will NOT reset preferences back to their default + * values. For that functionality, use + * {@link PreferenceManager#getDefaultSharedPreferences(Context)} + * and clear it followed by a call to this method with this + * parameter set to true. + */ + public static void setDefaultValues(Context context, int resId, boolean readAgain) { + // Use the default shared preferences name and mode + setDefaultValues(context, getDefaultSharedPreferencesName(context), + getDefaultSharedPreferencesMode(), resId, readAgain); + } + + /** + * Similar to {@link #setDefaultValues(Context, int, boolean)} but allows + * the client to provide the filename and mode of the shared preferences + * file. + * + * @param context The context of the shared preferences. + * @param sharedPreferencesName A custom name for the shared preferences file. + * @param sharedPreferencesMode The file creation mode for the shared preferences file, such + * as {@link android.content.Context#MODE_PRIVATE} or {@link + * android.content.Context#MODE_PRIVATE} + * @param resId The resource ID of the preference XML file. + * @param readAgain Whether to re-read the default values. + * If false, this method will set the default values only if this + * method has never been called in the past (or if the + * {@link #KEY_HAS_SET_DEFAULT_VALUES} in the default value shared + * preferences file is false). To attempt to set the default values again + * bypassing this check, set {@code readAgain} to true. + *
+ * Note: this will NOT reset preferences back to their default + * values. For that functionality, use + * {@link PreferenceManager#getDefaultSharedPreferences(Context)} + * and clear it followed by a call to this method with this + * parameter set to true. + * @see #setDefaultValues(Context, int, boolean) + * @see #setSharedPreferencesName(String) + * @see #setSharedPreferencesMode(int) + */ + public static void setDefaultValues(Context context, String sharedPreferencesName, + int sharedPreferencesMode, int resId, boolean readAgain) { + final SharedPreferences defaultValueSp = context.getSharedPreferences( + KEY_HAS_SET_DEFAULT_VALUES, Context.MODE_PRIVATE); + + if (readAgain || !defaultValueSp.getBoolean(KEY_HAS_SET_DEFAULT_VALUES, false)) { + final PreferenceManagerFix pm = new PreferenceManagerFix(context); + pm.setSharedPreferencesName(sharedPreferencesName); + pm.setSharedPreferencesMode(sharedPreferencesMode); + pm.inflateFromResource(context, resId, null); + + defaultValueSp.edit() + .putBoolean(KEY_HAS_SET_DEFAULT_VALUES, true) + .apply(); + } + } } diff --git a/preference-v7/src/main/java/com/takisoft/fix/support/v7/preference/PreferenceFragmentCompatDividers.java b/preference-v7/src/main/java/com/takisoft/fix/support/v7/preference/PreferenceFragmentCompatDividers.java index a6f2058..aab478e 100644 --- a/preference-v7/src/main/java/com/takisoft/fix/support/v7/preference/PreferenceFragmentCompatDividers.java +++ b/preference-v7/src/main/java/com/takisoft/fix/support/v7/preference/PreferenceFragmentCompatDividers.java @@ -17,9 +17,14 @@ import java.lang.annotation.RetentionPolicy; /** + * @deprecated Use {@link PreferenceFragmentCompat} instead as it provides the official (and fixed) + * divider settings. If you want to customize dividers, use the hidden API attributes + * {@code app:allowDividerAbove} and {@code app:allowDividerBelow} on the preferences in the XML. + *
* As a user requested, here's a variant of PreferenceFragmentCompatFix that allows one to fully * customize the dividers between categories and items. */ +@Deprecated abstract public class PreferenceFragmentCompatDividers extends PreferenceFragmentCompat { /** * Draws the divider implementation of the official support library. @@ -118,7 +123,7 @@ abstract public class PreferenceFragmentCompatDividers extends PreferenceFragmen private boolean divPrefInvalid = false; @DividerPrefFlags - private int divPrefFlags = DIVIDER_DEFAULT; + private int divPrefFlags = DIVIDER_OFFICIAL; private DividerItemDecoration divItemDecoration; @@ -427,4 +432,4 @@ public void setDividerHeight(int dividerHeight) { PreferenceFragmentCompatDividers.this.getListView().invalidateItemDecorations(); } } -} +} \ No newline at end of file diff --git a/preference-v7/src/main/res/values-v17/styles.xml b/preference-v7/src/main/res/values-v17/styles.xml index 8e79f0b..fe97256 100644 --- a/preference-v7/src/main/res/values-v17/styles.xml +++ b/preference-v7/src/main/res/values-v17/styles.xml @@ -2,7 +2,8 @@ @@ -14,7 +15,8 @@ @@ -25,14 +27,16 @@ @@ -43,7 +47,8 @@