|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.preference.PreferenceManager
public class PreferenceManager
The PreferenceManager is used to help create preference hierarchies
from activities or XML.
In most cases, clients should use
PreferenceActivity.addPreferencesFromIntent(android.content.Intent) or
PreferenceActivity.addPreferencesFromResource(int).
PreferenceActivity| Nested Class Summary | |
|---|---|
static interface |
PreferenceManager.OnActivityDestroyListener
Interface definition for a class that will be called when the container's activity is destroyed. |
static interface |
PreferenceManager.OnActivityResultListener
Interface definition for a class that will be called when the container's activity receives an activity result. |
static interface |
PreferenceManager.OnActivityStopListener
Interface definition for a class that will be called when the container's activity is stopped. |
(package private) static interface |
PreferenceManager.OnPreferenceTreeClickListener
Interface definition for a callback to be invoked when a Preference in the hierarchy rooted at this PreferenceScreen is
clicked. |
| Field Summary | |
|---|---|
static String |
KEY_HAS_SET_DEFAULT_VALUES
|
static String |
METADATA_KEY_PREFERENCES
The Activity meta-data key for its XML preference hierarchy. |
| Constructor Summary | |
|---|---|
PreferenceManager(Activity activity,
int firstRequestCode)
|
|
| Method Summary | |
|---|---|
(package private) void |
addPreferencesScreen(DialogInterface screen)
|
PreferenceScreen |
createPreferenceScreen(Context context)
|
(package private) void |
dispatchActivityDestroy()
Called by the PreferenceManager to dispatch the activity destroy
event. |
(package private) void |
dispatchActivityResult(int requestCode,
int resultCode,
Intent data)
Called by the PreferenceManager to dispatch a subactivity result. |
(package private) void |
dispatchActivityStop()
Called by the PreferenceManager to dispatch the activity stop
event. |
(package private) void |
dispatchNewIntent(Intent intent)
Called by PreferenceActivity to dispatch the new Intent event. |
Preference |
findPreference(CharSequence key)
Finds a Preference based on its key. |
(package private) Activity |
getActivity()
Returns the activity that shows the preferences. |
(package private) Context |
getContext()
Returns the context. |
static SharedPreferences |
getDefaultSharedPreferences(Context context)
Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context. |
(package private) SharedPreferences.Editor |
getEditor()
Returns an editor to use when modifying the shared preferences. |
(package private) long |
getNextId()
Called by a preference to get a unique ID in its hierarchy. |
(package private) int |
getNextRequestCode()
Returns a request code that is unique for the activity. |
(package private) PreferenceManager.OnPreferenceTreeClickListener |
getOnPreferenceTreeClickListener()
|
(package private) PreferenceScreen |
getPreferenceScreen()
Returns the root of the preference hierarchy managed by this class. |
SharedPreferences |
getSharedPreferences()
Gets a SharedPreferences instance that preferences managed by this will use. |
int |
getSharedPreferencesMode()
Returns the current mode of the SharedPreferences file that preferences managed by this will use. |
String |
getSharedPreferencesName()
Returns the current name of the SharedPreferences file that preferences managed by this will use. |
(package private) PreferenceScreen |
inflateFromIntent(Intent queryIntent,
PreferenceScreen rootPreferences)
Inflates a preference hierarchy from the preference hierarchies of Activities that match the given Intent. |
(package private) PreferenceScreen |
inflateFromResource(Context context,
int resId,
PreferenceScreen rootPreferences)
Inflates a preference hierarchy from XML. |
(package private) void |
registerOnActivityDestroyListener(PreferenceManager.OnActivityDestroyListener listener)
Registers a listener. |
(package private) void |
registerOnActivityResultListener(PreferenceManager.OnActivityResultListener listener)
Registers a listener. |
(package private) void |
registerOnActivityStopListener(PreferenceManager.OnActivityStopListener listener)
Registers a listener. |
(package private) void |
removePreferencesScreen(DialogInterface screen)
|
static void |
setDefaultValues(Context context,
int resId,
boolean readAgain)
Sets the default values from a preference hierarchy in XML. |
static void |
setDefaultValues(Context context,
String sharedPreferencesName,
int sharedPreferencesMode,
int resId,
boolean readAgain)
Similar to setDefaultValues(Context, int, boolean) but allows
the client to provide the filename and mode of the shared preferences
file. |
(package private) void |
setOnPreferenceTreeClickListener(PreferenceManager.OnPreferenceTreeClickListener listener)
Sets the callback to be invoked when a Preference in the
hierarchy rooted at this PreferenceManager is clicked. |
(package private) boolean |
setPreferences(PreferenceScreen preferenceScreen)
Sets the root of the preference hierarchy. |
void |
setSharedPreferencesMode(int sharedPreferencesMode)
Sets the mode of the SharedPreferences file that preferences managed by this will use. |
void |
setSharedPreferencesName(String sharedPreferencesName)
Sets the name of the SharedPreferences file that preferences managed by this will use. |
(package private) boolean |
shouldCommit()
Whether it is the client's responsibility to commit on the getEditor(). |
(package private) void |
unregisterOnActivityDestroyListener(PreferenceManager.OnActivityDestroyListener listener)
Unregisters a listener. |
(package private) void |
unregisterOnActivityResultListener(PreferenceManager.OnActivityResultListener listener)
Unregisters a listener. |
(package private) void |
unregisterOnActivityStopListener(PreferenceManager.OnActivityStopListener listener)
Unregisters a listener. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String METADATA_KEY_PREFERENCES
public static final String KEY_HAS_SET_DEFAULT_VALUES
| Constructor Detail |
|---|
PreferenceManager(Activity activity,
int firstRequestCode)
| Method Detail |
|---|
PreferenceScreen inflateFromIntent(Intent queryIntent,
PreferenceScreen rootPreferences)
Activities that match the given Intent. An
Activity defines its preference hierarchy with meta-data using
the METADATA_KEY_PREFERENCES key.
If a preference hierarchy is given, the new preference hierarchies will be merged in.
queryIntent - The intent to match activities.rootPreferences - Optional existing hierarchy to merge the new
hierarchies into.
PreferenceScreen inflateFromResource(Context context,
int resId,
PreferenceScreen rootPreferences)
context - The context of the resource.resId - The resource ID of the XML to inflate.rootPreferences - Optional existing hierarchy to merge the new
hierarchies into.
public PreferenceScreen createPreferenceScreen(Context context)
long getNextId()
public String getSharedPreferencesName()
Context.getSharedPreferences(String, int).Context.getSharedPreferences(String, int)public void setSharedPreferencesName(String sharedPreferencesName)
sharedPreferencesName - The name of the SharedPreferences file.Context.getSharedPreferences(String, int)public int getSharedPreferencesMode()
Context.getSharedPreferences(String, int).Context.getSharedPreferences(String, int)public void setSharedPreferencesMode(int sharedPreferencesMode)
sharedPreferencesMode - The mode of the SharedPreferences file.Context.getSharedPreferences(String, int)public SharedPreferences getSharedPreferences()
public static SharedPreferences getDefaultSharedPreferences(Context context)
context - The context of the preferences whose values are wanted.
PreferenceScreen getPreferenceScreen()
PreferenceScreen object that is at the root of the hierarchy.boolean setPreferences(PreferenceScreen preferenceScreen)
preferenceScreen - The root PreferenceScreen of the preference hierarchy.
PreferenceScreen given is different than the previous.public Preference findPreference(CharSequence key)
Preference based on its key.
key - The key of the preference to retrieve.
Preference with the key, or null.PreferenceGroup.findPreference(CharSequence)
public static void setDefaultValues(Context context,
int resId,
boolean readAgain)
If readAgain is false, this will only set the default values if this
method has never been called in the past (or the
KEY_HAS_SET_DEFAULT_VALUES in the default value shared
preferences file is false). To attempt to set the default values again
bypassing this check, set readAgain to true.
context - The context of the shared preferences.resId - The resource ID of the preference hierarchy XML file.readAgain - Whether to re-read the default values.
Note: this will NOT reset preferences back to their default
values. For that functionality, use
getDefaultSharedPreferences(Context)
and clear it followed by a call to this method with this
parameter set to true.
public static void setDefaultValues(Context context,
String sharedPreferencesName,
int sharedPreferencesMode,
int resId,
boolean readAgain)
setDefaultValues(Context, int, boolean) but allows
the client to provide the filename and mode of the shared preferences
file.
setDefaultValues(Context, int, boolean),
setSharedPreferencesName(String),
setSharedPreferencesMode(int)SharedPreferences.Editor getEditor()
Do NOT commit unless shouldCommit() returns true.
shouldCommit()boolean shouldCommit()
getEditor(). This will return false in cases where the writes
should be batched, for example when inflating preferences from XML.
Activity getActivity()
getContext() is
preferred.
This will return null if this class was instantiated with a Context instead of Activity. For example, when setting the default values.
mContextContext getContext()
getActivity() when
possible.
void registerOnActivityResultListener(PreferenceManager.OnActivityResultListener listener)
PreferenceManager.OnActivityResultListenervoid unregisterOnActivityResultListener(PreferenceManager.OnActivityResultListener listener)
PreferenceManager.OnActivityResultListener
void dispatchActivityResult(int requestCode,
int resultCode,
Intent data)
PreferenceManager to dispatch a subactivity result.
void registerOnActivityStopListener(PreferenceManager.OnActivityStopListener listener)
PreferenceManager.OnActivityStopListenervoid unregisterOnActivityStopListener(PreferenceManager.OnActivityStopListener listener)
PreferenceManager.OnActivityStopListenervoid dispatchActivityStop()
PreferenceManager to dispatch the activity stop
event.
void registerOnActivityDestroyListener(PreferenceManager.OnActivityDestroyListener listener)
PreferenceManager.OnActivityDestroyListenervoid unregisterOnActivityDestroyListener(PreferenceManager.OnActivityDestroyListener listener)
PreferenceManager.OnActivityDestroyListenervoid dispatchActivityDestroy()
PreferenceManager to dispatch the activity destroy
event.
int getNextRequestCode()
void addPreferencesScreen(DialogInterface screen)
void removePreferencesScreen(DialogInterface screen)
void dispatchNewIntent(Intent intent)
PreferenceActivity to dispatch the new Intent event.
intent - The new Intent.void setOnPreferenceTreeClickListener(PreferenceManager.OnPreferenceTreeClickListener listener)
Preference in the
hierarchy rooted at this PreferenceManager is clicked.
listener - The callback to be invoked.PreferenceManager.OnPreferenceTreeClickListener getOnPreferenceTreeClickListener()
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||