Skip to content

Commit ea63a45

Browse files
authored
Merge pull request #172 from Mygod/androidx
Refactor to AndroidX
2 parents 1325747 + 4420160 commit ea63a45

File tree

199 files changed

+315
-2116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+315
-2116
lines changed

README.md

Lines changed: 23 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# Android Support library - preference v7 bugfix
1+
# AndroidX Preference eXtended
22

3-
> **BREAKING CHANGE** in 26.1.0.3: The custom attribute names for extra preference types use `pref_` prefix in order to avoid name collision with other libraries. See the changelog for more details.
4-
5-
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`.
3+
This library is meant to fix some of the problems found in the official AndroidX preference library. Also, there are [new preference types](#extra-types) available, such as `RingtonePreference`, `DatePickerPreference`, and `TimePickerPreference`.
64

75
[ ![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)
86

@@ -16,23 +14,16 @@ If you would like to support me, you may donate some small amount via PayPal.
1614

1715
## How to use the library?
1816
### 1. Add gradle dependency
19-
First, **remove** the unnecessary lines of preference-v7 and preference-v14 from your gradle file as the bugfix contains both of them:
20-
```gradle
21-
implementation 'com.android.support:preference-v7:27.1.1'
22-
implementation 'com.android.support:preference-v14:27.1.1'
23-
```
24-
And **add** this single line to your gradle file:
17+
**Add** this to your gradle file:
2518
```gradle
26-
implementation 'com.takisoft.fix:preference-v7:27.1.1.1'
19+
implementation "androidx.preference:preference:$androidxVersion"
20+
implementation 'com.takisoft.preferencex:preferencex:1.0.0-alpha1'
2721
```
28-
> 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.
2922

3023
### 2. Use the appropriate class as your fragment's base
31-
You can use either `PreferenceFragmentCompat` or `PreferenceFragmentCompatDividers`. The former is the fixed version of the original fragment while the latter is an extended one where you can set the dividers using the divider flags. The `PreferenceFragmentCompatDividers` is the recommended approach as it uses the updated Material Design guidelines to create the appropriate divider config.
3224

33-
#### Option 1 - `PreferenceFragmentCompat`
3425
```java
35-
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat;
26+
import com.takisoft.preferencex.PreferenceFragmentCompat;
3627

3728
public class MyPreferenceFragment extends PreferenceFragmentCompat {
3829

@@ -44,75 +35,27 @@ public class MyPreferenceFragment extends PreferenceFragmentCompat {
4435
}
4536
}
4637
```
47-
> **Warning!** Watch out for the correct package name when importing `PreferenceFragmentCompat`, it should come from `com.takisoft.fix.support.v7.preference`.
48-
---
49-
#### Option 2 - `PreferenceFragmentCompatDividers`
50-
```java
51-
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers;
38+
> **Warning!** Watch out for the correct package name when importing `PreferenceFragmentCompat`, it should come from `com.takisoft.preferencex`.
5239
53-
public class MyPreferenceFragment extends PreferenceFragmentCompatDividers {
54-
55-
@Override
56-
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
57-
setPreferencesFromResource(R.xml.settings, rootKey);
58-
59-
// additional setup
60-
}
61-
62-
@Override
63-
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
64-
try {
65-
return super.onCreateView(inflater, container, savedInstanceState);
66-
} finally {
67-
setDividerPreferences(DIVIDER_PADDING_CHILD | DIVIDER_CATEGORY_AFTER_LAST | DIVIDER_CATEGORY_BETWEEN);
68-
}
69-
}
70-
}
71-
```
72-
73-
### 3. Use the appropriate theme
74-
You should set your containing `Activity`'s theme to either a variant of `@style/PreferenceFixTheme` or create your own and use it as the parent theme. `PreferenceFixTheme` is based on `Theme.AppCompat` and contains the required attribute `preferenceTheme`. The fix theme is available for all `Theme.AppCompat` variants, such as `NoActionBar`, `Light`, etc.
75-
For example, the sample app uses `PreferenceFixTheme.Light.NoActionBar` as the parent theme:
76-
```xml
77-
<style name="Theme.MyTheme" parent="@style/PreferenceFixTheme.Light.NoActionBar">
78-
<item name="colorAccent">@color/accent</item>
79-
<item name="colorPrimary">@color/primary</item>
80-
<item name="colorPrimaryDark">@color/primary_dark</item>
81-
<!-- [...] -->
82-
</style>
83-
```
84-
85-
### 4. That's it!
86-
Now you can enjoy using the support preferences API without losing all your hair.
40+
Now you can enjoy using preferenceX.
8741

8842
---
8943

9044
## Extra types
9145

92-
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
93-
94-
```gradle
95-
implementation 'com.takisoft.fix:preference-v7-extras:27.1.1.1'
96-
```
97-
98-
or one or more groups:
46+
There are additional preferences not part of the official support library, but decided to add them to some extra libraries. You can add them to your project using Gradle.
9947

10048
Preference | Dependency | Preview
10149
-|-|-
102-
[`RingtonePreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#ringtonepreference) | `compile 'com.takisoft.fix:preference-v7-ringtone:27.1.1.1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/ringtone_api26.png)
103-
[`DatePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#datepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:27.1.1.1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/datepicker_api26.png)
104-
[`TimePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#timepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:27.1.1.1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/timepicker_api26.png)
105-
[`ColorPickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#colorpickerpreference) | `compile 'com.takisoft.fix:preference-v7-colorpicker:27.1.1.1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/colorpicker_api26_fixed.png)
106-
[`SimpleMenuPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#simplemenupreference) | `compile 'com.takisoft.fix:preference-v7-simplemenu:27.1.1.1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/simplemenu_api26.png)
50+
[`RingtonePreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#ringtonepreference) | `implementation 'com.takisoft.preferencex:preferencex-ringtone:1.0.0-alpha1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/ringtone_api26.png)
51+
[`DatePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#datepickerpreference) | `implementation 'com.takisoft.preferencex:preferencex-datetimepicker:1.0.0-alpha1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/datepicker_api26.png)
52+
[`TimePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#timepickerpreference) | `implementation 'com.takisoft.preferencex:preferencex-datetimepicker:1.0.0-alpha1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/timepicker_api26.png)
53+
[`ColorPickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#colorpickerpreference) | `implementation 'com.takisoft.preferencex:preferencex-colorpicker:1.0.0-alpha1'` | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/colorpicker_api26_fixed.png)
54+
[`SimpleMenuPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#simplemenupreference) | `implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0-alpha1'` (can be used independent of `preferencex`) | ![API 26](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/simplemenu_api26.png)
10755

10856
---
10957

11058
## Custom solutions
111-
### Dividers
112-
If you use `PreferenceFragmentCompatDividers` as your base class for the preference fragment, you can use 3 new methods to customize the dividers:
113-
- `setDivider(Drawable drawable)`: Sets a custom `Drawable` as the divider.
114-
- `setDividerHeight(int height)`: Sets the height of the drawable; useful for XML resources.
115-
- `setDividerPreferences(int flags)`: Sets where the dividers should appear. Check the documentation of the method for more details about the available flags.
11659

11760
### Hijacked `EditTextPreference`
11861
The support implementation of `EditTextPreference` ignores many of the basic yet very important attributes as it doesn't forward them to the underlying `EditText` widget. In my opinion this is a result of some twisted thinking which would require someone to create custom dialog layouts for some simple tasks, like showing a numbers-only dialog. This is the main reason why the `EditTextPreference` gets hijacked by this lib: it replaces certain aspects of the original class in order to forward all the XML attributes set (such as `inputType`) on the `EditTextPreference` to the `EditText`, and also provides a `getEditText()` method so it can be manipulated directly.
@@ -131,25 +74,21 @@ if (etPref != null) {
13174
// do something with inputType
13275
}
13376
```
134-
> **Note!** Watch out for the correct package name when importing `EditTextPreference`, it should come from `com.takisoft.fix.support.v7.preference`. If you import from the wrong package (i.e. `android.support.v7.preference`), the `getEditText()` method will not be available, however, the XML attributes will still be forwarded and processed by the `EditText`.
77+
> **Note!** Watch out for the correct package name when importing `EditTextPreference`, it should come from `com.takisoft.preferencex`. If you import from the wrong package (i.e. `androidx.preference`), the `getEditText()` method will not be available, however, the XML attributes will still be forwarded and processed by the `EditText`.
13578
79+
### Others
13680

137-
### PreferenceCategory's bottom margin reduce
138-
Some people found the preference category's bottom margin too big, so now you can change it from the styles by setting the `preferenceCategory_marginBottom` value in your theme, for example:
139-
```xml
140-
<item name="preferenceCategory_marginBottom">0dp</item>
141-
```
81+
* Convenience methods in `PreferenceFragmentCompat`;
82+
* `PreferenceCategory` with different colors;
83+
* `AutoSummaryEditTextPreference`;
84+
* `PreferenceActivityResultListener`;
85+
* `EditTextPreference` correctly calls `notifyChange`. ([#66](https://github.com/Gericop/Android-Support-Preference-V7-Fix/pull/66))
14286

143-
### Preference dialog's message style
144-
The original implementation uses `?attr/textAppearanceSmall` as the message style in the popup dialog (the one you find when clicking on an `EditTextPreference` with a set `android:dialogMessage` attribute), but it seems really small and might be hard to read. In order to fix that, a new attribute has been introduced to the `PreferenceFixTheme`: `preferenceDialog_messageAppearance`. This attribute controls the appearance of the message in the dialog and is set to `@style/TextAppearance.AppCompat.Subhead` by default. If you wish to change this, you'll just have to add the following line to your theme:
145-
```xml
146-
<item name="preferenceDialog_messageAppearance">@style/YourTextAppearance</item>
147-
```
14887

14988
---
15089

15190
## Version
152-
The current stable version is **27.1.1.1**.
91+
The current stable version is **1.0.0-alpha1**.
15392

15493
## Notes #
15594
This demo / bugfix is set to work on API level 14+.
@@ -170,7 +109,7 @@ API 15 | API 21 | API 26
170109

171110
**2018-05-11**
172111

173-
New version: 27.1.1.1 (based on v27.1.1)
112+
New version: 1.0.0-alpha1 (based on v27.1.1)
174113

175114
- No support preferences related changes in the support library.
176115
- Bug fixes (#153, #149, #155, #152).

app/build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ android {
2121
}
2222

2323
dependencies {
24-
implementation 'com.android.support:multidex:1.0.3'
25-
implementation "com.android.support:appcompat-v7:${rootProject.supportLibraryVersion}"
26-
implementation project(':preference-v7-material')
27-
implementation project(':preference-v7-extras')
24+
implementation 'androidx.multidex:multidex:2.0.0'
25+
implementation "androidx.appcompat:appcompat:$androidxVersion"
26+
implementation "com.google.android.material:material:$androidxVersion"
27+
implementation project(':preferencex')
28+
implementation project(':preferencex-colorpicker')
29+
implementation project(':preferencex-datetimepicker')
30+
implementation project(':preferencex-ringtone')
31+
implementation project(':preferencex-simplemenu')
2832
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.takisoft.preferencefix">
4-
5-
<uses-sdk xmlns:tools="http://schemas.android.com/tools"
6-
tools:overrideLibrary="android.support.v14.preference,android.support.v7.appcompat,android.support.v7.preference,android.support.graphics.drawable,android.support.compat,android.support.v4,android.support.coreutils,android.support.mediacompat,android.support.coreui,android.support.fragment,android.support.v7.recyclerview" />
3+
package="com.takisoft.preferencex.demo">
74

85
<!-- Used by RingtonePreference to allow adding custom ringtones -->
96
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

app/src/main/java/com/takisoft/preferencefix/MyApplication.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/src/main/java/com/takisoft/preferencefix/ActivityResultTestPreference.java renamed to app/src/main/java/com/takisoft/preferencex/demo/ActivityResultTestPreference.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
package com.takisoft.preferencefix;
1+
package com.takisoft.preferencex.demo;
22

33
import android.app.Activity;
44
import android.content.Context;
55
import android.content.Intent;
6-
import android.support.annotation.NonNull;
7-
import android.support.annotation.Nullable;
8-
import android.support.v7.preference.Preference;
6+
import androidx.annotation.NonNull;
7+
import androidx.annotation.Nullable;
8+
import androidx.preference.Preference;
99
import android.util.AttributeSet;
1010
import android.widget.Toast;
1111

12-
import com.takisoft.fix.support.v7.preference.PreferenceActivityResultListener;
13-
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat;
12+
import com.takisoft.preferencex.PreferenceActivityResultListener;
13+
import com.takisoft.preferencex.PreferenceFragmentCompat;
1414

1515
public class ActivityResultTestPreference extends Preference implements PreferenceActivityResultListener {
1616
public static final int RC_GET_CONTENT = 3462;

app/src/main/java/com/takisoft/preferencefix/MainActivity.java renamed to app/src/main/java/com/takisoft/preferencex/demo/MainActivity.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
package com.takisoft.preferencefix;
1+
package com.takisoft.preferencex.demo;
22

33
import android.os.Bundle;
4-
import android.support.annotation.Nullable;
5-
import android.support.v4.app.FragmentTransaction;
6-
import android.support.v7.app.AppCompatActivity;
7-
import android.support.v7.preference.PreferenceFragmentCompat;
8-
import android.support.v7.preference.PreferenceScreen;
9-
import android.support.v7.widget.Toolbar;
4+
import androidx.annotation.Nullable;
5+
import androidx.fragment.app.FragmentTransaction;
6+
import androidx.appcompat.app.AppCompatActivity;
7+
import androidx.preference.PreferenceFragmentCompat;
8+
import androidx.preference.PreferenceScreen;
9+
import androidx.appcompat.widget.Toolbar;
1010

1111
public class MainActivity extends AppCompatActivity implements PreferenceFragmentCompat.OnPreferenceStartScreenCallback {
1212

1313
@Override
1414
protected void onCreate(@Nullable Bundle savedInstanceState) {
1515
super.onCreate(savedInstanceState);
16-
setContentView(R.layout.activity_main);
16+
setContentView(com.takisoft.preferencefix.R.layout.activity_main);
1717

18-
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
18+
setSupportActionBar((Toolbar) findViewById(com.takisoft.preferencefix.R.id.toolbar));
1919

2020
if (savedInstanceState == null) {
2121
MyPreferenceFragment fragment = new MyPreferenceFragment();
2222

2323
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
24-
ft.replace(R.id.fragment, fragment);
24+
ft.replace(com.takisoft.preferencefix.R.id.fragment, fragment);
2525
ft.commitAllowingStateLoss();
2626
}
2727
}
@@ -35,7 +35,7 @@ public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragme
3535

3636
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
3737
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
38-
ft.replace(R.id.fragment, fragment, preferenceScreen.getKey());
38+
ft.replace(com.takisoft.preferencefix.R.id.fragment, fragment, preferenceScreen.getKey());
3939
ft.addToBackStack(preferenceScreen.getKey());
4040
ft.commitAllowingStateLoss();
4141

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.takisoft.preferencex.demo;
2+
3+
import androidx.multidex.MultiDexApplication;
4+
5+
public class MyApplication extends MultiDexApplication {
6+
}

app/src/main/java/com/takisoft/preferencefix/MyPreferenceFragment.java renamed to app/src/main/java/com/takisoft/preferencex/demo/MyPreferenceFragment.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
package com.takisoft.preferencefix;
1+
package com.takisoft.preferencex.demo;
22

33
import android.content.Context;
44
import android.os.Bundle;
5-
import android.support.annotation.Nullable;
6-
import android.support.v7.preference.Preference;
7-
import android.support.v7.preference.PreferenceCategory;
8-
import android.view.LayoutInflater;
9-
import android.view.View;
10-
import android.view.ViewGroup;
115

12-
import com.takisoft.fix.support.v7.preference.EditTextPreference;
13-
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers;
6+
import com.takisoft.preferencex.EditTextPreference;
7+
import com.takisoft.preferencex.PreferenceFragmentCompat;
8+
9+
import androidx.annotation.Nullable;
10+
import androidx.preference.Preference;
11+
import androidx.preference.PreferenceCategory;
1412

1513
/**
1614
* A placeholder fragment containing a simple view.
1715
*/
18-
public class MyPreferenceFragment extends PreferenceFragmentCompatDividers {
16+
public class MyPreferenceFragment extends PreferenceFragmentCompat {
1917

2018
@Override
2119
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
@@ -46,16 +44,6 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
4644
}
4745
}
4846

49-
@Override
50-
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
51-
try {
52-
return super.onCreateView(inflater, container, savedInstanceState);
53-
} finally {
54-
// Uncomment this if you want to change the divider style
55-
// setDividerPreferences(DIVIDER_OFFICIAL);
56-
}
57-
}
58-
5947
private void testDynamicPrefs() {
6048
final Context ctx = getPreferenceManager().getContext(); // this is the material styled context
6149

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
android:layout_height="match_parent"
44
android:orientation="vertical">
55

6-
<android.support.v7.widget.Toolbar
6+
<androidx.appcompat.widget.Toolbar
77
android:id="@+id/toolbar"
88
android:layout_width="match_parent"
99
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)