From cf64ee370cae1de284086613fb722824cbfdb7f6 Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Sat, 4 Jun 2016 21:21:35 +0300 Subject: [PATCH 01/12] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a61dbc..7c12d15 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ In addition to all of those, I've disabled the truncating of the text of all the Import ====== -Via gradle (as shown here: https://jitpack.io/#AndroidDeveloperLB/MaterialPreferenceLibrary/7 ) : +Via gradle : allprojects { repositories { @@ -31,8 +31,12 @@ Via gradle (as shown here: https://jitpack.io/#AndroidDeveloperLB/MaterialPrefer } dependencies { - compile 'com.github.AndroidDeveloperLB:MaterialPreferenceLibrary:7' + compile 'com.github.AndroidDeveloperLB:MaterialPreferenceLibrary:###' } + +Where "###" is the number as shown here: https://jitpack.io/#AndroidDeveloperLB/MaterialPreferenceLibrary/ ). + + Sample ================================== From cbca43aa4677d567a7901996ab98dfbd7d89c627 Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Sat, 4 Jun 2016 21:21:56 +0300 Subject: [PATCH 02/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c12d15..0417edc 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Via gradle : compile 'com.github.AndroidDeveloperLB:MaterialPreferenceLibrary:###' } -Where "###" is the number as shown here: https://jitpack.io/#AndroidDeveloperLB/MaterialPreferenceLibrary/ ). +Where "###" is the number as shown here: https://jitpack.io/#AndroidDeveloperLB/MaterialPreferenceLibrary/ . From 8055eefe06830faef5910b249d889a49f0869888 Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Sat, 4 Jun 2016 21:22:07 +0300 Subject: [PATCH 03/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0417edc..ff4f889 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Via gradle : compile 'com.github.AndroidDeveloperLB:MaterialPreferenceLibrary:###' } -Where "###" is the number as shown here: https://jitpack.io/#AndroidDeveloperLB/MaterialPreferenceLibrary/ . +where "###" is the number as shown here: https://jitpack.io/#AndroidDeveloperLB/MaterialPreferenceLibrary/ . From 29f5df1c95195d37df80ab6e42fa5d4adc7af47f Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Wed, 22 Mar 2017 01:58:53 +0200 Subject: [PATCH 04/12] fixed issue of dialogMessage not used and shown updated all sdks. --- .idea/gradle.xml | 1 + .idea/misc.xml | 5 +- .idea/runConfigurations.xml | 12 + app/app.iml | 36 +- app/build.gradle | 10 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- material_preferences_library/build.gradle | 10 +- .../material_preferences_library.iml | 30 +- .../EditTextPreference.java | 326 ++++++++---------- .../mpl__edittext_dialog_preference.xml | 2 +- 11 files changed, 209 insertions(+), 229 deletions(-) create mode 100644 .idea/runConfigurations.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 1417f1b..c1f3a1a 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -12,6 +12,7 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index a889174..8f8b72d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + + - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index b7bb17d..b07213c 100644 --- a/app/app.iml +++ b/app/app.iml @@ -9,7 +9,6 @@ \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index e41a62c..210efe0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "23.0.3" + compileSdkVersion 25 + buildToolsVersion '25.0.2' defaultConfig { vectorDrawables.useSupportLibrary = true applicationId "com.lb.material_preferences" - minSdkVersion 7 - targetSdkVersion 23 + minSdkVersion 9 + targetSdkVersion 25 versionCode 1 versionName "1.0" } @@ -32,7 +32,7 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:23.4.0' + compile 'com.android.support:appcompat-v7:25.3.0' compile project(':material_preferences_library') // compile 'com.github.AndroidDeveloperLB:MaterialPreferenceLibrary:7' diff --git a/build.gradle b/build.gradle index 8d3667b..08a8621 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { // https://bintray.com/android/android-tools/com.android.tools.build.gradle/view - classpath 'com.android.tools.build:gradle:2.1.2' + classpath 'com.android.tools.build:gradle:2.3.0' // https://github.com/dcendents/android-maven-gradle-plugin classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7eacb9d..fe0c328 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Mar 05 10:37:58 IST 2016 +#Wed Mar 22 01:53:52 IST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/material_preferences_library/build.gradle b/material_preferences_library/build.gradle index d1879a6..b859ca2 100644 --- a/material_preferences_library/build.gradle +++ b/material_preferences_library/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "23.0.3" + compileSdkVersion 25 + buildToolsVersion '25.0.2' defaultConfig { vectorDrawables.useSupportLibrary = true - minSdkVersion 7 - targetSdkVersion 23 + minSdkVersion 9 + targetSdkVersion 25 versionCode 1 versionName "1.0" } @@ -25,5 +25,5 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:23.4.0' + compile 'com.android.support:appcompat-v7:25.3.0' } diff --git a/material_preferences_library/material_preferences_library.iml b/material_preferences_library/material_preferences_library.iml index 9d3b60b..5a80f7a 100644 --- a/material_preferences_library/material_preferences_library.iml +++ b/material_preferences_library/material_preferences_library.iml @@ -9,7 +9,6 @@ @@ -33,12 +32,14 @@ + + @@ -46,7 +47,6 @@ - @@ -54,7 +54,6 @@ - @@ -62,7 +61,6 @@ - @@ -70,7 +68,6 @@ - @@ -78,19 +75,17 @@ - - - + @@ -99,12 +94,17 @@ - + - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java index 9d82436..ef647e7 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java @@ -23,7 +23,6 @@ import android.os.Build.VERSION_CODES; import android.os.Parcel; import android.os.Parcelable; -import android.support.v7.app.AlertDialog.Builder; import android.support.v7.widget.AppCompatEditText; import android.text.TextUtils; import android.util.AttributeSet; @@ -46,44 +45,38 @@ * This preference will store a string into the SharedPreferences. *

*/ -public class EditTextPreference extends DialogPreference - { - /** - * The edit text shown in the dialog. - */ - private EditText mEditText; - - private String mText; - - @TargetApi(VERSION_CODES.LOLLIPOP) - public EditTextPreference(Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes) - { - super(context,attrs,defStyleAttr,defStyleRes); +public class EditTextPreference extends DialogPreference { + /** + * The edit text shown in the dialog. + */ + private EditText mEditText; + + private String mText; + + @TargetApi(VERSION_CODES.LOLLIPOP) + public EditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); } - public EditTextPreference(Context context,AttributeSet attrs,int defStyleAttr) - { - super(context,attrs,defStyleAttr); + public EditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); } - public EditTextPreference(Context context,AttributeSet attrs) - { - this(context,attrs,R.attr.editTextPreferenceStyle); + public EditTextPreference(Context context, AttributeSet attrs) { + this(context, attrs, R.attr.editTextPreferenceStyle); } - public EditTextPreference(Context context) - { - this(context,null); + public EditTextPreference(Context context) { + this(context, null); } - @Override - protected void init(final Context context,final AttributeSet attrs,final int defStyleAttr,final int defStyleRes) - { - super.init(context,attrs,defStyleAttr,defStyleRes); - mEditText=new AppCompatEditText(context,attrs); + @Override + protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { + super.init(context, attrs, defStyleAttr, defStyleRes); + mEditText = new AppCompatEditText(context, attrs); - // Give it an ID so it can be saved/restored - mEditText.setId(android.R.id.edit); + // Give it an ID so it can be saved/restored + mEditText.setId(android.R.id.edit); /* * The preference framework and view framework both have an 'enabled' @@ -91,188 +84,161 @@ protected void init(final Context context,final AttributeSet attrs,final int def * the preference framework, but it was also given to the view framework. * We reset the enabled state. */ - mEditText.setEnabled(true); - setDialogLayoutResource(R.layout.mpl__edittext_dialog_preference); + mEditText.setEnabled(true); + setDialogLayoutResource(R.layout.mpl__edittext_dialog_preference); } - /** - * Saves the text to the {@link SharedPreferences}. - * - * @param text The text to save - */ - public void setText(String text) - { - final boolean wasBlocking=shouldDisableDependents(); + /** + * Saves the text to the {@link SharedPreferences}. + * + * @param text The text to save + */ + public void setText(String text) { + final boolean wasBlocking = shouldDisableDependents(); - mText=text; + mText = text; - persistString(text); + persistString(text); - final boolean isBlocking=shouldDisableDependents(); - if(isBlocking!=wasBlocking) - { - notifyDependencyChange(isBlocking); - } + final boolean isBlocking = shouldDisableDependents(); + if (isBlocking != wasBlocking) { + notifyDependencyChange(isBlocking); + } } - /** - * Gets the text from the {@link SharedPreferences}. - * - * @return The current preference value. - */ - public String getText() - { - return mText; + /** + * Gets the text from the {@link SharedPreferences}. + * + * @return The current preference value. + */ + public String getText() { + return mText; } - @Override - protected void onBindDialogView(View view) - { - super.onBindDialogView(view); - - EditText editText=mEditText; - editText.setText(getText()); - - ViewParent oldParent=editText.getParent(); - if(oldParent!=view) - { - if(oldParent!=null) - { - ((ViewGroup)oldParent).removeView(editText); + @Override + protected void onBindDialogView(View view) { + super.onBindDialogView(view); + + EditText editText = mEditText; + editText.setText(getText()); + + ViewParent oldParent = editText.getParent(); + if (oldParent != view) { + if (oldParent != null) { + ((ViewGroup) oldParent).removeView(editText); + } + onAddEditTextToDialogView(view, editText); } - onAddEditTextToDialogView(view,editText); - } } - /** - * Adds the EditText widget of this preference to the dialog's view. - * - * @param dialogView The dialog view. - */ - protected void onAddEditTextToDialogView(View dialogView,EditText editText) - { - ViewGroup container=(ViewGroup)dialogView - .findViewById(R.id.edittext_container); - if(container!=null) - { - container.addView(editText,ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT); - } + /** + * Adds the EditText widget of this preference to the dialog's view. + * + * @param dialogView The dialog view. + */ + protected void onAddEditTextToDialogView(View dialogView, EditText editText) { + ViewGroup container = (ViewGroup) dialogView + .findViewById(R.id.edittext_container); + if (container != null) { + container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT); + } } - @Override - protected void onDialogClosed(boolean positiveResult) - { - super.onDialogClosed(positiveResult); - if(positiveResult) - { - String value=mEditText.getText().toString(); - if(callChangeListener(value)) - { - setText(value); + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + if (positiveResult) { + String value = mEditText.getText().toString(); + if (callChangeListener(value)) { + setText(value); + } } - } } - @Override - protected Object onGetDefaultValue(TypedArray a,int index) - { - return a.getString(index); + @Override + protected Object onGetDefaultValue(TypedArray a, int index) { + return a.getString(index); } - @Override - protected void onSetInitialValue(boolean restoreValue,Object defaultValue) - { - setText(restoreValue?getPersistedString(mText):(String)defaultValue); + @Override + protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { + setText(restoreValue ? getPersistedString(mText) : (String) defaultValue); } - @Override - public boolean shouldDisableDependents() - { - return TextUtils.isEmpty(mText)||super.shouldDisableDependents(); + @Override + public boolean shouldDisableDependents() { + return TextUtils.isEmpty(mText) || super.shouldDisableDependents(); } - /** - * Returns the {@link EditText} widget that will be shown in the dialog. - * - * @return The {@link EditText} widget that will be shown in the dialog. - */ - public EditText getEditText() - { - return mEditText; + /** + * Returns the {@link EditText} widget that will be shown in the dialog. + * + * @return The {@link EditText} widget that will be shown in the dialog. + */ + public EditText getEditText() { + return mEditText; } - protected boolean needInputMethod() - { - // We want the input method to show, if possible, when dialog is displayed - return true; + protected boolean needInputMethod() { + // We want the input method to show, if possible, when dialog is displayed + return true; } - @Override - protected Parcelable onSaveInstanceState() - { - final Parcelable superState=super.onSaveInstanceState(); - if(isPersistent()) - { - // No need to save instance state since it's persistent - return superState; - } - - final SavedState myState=new SavedState(superState); - myState.text=getText(); - return myState; + @Override + protected Parcelable onSaveInstanceState() { + final Parcelable superState = super.onSaveInstanceState(); + if (isPersistent()) { + // No need to save instance state since it's persistent + return superState; + } + + final SavedState myState = new SavedState(superState); + myState.text = getText(); + return myState; } - @Override - protected void onRestoreInstanceState(Parcelable state) - { - if(state==null||!state.getClass().equals(SavedState.class)) - { - // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state); - return; - } - - SavedState myState=(SavedState)state; - super.onRestoreInstanceState(myState.getSuperState()); - setText(myState.text); + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (state == null || !state.getClass().equals(SavedState.class)) { + // Didn't save state for us in onSaveInstanceState + super.onRestoreInstanceState(state); + return; + } + + SavedState myState = (SavedState) state; + super.onRestoreInstanceState(myState.getSuperState()); + setText(myState.text); } - private static class SavedState extends BaseSavedState - { - String text; + private static class SavedState extends BaseSavedState { + String text; + + public SavedState(Parcel source) { + super(source); + text = source.readString(); + } - public SavedState(Parcel source) - { - super(source); - text=source.readString(); - } + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeString(text); + } - @Override - public void writeToParcel(Parcel dest,int flags) - { - super.writeToParcel(dest,flags); - dest.writeString(text); - } - - public SavedState(Parcelable superState) - { - super(superState); - } - - public static final Creator CREATOR= - new Creator() - { - public SavedState createFromParcel(Parcel in) - { - return new SavedState(in); - } - - public SavedState[] newArray(int size) - { - return new SavedState[size]; - } - }; + public SavedState(Parcelable superState) { + super(superState); + } + + public static final Creator CREATOR = + new Creator() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; } - } +} diff --git a/material_preferences_library/src/main/res/layout/mpl__edittext_dialog_preference.xml b/material_preferences_library/src/main/res/layout/mpl__edittext_dialog_preference.xml index bc568ea..b6eb113 100644 --- a/material_preferences_library/src/main/res/layout/mpl__edittext_dialog_preference.xml +++ b/material_preferences_library/src/main/res/layout/mpl__edittext_dialog_preference.xml @@ -30,7 +30,7 @@ android:padding="20dp"> Date: Wed, 14 Mar 2018 22:37:52 +0200 Subject: [PATCH 05/12] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ff4f889..d3b69e8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Release](https://img.shields.io/github/release/AndroidDeveloperLB/MaterialPreferenceLibrary.svg?style=flat)](https://jitpack.io/#AndroidDeveloperLB/MaterialPreferenceLibrary) + MaterialPreferenceLibrary ================================== From 9ec5f2d491560f82fc7c92669e19feabe27b9aee Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Fri, 16 Mar 2018 00:56:49 +0200 Subject: [PATCH 06/12] updated sdks --- .idea/assetWizardSettings.xml | 47 + .idea/caches/build_file_checksums.ser | Bin 0 -> 606 bytes .idea/codeStyles/Project.xml | 29 + .idea/compiler.xml | 22 - .idea/copyright/profiles_settings.xml | 3 - .idea/misc.xml | 38 +- MaterialPreferenceLibrary.iml | 2 +- app/app.iml | 80 +- app/build.gradle | 14 +- .../SettingsActivity.java | 165 ++-- .../drawable-nodpi/ic_brush_black_24dp.xml | 5 + build.gradle | 6 +- gradle/wrapper/gradle-wrapper.properties | 4 +- material_preferences_library/build.gradle | 11 +- .../material_preferences_library.iml | 60 +- .../PreferenceActivity.java | 121 ++- .../CheckBoxPreference.java | 59 +- .../custom_preferences/DialogPreference.java | 858 ++++++++---------- .../custom_preferences/ListPreference.java | 525 +++++------ .../custom_preferences/Preference.java | 187 ++-- .../PreferenceManagerEx.java | 92 +- .../custom_preferences/SwitchPreference.java | 290 +++--- .../TwoStatePreference.java | 447 +++++---- .../internal/widget/PreferenceImageView.java | 112 +-- 24 files changed, 1489 insertions(+), 1688 deletions(-) create mode 100644 .idea/assetWizardSettings.xml create mode 100644 .idea/caches/build_file_checksums.ser create mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 app/src/main/res/drawable-nodpi/ic_brush_black_24dp.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..9bc2c88 --- /dev/null +++ b/.idea/assetWizardSettings.xml @@ -0,0 +1,47 @@ + + + + + + \ No newline at end of file diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000000000000000000000000000000000000..ddefbcae04cf19b444bd91f297f3af0c9c9d796b GIT binary patch literal 606 zcmZ4UmVvdnh`~NNKUXg?FQq6yGexf?KR>5fFEb@IQ7^qHF(oHeub?PDD>b=9F91S2 zm1gFoxMk*~I%lLNXBU^|7Q2L-Ts|(GuF1r}nf0c16UfOzUdzUjYrNwDiK-jgFf!4&Ak z;?$Co%)Insn8reeItDh7+Om(Yzn|U7(P3ecSDyU$WLpV?y0cYGXmM&$aZD+YjDhNi zK?Gz$YEemMYH=ytj4QG|H~SejvAk^Hobl#|Q(XxI4~i?{3LE!66xy)xQE};S>t83r zL`s2P%E?bo%mGCYhN=DY6c$FEoxy*`BqM46t(dM72F={WlGLKi#GLqoqSUn1qSU

MDCRW}5(QnpHzFbLxDiFSB2Lz&(x<)(SH{^lP- HepUbgSVh&x literal 0 HcmV?d00001 diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8f8b72d..df29872 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - - - - + - - - - - 1.8 - - - - - - - \ No newline at end of file diff --git a/MaterialPreferenceLibrary.iml b/MaterialPreferenceLibrary.iml index 00e3c31..49048d8 100644 --- a/MaterialPreferenceLibrary.iml +++ b/MaterialPreferenceLibrary.iml @@ -1,5 +1,5 @@ - + diff --git a/app/app.iml b/app/app.iml index b07213c..beede04 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -22,25 +22,26 @@ - - - + + + + - + - + @@ -55,6 +56,13 @@ + + + + + + + @@ -62,13 +70,6 @@ - - - - - - - @@ -76,42 +77,49 @@ + + + + + + + + - - + - - - - - - + + - + - - + - + - - - - - - - - - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 210efe0..3cfccbf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,16 +1,16 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 27 defaultConfig { vectorDrawables.useSupportLibrary = true applicationId "com.lb.material_preferences" - minSdkVersion 9 - targetSdkVersion 25 + minSdkVersion 14 + targetSdkVersion 27 versionCode 1 versionName "1.0" + vectorDrawables.useSupportLibrary = true } buildTypes { release { @@ -31,9 +31,9 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:25.3.0' - compile project(':material_preferences_library') + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:27.1.0' + implementation project(':material_preferences_library') // compile 'com.github.AndroidDeveloperLB:MaterialPreferenceLibrary:7' } diff --git a/app/src/main/java/com/lb/material_preferences/SettingsActivity.java b/app/src/main/java/com/lb/material_preferences/SettingsActivity.java index 13d9222..1144041 100644 --- a/app/src/main/java/com/lb/material_preferences/SettingsActivity.java +++ b/app/src/main/java/com/lb/material_preferences/SettingsActivity.java @@ -6,7 +6,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceManager; @@ -21,112 +20,84 @@ import java.util.ArrayList; import java.util.List; -public class SettingsActivity extends PreferenceActivity - { +public class SettingsActivity extends PreferenceActivity { - @Override - protected void onCreate(final Bundle savedInstanceState) - { - final String themePrefKey=getString(R.string.pref_theme), defaultTheme=getResources().getString(R.string.pref_theme_default); - final String theme=PreferenceManager.getDefaultSharedPreferences(this).getString(themePrefKey,defaultTheme); - switch(theme) - { - case "dark": - setTheme(R.style.AppTheme_Dark); - break; - case "light": - setTheme(R.style.AppTheme_Light); - break; - } - super.onCreate(savedInstanceState); - ListPreference themeListPreference=(ListPreference)findPreference(getString(R.string.pref_theme)); - themeListPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() - { @Override - public boolean onPreferenceChange(final Preference preference,final Object newValue) - { - restartActivity(SettingsActivity.this); - return true; - } - }); - handleActionBarMenu(); + protected void onCreate(final Bundle savedInstanceState) { + final String themePrefKey = getString(R.string.pref_theme), defaultTheme = getResources().getString(R.string.pref_theme_default); + final String theme = PreferenceManager.getDefaultSharedPreferences(this).getString(themePrefKey, defaultTheme); + switch (theme) { + case "dark": + setTheme(R.style.AppTheme_Dark); + break; + case "light": + setTheme(R.style.AppTheme_Light); + break; + } + super.onCreate(savedInstanceState); + ListPreference themeListPreference = (ListPreference) findPreference(getString(R.string.pref_theme)); + themeListPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(final Preference preference, final Object newValue) { + restartActivity(SettingsActivity.this); + return true; + } + }); + handleActionBarMenu(); } - private void handleActionBarMenu() - { - getToolbar().inflateMenu(R.menu.activity_main); - final OnMenuItemClickListener onMenuItemClickListener=new OnMenuItemClickListener() - { - @Override - public boolean onMenuItemClick(final MenuItem item) - { - String url=null; - switch(item.getItemId()) - { - case R.id.menuItem_all_my_apps: - url="https://play.google.com/store/apps/developer?id=AndroidDeveloperLB"; - break; - case R.id.menuItem_all_my_repositories: - url="https://github.com/AndroidDeveloperLB"; - break; - case R.id.menuItem_current_repository_website: - url="https://github.com/AndroidDeveloperLB/MaterialPreferenceLibrary"; - break; - } - if(url==null) - return true; - final Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse(url)); - intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - startActivity(intent); - return true; - } - }; - setOnMenuItemClickListenerRecursive(getToolbar().getMenu(),onMenuItemClickListener); + private void handleActionBarMenu() { + getToolbar().inflateMenu(R.menu.activity_main); + final OnMenuItemClickListener onMenuItemClickListener = new OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(final MenuItem item) { + String url = null; + switch (item.getItemId()) { + case R.id.menuItem_all_my_apps: + url = "https://play.google.com/store/apps/developer?id=AndroidDeveloperLB"; + break; + case R.id.menuItem_all_my_repositories: + url = "https://github.com/AndroidDeveloperLB"; + break; + case R.id.menuItem_current_repository_website: + url = "https://github.com/AndroidDeveloperLB/MaterialPreferenceLibrary"; + break; + } + if (url == null) + return true; + final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); + startActivity(intent); + return true; + } + }; + setOnMenuItemClickListenerRecursive(getToolbar().getMenu(), onMenuItemClickListener); } - private static void setOnMenuItemClickListenerRecursive(Menu menu,OnMenuItemClickListener listener) - { - List

menus=new ArrayList<>(1); - menus.add(menu); - while(!menus.isEmpty()) - { - final Menu currentMenu=menus.remove(0); - for(int i=0;i menus = new ArrayList<>(1); + menus.add(menu); + while (!menus.isEmpty()) { + final Menu currentMenu = menus.remove(0); + for (int i = 0; i < currentMenu.size(); ++i) { + final MenuItem item = currentMenu.getItem(i); + item.setOnMenuItemClickListener(listener); + final SubMenu subMenu = item.getSubMenu(); + if (subMenu != null) + menus.add(subMenu); + } } - } } - @Override - protected int getPreferencesXmlId() - { - return R.xml.settings_example; + @Override + protected int getPreferencesXmlId() { + return R.xml.settings_example; } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static void restartActivity(final Activity activity) - { - if(android.os.Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) - activity.recreate(); - else - { - new Handler().post(new Runnable() - { - @Override - public void run() - { - activity.overridePendingTransition(0,0); - activity.startActivity(activity.getIntent()); - } - }); - activity.finish(); - } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public static void restartActivity(final Activity activity) { + activity.recreate(); } - } +} diff --git a/app/src/main/res/drawable-nodpi/ic_brush_black_24dp.xml b/app/src/main/res/drawable-nodpi/ic_brush_black_24dp.xml new file mode 100644 index 0000000..f156118 --- /dev/null +++ b/app/src/main/res/drawable-nodpi/ic_brush_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/build.gradle b/build.gradle index 08a8621..0e4cfad 100644 --- a/build.gradle +++ b/build.gradle @@ -3,12 +3,13 @@ buildscript { repositories { jcenter() + google() } dependencies { // https://bintray.com/android/android-tools/com.android.tools.build.gradle/view - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:3.2.0-alpha06' // https://github.com/dcendents/android-maven-gradle-plugin - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' +// classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -17,5 +18,6 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fe0c328..cd91197 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Mar 22 01:53:52 IST 2017 +#Tue Mar 13 22:57:36 IST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip diff --git a/material_preferences_library/build.gradle b/material_preferences_library/build.gradle index b859ca2..33beb6a 100644 --- a/material_preferences_library/build.gradle +++ b/material_preferences_library/build.gradle @@ -1,13 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 27 defaultConfig { vectorDrawables.useSupportLibrary = true - minSdkVersion 9 - targetSdkVersion 25 + minSdkVersion 14 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -24,6 +23,6 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:25.3.0' + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:27.1.0' } diff --git a/material_preferences_library/material_preferences_library.iml b/material_preferences_library/material_preferences_library.iml index 5a80f7a..802fbc7 100644 --- a/material_preferences_library/material_preferences_library.iml +++ b/material_preferences_library/material_preferences_library.iml @@ -1,5 +1,5 @@ - + @@ -23,25 +23,26 @@ - - - + + + + - + - + @@ -56,6 +57,13 @@ + + + + + + + @@ -77,15 +85,18 @@ - - - - + + + - + + + + + @@ -94,17 +105,22 @@ - + - - - - - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java index 15dedc3..df6d80e 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java @@ -1,4 +1,5 @@ package com.lb.material_preferences_library; + import android.app.Activity; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; @@ -16,79 +17,71 @@ import java.util.Map; import java.util.Stack; -public abstract class PreferenceActivity extends AppCompatPreferenceActivity - { - private Toolbar _toolbar; +public abstract class PreferenceActivity extends AppCompatPreferenceActivity { + private Toolbar _toolbar; - /** this should return the R.xml.menu file of the preferenceActivity */ - protected abstract - @XmlRes - int getPreferencesXmlId(); + /** + * this should return the R.xml.menu file of the preferenceActivity + */ + protected abstract + @XmlRes + int getPreferencesXmlId(); - public Toolbar getToolbar() - { - return _toolbar; + public Toolbar getToolbar() { + return _toolbar; } - @SuppressWarnings("deprecation") - @Override - protected void onCreate(final Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.mpl__preference_activity); - _toolbar=(Toolbar)findViewById(R.id.abp__toolbar); - if(VERSION.SDK_INT>=VERSION_CODES.LOLLIPOP) - { - View shadowView=findViewById(R.id.abp__shadowView); - final ViewGroup parent=(ViewGroup)shadowView.getParent(); - parent.removeView(shadowView); - } - addPreferencesFromResource(getPreferencesXmlId()); - final Map preferenceToParentMap=buildPreferenceParentTree(this); - for(PreferenceGroup preferenceGroup : preferenceToParentMap.values()) - if(preferenceGroup!=null&&preferenceGroup instanceof PreferenceScreen) - preferenceGroup.setLayoutResource(R.layout.mpl__preference); - _toolbar.setClickable(true); - _toolbar.setNavigationIcon(getResIdFromAttribute(this,R.attr.homeAsUpIndicator)); - _toolbar.setNavigationOnClickListener(new View.OnClickListener() - { + @SuppressWarnings("deprecation") @Override - public void onClick(final View v) - { - finish(); - } - }); - _toolbar.setTitle(getTitle()); + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.mpl__preference_activity); + _toolbar = (Toolbar) findViewById(R.id.abp__toolbar); + if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { + View shadowView = findViewById(R.id.abp__shadowView); + final ViewGroup parent = (ViewGroup) shadowView.getParent(); + parent.removeView(shadowView); + } + addPreferencesFromResource(getPreferencesXmlId()); + final Map preferenceToParentMap = buildPreferenceParentTree(this); + for (PreferenceGroup preferenceGroup : preferenceToParentMap.values()) + if (preferenceGroup != null && preferenceGroup instanceof PreferenceScreen) + preferenceGroup.setLayoutResource(R.layout.mpl__preference); + _toolbar.setClickable(true); + _toolbar.setNavigationIcon(getResIdFromAttribute(this, R.attr.homeAsUpIndicator)); + _toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View v) { + finish(); + } + }); + _toolbar.setTitle(getTitle()); } - private static int getResIdFromAttribute(final Activity activity,final int attr) - { - if(attr==0) - return 0; - final TypedValue typedValue=new TypedValue(); - activity.getTheme().resolveAttribute(attr,typedValue,true); - return typedValue.resourceId; + private static int getResIdFromAttribute(final Activity activity, final int attr) { + if (attr == 0) + return 0; + final TypedValue typedValue = new TypedValue(); + activity.getTheme().resolveAttribute(attr, typedValue, true); + return typedValue.resourceId; } - @SuppressWarnings("deprecation") - public static Map buildPreferenceParentTree(final android.preference.PreferenceActivity activity) - { - final Map result=new HashMap<>(); - final Stack curParents=new Stack<>(); - curParents.add(activity.getPreferenceScreen()); - while(!curParents.isEmpty()) - { - final PreferenceGroup parent=curParents.pop(); - final int childCount=parent.getPreferenceCount(); - for(int i=0;i buildPreferenceParentTree(final android.preference.PreferenceActivity activity) { + final Map result = new HashMap<>(); + final Stack curParents = new Stack<>(); + curParents.add(activity.getPreferenceScreen()); + while (!curParents.isEmpty()) { + final PreferenceGroup parent = curParents.pop(); + final int childCount = parent.getPreferenceCount(); + for (int i = 0; i < childCount; ++i) { + final Preference child = parent.getPreference(i); + result.put(child, parent); + if (child instanceof PreferenceGroup) + curParents.push((PreferenceGroup) child); + } } - } - return result; + return result; } - } +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/CheckBoxPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/CheckBoxPreference.java index b1c5c99..f624fb8 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/CheckBoxPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/CheckBoxPreference.java @@ -34,48 +34,41 @@ * @attr ref android.R.styleable#CheckBoxPreference_summaryOn * @attr ref android.R.styleable#CheckBoxPreference_disableDependentsState */ -public class CheckBoxPreference extends TwoStatePreference - { +public class CheckBoxPreference extends TwoStatePreference { - public CheckBoxPreference(Context context,AttributeSet attrs,int defStyleAttr) - { - super(context,attrs,defStyleAttr); + public CheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); } - public CheckBoxPreference(Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes) - { - super(context,attrs,defStyleAttr,defStyleRes); + public CheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); } - @Override - protected void init(final Context context,final AttributeSet attrs,final int defStyleAttr,final int defStyleRes) - { - super.init(context,attrs,defStyleAttr,defStyleRes); - setWidgetLayoutResource(R.layout.mpl__preference_widget_checkbox); - final TypedArray a=context.obtainStyledAttributes(attrs,R.styleable.CheckBoxPreference,defStyleAttr,defStyleRes); - setSummaryOn(a.getString(R.styleable.CheckBoxPreference_summaryOn)); - setSummaryOff(a.getString(R.styleable.CheckBoxPreference_summaryOff)); - setDisableDependentsState(a.getBoolean(R.styleable.CheckBoxPreference_disableDependentsState,false)); - a.recycle(); + @Override + protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { + super.init(context, attrs, defStyleAttr, defStyleRes); + setWidgetLayoutResource(R.layout.mpl__preference_widget_checkbox); + final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckBoxPreference, defStyleAttr, defStyleRes); + setSummaryOn(a.getString(R.styleable.CheckBoxPreference_summaryOn)); + setSummaryOff(a.getString(R.styleable.CheckBoxPreference_summaryOff)); + setDisableDependentsState(a.getBoolean(R.styleable.CheckBoxPreference_disableDependentsState, false)); + a.recycle(); } - public CheckBoxPreference(Context context,AttributeSet attrs) - { - this(context,attrs,R.attr.checkBoxPreferenceStyle); + public CheckBoxPreference(Context context, AttributeSet attrs) { + this(context, attrs, R.attr.checkBoxPreferenceStyle); } - public CheckBoxPreference(Context context) - { - this(context,null); + public CheckBoxPreference(Context context) { + this(context, null); } - @Override - protected void onBindView(View view) - { - super.onBindView(view); - View checkboxView=view.findViewById(android.R.id.checkbox); - if(checkboxView!=null&&checkboxView instanceof Checkable) - ((Checkable)checkboxView).setChecked(mChecked); - syncSummaryView(view); + @Override + protected void onBindView(View view) { + super.onBindView(view); + View checkboxView = view.findViewById(android.R.id.checkbox); + if (checkboxView != null && checkboxView instanceof Checkable) + ((Checkable) checkboxView).setChecked(mChecked); + syncSummaryView(view); } - } +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/DialogPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/DialogPreference.java index 2693320..3996422 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/DialogPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/DialogPreference.java @@ -15,6 +15,7 @@ */ package com.lb.material_preferences_library.custom_preferences; + import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; @@ -51,500 +52,445 @@ */ public abstract class DialogPreference extends Preference implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, - PreferenceManager.OnActivityDestroyListener - { - private AlertDialog.Builder mBuilder; + PreferenceManager.OnActivityDestroyListener { + private AlertDialog.Builder mBuilder; - private CharSequence mDialogTitle; - private CharSequence mDialogMessage; - private Drawable mDialogIcon; - private CharSequence mPositiveButtonText; - private CharSequence mNegativeButtonText; - private int mDialogLayoutResId; + private CharSequence mDialogTitle; + private CharSequence mDialogMessage; + private Drawable mDialogIcon; + private CharSequence mPositiveButtonText; + private CharSequence mNegativeButtonText; + private int mDialogLayoutResId; - /** The dialog, if it is showing. */ - private Dialog mDialog; + /** + * The dialog, if it is showing. + */ + private Dialog mDialog; - /** Which button was clicked. */ - private int mWhichButtonClicked; + /** + * Which button was clicked. + */ + private int mWhichButtonClicked; - public DialogPreference( - Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes) - { - super(context,attrs,defStyleAttr,defStyleRes); + public DialogPreference( + Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); } - public DialogPreference(Context context,AttributeSet attrs,int defStyleAttr) - { - super(context,attrs,defStyleAttr); + public DialogPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); } - public DialogPreference(Context context,AttributeSet attrs) - { - this(context,attrs,R.attr.dialogPreferenceStyle); + public DialogPreference(Context context, AttributeSet attrs) { + this(context, attrs, R.attr.dialogPreferenceStyle); } - public DialogPreference(Context context) - { - this(context,null); + public DialogPreference(Context context) { + this(context, null); } - @Override - protected void init(final Context context,final AttributeSet attrs,final int defStyleAttr,final int defStyleRes) - { - super.init(context,attrs,defStyleAttr,defStyleRes); - final TypedArray a=context.obtainStyledAttributes(attrs, - R.styleable.DialogPreference,defStyleAttr,defStyleRes); - mDialogTitle=a.getString(R.styleable.DialogPreference_dialogTitle); - if(mDialogTitle==null) - { + @Override + protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { + super.init(context, attrs, defStyleAttr, defStyleRes); + final TypedArray a = context.obtainStyledAttributes(attrs, + R.styleable.DialogPreference, defStyleAttr, defStyleRes); + mDialogTitle = a.getString(R.styleable.DialogPreference_dialogTitle); + if (mDialogTitle == null) { // Fallback on the regular title of the preference // (the one that is seen in the list) - mDialogTitle=getTitle(); - } - - mDialogMessage=a.getString(R.styleable.DialogPreference_dialogMessage); - mDialogIcon=a.getDrawable(R.styleable.DialogPreference_dialogIcon); - mPositiveButtonText=a.getString(R.styleable.DialogPreference_positiveButtonText); - mNegativeButtonText=a.getString(R.styleable.DialogPreference_negativeButtonText); - mDialogLayoutResId=a.getResourceId(R.styleable.DialogPreference_dialogLayout,mDialogLayoutResId); - a.recycle(); - } - - /** - * Sets the title of the dialog. This will be shown on subsequent dialogs. - * - * @param dialogTitle The title. - */ - public void setDialogTitle(CharSequence dialogTitle) - { - mDialogTitle=dialogTitle; - } - - /** - * Returns the title to be shown on subsequent dialogs. - * - * @return The title. - */ - public CharSequence getDialogTitle() - { - return mDialogTitle; - } - - /** - * @param dialogTitleResId The dialog title as a resource. - * @see #setDialogTitle(CharSequence) - */ - public void setDialogTitle(int dialogTitleResId) - { - setDialogTitle(getContext().getString(dialogTitleResId)); - } - - /** - * Sets the message of the dialog. This will be shown on subsequent dialogs. - *

- * This message forms the content View of the dialog and conflicts with - * list-based dialogs, for example. If setting a custom View on a dialog via - * {@link #setDialogLayoutResource(int)}, include a text View with ID - * {@link android.R.id#message} and it will be populated with this message. - * - * @param dialogMessage The message. - */ - public void setDialogMessage(CharSequence dialogMessage) - { - mDialogMessage=dialogMessage; - } - - /** - * Returns the message to be shown on subsequent dialogs. - * - * @return The message. - */ - public CharSequence getDialogMessage() - { - return mDialogMessage; - } - - /** - * @param dialogMessageResId The dialog message as a resource. - * @see #setDialogMessage(CharSequence) - */ - public void setDialogMessage(int dialogMessageResId) - { - setDialogMessage(getContext().getString(dialogMessageResId)); - } - - /** - * Sets the icon of the dialog. This will be shown on subsequent dialogs. - * - * @param dialogIcon The icon, as a {@link Drawable}. - */ - public void setDialogIcon(Drawable dialogIcon) - { - mDialogIcon=dialogIcon; - } - - /** - * Returns the icon to be shown on subsequent dialogs. - * - * @return The icon, as a {@link Drawable}. - */ - public Drawable getDialogIcon() - { - return mDialogIcon; - } - - /** - * Sets the icon (resource ID) of the dialog. This will be shown on - * subsequent dialogs. - * - * @param dialogIconRes The icon, as a resource ID. - */ - public void setDialogIcon(int dialogIconRes) - { - mDialogIcon=ResourcesCompat.getDrawable(getContext().getResources(),dialogIconRes,null); - } - - /** - * Sets the text of the positive button of the dialog. This will be shown on - * subsequent dialogs. - * - * @param positiveButtonText The text of the positive button. - */ - public void setPositiveButtonText(CharSequence positiveButtonText) - { - mPositiveButtonText=positiveButtonText; - } - - /** - * Returns the text of the positive button to be shown on subsequent - * dialogs. - * - * @return The text of the positive button. - */ - public CharSequence getPositiveButtonText() - { - return mPositiveButtonText; - } - - /** - * @param positiveButtonTextResId The positive button text as a resource. - * @see #setPositiveButtonText(CharSequence) - */ - public void setPositiveButtonText(int positiveButtonTextResId) - { - setPositiveButtonText(getContext().getString(positiveButtonTextResId)); - } - - /** - * Sets the text of the negative button of the dialog. This will be shown on - * subsequent dialogs. - * - * @param negativeButtonText The text of the negative button. - */ - public void setNegativeButtonText(CharSequence negativeButtonText) - { - mNegativeButtonText=negativeButtonText; - } - - /** - * Returns the text of the negative button to be shown on subsequent - * dialogs. - * - * @return The text of the negative button. - */ - public CharSequence getNegativeButtonText() - { - return mNegativeButtonText; - } - - /** - * @param negativeButtonTextResId The negative button text as a resource. - * @see #setNegativeButtonText(CharSequence) - */ - public void setNegativeButtonText(int negativeButtonTextResId) - { - setNegativeButtonText(getContext().getString(negativeButtonTextResId)); - } - - /** - * Returns the layout resource that is used as the content View for - * subsequent dialogs. - * - * @return The layout resource. - */ - public int getDialogLayoutResource() - { - return mDialogLayoutResId; - } - - /** - * Sets the layout resource that is inflated as the {@link View} to be shown - * as the content View of subsequent dialogs. - * - * @param dialogLayoutResId The layout resource ID to be inflated. - * @see #setDialogMessage(CharSequence) - */ - public void setDialogLayoutResource(int dialogLayoutResId) - { - mDialogLayoutResId=dialogLayoutResId; - } - - /** - * Prepares the dialog builder to be shown when the preference is clicked. - * Use this to set custom properties on the dialog. - *

- * Do not {@link AlertDialog.Builder#create()} or - * {@link AlertDialog.Builder#show()}. - */ - protected void onPrepareDialogBuilder(AlertDialog.Builder builder) - { - } - - @Override - protected void onClick() - { - if(mDialog!=null&&mDialog.isShowing()) return; - - showDialog(null); - } - - /** - * Shows the dialog associated with this Preference. This is normally initiated - * automatically on clicking on the preference. Call this method if you need to - * show the dialog on some other event. - * - * @param state Optional instance state to restore on the dialog - */ - protected void showDialog(Bundle state) - { - Context context=getContext(); - - mWhichButtonClicked=DialogInterface.BUTTON_NEGATIVE; - mBuilder=new AlertDialog.Builder(context) - .setTitle(mDialogTitle) - .setIcon(mDialogIcon) - .setPositiveButton(mPositiveButtonText,this) - .setNegativeButton(mNegativeButtonText,this); - View contentView=onCreateDialogView(); - if(contentView!=null) - { - onBindDialogView(contentView); - mBuilder.setView(contentView); - } - else - { - mBuilder.setMessage(mDialogMessage); - } - - onPrepareDialogBuilder(mBuilder); - PreferenceManagerEx.getInstance().registerOnActivityDestroyListener(getPreferenceManager(),this); + mDialogTitle = getTitle(); + } + + mDialogMessage = a.getString(R.styleable.DialogPreference_dialogMessage); + mDialogIcon = a.getDrawable(R.styleable.DialogPreference_dialogIcon); + mPositiveButtonText = a.getString(R.styleable.DialogPreference_positiveButtonText); + mNegativeButtonText = a.getString(R.styleable.DialogPreference_negativeButtonText); + mDialogLayoutResId = a.getResourceId(R.styleable.DialogPreference_dialogLayout, mDialogLayoutResId); + a.recycle(); + } + + /** + * Sets the title of the dialog. This will be shown on subsequent dialogs. + * + * @param dialogTitle The title. + */ + public void setDialogTitle(CharSequence dialogTitle) { + mDialogTitle = dialogTitle; + } + + /** + * Returns the title to be shown on subsequent dialogs. + * + * @return The title. + */ + public CharSequence getDialogTitle() { + return mDialogTitle; + } + + /** + * @param dialogTitleResId The dialog title as a resource. + * @see #setDialogTitle(CharSequence) + */ + public void setDialogTitle(int dialogTitleResId) { + setDialogTitle(getContext().getString(dialogTitleResId)); + } + + /** + * Sets the message of the dialog. This will be shown on subsequent dialogs. + *

+ * This message forms the content View of the dialog and conflicts with + * list-based dialogs, for example. If setting a custom View on a dialog via + * {@link #setDialogLayoutResource(int)}, include a text View with ID + * {@link android.R.id#message} and it will be populated with this message. + * + * @param dialogMessage The message. + */ + public void setDialogMessage(CharSequence dialogMessage) { + mDialogMessage = dialogMessage; + } + + /** + * Returns the message to be shown on subsequent dialogs. + * + * @return The message. + */ + public CharSequence getDialogMessage() { + return mDialogMessage; + } + + /** + * @param dialogMessageResId The dialog message as a resource. + * @see #setDialogMessage(CharSequence) + */ + public void setDialogMessage(int dialogMessageResId) { + setDialogMessage(getContext().getString(dialogMessageResId)); + } + + /** + * Sets the icon of the dialog. This will be shown on subsequent dialogs. + * + * @param dialogIcon The icon, as a {@link Drawable}. + */ + public void setDialogIcon(Drawable dialogIcon) { + mDialogIcon = dialogIcon; + } + + /** + * Returns the icon to be shown on subsequent dialogs. + * + * @return The icon, as a {@link Drawable}. + */ + public Drawable getDialogIcon() { + return mDialogIcon; + } + + /** + * Sets the icon (resource ID) of the dialog. This will be shown on + * subsequent dialogs. + * + * @param dialogIconRes The icon, as a resource ID. + */ + public void setDialogIcon(int dialogIconRes) { + mDialogIcon = ResourcesCompat.getDrawable(getContext().getResources(), dialogIconRes, null); + } + + /** + * Sets the text of the positive button of the dialog. This will be shown on + * subsequent dialogs. + * + * @param positiveButtonText The text of the positive button. + */ + public void setPositiveButtonText(CharSequence positiveButtonText) { + mPositiveButtonText = positiveButtonText; + } + + /** + * Returns the text of the positive button to be shown on subsequent + * dialogs. + * + * @return The text of the positive button. + */ + public CharSequence getPositiveButtonText() { + return mPositiveButtonText; + } + + /** + * @param positiveButtonTextResId The positive button text as a resource. + * @see #setPositiveButtonText(CharSequence) + */ + public void setPositiveButtonText(int positiveButtonTextResId) { + setPositiveButtonText(getContext().getString(positiveButtonTextResId)); + } + + /** + * Sets the text of the negative button of the dialog. This will be shown on + * subsequent dialogs. + * + * @param negativeButtonText The text of the negative button. + */ + public void setNegativeButtonText(CharSequence negativeButtonText) { + mNegativeButtonText = negativeButtonText; + } + + /** + * Returns the text of the negative button to be shown on subsequent + * dialogs. + * + * @return The text of the negative button. + */ + public CharSequence getNegativeButtonText() { + return mNegativeButtonText; + } + + /** + * @param negativeButtonTextResId The negative button text as a resource. + * @see #setNegativeButtonText(CharSequence) + */ + public void setNegativeButtonText(int negativeButtonTextResId) { + setNegativeButtonText(getContext().getString(negativeButtonTextResId)); + } + + /** + * Returns the layout resource that is used as the content View for + * subsequent dialogs. + * + * @return The layout resource. + */ + public int getDialogLayoutResource() { + return mDialogLayoutResId; + } + + /** + * Sets the layout resource that is inflated as the {@link View} to be shown + * as the content View of subsequent dialogs. + * + * @param dialogLayoutResId The layout resource ID to be inflated. + * @see #setDialogMessage(CharSequence) + */ + public void setDialogLayoutResource(int dialogLayoutResId) { + mDialogLayoutResId = dialogLayoutResId; + } + + /** + * Prepares the dialog builder to be shown when the preference is clicked. + * Use this to set custom properties on the dialog. + *

+ * Do not {@link AlertDialog.Builder#create()} or + * {@link AlertDialog.Builder#show()}. + */ + protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { + } + + @Override + protected void onClick() { + if (mDialog != null && mDialog.isShowing()) return; + + showDialog(null); + } + + /** + * Shows the dialog associated with this Preference. This is normally initiated + * automatically on clicking on the preference. Call this method if you need to + * show the dialog on some other event. + * + * @param state Optional instance state to restore on the dialog + */ + protected void showDialog(Bundle state) { + Context context = getContext(); + + mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE; + mBuilder = new AlertDialog.Builder(context) + .setTitle(mDialogTitle) + .setIcon(mDialogIcon) + .setPositiveButton(mPositiveButtonText, this) + .setNegativeButton(mNegativeButtonText, this); + View contentView = onCreateDialogView(); + if (contentView != null) { + onBindDialogView(contentView); + mBuilder.setView(contentView); + } else { + mBuilder.setMessage(mDialogMessage); + } + + onPrepareDialogBuilder(mBuilder); + PreferenceManagerEx.getInstance().registerOnActivityDestroyListener(getPreferenceManager(), this); // Create the dialog - final Dialog dialog=mDialog=mBuilder.create(); - if(state!=null) - { - dialog.onRestoreInstanceState(state); - } - if(needInputMethod()) - { - requestInputMethod(dialog); - } - dialog.setOnDismissListener(this); - dialog.show(); - } - - /** - * Returns whether the preference needs to display a soft input method when the dialog - * is displayed. Default is false. Subclasses should override this method if they need - * the soft input method brought up automatically. - * - * @hide - */ - protected boolean needInputMethod() - { - return false; - } - - /** - * Sets the required flags on the dialog window to enable input method window to show up. - */ - private void requestInputMethod(Dialog dialog) - { - Window window=dialog.getWindow(); - window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); - } - - /** - * Creates the content view for the dialog (if a custom content view is - * required). By default, it inflates the dialog layout resource if it is - * set. - * - * @return The content View for the dialog. - * @see #setLayoutResource(int) - */ - protected View onCreateDialogView() - { - if(mDialogLayoutResId==0) - { - return null; - } - - LayoutInflater inflater=LayoutInflater.from(mBuilder.getContext()); - return inflater.inflate(mDialogLayoutResId,null); - } - - /** - * Binds views in the content View of the dialog to data. - *

- * Make sure to call through to the superclass implementation. - * - * @param view The content View of the dialog, if it is custom. - */ - protected void onBindDialogView(View view) - { - View dialogMessageView=view.findViewById(android.R.id.message); - - if(dialogMessageView!=null) - { - final CharSequence message=getDialogMessage(); - int newVisibility=View.GONE; - - if(!TextUtils.isEmpty(message)) - { - if(dialogMessageView instanceof TextView) - { - ((TextView)dialogMessageView).setText(message); - } - - newVisibility=View.VISIBLE; + final Dialog dialog = mDialog = mBuilder.create(); + if (state != null) { + dialog.onRestoreInstanceState(state); + } + if (needInputMethod()) { + requestInputMethod(dialog); } + dialog.setOnDismissListener(this); + dialog.show(); + } + + /** + * Returns whether the preference needs to display a soft input method when the dialog + * is displayed. Default is false. Subclasses should override this method if they need + * the soft input method brought up automatically. + * + * @hide + */ + protected boolean needInputMethod() { + return false; + } + + /** + * Sets the required flags on the dialog window to enable input method window to show up. + */ + private void requestInputMethod(Dialog dialog) { + Window window = dialog.getWindow(); + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + } + + /** + * Creates the content view for the dialog (if a custom content view is + * required). By default, it inflates the dialog layout resource if it is + * set. + * + * @return The content View for the dialog. + * @see #setLayoutResource(int) + */ + protected View onCreateDialogView() { + if (mDialogLayoutResId == 0) { + return null; + } + + LayoutInflater inflater = LayoutInflater.from(mBuilder.getContext()); + return inflater.inflate(mDialogLayoutResId, null); + } + + /** + * Binds views in the content View of the dialog to data. + *

+ * Make sure to call through to the superclass implementation. + * + * @param view The content View of the dialog, if it is custom. + */ + protected void onBindDialogView(View view) { + View dialogMessageView = view.findViewById(android.R.id.message); + + if (dialogMessageView != null) { + final CharSequence message = getDialogMessage(); + int newVisibility = View.GONE; + + if (!TextUtils.isEmpty(message)) { + if (dialogMessageView instanceof TextView) { + ((TextView) dialogMessageView).setText(message); + } - if(dialogMessageView.getVisibility()!=newVisibility) - { - dialogMessageView.setVisibility(newVisibility); + newVisibility = View.VISIBLE; + } + + if (dialogMessageView.getVisibility() != newVisibility) { + dialogMessageView.setVisibility(newVisibility); + } } - } } - public void onClick(DialogInterface dialog,int which) - { - mWhichButtonClicked=which; + public void onClick(DialogInterface dialog, int which) { + mWhichButtonClicked = which; } - public void onDismiss(DialogInterface dialog) - { - PreferenceManagerEx.getInstance().unregisterOnActivityDestroyListener(getPreferenceManager(),this); + public void onDismiss(DialogInterface dialog) { + PreferenceManagerEx.getInstance().unregisterOnActivityDestroyListener(getPreferenceManager(), this); - mDialog=null; - onDialogClosed(mWhichButtonClicked==DialogInterface.BUTTON_POSITIVE); + mDialog = null; + onDialogClosed(mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE); } - /** - * Called when the dialog is dismissed and should be used to save data to - * the {@link SharedPreferences}. - * - * @param positiveResult Whether the positive button was clicked (true), or - * the negative button was clicked or the dialog was canceled (false). - */ - protected void onDialogClosed(boolean positiveResult) - { + /** + * Called when the dialog is dismissed and should be used to save data to + * the {@link SharedPreferences}. + * + * @param positiveResult Whether the positive button was clicked (true), or + * the negative button was clicked or the dialog was canceled (false). + */ + protected void onDialogClosed(boolean positiveResult) { } - /** - * Gets the dialog that is shown by this preference. - * - * @return The dialog, or null if a dialog is not being shown. - */ - public Dialog getDialog() - { - return mDialog; + /** + * Gets the dialog that is shown by this preference. + * + * @return The dialog, or null if a dialog is not being shown. + */ + public Dialog getDialog() { + return mDialog; } - /** - * {@inheritDoc} - */ - public void onActivityDestroy() - { + /** + * {@inheritDoc} + */ + public void onActivityDestroy() { - if(mDialog==null||!mDialog.isShowing()) - { - return; - } + if (mDialog == null || !mDialog.isShowing()) { + return; + } - mDialog.dismiss(); + mDialog.dismiss(); } - @Override - protected Parcelable onSaveInstanceState() - { - final Parcelable superState=super.onSaveInstanceState(); - if(mDialog==null||!mDialog.isShowing()) - { - return superState; - } + @Override + protected Parcelable onSaveInstanceState() { + final Parcelable superState = super.onSaveInstanceState(); + if (mDialog == null || !mDialog.isShowing()) { + return superState; + } - final SavedState myState=new SavedState(superState); - myState.isDialogShowing=true; - myState.dialogBundle=mDialog.onSaveInstanceState(); - return myState; + final SavedState myState = new SavedState(superState); + myState.isDialogShowing = true; + myState.dialogBundle = mDialog.onSaveInstanceState(); + return myState; } - @Override - protected void onRestoreInstanceState(Parcelable state) - { - if(state==null||!state.getClass().equals(SavedState.class)) - { + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (state == null || !state.getClass().equals(SavedState.class)) { // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state); - return; - } - - SavedState myState=(SavedState)state; - super.onRestoreInstanceState(myState.getSuperState()); - if(myState.isDialogShowing) - { - showDialog(myState.dialogBundle); - } - } - - private static class SavedState extends BaseSavedState - { - public static final Parcelable.Creator CREATOR= - new Parcelable.Creator() - { - public SavedState createFromParcel(Parcel in) - { - return new SavedState(in); - } - - public SavedState[] newArray(int size) - { - return new SavedState[size]; - } - }; - boolean isDialogShowing; - Bundle dialogBundle; - - public SavedState(Parcel source) - { - super(source); - isDialogShowing=source.readInt()==1; - dialogBundle=source.readBundle(); - } - - public SavedState(Parcelable superState) - { - super(superState); - } + super.onRestoreInstanceState(state); + return; + } - @Override - public void writeToParcel(Parcel dest,int flags) - { - super.writeToParcel(dest,flags); - dest.writeInt(isDialogShowing?1:0); - dest.writeBundle(dialogBundle); - } + SavedState myState = (SavedState) state; + super.onRestoreInstanceState(myState.getSuperState()); + if (myState.isDialogShowing) { + showDialog(myState.dialogBundle); + } + } + + private static class SavedState extends BaseSavedState { + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + boolean isDialogShowing; + Bundle dialogBundle; + + public SavedState(Parcel source) { + super(source); + isDialogShowing = source.readInt() == 1; + dialogBundle = source.readBundle(); + } + + public SavedState(Parcelable superState) { + super(superState); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(isDialogShowing ? 1 : 0); + dest.writeBundle(dialogBundle); + } } - } +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/ListPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/ListPreference.java index e98c7f5..62085db 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/ListPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/ListPreference.java @@ -38,44 +38,38 @@ * @attr ref android.R.styleable#ListPreference_entries * @attr ref android.R.styleable#ListPreference_entryValues */ -public class ListPreference extends DialogPreference - { - private CharSequence[] mEntries; - private CharSequence[] mEntryValues; - private String mValue; - private String mSummary; - private int mClickedDialogEntryIndex; - private boolean mValueSet; - - public ListPreference(Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes) - { - super(context,attrs,defStyleAttr,defStyleRes); +public class ListPreference extends DialogPreference { + private CharSequence[] mEntries; + private CharSequence[] mEntryValues; + private String mValue; + private String mSummary; + private int mClickedDialogEntryIndex; + private boolean mValueSet; + + public ListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); } - public ListPreference(Context context,AttributeSet attrs,int defStyleAttr) - { - super(context,attrs,defStyleAttr); + public ListPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); } - public ListPreference(Context context,AttributeSet attrs) - { - this(context,attrs,R.attr.dialogPreferenceStyle); + public ListPreference(Context context, AttributeSet attrs) { + this(context, attrs, R.attr.dialogPreferenceStyle); } - public ListPreference(Context context) - { - this(context,null); + public ListPreference(Context context) { + this(context, null); } - @Override - protected void init(final Context context,final AttributeSet attrs,final int defStyleAttr,final int defStyleRes) - { - super.init(context,attrs,defStyleAttr,defStyleRes); - TypedArray a=context.obtainStyledAttributes( - attrs,R.styleable.ListPreference,defStyleAttr,defStyleRes); - mEntries=a.getTextArray(R.styleable.ListPreference_entries); - mEntryValues=a.getTextArray(R.styleable.ListPreference_entryValues); - a.recycle(); + @Override + protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { + super.init(context, attrs, defStyleAttr, defStyleRes); + TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes); + mEntries = a.getTextArray(R.styleable.ListPreference_entries); + mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues); + a.recycle(); /* Retrieve the Preference summary attribute since it's private * in the Preference class. @@ -84,207 +78,182 @@ protected void init(final Context context,final AttributeSet attrs,final int def // R.styleable.Preference,defStyleAttr,defStyleRes); // mSummary=a.getString(R.styleable.Preference_summary); // a.recycle(); - mSummary=super.getSummary()==null?null:super.getSummary().toString(); + mSummary = super.getSummary() == null ? null : super.getSummary().toString(); } - /** - * Sets the human-readable entries to be shown in the list. This will be - * shown in subsequent dialogs. - *

- * Each entry must have a corresponding index in - * {@link #setEntryValues(CharSequence[])}. - * - * @param entries The entries. - * @see #setEntryValues(CharSequence[]) - */ - public void setEntries(CharSequence[] entries) - { - mEntries=entries; + /** + * Sets the human-readable entries to be shown in the list. This will be + * shown in subsequent dialogs. + *

+ * Each entry must have a corresponding index in + * {@link #setEntryValues(CharSequence[])}. + * + * @param entries The entries. + * @see #setEntryValues(CharSequence[]) + */ + public void setEntries(CharSequence[] entries) { + mEntries = entries; } - /** - * @param entriesResId The entries array as a resource. - * @see #setEntries(CharSequence[]) - */ - public void setEntries(int entriesResId) - { - setEntries(getContext().getResources().getTextArray(entriesResId)); + /** + * @param entriesResId The entries array as a resource. + * @see #setEntries(CharSequence[]) + */ + public void setEntries(int entriesResId) { + setEntries(getContext().getResources().getTextArray(entriesResId)); } - /** - * The list of entries to be shown in the list in subsequent dialogs. - * - * @return The list as an array. - */ - public CharSequence[] getEntries() - { - return mEntries; + /** + * The list of entries to be shown in the list in subsequent dialogs. + * + * @return The list as an array. + */ + public CharSequence[] getEntries() { + return mEntries; } - /** - * The array to find the value to save for a preference when an entry from - * entries is selected. If a user clicks on the second item in entries, the - * second item in this array will be saved to the preference. - * - * @param entryValues The array to be used as values to save for the preference. - */ - public void setEntryValues(CharSequence[] entryValues) - { - mEntryValues=entryValues; + /** + * The array to find the value to save for a preference when an entry from + * entries is selected. If a user clicks on the second item in entries, the + * second item in this array will be saved to the preference. + * + * @param entryValues The array to be used as values to save for the preference. + */ + public void setEntryValues(CharSequence[] entryValues) { + mEntryValues = entryValues; } - /** - * @param entryValuesResId The entry values array as a resource. - * @see #setEntryValues(CharSequence[]) - */ - public void setEntryValues(int entryValuesResId) - { - setEntryValues(getContext().getResources().getTextArray(entryValuesResId)); + /** + * @param entryValuesResId The entry values array as a resource. + * @see #setEntryValues(CharSequence[]) + */ + public void setEntryValues(int entryValuesResId) { + setEntryValues(getContext().getResources().getTextArray(entryValuesResId)); } - /** - * Returns the array of values to be saved for the preference. - * - * @return The array of values. - */ - public CharSequence[] getEntryValues() - { - return mEntryValues; + /** + * Returns the array of values to be saved for the preference. + * + * @return The array of values. + */ + public CharSequence[] getEntryValues() { + return mEntryValues; } - /** - * Sets the value of the key. This should be one of the entries in - * {@link #getEntryValues()}. - * - * @param value The value to set for the key. - */ - public void setValue(String value) - { + /** + * Sets the value of the key. This should be one of the entries in + * {@link #getEntryValues()}. + * + * @param value The value to set for the key. + */ + public void setValue(String value) { // Always persist/notify the first time. - final boolean changed=!TextUtils.equals(mValue,value); - if(changed||!mValueSet) - { - mValue=value; - mValueSet=true; - persistString(value); - if(changed) - { - notifyChanged(); + final boolean changed = !TextUtils.equals(mValue, value); + if (changed || !mValueSet) { + mValue = value; + mValueSet = true; + persistString(value); + if (changed) { + notifyChanged(); + } } - } } - /** - * Returns the summary of this ListPreference. If the summary - * has a {@linkplain java.lang.String#format String formatting} - * marker in it (i.e. "%s" or "%1$s"), then the current entry - * value will be substituted in its place. - * - * @return the summary with appropriate string substitution - */ - @Override - public CharSequence getSummary() - { - final CharSequence entry=getEntry(); - if(mSummary==null) - { - return super.getSummary(); - } - else - { - return String.format(mSummary,entry==null?"":entry); - } + /** + * Returns the summary of this ListPreference. If the summary + * has a {@linkplain java.lang.String#format String formatting} + * marker in it (i.e. "%s" or "%1$s"), then the current entry + * value will be substituted in its place. + * + * @return the summary with appropriate string substitution + */ + @Override + public CharSequence getSummary() { + final CharSequence entry = getEntry(); + if (mSummary == null) { + return super.getSummary(); + } else { + return String.format(mSummary, entry == null ? "" : entry); + } } - /** - * Sets the summary for this Preference with a CharSequence. - * If the summary has a - * {@linkplain java.lang.String#format String formatting} - * marker in it (i.e. "%s" or "%1$s"), then the current entry - * value will be substituted in its place when it's retrieved. - * - * @param summary The summary for the preference. - */ - @Override - public void setSummary(CharSequence summary) - { - super.setSummary(summary); - if(summary==null&&mSummary!=null) - { - mSummary=null; - } - else if(summary!=null&&!summary.equals(mSummary)) - { - mSummary=summary.toString(); - } + /** + * Sets the summary for this Preference with a CharSequence. + * If the summary has a + * {@linkplain java.lang.String#format String formatting} + * marker in it (i.e. "%s" or "%1$s"), then the current entry + * value will be substituted in its place when it's retrieved. + * + * @param summary The summary for the preference. + */ + @Override + public void setSummary(CharSequence summary) { + super.setSummary(summary); + if (summary == null && mSummary != null) { + mSummary = null; + } else if (summary != null && !summary.equals(mSummary)) { + mSummary = summary.toString(); + } } - /** - * Sets the value to the given index from the entry values. - * - * @param index The index of the value to set. - */ - public void setValueIndex(int index) - { - if(mEntryValues!=null) - { - setValue(mEntryValues[index].toString()); - } + /** + * Sets the value to the given index from the entry values. + * + * @param index The index of the value to set. + */ + public void setValueIndex(int index) { + if (mEntryValues != null) { + setValue(mEntryValues[index].toString()); + } } - /** - * Returns the value of the key. This should be one of the entries in - * {@link #getEntryValues()}. - * - * @return The value of the key. - */ - public String getValue() - { - return mValue; + /** + * Returns the value of the key. This should be one of the entries in + * {@link #getEntryValues()}. + * + * @return The value of the key. + */ + public String getValue() { + return mValue; } - /** - * Returns the entry corresponding to the current value. - * - * @return The entry corresponding to the current value, or null. - */ - public CharSequence getEntry() - { - int index=getValueIndex(); - return index>=0&&mEntries!=null?mEntries[index]:null; + /** + * Returns the entry corresponding to the current value. + * + * @return The entry corresponding to the current value, or null. + */ + public CharSequence getEntry() { + int index = getValueIndex(); + return index >= 0 && mEntries != null ? mEntries[index] : null; } - /** - * Returns the index of the given value (in the entry values array). - * - * @param value The value whose index should be returned. - * @return The index of the value, or -1 if not found. - */ - public int findIndexOfValue(String value) - { - if(value!=null&&mEntryValues!=null) - for(int i=mEntryValues.length-1;i>=0;i--) - if(mEntryValues[i].equals(value)) - return i; - return -1; + /** + * Returns the index of the given value (in the entry values array). + * + * @param value The value whose index should be returned. + * @return The index of the value, or -1 if not found. + */ + public int findIndexOfValue(String value) { + if (value != null && mEntryValues != null) + for (int i = mEntryValues.length - 1; i >= 0; i--) + if (mEntryValues[i].equals(value)) + return i; + return -1; } - private int getValueIndex() - { - return findIndexOfValue(mValue); + private int getValueIndex() { + return findIndexOfValue(mValue); } - @Override - protected void onPrepareDialogBuilder(Builder builder) - { - super.onPrepareDialogBuilder(builder); - if(mEntries==null||mEntryValues==null) - { - throw new IllegalStateException( - "ListPreference requires an entries array and an entryValues array."); - } - mClickedDialogEntryIndex=getValueIndex(); - // final ListView listView=new ListView(getContext()); + @Override + protected void onPrepareDialogBuilder(Builder builder) { + super.onPrepareDialogBuilder(builder); + if (mEntries == null || mEntryValues == null) { + throw new IllegalStateException( + "ListPreference requires an entries array and an entryValues array."); + } + mClickedDialogEntryIndex = getValueIndex(); + // final ListView listView=new ListView(getContext()); // listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // listView.setOnItemClickListener(new OnItemClickListener() // { @@ -302,124 +271,106 @@ protected void onPrepareDialogBuilder(Builder builder) // } // }); // listView.setAdapter(new ArrayAdapter<>(getContext(),R.layout.mpl__simple_list_item_single_choice,entries)); - // builder.setView(listView); + // builder.setView(listView); - builder.setSingleChoiceItems(new ArrayAdapter<>(getContext(),R.layout.mpl__simple_list_item_single_choice,mEntries),mClickedDialogEntryIndex, - new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog,int which) - { - mClickedDialogEntryIndex=which; + builder.setSingleChoiceItems(new ArrayAdapter<>(getContext(), R.layout.mpl__simple_list_item_single_choice, mEntries), mClickedDialogEntryIndex, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + mClickedDialogEntryIndex = which; /* * Clicking on an item simulates the positive button * click, and dismisses the dialog. */ - ListPreference.this.onClick(dialog,DialogInterface.BUTTON_POSITIVE); - dialog.dismiss(); - } - }); + ListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE); + dialog.dismiss(); + } + }); /* * The typical interaction for list-based dialogs is to have * click-on-an-item dismiss the dialog instead of the user having to * press 'Ok'. */ - builder.setPositiveButton(null,null); + builder.setPositiveButton(null, null); } - @Override - protected void onDialogClosed(boolean positiveResult) - { - super.onDialogClosed(positiveResult); - - if(positiveResult&&mClickedDialogEntryIndex>=0&&mEntryValues!=null) - { - String value=mEntryValues[mClickedDialogEntryIndex].toString(); - if(callChangeListener(value)) - { - setValue(value); + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + if (positiveResult && mClickedDialogEntryIndex >= 0 && mEntryValues != null) { + String value = mEntryValues[mClickedDialogEntryIndex].toString(); + if (callChangeListener(value)) { + setValue(value); + } } - } } - @Override - protected Object onGetDefaultValue(TypedArray a,int index) - { - return a.getString(index); + @Override + protected Object onGetDefaultValue(TypedArray a, int index) { + return a.getString(index); } - @Override - protected void onSetInitialValue(boolean restoreValue,Object defaultValue) - { - setValue(restoreValue?getPersistedString(mValue):(String)defaultValue); + @Override + protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { + setValue(restoreValue ? getPersistedString(mValue) : (String) defaultValue); } - @Override - protected Parcelable onSaveInstanceState() - { - final Parcelable superState=super.onSaveInstanceState(); - if(isPersistent()) - { + @Override + protected Parcelable onSaveInstanceState() { + final Parcelable superState = super.onSaveInstanceState(); + if (isPersistent()) { // No need to save instance state since it's persistent - return superState; - } + return superState; + } - final SavedState myState=new SavedState(superState); - myState.value=getValue(); - return myState; + final SavedState myState = new SavedState(superState); + myState.value = getValue(); + return myState; } - @Override - protected void onRestoreInstanceState(Parcelable state) - { - if(state==null||!state.getClass().equals(SavedState.class)) - { + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (state == null || !state.getClass().equals(SavedState.class)) { // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state); - return; - } + super.onRestoreInstanceState(state); + return; + } - SavedState myState=(SavedState)state; - super.onRestoreInstanceState(myState.getSuperState()); - setValue(myState.value); + SavedState myState = (SavedState) state; + super.onRestoreInstanceState(myState.getSuperState()); + setValue(myState.value); } - private static class SavedState extends BaseSavedState - { - String value; + private static class SavedState extends BaseSavedState { + String value; - public SavedState(Parcel source) - { - super(source); - value=source.readString(); - } + public SavedState(Parcel source) { + super(source); + value = source.readString(); + } - @Override - public void writeToParcel(Parcel dest,int flags) - { - super.writeToParcel(dest,flags); - dest.writeString(value); - } - - public SavedState(Parcelable superState) - { - super(superState); - } - - public static final Parcelable.Creator CREATOR= - new Parcelable.Creator() - { - public SavedState createFromParcel(Parcel in) - { - return new SavedState(in); - } - - public SavedState[] newArray(int size) - { - return new SavedState[size]; - } - }; + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeString(value); + } + + public SavedState(Parcelable superState) { + super(superState); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; } - } +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java index 37d17ce..2660067 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java @@ -6,7 +6,7 @@ import android.graphics.drawable.Drawable; import android.os.Build.VERSION_CODES; import android.support.annotation.DrawableRes; -import android.support.v4.content.ContextCompat; +import android.support.v7.content.res.AppCompatResources; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; @@ -14,125 +14,106 @@ import com.lb.material_preferences_library.R; -public class Preference extends android.preference.Preference - { - private boolean _isInitialized=false; - private int _iconResId; - private Drawable _icon; +public class Preference extends android.preference.Preference { + private boolean _isInitialized = false; + private int _iconResId; + private Drawable _icon; - protected void init(final Context context,final AttributeSet attrs,final int defStyleAttr,final int defStyleRes) - { - setLayoutResource(R.layout.mpl__preference); - final TypedArray a=context.obtainStyledAttributes(attrs,R.styleable.Preference,defStyleAttr,defStyleRes); - _iconResId=a.getResourceId(R.styleable.Preference_icon,0); - a.recycle(); + protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { + setLayoutResource(R.layout.mpl__preference); + final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Preference, defStyleAttr, defStyleRes); + _iconResId = a.getResourceId(R.styleable.Preference_icon, 0); + a.recycle(); } - @TargetApi(VERSION_CODES.LOLLIPOP) - public Preference(final Context context,final AttributeSet attrs,final int defStyleAttr,final int defStyleRes) - { - super(context,attrs,defStyleAttr,defStyleRes); - if(!_isInitialized) - { - _isInitialized=true; - init(context,attrs,defStyleAttr,defStyleRes); - } + @TargetApi(VERSION_CODES.LOLLIPOP) + public Preference(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + if (!_isInitialized) { + _isInitialized = true; + init(context, attrs, defStyleAttr, defStyleRes); + } } - /** - * Sets the icon for this Preference with a Drawable. - * This icon will be placed into the ID - * {@link android.R.id#icon} within the View created by - * {@link #onCreateView(ViewGroup)}. - * - * @param icon The optional icon for this Preference. - */ - public void setIcon(Drawable icon) - { - if((icon==null&&_icon!=null)||(icon!=null&&_icon!=icon)) - { - _icon=icon; - notifyChanged(); - } + /** + * Sets the icon for this Preference with a Drawable. + * This icon will be placed into the ID + * {@link android.R.id#icon} within the View created by + * {@link #onCreateView(ViewGroup)}. + * + * @param icon The optional icon for this Preference. + */ + public void setIcon(Drawable icon) { + if ((icon == null && _icon != null) || (icon != null && _icon != icon)) { + _icon = icon; + notifyChanged(); + } } - /** - * Sets the icon for this Preference with a resource ID. - * - * @param iconResId The icon as a resource ID. - * @see #setIcon(Drawable) - */ - public void setIconCompat(@DrawableRes int iconResId) - { - if(_iconResId!=iconResId) - { - _iconResId=iconResId; - setIcon(ContextCompat.getDrawable(getContext(),iconResId)); - } + /** + * Sets the icon for this Preference with a resource ID. + * + * @param iconResId The icon as a resource ID. + * @see #setIcon(Drawable) + */ + public void setIconCompat(@DrawableRes int iconResId) { + if (_iconResId != iconResId) { + _iconResId = iconResId; + setIcon(AppCompatResources.getDrawable(getContext(), iconResId)); + } } - /** - * Returns the icon of this Preference. - * - * @return The icon. - * @see #setIcon(Drawable) - */ - public Drawable getIconCompat() - { - return _icon; + /** + * Returns the icon of this Preference. + * + * @return The icon. + * @see #setIcon(Drawable) + */ + public Drawable getIconCompat() { + return _icon; } - public Preference(Context context,AttributeSet attrs,int defStyleAttr) - { - super(context,attrs,defStyleAttr); - if(!_isInitialized) - { - _isInitialized=true; - init(context,attrs,defStyleAttr,0); - } + public Preference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + if (!_isInitialized) { + _isInitialized = true; + init(context, attrs, defStyleAttr, 0); + } } - public Preference(Context context,AttributeSet attrs) - { - super(context,attrs); - if(!_isInitialized) - { - _isInitialized=true; - init(context,attrs,0,0); - } + public Preference(Context context, AttributeSet attrs) { + super(context, attrs); + if (!_isInitialized) { + _isInitialized = true; + init(context, attrs, 0, 0); + } } - public Preference(Context context) - { - super(context); - if(!_isInitialized) - { - _isInitialized=true; - init(context,null,0,0); - } + public Preference(Context context) { + super(context); + if (!_isInitialized) { + _isInitialized = true; + init(context, null, 0, 0); + } } - @Override - protected void onBindView(final View view) - { - super.onBindView(view); - final ImageView imageView=(ImageView)view.findViewById(R.id.icon); - if(imageView!=null) - { - if(_iconResId!=0||_icon!=null) - { - if(_icon==null) - _icon=ContextCompat.getDrawable(getContext(),_iconResId); - if(_icon!=null) - imageView.setImageDrawable(_icon); + @Override + protected void onBindView(final View view) { + super.onBindView(view); + final ImageView imageView = (ImageView) view.findViewById(R.id.icon); + if (imageView != null) { + if (_iconResId != 0 || _icon != null) { + if (_icon == null) + _icon = AppCompatResources.getDrawable(getContext(), _iconResId); + if (_icon != null) + imageView.setImageDrawable(_icon); + } + imageView.setVisibility(_icon != null ? View.VISIBLE : View.GONE); } - imageView.setVisibility(_icon!=null?View.VISIBLE:View.GONE); - } - final View imageFrame=view.findViewById(R.id.icon_frame); - if(imageFrame!=null) - { - imageFrame.setVisibility(_icon!=null?View.VISIBLE:View.GONE); - } + final View imageFrame = view.findViewById(R.id.icon_frame); + if (imageFrame != null) { + imageFrame.setVisibility(_icon != null ? View.VISIBLE : View.GONE); + } } - } +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/PreferenceManagerEx.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/PreferenceManagerEx.java index da73056..24ebc62 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/PreferenceManagerEx.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/PreferenceManagerEx.java @@ -1,67 +1,57 @@ package com.lb.material_preferences_library.custom_preferences; + import android.preference.PreferenceManager; import java.lang.reflect.Method; -/**used to access some methods of original PreferenceManager*/ -public class PreferenceManagerEx - { - private Method METHOD_UNREGISTER_ON_ACTIVITY_DESTROY_LISTENER; - private Method METHOD_REGISTER_ON_ACTIVITY_DESTROY_LISTENER; - private static final PreferenceManagerEx INSTANCE=new PreferenceManagerEx(); +/** + * used to access some methods of original PreferenceManager + */ +public class PreferenceManagerEx { + private Method METHOD_UNREGISTER_ON_ACTIVITY_DESTROY_LISTENER; + private Method METHOD_REGISTER_ON_ACTIVITY_DESTROY_LISTENER; + private static final PreferenceManagerEx INSTANCE = new PreferenceManagerEx(); - private PreferenceManagerEx() - { + private PreferenceManagerEx() { } - public void unregisterOnActivityDestroyListener(PreferenceManager pm,PreferenceManager.OnActivityDestroyListener listener) - { - Method unregisterMethod=METHOD_UNREGISTER_ON_ACTIVITY_DESTROY_LISTENER; - try - { - if(unregisterMethod==null) - { - //this is used to hook to the onActivityDestroy method, to avoid a window leak when config-changes while the dialog is shown - unregisterMethod=pm.getClass().getDeclaredMethod("unregisterOnActivityDestroyListener", - PreferenceManager.OnActivityDestroyListener.class); - unregisterMethod.setAccessible(true); - } - unregisterMethod.invoke(pm,listener); - } - catch(Exception e) - { - e.printStackTrace(); + public void unregisterOnActivityDestroyListener(PreferenceManager pm, PreferenceManager.OnActivityDestroyListener listener) { + Method unregisterMethod = METHOD_UNREGISTER_ON_ACTIVITY_DESTROY_LISTENER; + try { + if (unregisterMethod == null) { + //this is used to hook to the onActivityDestroy method, to avoid a window leak when config-changes while the dialog is shown + unregisterMethod = pm.getClass().getDeclaredMethod("unregisterOnActivityDestroyListener", + PreferenceManager.OnActivityDestroyListener.class); + unregisterMethod.setAccessible(true); + } + unregisterMethod.invoke(pm, listener); + } catch (Exception e) { + e.printStackTrace(); // unregisterMethod=null; - } - METHOD_UNREGISTER_ON_ACTIVITY_DESTROY_LISTENER=unregisterMethod; + } + METHOD_UNREGISTER_ON_ACTIVITY_DESTROY_LISTENER = unregisterMethod; } - public void registerOnActivityDestroyListener(PreferenceManager pm,PreferenceManager.OnActivityDestroyListener listener) - { - // - Method registerMethod=METHOD_REGISTER_ON_ACTIVITY_DESTROY_LISTENER; - try - { - if(registerMethod==null) - { - //this is used to hook to the onActivityDestroy method, to avoid a window leak when config-changes while the dialog is shown - registerMethod=pm.getClass().getDeclaredMethod("registerOnActivityDestroyListener", - PreferenceManager.OnActivityDestroyListener.class); - registerMethod.setAccessible(true); - } - registerMethod.invoke(pm,listener); - } - catch(Exception e) - { - e.printStackTrace(); + public void registerOnActivityDestroyListener(PreferenceManager pm, PreferenceManager.OnActivityDestroyListener listener) { + // + Method registerMethod = METHOD_REGISTER_ON_ACTIVITY_DESTROY_LISTENER; + try { + if (registerMethod == null) { + //this is used to hook to the onActivityDestroy method, to avoid a window leak when config-changes while the dialog is shown + registerMethod = pm.getClass().getDeclaredMethod("registerOnActivityDestroyListener", + PreferenceManager.OnActivityDestroyListener.class); + registerMethod.setAccessible(true); + } + registerMethod.invoke(pm, listener); + } catch (Exception e) { + e.printStackTrace(); // registerMethod=null; - } - METHOD_REGISTER_ON_ACTIVITY_DESTROY_LISTENER=registerMethod; + } + METHOD_REGISTER_ON_ACTIVITY_DESTROY_LISTENER = registerMethod; } - public static PreferenceManagerEx getInstance() - { - return INSTANCE; + public static PreferenceManagerEx getInstance() { + return INSTANCE; } - } +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java index 27502a2..e73c073 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java @@ -21,191 +21,171 @@ * @attr ref android.R.styleable#SwitchPreference_switchTextOn * @attr ref android.R.styleable#SwitchPreference_disableDependentsState */ -public class SwitchPreference extends TwoStatePreference - { - private final Listener mListener=new Listener(); +public class SwitchPreference extends TwoStatePreference { + private final Listener mListener = new Listener(); - // Switch text for on and off states - private CharSequence mSwitchOn; - private CharSequence mSwitchOff; + // Switch text for on and off states + private CharSequence mSwitchOn; + private CharSequence mSwitchOff; - private class Listener implements CompoundButton.OnCheckedChangeListener - { - @Override - public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) - { - if(!callChangeListener(isChecked)) - { + private class Listener implements CompoundButton.OnCheckedChangeListener { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (!callChangeListener(isChecked)) { // Listener didn't like it, change it back. // CompoundButton will make sure we don't recurse. - buttonView.setChecked(!isChecked); - return; - } + buttonView.setChecked(!isChecked); + return; + } - SwitchPreference.this.setChecked(isChecked); - } + SwitchPreference.this.setChecked(isChecked); + } } - /** - * Construct a new SwitchPreference with the given style options. - * - * @param context The Context that will style this preference - * @param attrs Style attributes that differ from the default - * @param defStyleAttr An attribute in the current theme that contains a - * reference to a style resource that supplies default values for - * the view. Can be 0 to not look for defaults. - * @param defStyleRes A resource identifier of a style resource that - * supplies default values for the view, used only if - * defStyleAttr is 0 or can not be found in the theme. Can be 0 - * to not look for defaults. - */ - public SwitchPreference(Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes) - { - super(context,attrs,defStyleAttr,defStyleRes); + /** + * Construct a new SwitchPreference with the given style options. + * + * @param context The Context that will style this preference + * @param attrs Style attributes that differ from the default + * @param defStyleAttr An attribute in the current theme that contains a + * reference to a style resource that supplies default values for + * the view. Can be 0 to not look for defaults. + * @param defStyleRes A resource identifier of a style resource that + * supplies default values for the view, used only if + * defStyleAttr is 0 or can not be found in the theme. Can be 0 + * to not look for defaults. + */ + public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); } - /** - * Construct a new SwitchPreference with the given style options. - * - * @param context The Context that will style this preference - * @param attrs Style attributes that differ from the default - * @param defStyleAttr An attribute in the current theme that contains a - * reference to a style resource that supplies default values for - * the view. Can be 0 to not look for defaults. - */ - public SwitchPreference(Context context,AttributeSet attrs,int defStyleAttr) - { - super(context,attrs,defStyleAttr); + /** + * Construct a new SwitchPreference with the given style options. + * + * @param context The Context that will style this preference + * @param attrs Style attributes that differ from the default + * @param defStyleAttr An attribute in the current theme that contains a + * reference to a style resource that supplies default values for + * the view. Can be 0 to not look for defaults. + */ + public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); } - /** - * Construct a new SwitchPreference with the given style options. - * - * @param context The Context that will style this preference - * @param attrs Style attributes that differ from the default - */ - public SwitchPreference(Context context,AttributeSet attrs) - { - this(context,attrs,R.attr.switchPreferenceStyle); + /** + * Construct a new SwitchPreference with the given style options. + * + * @param context The Context that will style this preference + * @param attrs Style attributes that differ from the default + */ + public SwitchPreference(Context context, AttributeSet attrs) { + this(context, attrs, R.attr.switchPreferenceStyle); } - - /** - * Construct a new SwitchPreference with default style options. - * - * @param context The Context that will style this preference - */ - public SwitchPreference(Context context) - { - this(context,null); + /** + * Construct a new SwitchPreference with default style options. + * + * @param context The Context that will style this preference + */ + public SwitchPreference(Context context) { + this(context, null); } - @Override - protected void init(final Context context,final AttributeSet attrs,final int defStyleAttr,final int defStyleRes) - { - super.init(context,attrs,defStyleAttr,defStyleRes); - this.setWidgetLayoutResource(R.layout.mpl__switch_preference); - - TypedArray a=context.obtainStyledAttributes(attrs, - R.styleable.SwitchPreference,defStyleAttr,defStyleRes); - setSummaryOn(a.getString(R.styleable.SwitchPreference_summaryOn)); - setSummaryOff(a.getString(R.styleable.SwitchPreference_summaryOff)); - setSwitchTextOn(a.getString( - R.styleable.SwitchPreference_switchTextOn)); - setSwitchTextOff(a.getString( - R.styleable.SwitchPreference_switchTextOff)); - setDisableDependentsState(a.getBoolean( - R.styleable.SwitchPreference_disableDependentsState,false)); - a.recycle(); + @Override + protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { + super.init(context, attrs, defStyleAttr, defStyleRes); + this.setWidgetLayoutResource(R.layout.mpl__switch_preference); + + TypedArray a = context.obtainStyledAttributes(attrs, + R.styleable.SwitchPreference, defStyleAttr, defStyleRes); + setSummaryOn(a.getString(R.styleable.SwitchPreference_summaryOn)); + setSummaryOff(a.getString(R.styleable.SwitchPreference_summaryOff)); + setSwitchTextOn(a.getString( + R.styleable.SwitchPreference_switchTextOn)); + setSwitchTextOff(a.getString( + R.styleable.SwitchPreference_switchTextOff)); + setDisableDependentsState(a.getBoolean( + R.styleable.SwitchPreference_disableDependentsState, false)); + a.recycle(); } - @Override - protected void onBindView(View view) - { - super.onBindView(view); - View checkableView=view.findViewById(android.R.id.checkbox); - if(checkableView!=null&&checkableView instanceof Checkable) - { - if(checkableView instanceof SwitchCompat) - { - final SwitchCompat switchView=(SwitchCompat)checkableView; - switchView.setOnCheckedChangeListener(null); - } - - ((Checkable)checkableView).setChecked(mChecked); - - if(checkableView instanceof SwitchCompat) - { - final SwitchCompat switchView=(SwitchCompat)checkableView; - switchView.setTextOn(mSwitchOn); - switchView.setTextOff(mSwitchOff); - switchView.setOnCheckedChangeListener(mListener); + @Override + protected void onBindView(View view) { + super.onBindView(view); + View checkableView = view.findViewById(android.R.id.checkbox); + if (checkableView != null && checkableView instanceof Checkable) { + if (checkableView instanceof SwitchCompat) { + final SwitchCompat switchView = (SwitchCompat) checkableView; + switchView.setOnCheckedChangeListener(null); + } + + ((Checkable) checkableView).setChecked(mChecked); + + if (checkableView instanceof SwitchCompat) { + final SwitchCompat switchView = (SwitchCompat) checkableView; + switchView.setTextOn(mSwitchOn); + switchView.setTextOff(mSwitchOff); + switchView.setOnCheckedChangeListener(mListener); + } } - } - syncSummaryView(view); + syncSummaryView(view); } - /** - * Set the text displayed on the switch widget in the on state. - * This should be a very short string; one word if possible. - * - * @param onText Text to display in the on state - */ - public void setSwitchTextOn(CharSequence onText) - { - mSwitchOn=onText; - notifyChanged(); + /** + * Set the text displayed on the switch widget in the on state. + * This should be a very short string; one word if possible. + * + * @param onText Text to display in the on state + */ + public void setSwitchTextOn(CharSequence onText) { + mSwitchOn = onText; + notifyChanged(); } - /** - * Set the text displayed on the switch widget in the off state. - * This should be a very short string; one word if possible. - * - * @param offText Text to display in the off state - */ - public void setSwitchTextOff(CharSequence offText) - { - mSwitchOff=offText; - notifyChanged(); + /** + * Set the text displayed on the switch widget in the off state. + * This should be a very short string; one word if possible. + * + * @param offText Text to display in the off state + */ + public void setSwitchTextOff(CharSequence offText) { + mSwitchOff = offText; + notifyChanged(); } - /** - * Set the text displayed on the switch widget in the on state. - * This should be a very short string; one word if possible. - * - * @param resId The text as a string resource ID - */ - public void setSwitchTextOn(int resId) - { - setSwitchTextOn(getContext().getString(resId)); + /** + * Set the text displayed on the switch widget in the on state. + * This should be a very short string; one word if possible. + * + * @param resId The text as a string resource ID + */ + public void setSwitchTextOn(int resId) { + setSwitchTextOn(getContext().getString(resId)); } - /** - * Set the text displayed on the switch widget in the off state. - * This should be a very short string; one word if possible. - * - * @param resId The text as a string resource ID - */ - public void setSwitchTextOff(int resId) - { - setSwitchTextOff(getContext().getString(resId)); + /** + * Set the text displayed on the switch widget in the off state. + * This should be a very short string; one word if possible. + * + * @param resId The text as a string resource ID + */ + public void setSwitchTextOff(int resId) { + setSwitchTextOff(getContext().getString(resId)); } - /** - * @return The text that will be displayed on the switch widget in the on state - */ - public CharSequence getSwitchTextOn() - { - return mSwitchOn; + /** + * @return The text that will be displayed on the switch widget in the on state + */ + public CharSequence getSwitchTextOn() { + return mSwitchOn; } - /** - * @return The text that will be displayed on the switch widget in the off state - */ - public CharSequence getSwitchTextOff() - { - return mSwitchOff; + /** + * @return The text that will be displayed on the switch widget in the off state + */ + public CharSequence getSwitchTextOff() { + return mSwitchOff; } - } \ No newline at end of file +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/TwoStatePreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/TwoStatePreference.java index 01d4ac8..2b25f59 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/TwoStatePreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/TwoStatePreference.java @@ -1,4 +1,5 @@ package com.lb.material_preferences_library.custom_preferences; + import android.content.Context; import android.content.SharedPreferences; import android.content.res.TypedArray; @@ -14,298 +15,254 @@ * boolean value in SharedPreferences, and may have dependent preferences that are * enabled/disabled based on the current state. */ -public abstract class TwoStatePreference extends Preference - { - private CharSequence mSummaryOn; - private CharSequence mSummaryOff; - boolean mChecked; - private boolean mCheckedSet; - private boolean mDisableDependentsState; - - public TwoStatePreference( - Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes) - { - super(context,attrs,defStyleAttr,defStyleRes); +public abstract class TwoStatePreference extends Preference { + private CharSequence mSummaryOn; + private CharSequence mSummaryOff; + boolean mChecked; + private boolean mCheckedSet; + private boolean mDisableDependentsState; + + public TwoStatePreference( + Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); } - public TwoStatePreference(Context context,AttributeSet attrs,int defStyleAttr) - { - super(context,attrs,defStyleAttr); + public TwoStatePreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); } - public TwoStatePreference(Context context,AttributeSet attrs) - { - this(context,attrs,0); + public TwoStatePreference(Context context, AttributeSet attrs) { + this(context, attrs, 0); } - public TwoStatePreference(Context context) - { - this(context,null); + public TwoStatePreference(Context context) { + this(context, null); } - @Override - protected void onClick() - { - super.onClick(); + @Override + protected void onClick() { + super.onClick(); - final boolean newValue=!isChecked(); - if(callChangeListener(newValue)) - { - setChecked(newValue); - } + final boolean newValue = !isChecked(); + if (callChangeListener(newValue)) { + setChecked(newValue); + } } - /** - * Sets the checked state and saves it to the {@link SharedPreferences}. - * - * @param checked The checked state. - */ - public void setChecked(boolean checked) - { - // Always persist/notify the first time; don't assume the field's default of false. - final boolean changed=mChecked!=checked; - if(changed||!mCheckedSet) - { - mChecked=checked; - mCheckedSet=true; - persistBoolean(checked); - if(changed) - { - notifyDependencyChange(shouldDisableDependents()); - notifyChanged(); + /** + * Sets the checked state and saves it to the {@link SharedPreferences}. + * + * @param checked The checked state. + */ + public void setChecked(boolean checked) { + // Always persist/notify the first time; don't assume the field's default of false. + final boolean changed = mChecked != checked; + if (changed || !mCheckedSet) { + mChecked = checked; + mCheckedSet = true; + persistBoolean(checked); + if (changed) { + notifyDependencyChange(shouldDisableDependents()); + notifyChanged(); + } } - } } - /** - * Returns the checked state. - * - * @return The checked state. - */ - public boolean isChecked() - { - return mChecked; + /** + * Returns the checked state. + * + * @return The checked state. + */ + public boolean isChecked() { + return mChecked; } - @Override - public boolean shouldDisableDependents() - { - boolean shouldDisable=mDisableDependentsState?mChecked:!mChecked; - return shouldDisable||super.shouldDisableDependents(); + @Override + public boolean shouldDisableDependents() { + boolean shouldDisable = mDisableDependentsState ? mChecked : !mChecked; + return shouldDisable || super.shouldDisableDependents(); } - /** - * Sets the summary to be shown when checked. - * - * @param summary The summary to be shown when checked. - */ - public void setSummaryOn(CharSequence summary) - { - mSummaryOn=summary; - if(isChecked()) - { - notifyChanged(); - } + /** + * Sets the summary to be shown when checked. + * + * @param summary The summary to be shown when checked. + */ + public void setSummaryOn(CharSequence summary) { + mSummaryOn = summary; + if (isChecked()) { + notifyChanged(); + } } - /** - * @param summaryResId The summary as a resource. - * @see #setSummaryOn(CharSequence) - */ - public void setSummaryOn(int summaryResId) - { - setSummaryOn(getContext().getString(summaryResId)); + /** + * @param summaryResId The summary as a resource. + * @see #setSummaryOn(CharSequence) + */ + public void setSummaryOn(int summaryResId) { + setSummaryOn(getContext().getString(summaryResId)); } - /** - * Returns the summary to be shown when checked. - * - * @return The summary. - */ - public CharSequence getSummaryOn() - { - return mSummaryOn; + /** + * Returns the summary to be shown when checked. + * + * @return The summary. + */ + public CharSequence getSummaryOn() { + return mSummaryOn; } - /** - * Sets the summary to be shown when unchecked. - * - * @param summary The summary to be shown when unchecked. - */ - public void setSummaryOff(CharSequence summary) - { - mSummaryOff=summary; - if(!isChecked()) - { - notifyChanged(); - } + /** + * Sets the summary to be shown when unchecked. + * + * @param summary The summary to be shown when unchecked. + */ + public void setSummaryOff(CharSequence summary) { + mSummaryOff = summary; + if (!isChecked()) { + notifyChanged(); + } } - /** - * @param summaryResId The summary as a resource. - * @see #setSummaryOff(CharSequence) - */ - public void setSummaryOff(int summaryResId) - { - setSummaryOff(getContext().getString(summaryResId)); + /** + * @param summaryResId The summary as a resource. + * @see #setSummaryOff(CharSequence) + */ + public void setSummaryOff(int summaryResId) { + setSummaryOff(getContext().getString(summaryResId)); } - /** - * Returns the summary to be shown when unchecked. - * - * @return The summary. - */ - public CharSequence getSummaryOff() - { - return mSummaryOff; + /** + * Returns the summary to be shown when unchecked. + * + * @return The summary. + */ + public CharSequence getSummaryOff() { + return mSummaryOff; } - /** - * Returns whether dependents are disabled when this preference is on ({@code true}) - * or when this preference is off ({@code false}). - * - * @return Whether dependents are disabled when this preference is on ({@code true}) - * or when this preference is off ({@code false}). - */ - public boolean getDisableDependentsState() - { - return mDisableDependentsState; + /** + * Returns whether dependents are disabled when this preference is on ({@code true}) + * or when this preference is off ({@code false}). + * + * @return Whether dependents are disabled when this preference is on ({@code true}) + * or when this preference is off ({@code false}). + */ + public boolean getDisableDependentsState() { + return mDisableDependentsState; } - /** - * Sets whether dependents are disabled when this preference is on ({@code true}) - * or when this preference is off ({@code false}). - * - * @param disableDependentsState The preference state that should disable dependents. - */ - public void setDisableDependentsState(boolean disableDependentsState) - { - mDisableDependentsState=disableDependentsState; + /** + * Sets whether dependents are disabled when this preference is on ({@code true}) + * or when this preference is off ({@code false}). + * + * @param disableDependentsState The preference state that should disable dependents. + */ + public void setDisableDependentsState(boolean disableDependentsState) { + mDisableDependentsState = disableDependentsState; } - @Override - protected Object onGetDefaultValue(TypedArray a,int index) - { - return a.getBoolean(index,false); + @Override + protected Object onGetDefaultValue(TypedArray a, int index) { + return a.getBoolean(index, false); } - @Override - protected void onSetInitialValue(boolean restoreValue,Object defaultValue) - { - setChecked(restoreValue?getPersistedBoolean(mChecked) - :(Boolean)defaultValue); + @Override + protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { + setChecked(restoreValue ? getPersistedBoolean(mChecked) + : (Boolean) defaultValue); } - /** - * Sync a summary view contained within view's subhierarchy with the correct summary text. - * - * @param view View where a summary should be located - */ - void syncSummaryView(View view) - { - // Sync the summary view - TextView summaryView=(TextView)view.findViewById(android.R.id.summary); - if(summaryView!=null) - { - boolean useDefaultSummary=true; - if(mChecked&&!TextUtils.isEmpty(mSummaryOn)) - { - summaryView.setText(mSummaryOn); - useDefaultSummary=false; - } - else if(!mChecked&&!TextUtils.isEmpty(mSummaryOff)) - { - summaryView.setText(mSummaryOff); - useDefaultSummary=false; + /** + * Sync a summary view contained within view's subhierarchy with the correct summary text. + * + * @param view View where a summary should be located + */ + void syncSummaryView(View view) { + // Sync the summary view + TextView summaryView = (TextView) view.findViewById(android.R.id.summary); + if (summaryView != null) { + boolean useDefaultSummary = true; + if (mChecked && !TextUtils.isEmpty(mSummaryOn)) { + summaryView.setText(mSummaryOn); + useDefaultSummary = false; + } else if (!mChecked && !TextUtils.isEmpty(mSummaryOff)) { + summaryView.setText(mSummaryOff); + useDefaultSummary = false; + } + + if (useDefaultSummary) { + final CharSequence summary = getSummary(); + if (!TextUtils.isEmpty(summary)) { + summaryView.setText(summary); + useDefaultSummary = false; + } + } + + int newVisibility = View.GONE; + if (!useDefaultSummary) { + // Someone has written to it + newVisibility = View.VISIBLE; + } + if (newVisibility != summaryView.getVisibility()) { + summaryView.setVisibility(newVisibility); + } } + } - if(useDefaultSummary) - { - final CharSequence summary=getSummary(); - if(!TextUtils.isEmpty(summary)) - { - summaryView.setText(summary); - useDefaultSummary=false; - } + @Override + protected Parcelable onSaveInstanceState() { + final Parcelable superState = super.onSaveInstanceState(); + if (isPersistent()) { + // No need to save instance state since it's persistent + return superState; } - int newVisibility=View.GONE; - if(!useDefaultSummary) - { - // Someone has written to it - newVisibility=View.VISIBLE; - } - if(newVisibility!=summaryView.getVisibility()) - { - summaryView.setVisibility(newVisibility); - } - } + final SavedState myState = new SavedState(superState); + myState.checked = isChecked(); + return myState; } - @Override - protected Parcelable onSaveInstanceState() - { - final Parcelable superState=super.onSaveInstanceState(); - if(isPersistent()) - { - // No need to save instance state since it's persistent - return superState; - } - - final SavedState myState=new SavedState(superState); - myState.checked=isChecked(); - return myState; - } + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (state == null || !state.getClass().equals(SavedState.class)) { + // Didn't save state for us in onSaveInstanceState + super.onRestoreInstanceState(state); + return; + } - @Override - protected void onRestoreInstanceState(Parcelable state) - { - if(state==null||!state.getClass().equals(SavedState.class)) - { - // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state); - return; - } - - SavedState myState=(SavedState)state; - super.onRestoreInstanceState(myState.getSuperState()); - setChecked(myState.checked); + SavedState myState = (SavedState) state; + super.onRestoreInstanceState(myState.getSuperState()); + setChecked(myState.checked); } - static class SavedState extends BaseSavedState - { - boolean checked; + static class SavedState extends BaseSavedState { + boolean checked; - public SavedState(Parcel source) - { - super(source); - checked=source.readInt()==1; - } + public SavedState(Parcel source) { + super(source); + checked = source.readInt() == 1; + } - @Override - public void writeToParcel(Parcel dest,int flags) - { - super.writeToParcel(dest,flags); - dest.writeInt(checked?1:0); - } - - public SavedState(Parcelable superState) - { - super(superState); - } - - public static final Parcelable.Creator CREATOR= - new Parcelable.Creator() - { - public SavedState createFromParcel(Parcel in) - { - return new SavedState(in); - } - - public SavedState[] newArray(int size) - { - return new SavedState[size]; - } - }; + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(checked ? 1 : 0); + } + + public SavedState(Parcelable superState) { + super(superState); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; } - } \ No newline at end of file +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/internal/widget/PreferenceImageView.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/internal/widget/PreferenceImageView.java index 95d7eec..d3cad71 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/internal/widget/PreferenceImageView.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/internal/widget/PreferenceImageView.java @@ -19,7 +19,6 @@ import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; -import android.widget.ImageView; import com.lb.material_preferences_library.R; @@ -30,36 +29,32 @@ * * @hide */ -public class PreferenceImageView extends ImageView - { +public class PreferenceImageView extends android.support.v7.widget.AppCompatImageView { - private int mMaxWidth=Integer.MAX_VALUE; - private int mMaxHeight=Integer.MAX_VALUE; + private int mMaxWidth = Integer.MAX_VALUE; + private int mMaxHeight = Integer.MAX_VALUE; - public PreferenceImageView(Context context) - { - this(context,null); + public PreferenceImageView(Context context) { + this(context, null); } - public PreferenceImageView(Context context,AttributeSet attrs) - { - this(context,attrs,0); + public PreferenceImageView(Context context, AttributeSet attrs) { + this(context, attrs, 0); } - public PreferenceImageView(Context context,AttributeSet attrs,int defStyleAttr) - { - super(context,attrs,defStyleAttr); + public PreferenceImageView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); - final TypedArray a=context.obtainStyledAttributes( - attrs,R.styleable.PreferenceImageView,defStyleAttr,0); + final TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.PreferenceImageView, defStyleAttr, 0); - setMaxWidth(a.getDimensionPixelSize( - R.styleable.PreferenceImageView_maxWidth,Integer.MAX_VALUE)); + setMaxWidth(a.getDimensionPixelSize( + R.styleable.PreferenceImageView_maxWidth, Integer.MAX_VALUE)); - setMaxHeight(a.getDimensionPixelSize( - R.styleable.PreferenceImageView_maxHeight,Integer.MAX_VALUE)); + setMaxHeight(a.getDimensionPixelSize( + R.styleable.PreferenceImageView_maxHeight, Integer.MAX_VALUE)); - a.recycle(); + a.recycle(); } // public PreferenceImageView(Context context, AttributeSet attrs, int defStyleAttr, @@ -67,57 +62,48 @@ public PreferenceImageView(Context context,AttributeSet attrs,int defStyleAttr) // super(context, attrs, defStyleAttr, defStyleRes); // } - @Override - public void setMaxWidth(int maxWidth) - { - mMaxWidth=maxWidth; - super.setMaxWidth(maxWidth); + @Override + public void setMaxWidth(int maxWidth) { + mMaxWidth = maxWidth; + super.setMaxWidth(maxWidth); } - public int getMaxWidth() - { - return mMaxWidth; + public int getMaxWidth() { + return mMaxWidth; } - @Override - public void setMaxHeight(int maxHeight) - { - mMaxHeight=maxHeight; - super.setMaxHeight(maxHeight); + @Override + public void setMaxHeight(int maxHeight) { + mMaxHeight = maxHeight; + super.setMaxHeight(maxHeight); } - public int getMaxHeight() - { - return mMaxHeight; + public int getMaxHeight() { + return mMaxHeight; } - @Override - protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec) - { - final int widthMode=MeasureSpec.getMode(widthMeasureSpec); - if(widthMode==MeasureSpec.AT_MOST||widthMode==MeasureSpec.UNSPECIFIED) - { - final int widthSize=MeasureSpec.getSize(widthMeasureSpec); - final int maxWidth=getMaxWidth(); - if(maxWidth!=Integer.MAX_VALUE - &&(maxWidth Date: Fri, 16 Mar 2018 12:06:02 +0200 Subject: [PATCH 07/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3b69e8..90ad553 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Contribution is appreciated. Please try to be "loyal" to the original code of An Requirements == This library needs: - - API 7 and above. + - API 14 and above (release 10 supports even below). - AppCompat v7. That's it. From 79cd403a11b2af4add0ddaf67dc1dc39f66fd4ec Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Fri, 16 Mar 2018 14:43:04 +0200 Subject: [PATCH 08/12] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 90ad553..4d51edb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ MaterialPreferenceLibrary ================================== -Allows to have a nice Material-Design look&feel for API 7 and above for the PreferenceActivity, including most commonly used preferences and also showing the actionBar. +Allows to have a nice Material-Design look&feel for API 14 (even below if you use release 10 of the library) and above for the PreferenceActivity, including most commonly used preferences and also showing the actionBar. All the dialogs are using the support library's dialogs, including accent-color. You can even choose which theme to use. @@ -80,7 +80,7 @@ Contribution is appreciated. Please try to be "loyal" to the original code of An Requirements == This library needs: - - API 14 and above (release 10 supports even below). + - Android API 14 and above (release 10 supports even below). - AppCompat v7. That's it. From 444364832f781c640d7338aea61b7a6e56ebbc47 Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Sun, 24 Jun 2018 01:41:53 +0300 Subject: [PATCH 09/12] updated sdks --- .idea/assetWizardSettings.xml | 47 ----------- .idea/caches/build_file_checksums.ser | Bin 606 -> 606 bytes .idea/misc.xml | 8 +- MaterialPreferenceLibrary.iml | 2 +- app/app.iml | 76 +++++++++++------- app/build.gradle | 10 +-- build.gradle | 6 +- gradle.properties | 4 +- gradle/wrapper/gradle-wrapper.properties | 4 +- material_preferences_library/build.gradle | 10 +-- .../material_preferences_library.iml | 70 +++++++++------- .../AppCompatPreferenceActivity.java | 15 ++-- .../PreferenceActivity.java | 4 +- .../custom_preferences/DialogPreference.java | 4 +- .../EditTextPreference.java | 2 +- .../custom_preferences/ListPreference.java | 2 +- .../custom_preferences/Preference.java | 4 +- .../custom_preferences/SwitchPreference.java | 2 +- .../internal/widget/PreferenceImageView.java | 2 +- .../mpl__edittext_dialog_preference.xml | 6 +- .../src/main/res/layout/mpl__preference.xml | 14 ++-- .../res/layout/mpl__preference_activity.xml | 6 +- .../mpl__preference_widget_checkbox.xml | 22 ++--- .../mpl__simple_list_item_single_choice.xml | 30 +++---- .../res/layout/mpl__switch_preference.xml | 18 ++--- 25 files changed, 182 insertions(+), 186 deletions(-) delete mode 100644 .idea/assetWizardSettings.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml deleted file mode 100644 index 9bc2c88..0000000 --- a/.idea/assetWizardSettings.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index ddefbcae04cf19b444bd91f297f3af0c9c9d796b..60b1dbd72b7fc4ec889204d1113702023122750d 100644 GIT binary patch delta 117 zcmV-*0E++K1l|OYmjz@l!>rVioOcjmx@?*6jg--)3&_(br=Zr8BLRsJnx%`Or|5^# zEn63LWK%k2le_^P5H1ULaWXxYZn|E?2WyDSQj_TcHV}eidgci%I;Ex#fIX@w6o5qsBq*br)DwHT8x X0v-`7S6cvfE~+Dfo_$X@@KpJDVi_@p diff --git a/.idea/misc.xml b/.idea/misc.xml index df29872..5aa9d94 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,27 +12,29 @@ - + diff --git a/MaterialPreferenceLibrary.iml b/MaterialPreferenceLibrary.iml index 49048d8..2ef1074 100644 --- a/MaterialPreferenceLibrary.iml +++ b/MaterialPreferenceLibrary.iml @@ -8,7 +8,7 @@ - + diff --git a/app/app.iml b/app/app.iml index beede04..d8fc8e5 100644 --- a/app/app.iml +++ b/app/app.iml @@ -22,20 +22,20 @@ - - - + + + - + - + @@ -84,42 +84,64 @@ - - + + + + + - + + - - + + + + + - + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3cfccbf..4cf16af 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { vectorDrawables.useSupportLibrary = true applicationId "com.lb.material_preferences" minSdkVersion 14 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "1.0" vectorDrawables.useSupportLibrary = true @@ -19,8 +19,8 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } repositories { jcenter() @@ -32,7 +32,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:27.1.0' + implementation 'androidx.appcompat:appcompat:1.0.0-alpha3' implementation project(':material_preferences_library') // compile 'com.github.AndroidDeveloperLB:MaterialPreferenceLibrary:7' diff --git a/build.gradle b/build.gradle index 0e4cfad..cbc2cbf 100644 --- a/build.gradle +++ b/build.gradle @@ -2,12 +2,12 @@ buildscript { repositories { - jcenter() google() + jcenter() } dependencies { // https://bintray.com/android/android-tools/com.android.tools.build.gradle/view - classpath 'com.android.tools.build:gradle:3.2.0-alpha06' + classpath 'com.android.tools.build:gradle:3.2.0-beta01' // https://github.com/dcendents/android-maven-gradle-plugin // classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' // NOTE: Do not place your application dependencies here; they belong @@ -17,7 +17,7 @@ buildscript { allprojects { repositories { - jcenter() google() + jcenter() } } diff --git a/gradle.properties b/gradle.properties index 1d3591c..acf164f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,6 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +android.enableJetifier=true +android.useAndroidX=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cd91197..42b7f23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Mar 13 22:57:36 IST 2018 +#Sun Jun 24 01:18:21 IDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/material_preferences_library/build.gradle b/material_preferences_library/build.gradle index 33beb6a..7e00a0c 100644 --- a/material_preferences_library/build.gradle +++ b/material_preferences_library/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { vectorDrawables.useSupportLibrary = true minSdkVersion 14 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "1.0" } @@ -17,12 +17,12 @@ android { // } // } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:27.1.0' + implementation 'androidx.appcompat:appcompat:1.0.0-alpha3' } diff --git a/material_preferences_library/material_preferences_library.iml b/material_preferences_library/material_preferences_library.iml index 802fbc7..72d127d 100644 --- a/material_preferences_library/material_preferences_library.iml +++ b/material_preferences_library/material_preferences_library.iml @@ -23,20 +23,20 @@ - - - + + + - + - + @@ -85,42 +85,58 @@ - - + + - + - - - + + + + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/AppCompatPreferenceActivity.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/AppCompatPreferenceActivity.java index ca29dea..1f53f1f 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/AppCompatPreferenceActivity.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/AppCompatPreferenceActivity.java @@ -19,19 +19,20 @@ import android.content.res.Configuration; import android.os.Bundle; import android.preference.PreferenceActivity; -import android.support.annotation.LayoutRes; -import android.support.annotation.Nullable; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatDelegate; -import android.support.v7.widget.Toolbar; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.LayoutRes; +import androidx.annotation.Nullable; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.appcompat.widget.Toolbar; + /** * A {@link PreferenceActivity} which implements and proxies the necessary calls * to be used with AppCompat. - * + *

* This technique can be used with an {@link android.app.Activity} class, not just * {@link PreferenceActivity}. */ @@ -125,4 +126,4 @@ private AppCompatDelegate getDelegate() { } return mDelegate; } -} \ No newline at end of file +} diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java index df6d80e..4ed9573 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java @@ -7,8 +7,8 @@ import android.preference.Preference; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; -import android.support.annotation.XmlRes; -import android.support.v7.widget.Toolbar; +import androidx.annotation.XmlRes; +import androidx.appcompat.widget.Toolbar; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/DialogPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/DialogPreference.java index 3996422..6de7d48 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/DialogPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/DialogPreference.java @@ -26,8 +26,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.preference.PreferenceManager; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v7.app.AlertDialog; +import androidx.core.content.res.ResourcesCompat; +import androidx.appcompat.app.AlertDialog; import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java index ef647e7..3440410 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java @@ -23,7 +23,7 @@ import android.os.Build.VERSION_CODES; import android.os.Parcel; import android.os.Parcelable; -import android.support.v7.widget.AppCompatEditText; +import androidx.appcompat.widget.AppCompatEditText; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/ListPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/ListPreference.java index 62085db..da6117a 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/ListPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/ListPreference.java @@ -21,7 +21,7 @@ import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; -import android.support.v7.app.AlertDialog.Builder; +import androidx.appcompat.app.AlertDialog.Builder; import android.text.TextUtils; import android.util.AttributeSet; import android.widget.ArrayAdapter; diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java index 2660067..110a9e4 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/Preference.java @@ -5,8 +5,8 @@ import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Build.VERSION_CODES; -import android.support.annotation.DrawableRes; -import android.support.v7.content.res.AppCompatResources; +import androidx.annotation.DrawableRes; +import androidx.appcompat.content.res.AppCompatResources; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java index e73c073..fabcb9b 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java @@ -2,7 +2,7 @@ import android.content.Context; import android.content.res.TypedArray; -import android.support.v7.widget.SwitchCompat; +import androidx.appcompat.widget.SwitchCompat; import android.util.AttributeSet; import android.view.View; import android.widget.Checkable; diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/internal/widget/PreferenceImageView.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/internal/widget/PreferenceImageView.java index d3cad71..695141a 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/internal/widget/PreferenceImageView.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/internal/widget/PreferenceImageView.java @@ -29,7 +29,7 @@ * * @hide */ -public class PreferenceImageView extends android.support.v7.widget.AppCompatImageView { +public class PreferenceImageView extends androidx.appcompat.widget.AppCompatImageView { private int mMaxWidth = Integer.MAX_VALUE; private int mMaxHeight = Integer.MAX_VALUE; diff --git a/material_preferences_library/src/main/res/layout/mpl__edittext_dialog_preference.xml b/material_preferences_library/src/main/res/layout/mpl__edittext_dialog_preference.xml index b6eb113..e0e308f 100644 --- a/material_preferences_library/src/main/res/layout/mpl__edittext_dialog_preference.xml +++ b/material_preferences_library/src/main/res/layout/mpl__edittext_dialog_preference.xml @@ -22,14 +22,14 @@ android:layout_marginTop="48dp" android:overScrollMode="ifContentScrolls"> - - - + diff --git a/material_preferences_library/src/main/res/layout/mpl__preference.xml b/material_preferences_library/src/main/res/layout/mpl__preference.xml index 0f1170c..3b7f76b 100644 --- a/material_preferences_library/src/main/res/layout/mpl__preference.xml +++ b/material_preferences_library/src/main/res/layout/mpl__preference.xml @@ -20,7 +20,7 @@ - - - + - - - - + diff --git a/material_preferences_library/src/main/res/layout/mpl__preference_activity.xml b/material_preferences_library/src/main/res/layout/mpl__preference_activity.xml index d0850fe..4b31c0e 100644 --- a/material_preferences_library/src/main/res/layout/mpl__preference_activity.xml +++ b/material_preferences_library/src/main/res/layout/mpl__preference_activity.xml @@ -1,4 +1,4 @@ - - - \ No newline at end of file + diff --git a/material_preferences_library/src/main/res/layout/mpl__preference_widget_checkbox.xml b/material_preferences_library/src/main/res/layout/mpl__preference_widget_checkbox.xml index 05ab93b..9b1a727 100644 --- a/material_preferences_library/src/main/res/layout/mpl__preference_widget_checkbox.xml +++ b/material_preferences_library/src/main/res/layout/mpl__preference_widget_checkbox.xml @@ -3,9 +3,9 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,12 +15,12 @@ - + diff --git a/material_preferences_library/src/main/res/layout/mpl__simple_list_item_single_choice.xml b/material_preferences_library/src/main/res/layout/mpl__simple_list_item_single_choice.xml index b21861d..d4eeb57 100644 --- a/material_preferences_library/src/main/res/layout/mpl__simple_list_item_single_choice.xml +++ b/material_preferences_library/src/main/res/layout/mpl__simple_list_item_single_choice.xml @@ -1,16 +1,16 @@ - + diff --git a/material_preferences_library/src/main/res/layout/mpl__switch_preference.xml b/material_preferences_library/src/main/res/layout/mpl__switch_preference.xml index 26cc4b9..38b982a 100644 --- a/material_preferences_library/src/main/res/layout/mpl__switch_preference.xml +++ b/material_preferences_library/src/main/res/layout/mpl__switch_preference.xml @@ -1,10 +1,10 @@ - \ No newline at end of file + From 3628e6c63b01f2d8e0c96f003f2312e46f43f027 Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Sun, 24 Jun 2018 01:54:27 +0300 Subject: [PATCH 10/12] cleaned some code --- .../material_preferences_library/PreferenceActivity.java | 7 ++++--- .../custom_preferences/CheckBoxPreference.java | 2 +- .../custom_preferences/SwitchPreference.java | 5 +++-- .../custom_preferences/TwoStatePreference.java | 2 +- .../main/res/layout/mpl__preference_widget_checkbox.xml | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java index 4ed9573..17d030c 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/PreferenceActivity.java @@ -7,8 +7,6 @@ import android.preference.Preference; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; -import androidx.annotation.XmlRes; -import androidx.appcompat.widget.Toolbar; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; @@ -17,6 +15,9 @@ import java.util.Map; import java.util.Stack; +import androidx.annotation.XmlRes; +import androidx.appcompat.widget.Toolbar; + public abstract class PreferenceActivity extends AppCompatPreferenceActivity { private Toolbar _toolbar; @@ -45,7 +46,7 @@ protected void onCreate(final Bundle savedInstanceState) { addPreferencesFromResource(getPreferencesXmlId()); final Map preferenceToParentMap = buildPreferenceParentTree(this); for (PreferenceGroup preferenceGroup : preferenceToParentMap.values()) - if (preferenceGroup != null && preferenceGroup instanceof PreferenceScreen) + if (preferenceGroup instanceof PreferenceScreen) preferenceGroup.setLayoutResource(R.layout.mpl__preference); _toolbar.setClickable(true); _toolbar.setNavigationIcon(getResIdFromAttribute(this, R.attr.homeAsUpIndicator)); diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/CheckBoxPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/CheckBoxPreference.java index f624fb8..02452dd 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/CheckBoxPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/CheckBoxPreference.java @@ -67,7 +67,7 @@ public CheckBoxPreference(Context context) { protected void onBindView(View view) { super.onBindView(view); View checkboxView = view.findViewById(android.R.id.checkbox); - if (checkboxView != null && checkboxView instanceof Checkable) + if (checkboxView instanceof Checkable) ((Checkable) checkboxView).setChecked(mChecked); syncSummaryView(view); } diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java index fabcb9b..61423a1 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/SwitchPreference.java @@ -2,7 +2,6 @@ import android.content.Context; import android.content.res.TypedArray; -import androidx.appcompat.widget.SwitchCompat; import android.util.AttributeSet; import android.view.View; import android.widget.Checkable; @@ -10,6 +9,8 @@ import com.lb.material_preferences_library.R; +import androidx.appcompat.widget.SwitchCompat; + /** * A {@link Preference} that provides a two-state toggleable option. *

@@ -114,7 +115,7 @@ protected void init(final Context context, final AttributeSet attrs, final int d protected void onBindView(View view) { super.onBindView(view); View checkableView = view.findViewById(android.R.id.checkbox); - if (checkableView != null && checkableView instanceof Checkable) { + if (checkableView instanceof Checkable) { if (checkableView instanceof SwitchCompat) { final SwitchCompat switchView = (SwitchCompat) checkableView; switchView.setOnCheckedChangeListener(null); diff --git a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/TwoStatePreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/TwoStatePreference.java index 2b25f59..69a29bf 100644 --- a/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/TwoStatePreference.java +++ b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/TwoStatePreference.java @@ -79,7 +79,7 @@ public boolean isChecked() { @Override public boolean shouldDisableDependents() { - boolean shouldDisable = mDisableDependentsState ? mChecked : !mChecked; + boolean shouldDisable = mDisableDependentsState == mChecked; return shouldDisable || super.shouldDisableDependents(); } diff --git a/material_preferences_library/src/main/res/layout/mpl__preference_widget_checkbox.xml b/material_preferences_library/src/main/res/layout/mpl__preference_widget_checkbox.xml index 9b1a727..bee8bf1 100644 --- a/material_preferences_library/src/main/res/layout/mpl__preference_widget_checkbox.xml +++ b/material_preferences_library/src/main/res/layout/mpl__preference_widget_checkbox.xml @@ -17,7 +17,7 @@ inside android.R.layout.preference. --> Date: Fri, 6 Jul 2018 10:22:12 +0300 Subject: [PATCH 11/12] updated sdks --- .idea/caches/build_file_checksums.ser | Bin 606 -> 606 bytes MaterialPreferenceLibrary.iml | 8 -- app/app.iml | 78 ++++++++---------- app/build.gradle | 2 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- material_preferences_library/build.gradle | 2 +- .../material_preferences_library.iml | 78 ++++++++---------- 8 files changed, 73 insertions(+), 101 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 60b1dbd72b7fc4ec889204d1113702023122750d..d62832d15aa42c49c1ae7c127b1c312eee8de0e6 100644 GIT binary patch delta 98 zcmV-o0G2~sVlL2OW)k5lj#9A5RNOq8v%URzpJ=H1f$n-=94c1 EFS3a(%>V!Z delta 98 zcmV-o0G;XGCh`Vx?aQwYlzEIlj#9A5Q1ZR<_Ro1rKS#mJ*p=aS(7gU EFYr7nbpQYW diff --git a/MaterialPreferenceLibrary.iml b/MaterialPreferenceLibrary.iml index 2ef1074..c58f24e 100644 --- a/MaterialPreferenceLibrary.iml +++ b/MaterialPreferenceLibrary.iml @@ -1,13 +1,5 @@ - - - - - - diff --git a/app/app.iml b/app/app.iml index d8fc8e5..5c94e1c 100644 --- a/app/app.iml +++ b/app/app.iml @@ -29,16 +29,16 @@ - + - + - + - + @@ -84,64 +84,54 @@ - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 4cf16af..0af7b4a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.0.0-alpha3' + implementation 'androidx.appcompat:appcompat:1.0.0-beta01' implementation project(':material_preferences_library') // compile 'com.github.AndroidDeveloperLB:MaterialPreferenceLibrary:7' diff --git a/build.gradle b/build.gradle index cbc2cbf..019b3b9 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { // https://bintray.com/android/android-tools/com.android.tools.build.gradle/view - classpath 'com.android.tools.build:gradle:3.2.0-beta01' + classpath 'com.android.tools.build:gradle:3.3.0-alpha02' // https://github.com/dcendents/android-maven-gradle-plugin // classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 42b7f23..ad34c65 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Jun 24 01:18:21 IDT 2018 +#Fri Jul 06 09:09:00 IDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip diff --git a/material_preferences_library/build.gradle b/material_preferences_library/build.gradle index 7e00a0c..29b2c10 100644 --- a/material_preferences_library/build.gradle +++ b/material_preferences_library/build.gradle @@ -24,5 +24,5 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.0.0-alpha3' + implementation 'androidx.appcompat:appcompat:1.0.0-beta01' } diff --git a/material_preferences_library/material_preferences_library.iml b/material_preferences_library/material_preferences_library.iml index 72d127d..a9012cf 100644 --- a/material_preferences_library/material_preferences_library.iml +++ b/material_preferences_library/material_preferences_library.iml @@ -30,16 +30,16 @@ - + - + - + - + @@ -86,57 +86,47 @@ - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 1918cfd735de11ca4a7ebaf5015d7f3b2256fa26 Mon Sep 17 00:00:00 2001 From: AndroidDeveloperLB Date: Sun, 28 Oct 2018 19:08:34 +0200 Subject: [PATCH 12/12] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4d51edb..fc3ebd8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ [![Release](https://img.shields.io/github/release/AndroidDeveloperLB/MaterialPreferenceLibrary.svg?style=flat)](https://jitpack.io/#AndroidDeveloperLB/MaterialPreferenceLibrary) +Note : This library is not developed anymore, as there is an official way to support old Android versions with preferences that have same material design style, by using PreferenceFragmentCompat : https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat + MaterialPreferenceLibrary ==================================