diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e2a454..8d89f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +**2018-07-18** + +New version: 28.0.0.0-alpha3 (based on v28.0.0-alpha3) + +- No support preferences related changes in the support library. +- `PreferenceFragmentCompatDividers` is now deprecated. Use `PreferenceFragmentCompat` instead. +- Added `preference-v7-material` module which provides `Theme.MaterialComponents` related themes. +- Bug fixes #166, #169, #173 + **2018-07-04** New version: 27.1.1.2 (based on v27.1.1) diff --git a/README.md b/README.md index ef60281..dba6523 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,13 @@ This library is meant to fix some of the problems found in the official support preference-v7 library. Also, there are [new preference types](#extra-types) available, such as `RingtonePreference`, `DatePickerPreference`, and `TimePickerPreference`. +Support Library (28.0.0-alpha3): [ ![Download](https://api.bintray.com/packages/gericop/maven/com.takisoft.fix%3Apreference-v7/images/download.svg) ](https://bintray.com/gericop/maven/com.takisoft.fix%3Apreference-v7/_latestVersion) +AndroidX (1.0.0-beta01): +[ ![Download](https://api.bintray.com/packages/takisoft/android/com.takisoft.preferencex%3Apreferencex/images/download.svg) ](https://bintray.com/takisoft/android/com.takisoft.preferencex%3Apreferencex/_latestVersion) +> Check out the other available AndroidX artifacts at https://bintray.com/takisoft/android) + ### Donation If you would like to support me, you may donate some small amount via PayPal. @@ -18,12 +23,12 @@ If you would like to support me, you may donate some small amount via PayPal. ### 1. Add gradle dependency First, **remove** the unnecessary lines of preference-v7 and preference-v14 from your gradle file as the bugfix contains both of them: ```gradle -implementation 'com.android.support:preference-v7:27.1.1' -implementation 'com.android.support:preference-v14:27.1.1' +implementation 'com.android.support:preference-v7:28.0.0-alpha3' +implementation 'com.android.support:preference-v14:28.0.0-alpha3' ``` And **add** this single line to your gradle file: ```gradle -implementation 'com.takisoft.fix:preference-v7:27.1.1.2' +implementation 'com.takisoft.fix:preference-v7:28.0.0.0-alpha3' ``` > Notice the versioning: the first three numbers are *always* the same as the latest official library while the last number is for own updates. I try to keep it up-to-date but if, for whatever reasons, I wouldn't notice the new support library versions, just issue a ticket. @@ -47,6 +52,7 @@ public class MyPreferenceFragment extends PreferenceFragmentCompat { > **Warning!** Watch out for the correct package name when importing `PreferenceFragmentCompat`, it should come from `com.takisoft.fix.support.v7.preference`. --- #### Option 2 - `PreferenceFragmentCompatDividers` +> **Warning!** `PreferenceFragmentCompatDividers` is deprecated and will be removed from the AndroidX version of the lib. You should use `PreferenceFragmentCompat` instead. ```java import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers; @@ -82,6 +88,14 @@ For example, the sample app uses `PreferenceFixTheme.Light.NoActionBar` as the p ``` +**Theme.MaterialComponents** +There's a NEW module called `preference-v7-material` that provides the new `Theme.MaterialComponents` related themes. You can add it to your project like this: +```gradle +implementation 'com.takisoft.fix:preference-v7-material:28.0.0.0-alpha3' +``` + +> Note that you may need to use multidexing after this because it uses the support design library which is a huge codebase. + ### 4. That's it! Now you can enjoy using the support preferences API without losing all your hair. @@ -92,18 +106,18 @@ Now you can enjoy using the support preferences API without losing all your hair There are additional preferences not part of the official support library, but decided to add them to some extra libraries. You can add all of them to your project using ```gradle -implementation 'com.takisoft.fix:preference-v7-extras:27.1.1.2' +implementation 'com.takisoft.fix:preference-v7-extras:28.0.0.0-alpha3' ``` or one or more groups: Preference | Dependency | Preview -|-|- -[`RingtonePreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#ringtonepreference) | `compile 'com.takisoft.fix:preference-v7-ringtone:27.1.1.2'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/ringtone_api26.png) -[`DatePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#datepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:27.1.1.2'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/datepicker_api26.png) -[`TimePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#timepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:27.1.1.2'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/timepicker_api26.png) -[`ColorPickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#colorpickerpreference) | `compile 'com.takisoft.fix:preference-v7-colorpicker:27.1.1.2'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/colorpicker_api26_fixed.png) -[`SimpleMenuPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#simplemenupreference) | `compile 'com.takisoft.fix:preference-v7-simplemenu:27.1.1.2'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/simplemenu_api26.png) +[`RingtonePreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#ringtonepreference) | `compile 'com.takisoft.fix:preference-v7-ringtone:28.0.0.0-alpha3'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/ringtone_api26.png) +[`DatePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#datepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:28.0.0.0-alpha3'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/datepicker_api26.png) +[`TimePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#timepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:28.0.0.0-alpha3'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/timepicker_api26.png) +[`ColorPickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#colorpickerpreference) | `compile 'com.takisoft.fix:preference-v7-colorpicker:28.0.0.0-alpha3'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/colorpicker_api26_fixed.png) +[`SimpleMenuPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#simplemenupreference) | `compile 'com.takisoft.fix:preference-v7-simplemenu:28.0.0.0-alpha3'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/simplemenu_api26.png) --- @@ -149,7 +163,7 @@ The original implementation uses `?attr/textAppearanceSmall` as the message styl --- ## Version -The current stable version is **27.1.1.2**. +The current stable version is **28.0.0.0-alpha3**. ## Notes # This demo / bugfix is set to work on API level 14+. @@ -168,6 +182,15 @@ API 15 | API 21 | API 26 ### Changelog +**2018-07-18** + +New version: 28.0.0.0-alpha3 (based on v28.0.0-alpha3) + +- No support preferences related changes in the support library. +- `PreferenceFragmentCompatDividers` is now deprecated. Use `PreferenceFragmentCompat` instead. +- Added `preference-v7-material` module which provides `Theme.MaterialComponents` related themes. +- Bug fixes #166, #169, #173 + **2018-07-04** New version: 27.1.1.2 (based on v27.1.1) @@ -175,6 +198,20 @@ New version: 27.1.1.2 (based on v27.1.1) - No support preferences related changes in the support library. - RingtonePreference bug fixes(#164, #165, #167). +**2018-05-11** + +New version: 27.1.1.1 (based on v27.1.1) + +- No support preferences related changes in the support library. +- Bug fixes (#153, #149, #155, #152). + +**2018-04-10** + +New version: 27.1.1.0 (based on v27.1.1) + +- No support preferences related changes in the support library. +- Some bug fixes (see #147 for more info). + > For older changelogs, check out the [CHANGELOG](CHANGELOG.md) file. Feel free to ask / suggest anything on this page by creating a ticket (*issues*)! diff --git a/app/build.gradle b/app/build.gradle index 0b490e9..3f0cb0b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,6 +10,7 @@ android { targetSdkVersion rootProject.sdkVersion versionCode 1 versionName "1.0" + multiDexEnabled true } buildTypes { release { @@ -20,7 +21,8 @@ android { } dependencies { + implementation 'com.android.support:multidex:1.0.3' implementation "com.android.support:appcompat-v7:${rootProject.supportLibraryVersion}" - implementation project(':preference-v7') + implementation project(':preference-v7-material') implementation project(':preference-v7-extras') } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f5e430c..8fa4186 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ - + + + + + + + + + + + + + diff --git a/preference-v7-material/src/main/res/values-v21/styles.xml b/preference-v7-material/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..9a69e3a --- /dev/null +++ b/preference-v7-material/src/main/res/values-v21/styles.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/preference-v7-material/src/main/res/values/styles.xml b/preference-v7-material/src/main/res/values/styles.xml new file mode 100644 index 0000000..b7b4322 --- /dev/null +++ b/preference-v7-material/src/main/res/values/styles.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/preference-v7-material/src/test/java/com/takisoft/preferencefix/material/ExampleUnitTest.java b/preference-v7-material/src/test/java/com/takisoft/preferencefix/material/ExampleUnitTest.java new file mode 100644 index 0000000..42f1f5e --- /dev/null +++ b/preference-v7-material/src/test/java/com/takisoft/preferencefix/material/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.takisoft.preferencefix.material; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/preference-v7-simplemenu/build.gradle b/preference-v7-simplemenu/build.gradle index fc8c98b..aca0f97 100644 --- a/preference-v7-simplemenu/build.gradle +++ b/preference-v7-simplemenu/build.gradle @@ -46,7 +46,8 @@ ext { } dependencies { - implementation project(':preference-v7') + api "com.android.support:preference-v7:${rootProject.supportLibraryVersion}" + api "com.android.support:preference-v14:${rootProject.supportLibraryVersion}" } //apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/installv.gradle' diff --git a/preference-v7-simplemenu/src/main/res/layout-v21/preference_simplemenu.xml b/preference-v7-simplemenu/src/main/res/layout-v21/preference_simplemenu.xml index 5974719..866c5e0 100644 --- a/preference-v7-simplemenu/src/main/res/layout-v21/preference_simplemenu.xml +++ b/preference-v7-simplemenu/src/main/res/layout-v21/preference_simplemenu.xml @@ -1,5 +1,4 @@ - - - + android:baselineAligned="false" + android:gravity="center_vertical"> + android:minWidth="56dp" + android:orientation="horizontal" + android:paddingTop="4dp" + android:paddingEnd="8dp" + android:paddingBottom="4dp"> - - + app:maxHeight="48dp" + app:maxWidth="48dp" /> + android:layout_gravity="center_vertical" + android:visibility="invisible" /> - + - + - + diff --git a/preference-v7-simplemenu/src/main/res/layout/preference_simplemenu.xml b/preference-v7-simplemenu/src/main/res/layout/preference_simplemenu.xml index dbafafe..8821da5 100644 --- a/preference-v7-simplemenu/src/main/res/layout/preference_simplemenu.xml +++ b/preference-v7-simplemenu/src/main/res/layout/preference_simplemenu.xml @@ -1,5 +1,4 @@ - - - + android:paddingRight="?android:listPreferredItemPaddingRight"> + android:baselineAligned="false" + android:gravity="center_vertical"> + android:minWidth="60dp" + android:orientation="horizontal" + android:paddingTop="4dp" + android:paddingRight="12dp" + android:paddingBottom="4dp"> - - + app:maxHeight="48dp" + app:maxWidth="48dp" /> + android:layout_gravity="center_vertical" + android:visibility="invisible" /> - + - + - + diff --git a/preference-v7-simplemenu/src/main/res/values/styles.xml b/preference-v7-simplemenu/src/main/res/values/styles.xml index eefb8a0..0462f00 100644 --- a/preference-v7-simplemenu/src/main/res/values/styles.xml +++ b/preference-v7-simplemenu/src/main/res/values/styles.xml @@ -1,9 +1,6 @@ - - - diff --git a/preference-v7/src/main/java/android/support/v7/preference/PreferenceManagerFix.java b/preference-v7/src/main/java/android/support/v7/preference/PreferenceManagerFix.java index 4671e85..d5a8db6 100644 --- a/preference-v7/src/main/java/android/support/v7/preference/PreferenceManagerFix.java +++ b/preference-v7/src/main/java/android/support/v7/preference/PreferenceManagerFix.java @@ -100,4 +100,94 @@ private void setNoCommitFix(boolean noCommit) throws IllegalAccessException { this.noCommit = noCommit; } + + /** + * Returns the name of the {@link SharedPreferences} file that preferences will use. + * + * @param context the context to be used + * @return the name of the {@link SharedPreferences} file + */ + public static String getDefaultSharedPreferencesName(Context context) { + return context.getPackageName() + "_preferences"; + } + + /** + * Returns the mode of the {@link SharedPreferences} file that preferences will use. + * + * @return the mode of the {@link SharedPreferences} file + */ + public static int getDefaultSharedPreferencesMode() { + return Context.MODE_PRIVATE; + } + + /** + * Sets the default values from an XML preference file by reading the values defined + * by each {@link Preference} item's {@code android:defaultValue} attribute. This should + * be called by the application's main activity. + *

+ * + * @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 @@ diff --git a/preference-v7/src/main/res/values/styles.xml b/preference-v7/src/main/res/values/styles.xml index 7fa6c92..2459af2 100644 --- a/preference-v7/src/main/res/values/styles.xml +++ b/preference-v7/src/main/res/values/styles.xml @@ -1,8 +1,9 @@ - + @@ -14,7 +15,8 @@ @@ -25,14 +27,16 @@ @@ -43,7 +47,8 @@ @@ -52,7 +57,7 @@ 14sp sans - sans-serif-medium + sans-serif-medium bold ?android:attr/textColorPrimary diff --git a/settings.gradle b/settings.gradle index e63c2f2..a10899f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':preference-v7', ':preference-v7-extras', ':preference-v7-datetimepicker', ':preference-v7-ringtone', ':preference-v7-colorpicker', ':preference-v7-simplemenu' +include ':app', ':preference-v7', ':preference-v7-extras', ':preference-v7-datetimepicker', ':preference-v7-ringtone', ':preference-v7-colorpicker', ':preference-v7-simplemenu', ':preference-v7-material'