Skip to content

Commit 5781015

Browse files
committed
migrate to androidX preference dependency
1 parent f520994 commit 5781015

7 files changed

Lines changed: 29 additions & 33 deletions

File tree

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ android {
2222
}
2323

2424
dependencies {
25-
implementation 'androidx.appcompat:appcompat:1.0.2'
26-
implementation 'com.google.android.material:material:1.1.0-alpha02'
27-
implementation "com.github.skydoves:elasticviews:2.0.2"
25+
implementation "androidx.appcompat:appcompat:1.0.2"
26+
implementation "com.google.android.material:material:1.1.0-alpha04"
27+
implementation "com.github.skydoves:elasticviews:2.0.3"
28+
implementation "androidx.preference:preference:1.1.0-alpha04"
2829
implementation project(':colorpickerpreference')
2930
}
3031

app/src/main/java/com/skydoves/colorpickerpreferencedemo/PreferenceActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package com.skydoves.colorpickerpreferencedemo;
1818

1919
import android.os.Bundle;
20+
import androidx.appcompat.app.AppCompatActivity;
2021

2122
/** Developed by skydoves on 2018-02-11. Copyright (c) 2018 skydoves rights reserved. */
22-
public class PreferenceActivity extends AppCompatPreferenceActivity {
23+
public class PreferenceActivity extends AppCompatActivity {
2324

2425
@Override
2526
protected void onCreate(Bundle savedInstanceState) {
2627
super.onCreate(savedInstanceState);
27-
getFragmentManager()
28+
getSupportFragmentManager()
2829
.beginTransaction()
2930
.replace(android.R.id.content, new PreferenceFragment())
3031
.commit();

app/src/main/java/com/skydoves/colorpickerpreferencedemo/PreferenceFragment.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,34 @@
1919
import android.app.AlertDialog;
2020
import android.content.DialogInterface;
2121
import android.os.Bundle;
22-
import androidx.annotation.Nullable;
22+
2323
import com.skydoves.colorpickerpreference.ColorEnvelope;
2424
import com.skydoves.colorpickerpreference.ColorListener;
2525
import com.skydoves.colorpickerpreference.ColorPickerDialog;
2626
import com.skydoves.colorpickerpreference.ColorPickerPreference;
2727
import com.skydoves.colorpickerpreference.FlagMode;
2828

29+
import androidx.preference.PreferenceFragmentCompat;
30+
2931
/** Developed by skydoves on 2018-02-11. Copyright (c) 2018 skydoves rights reserved. */
30-
public class PreferenceFragment extends android.preference.PreferenceFragment {
32+
public class PreferenceFragment extends PreferenceFragmentCompat {
3133

3234
@Override
33-
public void onCreate(@Nullable Bundle savedInstanceState) {
34-
super.onCreate(savedInstanceState);
35+
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
3536
addPreferencesFromResource(R.xml.pref_settings);
3637
initColorPickerPreference();
3738
}
3839

3940
/** customizing ColorPreference's ColorPickerDialog */
4041
private void initColorPickerPreference() {
4142
ColorPickerPreference colorPickerPreference_toolbar =
42-
(ColorPickerPreference)
43-
findPreference(getActivity().getString(R.string.ToolbarColorPickerPreference));
43+
findPreference(getActivity().getString(R.string.ToolbarColorPickerPreference));
4444
ColorPickerDialog.Builder builder_toolbar =
4545
colorPickerPreference_toolbar.getColorPickerDialogBuilder();
4646
builder_toolbar.setFlagView(new CustomFlag(getActivity(), R.layout.layout_flag));
4747

4848
ColorPickerPreference colorPickerPreference_background =
49-
(ColorPickerPreference)
50-
findPreference(getActivity().getString(R.string.BackgroundColorPickerPreference));
49+
findPreference(getActivity().getString(R.string.BackgroundColorPickerPreference));
5150
colorPickerPreference_background.setColorPickerDialogBuilder(getCustomBuilder());
5251
}
5352

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
android:layout_height="0dp"
2222
android:layout_weight="1"
2323
android:onClick="example0"
24-
app:button_duration="150"
24+
app:button_duration="110"
2525
app:button_scale="0.8"
2626
app:layout_backgroundColor="@color/background800"
2727
app:layout_round="20">
@@ -32,6 +32,7 @@
3232
android:layout_centerInParent="true"
3333
android:padding="5dp"
3434
android:text="ColorPicker Example"
35+
android:layout_gravity="center"
3536
android:textColor="@android:color/white"
3637
android:textSize="21sp"
3738
android:textStyle="bold" />
@@ -47,7 +48,7 @@
4748
android:layout_height="0dp"
4849
android:layout_weight="1"
4950
android:onClick="example1"
50-
app:button_duration="150"
51+
app:button_duration="110"
5152
app:button_scale="0.8"
5253
app:layout_backgroundColor="@color/background800"
5354
app:layout_round="20">
@@ -56,8 +57,8 @@
5657
android:layout_width="wrap_content"
5758
android:layout_height="wrap_content"
5859
android:layout_centerInParent="true"
59-
android:padding="5dp"
6060
android:text="ColorPickerDialog Example"
61+
android:layout_gravity="center"
6162
android:textColor="@android:color/white"
6263
android:textSize="21sp"
6364
android:textStyle="bold" />
@@ -73,7 +74,7 @@
7374
android:layout_height="0dp"
7475
android:layout_weight="1"
7576
android:onClick="example2"
76-
app:button_duration="150"
77+
app:button_duration="110"
7778
app:button_scale="0.8"
7879
app:layout_backgroundColor="@color/background800"
7980
app:layout_round="20">
@@ -82,8 +83,8 @@
8283
android:layout_width="wrap_content"
8384
android:layout_height="wrap_content"
8485
android:layout_centerInParent="true"
85-
android:padding="5dp"
8686
android:text="ColorPreference Example"
87+
android:layout_gravity="center"
8788
android:textColor="@android:color/white"
8889
android:textSize="21sp"
8990
android:textStyle="bold" />

build.gradle

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
31
buildscript {
4-
5-
ext {
6-
supportLibrary = '28.0.0-rc02'
7-
}
8-
92
repositories {
103
google()
114
jcenter()
125
}
13-
146
dependencies {
15-
classpath "com.android.tools.build:gradle:3.3.0"
16-
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.16.0"
7+
classpath "com.android.tools.build:gradle:3.3.2"
8+
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.20.0"
179
classpath "com.novoda:bintray-release:0.9"
1810
}
1911
}

colorpickerpreference/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ android {
1414
}
1515

1616
dependencies {
17-
implementation "androidx.annotation:annotation:1.0.1"
17+
implementation "androidx.annotation:annotation:1.0.2"
18+
implementation "androidx.preference:preference:1.1.0-alpha04"
1819
}
1920

2021
apply from: '../spotless.gradle'

colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import android.content.res.TypedArray;
2323
import android.graphics.Color;
2424
import android.graphics.drawable.Drawable;
25-
import android.preference.Preference;
2625
import android.util.AttributeSet;
2726
import android.view.View;
27+
import androidx.preference.Preference;
28+
import androidx.preference.PreferenceViewHolder;
2829

2930
@SuppressWarnings("unused")
3031
public class ColorPickerPreference extends Preference {
@@ -85,9 +86,9 @@ private void onInit() {
8586
}
8687

8788
@Override
88-
protected void onBindView(View view) {
89-
super.onBindView(view);
90-
colorBox = view.findViewById(R.id.colorpicker_preference_colorbox);
89+
public void onBindViewHolder(PreferenceViewHolder holder) {
90+
super.onBindViewHolder(holder);
91+
colorBox = holder.findViewById(R.id.colorpicker_preference_colorbox);
9192
colorBox.setBackgroundColor(
9293
getPreferenceManager().getSharedPreferences().getInt(getKey(), default_color));
9394
}

0 commit comments

Comments
 (0)