public class RingtonePreference extends Preference implements PreferenceManager.OnActivityResultListener
Preference
that allows the user to choose a ringtone from those on the device.
The chosen ringtone's URI will be persisted as a string.
If the user chooses the "Default" item, the saved string will be one of
Settings.System.DEFAULT_RINGTONE_URI
,
Settings.System.DEFAULT_NOTIFICATION_URI
, or
Settings.System.DEFAULT_ALARM_ALERT_URI
. If the user chooses the "Silent"
item, the saved string will be an empty string.
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
RingtonePreference(Context context) |
RingtonePreference(Context context,
AttributeSet attrs) |
RingtonePreference(Context context,
AttributeSet attrs,
int defStyle) |
Modifier and Type | Method and Description |
---|---|
int |
getRingtoneType()
Returns the sound type(s) that are shown in the picker.
|
boolean |
getShowDefault()
Returns whether to a show an item for the default sound/ringtone.
|
boolean |
getShowSilent()
Returns whether to a show an item for 'Silent'.
|
boolean |
onActivityResult(int requestCode,
int resultCode,
Intent data)
See Activity's onActivityResult.
|
protected void |
onAttachedToHierarchy(PreferenceManager preferenceManager)
Called when this Preference has been attached to a Preference hierarchy.
|
protected void |
onClick()
Processes a click on the preference.
|
protected Object |
onGetDefaultValue(TypedArray a,
int index)
Called when a Preference is being inflated and the default value
attribute needs to be read.
|
protected void |
onPrepareRingtonePickerIntent(Intent ringtonePickerIntent)
Prepares the intent to launch the ringtone picker.
|
protected Uri |
onRestoreRingtone()
Called when the chooser is about to be shown and the current ringtone
should be marked.
|
protected void |
onSaveRingtone(Uri ringtoneUri)
Called when a ringtone is chosen.
|
protected void |
onSetInitialValue(boolean restorePersistedValue,
Object defaultValueObj)
Implement this to set the initial value of the Preference.
|
void |
setRingtoneType(int type)
Sets the sound type(s) that are shown in the picker.
|
void |
setShowDefault(boolean showDefault)
Sets whether to show an item for the default sound/ringtone.
|
void |
setShowSilent(boolean showSilent)
Sets whether to show an item for 'Silent'.
|
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getEditor, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPersistedStringSet, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getTitleRes, getView, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToActivity, onBindView, onCreateView, onDependencyChanged, onKey, onPrepareForRemoval, onRestoreInstanceState, onSaveInstanceState, peekExtras, persistBoolean, persistFloat, persistInt, persistLong, persistString, persistStringSet, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldDisableDependents, shouldPersist, toString
public RingtonePreference(Context context, AttributeSet attrs, int defStyle)
public RingtonePreference(Context context, AttributeSet attrs)
public RingtonePreference(Context context)
public int getRingtoneType()
setRingtoneType(int)
public void setRingtoneType(int type)
type
- The sound type(s) that are shown in the picker.RingtoneManager.EXTRA_RINGTONE_TYPE
public boolean getShowDefault()
public void setShowDefault(boolean showDefault)
showDefault
- Whether to show the default or not.RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT
public boolean getShowSilent()
public void setShowSilent(boolean showSilent)
showSilent
- Whether to show 'Silent'.RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT
protected void onClick()
Preference
SharedPreferences
. However, the overridden method should
call Preference.callChangeListener(Object)
to make sure the client wants to
update the preference's state with the new value.onClick
in class Preference
protected void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent)
ringtonePickerIntent
- The ringtone picker intent that can be
modified by putting extras.protected void onSaveRingtone(Uri ringtoneUri)
By default, this saves the ringtone URI to the persistent storage as a string.
ringtoneUri
- The chosen ringtone's Uri
. Can be null.protected Uri onRestoreRingtone()
By default, this restores the previous ringtone URI from the persistent storage.
protected Object onGetDefaultValue(TypedArray a, int index)
Preference
For example, if the value type is String, the body of the method would
proxy to TypedArray.getString(int)
.
onGetDefaultValue
in class Preference
a
- The set of attributes.index
- The index of the default value attribute.protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValueObj)
Preference
If restorePersistedValue is true, you should restore the
Preference value from the SharedPreferences
. If
restorePersistedValue is false, you should set the Preference
value to defaultValue that is given (and possibly store to SharedPreferences
if Preference.shouldPersist()
is true).
This may not always be called. One example is if it should not persist but there is no default value given.
onSetInitialValue
in class Preference
restorePersistedValue
- True to restore the persisted value;
false to use the given defaultValue.defaultValueObj
- The default value for this Preference. Only use this
if restorePersistedValue is false.protected void onAttachedToHierarchy(PreferenceManager preferenceManager)
Preference
onAttachedToHierarchy
in class Preference
preferenceManager
- The PreferenceManager of the hierarchy.public boolean onActivityResult(int requestCode, int resultCode, Intent data)
PreferenceManager.OnActivityResultListener
onActivityResult
in interface PreferenceManager.OnActivityResultListener