Methods Summary |
---|
protected boolean | callChangeListener(java.lang.Object newValue)Call this method after the user changes the preference, but before the
internal state is set. This allows the client to ignore the user value.
return mOnChangeListener == null ? true : mOnChangeListener.onPreferenceChange(this, newValue);
|
boolean | canRecycleLayout()
return mCanRecycleLayout;
|
public int | compareTo(android.preference.Preference another)Compares Preference objects based on order (if set), otherwise alphabetically on the titles.
if (mOrder != another.mOrder) {
// Do order comparison
return mOrder - another.mOrder;
} else if (mTitle == another.mTitle) {
// If titles are null or share same object comparison
return 0;
} else if (mTitle == null) {
return 1;
} else if (another.mTitle == null) {
return -1;
} else {
// Do name comparison
return CharSequences.compareToIgnoreCase(mTitle, another.mTitle);
}
|
void | dispatchRestoreInstanceState(android.os.Bundle container)Called by {@link #restoreHierarchyState} to retrieve the saved state for this
Preference and its children. May be overridden to modify how restoring
happens to the children of a Preference. For example, some Preference objects may
not want to save state for their children.
if (hasKey()) {
Parcelable state = container.getParcelable(mKey);
if (state != null) {
mBaseMethodCalled = false;
onRestoreInstanceState(state);
if (!mBaseMethodCalled) {
throw new IllegalStateException(
"Derived class did not call super.onRestoreInstanceState()");
}
}
}
|
void | dispatchSaveInstanceState(android.os.Bundle container)Called by {@link #saveHierarchyState} to store the instance for this Preference and its children.
May be overridden to modify how the save happens for children. For example, some
Preference objects may want to not store an instance for their children.
if (hasKey()) {
mBaseMethodCalled = false;
Parcelable state = onSaveInstanceState();
if (!mBaseMethodCalled) {
throw new IllegalStateException(
"Derived class did not call super.onSaveInstanceState()");
}
if (state != null) {
container.putParcelable(mKey, state);
}
}
|
private void | dispatchSetInitialValue()
// By now, we know if we are persistent.
final boolean shouldPersist = shouldPersist();
if (!shouldPersist || !getSharedPreferences().contains(mKey)) {
if (mDefaultValue != null) {
onSetInitialValue(false, mDefaultValue);
}
} else {
onSetInitialValue(true, null);
}
|
protected android.preference.Preference | findPreferenceInHierarchy(java.lang.String key)Finds a Preference in this hierarchy (the whole thing,
even above/below your {@link PreferenceScreen} screen break) with the given
key.
This only functions after we have been attached to a hierarchy.
if (TextUtils.isEmpty(key) || mPreferenceManager == null) {
return null;
}
return mPreferenceManager.findPreference(key);
|
public android.content.Context | getContext()Returns the {@link android.content.Context} of this Preference.
Each Preference in a Preference hierarchy can be
from different Context (for example, if multiple activities provide preferences into a single
{@link PreferenceActivity}). This Context will be used to save the Preference values.
return mContext;
|
public java.lang.String | getDependency()Returns the key of the dependency on this Preference.
return mDependencyKey;
|
public SharedPreferences.Editor | getEditor()Returns an {@link SharedPreferences.Editor} where this Preference can
save its value(s). Usually it's easier to use one of the helper save
methods: {@link #persistBoolean(boolean)}, {@link #persistFloat(float)},
{@link #persistInt(int)}, {@link #persistLong(long)},
{@link #persistString(String)}. To read values, see
{@link #getSharedPreferences()}. If {@link #shouldCommit()} returns
true, it is this Preference's responsibility to commit.
In some cases, writes to this will not be committed right away and hence
not show up in the SharedPreferences, this is intended behavior to
improve performance.
if (mPreferenceManager == null) {
return null;
}
return mPreferenceManager.getEditor();
|
public android.os.Bundle | getExtras()Return the extras Bundle object associated with this preference, creating
a new Bundle if there currently isn't one. You can use this to get and
set individual extra key/value pairs.
if (mExtras == null) {
mExtras = new Bundle();
}
return mExtras;
|
java.lang.StringBuilder | getFilterableStringBuilder()Returns the text that will be used to filter this Preference depending on
user input.
If overridding and calling through to the superclass, make sure to prepend
your additions with a space.
StringBuilder sb = new StringBuilder();
CharSequence title = getTitle();
if (!TextUtils.isEmpty(title)) {
sb.append(title).append(' ");
}
CharSequence summary = getSummary();
if (!TextUtils.isEmpty(summary)) {
sb.append(summary).append(' ");
}
if (sb.length() > 0) {
// Drop the last space
sb.setLength(sb.length() - 1);
}
return sb;
|
public java.lang.String | getFragment()Return the fragment class name associated with this Preference.
return mFragment;
|
public android.graphics.drawable.Drawable | getIcon()Returns the icon of this Preference.
return mIcon;
|
long | getId()Returns a unique ID for this Preference. This ID should be unique across all
Preference objects in a hierarchy.
return mId;
|
public android.content.Intent | getIntent()Return the {@link Intent} associated with this Preference.
return mIntent;
|
public java.lang.String | getKey()Gets the key for this Preference, which is also the key used for storing
values into SharedPreferences.
return mKey;
|
public int | getLayoutResource()Gets the layout resource that will be shown as the {@link View} for this Preference.
return mLayoutResId;
|
public android.preference.Preference$OnPreferenceChangeListener | getOnPreferenceChangeListener()Returns the callback to be invoked when this Preference is changed by the
user (but before the internal state has been updated).
return mOnChangeListener;
|
public android.preference.Preference$OnPreferenceClickListener | getOnPreferenceClickListener()Returns the callback to be invoked when this Preference is clicked.
return mOnClickListener;
|
public int | getOrder()Gets the order of this Preference with respect to other Preference objects
on the same level.
return mOrder;
|
protected boolean | getPersistedBoolean(boolean defaultReturnValue)Attempts to get a persisted boolean from the {@link android.content.SharedPreferences}.
if (!shouldPersist()) {
return defaultReturnValue;
}
return mPreferenceManager.getSharedPreferences().getBoolean(mKey, defaultReturnValue);
|
protected float | getPersistedFloat(float defaultReturnValue)Attempts to get a persisted float from the {@link android.content.SharedPreferences}.
if (!shouldPersist()) {
return defaultReturnValue;
}
return mPreferenceManager.getSharedPreferences().getFloat(mKey, defaultReturnValue);
|
protected int | getPersistedInt(int defaultReturnValue)Attempts to get a persisted int from the {@link android.content.SharedPreferences}.
if (!shouldPersist()) {
return defaultReturnValue;
}
return mPreferenceManager.getSharedPreferences().getInt(mKey, defaultReturnValue);
|
protected long | getPersistedLong(long defaultReturnValue)Attempts to get a persisted long from the {@link android.content.SharedPreferences}.
if (!shouldPersist()) {
return defaultReturnValue;
}
return mPreferenceManager.getSharedPreferences().getLong(mKey, defaultReturnValue);
|
protected java.lang.String | getPersistedString(java.lang.String defaultReturnValue)Attempts to get a persisted String from the {@link android.content.SharedPreferences}.
This will check if this Preference is persistent, get the SharedPreferences
from the {@link PreferenceManager}, and get the value.
if (!shouldPersist()) {
return defaultReturnValue;
}
return mPreferenceManager.getSharedPreferences().getString(mKey, defaultReturnValue);
|
protected java.util.Set | getPersistedStringSet(java.util.Set defaultReturnValue)Attempts to get a persisted set of Strings from the
{@link android.content.SharedPreferences}.
This will check if this Preference is persistent, get the SharedPreferences
from the {@link PreferenceManager}, and get the value.
if (!shouldPersist()) {
return defaultReturnValue;
}
return mPreferenceManager.getSharedPreferences().getStringSet(mKey, defaultReturnValue);
|
public PreferenceManager | getPreferenceManager()Gets the {@link PreferenceManager} that manages this Preference object's tree.
return mPreferenceManager;
|
public android.content.SharedPreferences | getSharedPreferences()Returns the {@link SharedPreferences} where this Preference can read its
value(s). Usually, it's easier to use one of the helper read methods:
{@link #getPersistedBoolean(boolean)}, {@link #getPersistedFloat(float)},
{@link #getPersistedInt(int)}, {@link #getPersistedLong(long)},
{@link #getPersistedString(String)}. To save values, see
{@link #getEditor()}.
In some cases, writes to the {@link #getEditor()} will not be committed
right away and hence not show up in the returned
{@link SharedPreferences}, this is intended behavior to improve
performance.
if (mPreferenceManager == null) {
return null;
}
return mPreferenceManager.getSharedPreferences();
|
public boolean | getShouldDisableView()Checks whether this Preference should disable its view when it's action is disabled.
return mShouldDisableView;
|
public java.lang.CharSequence | getSummary()Returns the summary of this Preference.
return mSummary;
|
public java.lang.CharSequence | getTitle()Returns the title of this Preference.
return mTitle;
|
public int | getTitleRes()Returns the title resource ID of this Preference. If the title did
not come from a resource, 0 is returned.
return mTitleRes;
|
public android.view.View | getView(android.view.View convertView, android.view.ViewGroup parent)Gets the View that will be shown in the {@link PreferenceActivity}.
if (convertView == null) {
convertView = onCreateView(parent);
}
onBindView(convertView);
return convertView;
|
public int | getWidgetLayoutResource()Gets the layout resource for the controllable widget portion of this Preference.
return mWidgetLayoutResId;
|
public boolean | hasKey()Checks whether this Preference has a valid key.
return !TextUtils.isEmpty(mKey);
|
public boolean | isEnabled()Checks whether this Preference should be enabled in the list.
return mEnabled && mDependencyMet && mParentDependencyMet;
|
public boolean | isPersistent()Checks whether this Preference is persistent. If it is, it stores its value(s) into
the persistent {@link SharedPreferences} storage.
return mPersistent;
|
public boolean | isSelectable()Checks whether this Preference should be selectable in the list.
return mSelectable;
|
protected void | notifyChanged()Should be called when the data of this {@link Preference} has changed.
if (mListener != null) {
mListener.onPreferenceChange(this);
}
|
public void | notifyDependencyChange(boolean disableDependents)Notifies any listening dependents of a change that affects the
dependency.
final List<Preference> dependents = mDependents;
if (dependents == null) {
return;
}
final int dependentsCount = dependents.size();
for (int i = 0; i < dependentsCount; i++) {
dependents.get(i).onDependencyChanged(this, disableDependents);
}
|
protected void | notifyHierarchyChanged()Should be called when a Preference has been
added/removed from this group, or the ordering should be
re-evaluated.
if (mListener != null) {
mListener.onPreferenceHierarchyChange(this);
}
|
protected void | onAttachedToActivity()Called when the Preference hierarchy has been attached to the
{@link PreferenceActivity}. This can also be called when this
Preference has been attached to a group that was already attached
to the {@link PreferenceActivity}.
// At this point, the hierarchy that this preference is in is connected
// with all other preferences.
registerDependency();
|
protected void | onAttachedToHierarchy(PreferenceManager preferenceManager)Called when this Preference has been attached to a Preference hierarchy.
Make sure to call the super implementation.
mPreferenceManager = preferenceManager;
mId = preferenceManager.getNextId();
dispatchSetInitialValue();
|
protected void | onBindView(android.view.View view)Binds the created View to the data for this Preference.
This is a good place to grab references to custom Views in the layout and
set properties on them.
Make sure to call through to the superclass's implementation.
final TextView titleView = (TextView) view.findViewById(com.android.internal.R.id.title);
if (titleView != null) {
final CharSequence title = getTitle();
if (!TextUtils.isEmpty(title)) {
titleView.setText(title);
titleView.setVisibility(View.VISIBLE);
} else {
titleView.setVisibility(View.GONE);
}
}
final TextView summaryView = (TextView) view.findViewById(
com.android.internal.R.id.summary);
if (summaryView != null) {
final CharSequence summary = getSummary();
if (!TextUtils.isEmpty(summary)) {
summaryView.setText(summary);
summaryView.setVisibility(View.VISIBLE);
} else {
summaryView.setVisibility(View.GONE);
}
}
final ImageView imageView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
if (imageView != null) {
if (mIconResId != 0 || mIcon != null) {
if (mIcon == null) {
mIcon = getContext().getDrawable(mIconResId);
}
if (mIcon != null) {
imageView.setImageDrawable(mIcon);
}
}
imageView.setVisibility(mIcon != null ? View.VISIBLE : View.GONE);
}
final View imageFrame = view.findViewById(com.android.internal.R.id.icon_frame);
if (imageFrame != null) {
imageFrame.setVisibility(mIcon != null ? View.VISIBLE : View.GONE);
}
if (mShouldDisableView) {
setEnabledStateOnViews(view, isEnabled());
}
|
protected void | onClick()Processes a click on the preference. This includes saving the value to
the {@link SharedPreferences}. However, the overridden method should
call {@link #callChangeListener(Object)} to make sure the client wants to
update the preference's state with the new value.
|
protected android.view.View | onCreateView(android.view.ViewGroup parent)Creates the View to be shown for this Preference in the
{@link PreferenceActivity}. The default behavior is to inflate the main
layout of this Preference (see {@link #setLayoutResource(int)}. If
changing this behavior, please specify a {@link ViewGroup} with ID
{@link android.R.id#widget_frame}.
Make sure to call through to the superclass's implementation.
final LayoutInflater layoutInflater =
(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = layoutInflater.inflate(mLayoutResId, parent, false);
final ViewGroup widgetFrame = (ViewGroup) layout
.findViewById(com.android.internal.R.id.widget_frame);
if (widgetFrame != null) {
if (mWidgetLayoutResId != 0) {
layoutInflater.inflate(mWidgetLayoutResId, widgetFrame);
} else {
widgetFrame.setVisibility(View.GONE);
}
}
return layout;
|
public void | onDependencyChanged(android.preference.Preference dependency, boolean disableDependent)Called when the dependency changes.
if (mDependencyMet == disableDependent) {
mDependencyMet = !disableDependent;
// Enabled state can change dependent preferences' states, so notify
notifyDependencyChange(shouldDisableDependents());
notifyChanged();
}
|
protected java.lang.Object | onGetDefaultValue(android.content.res.TypedArray a, int index)Called when a Preference is being inflated and the default value
attribute needs to be read. Since different Preference types have
different value types, the subclass should get and return the default
value which will be its value type.
For example, if the value type is String, the body of the method would
proxy to {@link TypedArray#getString(int)}.
return null;
|
public boolean | onKey(android.view.View v, int keyCode, android.view.KeyEvent event)Allows a Preference to intercept key events without having focus.
For example, SeekBarPreference uses this to intercept +/- to adjust
the progress.
return false;
|
public void | onParentChanged(android.preference.Preference parent, boolean disableChild)Called when the implicit parent dependency changes.
if (mParentDependencyMet == disableChild) {
mParentDependencyMet = !disableChild;
// Enabled state can change dependent preferences' states, so notify
notifyDependencyChange(shouldDisableDependents());
notifyChanged();
}
|
protected void | onPrepareForRemoval()Called when this Preference is being removed from the hierarchy. You
should remove any references to this Preference that you know about. Make
sure to call through to the superclass implementation.
unregisterDependency();
|
protected void | onRestoreInstanceState(android.os.Parcelable state)Hook allowing a Preference to re-apply a representation of its internal
state that had previously been generated by {@link #onSaveInstanceState}.
This function will never be called with a null state.
mBaseMethodCalled = true;
if (state != BaseSavedState.EMPTY_STATE && state != null) {
throw new IllegalArgumentException("Wrong state class -- expecting Preference State");
}
|
protected android.os.Parcelable | onSaveInstanceState()Hook allowing a Preference to generate a representation of its internal
state that can later be used to create a new instance with that same
state. This state should only contain information that is not persistent
or can be reconstructed later.
mBaseMethodCalled = true;
return BaseSavedState.EMPTY_STATE;
|
protected void | onSetInitialValue(boolean restorePersistedValue, java.lang.Object defaultValue)Implement this to set the initial value of the Preference.
If restorePersistedValue is true, you should restore the
Preference value from the {@link android.content.SharedPreferences}. If
restorePersistedValue is false, you should set the Preference
value to defaultValue that is given (and possibly store to SharedPreferences
if {@link #shouldPersist()} is true).
This may not always be called. One example is if it should not persist
but there is no default value given.
|
public android.os.Bundle | peekExtras()Return the extras Bundle object associated with this preference,
returning null if there is not currently one.
return mExtras;
|
public void | performClick(PreferenceScreen preferenceScreen)Called when a click should be performed.
if (!isEnabled()) {
return;
}
onClick();
if (mOnClickListener != null && mOnClickListener.onPreferenceClick(this)) {
return;
}
PreferenceManager preferenceManager = getPreferenceManager();
if (preferenceManager != null) {
PreferenceManager.OnPreferenceTreeClickListener listener = preferenceManager
.getOnPreferenceTreeClickListener();
if (preferenceScreen != null && listener != null
&& listener.onPreferenceTreeClick(preferenceScreen, this)) {
return;
}
}
if (mIntent != null) {
Context context = getContext();
context.startActivity(mIntent);
}
|
protected boolean | persistBoolean(boolean value)Attempts to persist a boolean to the {@link android.content.SharedPreferences}.
if (shouldPersist()) {
if (value == getPersistedBoolean(!value)) {
// It's already there, so the same as persisting
return true;
}
SharedPreferences.Editor editor = mPreferenceManager.getEditor();
editor.putBoolean(mKey, value);
tryCommit(editor);
return true;
}
return false;
|
protected boolean | persistFloat(float value)Attempts to persist a float to the {@link android.content.SharedPreferences}.
if (shouldPersist()) {
if (value == getPersistedFloat(Float.NaN)) {
// It's already there, so the same as persisting
return true;
}
SharedPreferences.Editor editor = mPreferenceManager.getEditor();
editor.putFloat(mKey, value);
tryCommit(editor);
return true;
}
return false;
|
protected boolean | persistInt(int value)Attempts to persist an int to the {@link android.content.SharedPreferences}.
if (shouldPersist()) {
if (value == getPersistedInt(~value)) {
// It's already there, so the same as persisting
return true;
}
SharedPreferences.Editor editor = mPreferenceManager.getEditor();
editor.putInt(mKey, value);
tryCommit(editor);
return true;
}
return false;
|
protected boolean | persistLong(long value)Attempts to persist a long to the {@link android.content.SharedPreferences}.
if (shouldPersist()) {
if (value == getPersistedLong(~value)) {
// It's already there, so the same as persisting
return true;
}
SharedPreferences.Editor editor = mPreferenceManager.getEditor();
editor.putLong(mKey, value);
tryCommit(editor);
return true;
}
return false;
|
protected boolean | persistString(java.lang.String value)Attempts to persist a String to the {@link android.content.SharedPreferences}.
This will check if this Preference is persistent, get an editor from
the {@link PreferenceManager}, put in the string, and check if we should commit (and
commit if so).
if (shouldPersist()) {
// Shouldn't store null
if (value == getPersistedString(null)) {
// It's already there, so the same as persisting
return true;
}
SharedPreferences.Editor editor = mPreferenceManager.getEditor();
editor.putString(mKey, value);
tryCommit(editor);
return true;
}
return false;
|
protected boolean | persistStringSet(java.util.Set values)Attempts to persist a set of Strings to the {@link android.content.SharedPreferences}.
This will check if this Preference is persistent, get an editor from
the {@link PreferenceManager}, put in the strings, and check if we should commit (and
commit if so).
if (shouldPersist()) {
// Shouldn't store null
if (values.equals(getPersistedStringSet(null))) {
// It's already there, so the same as persisting
return true;
}
SharedPreferences.Editor editor = mPreferenceManager.getEditor();
editor.putStringSet(mKey, values);
tryCommit(editor);
return true;
}
return false;
|
private void | registerDependency()
if (TextUtils.isEmpty(mDependencyKey)) return;
Preference preference = findPreferenceInHierarchy(mDependencyKey);
if (preference != null) {
preference.registerDependent(this);
} else {
throw new IllegalStateException("Dependency \"" + mDependencyKey
+ "\" not found for preference \"" + mKey + "\" (title: \"" + mTitle + "\"");
}
|
private void | registerDependent(android.preference.Preference dependent)Adds a dependent Preference on this Preference so we can notify it.
Usually, the dependent Preference registers itself (it's good for it to
know it depends on something), so please use
{@link Preference#setDependency(String)} on the dependent Preference.
if (mDependents == null) {
mDependents = new ArrayList<Preference>();
}
mDependents.add(dependent);
dependent.onDependencyChanged(this, shouldDisableDependents());
|
void | requireKey()Checks whether the key is present, and if it isn't throws an
exception. This should be called by subclasses that store preferences in
the {@link SharedPreferences}.
if (mKey == null) {
throw new IllegalStateException("Preference does not have a key assigned.");
}
mRequiresKey = true;
|
public void | restoreHierarchyState(android.os.Bundle container)Restore this Preference hierarchy's previously saved state from the given container.
dispatchRestoreInstanceState(container);
|
public void | saveHierarchyState(android.os.Bundle container)Store this Preference hierarchy's frozen state into the given container.
dispatchSaveInstanceState(container);
|
public void | setDefaultValue(java.lang.Object defaultValue)Sets the default value for this Preference, which will be set either if
persistence is off or persistence is on and the preference is not found
in the persistent storage.
mDefaultValue = defaultValue;
|
public void | setDependency(java.lang.String dependencyKey)Sets the key of a Preference that this Preference will depend on. If that
Preference is not set or is off, this Preference will be disabled.
// Unregister the old dependency, if we had one
unregisterDependency();
// Register the new
mDependencyKey = dependencyKey;
registerDependency();
|
public void | setEnabled(boolean enabled)Sets whether this Preference is enabled. If disabled, it will
not handle clicks.
if (mEnabled != enabled) {
mEnabled = enabled;
// Enabled state can change dependent preferences' states, so notify
notifyDependencyChange(shouldDisableDependents());
notifyChanged();
}
|
private void | setEnabledStateOnViews(android.view.View v, boolean enabled)Makes sure the view (and any children) get the enabled state changed.
v.setEnabled(enabled);
if (v instanceof ViewGroup) {
final ViewGroup vg = (ViewGroup) v;
for (int i = vg.getChildCount() - 1; i >= 0; i--) {
setEnabledStateOnViews(vg.getChildAt(i), enabled);
}
}
|
public void | setFragment(java.lang.String fragment)Sets the class name of a fragment to be shown when this Preference is clicked.
mFragment = fragment;
|
public void | setIcon(android.graphics.drawable.Drawable icon)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)}.
if ((icon == null && mIcon != null) || (icon != null && mIcon != icon)) {
mIcon = icon;
notifyChanged();
}
|
public void | setIcon(int iconResId)Sets the icon for this Preference with a resource ID.
mIconResId = iconResId;
setIcon(mContext.getDrawable(iconResId));
|
public void | setIntent(android.content.Intent intent)Sets an {@link Intent} to be used for
{@link Context#startActivity(Intent)} when this Preference is clicked.
mIntent = intent;
|
public void | setKey(java.lang.String key)Sets the key for this Preference, which is used as a key to the
{@link SharedPreferences}. This should be unique for the package.
mKey = key;
if (mRequiresKey && !hasKey()) {
requireKey();
}
|
public void | setLayoutResource(int layoutResId)Sets the layout resource that is inflated as the {@link View} to be shown
for this Preference. In most cases, the default layout is sufficient for
custom Preference objects and only the widget layout needs to be changed.
This layout should contain a {@link ViewGroup} with ID
{@link android.R.id#widget_frame} to be the parent of the specific widget
for this Preference. It should similarly contain
{@link android.R.id#title} and {@link android.R.id#summary}.
if (layoutResId != mLayoutResId) {
// Layout changed
mCanRecycleLayout = false;
}
mLayoutResId = layoutResId;
|
final void | setOnPreferenceChangeInternalListener(android.preference.Preference$OnPreferenceChangeInternalListener listener)Sets the internal change listener.
mListener = listener;
|
public void | setOnPreferenceChangeListener(android.preference.Preference$OnPreferenceChangeListener onPreferenceChangeListener)Sets the callback to be invoked when this Preference is changed by the
user (but before the internal state has been updated).
mOnChangeListener = onPreferenceChangeListener;
|
public void | setOnPreferenceClickListener(android.preference.Preference$OnPreferenceClickListener onPreferenceClickListener)Sets the callback to be invoked when this Preference is clicked.
mOnClickListener = onPreferenceClickListener;
|
public void | setOrder(int order)Sets the order of this Preference with respect to other
Preference objects on the same level. If this is not specified, the
default behavior is to sort alphabetically. The
{@link PreferenceGroup#setOrderingAsAdded(boolean)} can be used to order
Preference objects based on the order they appear in the XML.
if (order != mOrder) {
mOrder = order;
// Reorder the list
notifyHierarchyChanged();
}
|
public void | setPersistent(boolean persistent)Sets whether this Preference is persistent. When persistent,
it stores its value(s) into the persistent {@link SharedPreferences}
storage.
mPersistent = persistent;
|
public void | setSelectable(boolean selectable)Sets whether this Preference is selectable.
if (mSelectable != selectable) {
mSelectable = selectable;
notifyChanged();
}
|
public void | setShouldDisableView(boolean shouldDisableView)Sets whether this Preference should disable its view when it gets
disabled.
For example, set this and {@link #setEnabled(boolean)} to false for
preferences that are only displaying information and 1) should not be
clickable 2) should not have the view set to the disabled state.
mShouldDisableView = shouldDisableView;
notifyChanged();
|
public void | setSummary(java.lang.CharSequence summary)Sets the summary for this Preference with a CharSequence.
if (summary == null && mSummary != null || summary != null && !summary.equals(mSummary)) {
mSummary = summary;
notifyChanged();
}
|
public void | setSummary(int summaryResId)Sets the summary for this Preference with a resource ID.
setSummary(mContext.getString(summaryResId));
|
public void | setTitle(java.lang.CharSequence title)Sets the title for this Preference with a CharSequence.
This title will be placed into the ID
{@link android.R.id#title} within the View created by
{@link #onCreateView(ViewGroup)}.
if (title == null && mTitle != null || title != null && !title.equals(mTitle)) {
mTitleRes = 0;
mTitle = title;
notifyChanged();
}
|
public void | setTitle(int titleResId)Sets the title for this Preference with a resource ID.
setTitle(mContext.getString(titleResId));
mTitleRes = titleResId;
|
public void | setWidgetLayoutResource(int widgetLayoutResId)Sets the layout for the controllable widget portion of this Preference. This
is inflated into the main layout. For example, a {@link CheckBoxPreference}
would specify a custom layout (consisting of just the CheckBox) here,
instead of creating its own main layout.
if (widgetLayoutResId != mWidgetLayoutResId) {
// Layout changed
mCanRecycleLayout = false;
}
mWidgetLayoutResId = widgetLayoutResId;
|
public boolean | shouldCommit()Returns whether the {@link Preference} should commit its saved value(s) in
{@link #getEditor()}. This may return false in situations where batch
committing is being done (by the manager) to improve performance.
if (mPreferenceManager == null) {
return false;
}
return mPreferenceManager.shouldCommit();
|
public boolean | shouldDisableDependents()Checks whether this preference's dependents should currently be
disabled.
return !isEnabled();
|
protected boolean | shouldPersist()Checks whether, at the given time this method is called,
this Preference should store/restore its value(s) into the
{@link SharedPreferences}. This, at minimum, checks whether this
Preference is persistent and it currently has a key. Before you
save/restore from the {@link SharedPreferences}, check this first.
return mPreferenceManager != null && isPersistent() && hasKey();
|
public java.lang.String | toString()
return getFilterableStringBuilder().toString();
|
private void | tryCommit(SharedPreferences.Editor editor)
if (mPreferenceManager.shouldCommit()) {
try {
editor.apply();
} catch (AbstractMethodError unused) {
// The app injected its own pre-Gingerbread
// SharedPreferences.Editor implementation without
// an apply method.
editor.commit();
}
}
|
private void | unregisterDependency()
if (mDependencyKey != null) {
final Preference oldDependency = findPreferenceInHierarchy(mDependencyKey);
if (oldDependency != null) {
oldDependency.unregisterDependent(this);
}
}
|
private void | unregisterDependent(android.preference.Preference dependent)Removes a dependent Preference on this Preference.
if (mDependents != null) {
mDependents.remove(dependent);
}
|