+
@@ -9,7 +9,6 @@
-
@@ -20,33 +19,35 @@
-
+
-
-
-
+
+
+
-
-
+
+
+
-
+
-
-
+
+
+
-
+
+
-
@@ -54,15 +55,20 @@
-
+
+
+
+
+
+
+
-
@@ -70,7 +76,6 @@
-
@@ -78,33 +83,50 @@
-
-
-
-
-
-
-
+
+
-
-
-
+
+
+
+
-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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 15dedc3..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
@@ -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;
@@ -6,8 +7,6 @@
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
-import android.support.annotation.XmlRes;
-import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
@@ -16,79 +15,74 @@
import java.util.Map;
import java.util.Stack;
-public abstract class PreferenceActivity extends AppCompatPreferenceActivity
- {
- private Toolbar _toolbar;
+import androidx.annotation.XmlRes;
+import androidx.appcompat.widget.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 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..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
@@ -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 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..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
@@ -15,6 +15,7 @@
*/
package com.lb.material_preferences_library.custom_preferences;
+
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -25,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;
@@ -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/EditTextPreference.java b/material_preferences_library/src/main/java/com/lb/material_preferences_library/custom_preferences/EditTextPreference.java
index 9d82436..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,8 +23,7 @@
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 androidx.appcompat.widget.AppCompatEditText;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
@@ -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/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..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;
@@ -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..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.v4.content.ContextCompat;
+import androidx.annotation.DrawableRes;
+import androidx.appcompat.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..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 android.support.v7.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.
*
@@ -21,191 +22,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 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..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
@@ -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;
+ 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..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
@@ -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 androidx.appcompat.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
-
-
-
+
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..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
@@ -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
+