android.preference.RingtonePreference
The RingtonePreference allows the user to choose one from all of the
available ringtones. 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
DEFAULT_RINGTONE_URI or
DEFAULT_NOTIFICATION_URI. If the user chooses the "Silent"
item, the saved string will be an empty string.
Summary
XML Attributes
android:defaultValue,
android:dependency,
android:enabled,
android:key,
android:layout,
android:order,
android:persistent,
android:selectable,
android:shouldDisableView,
android:summary,
android:title,
android:widgetLayout
Attribute name |
Related methods |
|
android:defaultValue |
|
The default value for the preference, which will be set either if persistence
is off or persistence is on and the preference is not found in the persistent
storage. |
android:dependency |
|
The key of another Preference that this Preference will depend on. |
android:enabled |
|
Whether the Preference is enabled. |
android:key |
|
The key to store the Preference value. |
android:layout |
|
The layout for the Preference in a PreferenceActivity screen. |
android:order |
|
The order for the Preference (lower values are to be ordered first). |
android:persistent |
|
Whether the Preference stores its value to the shared preferences. |
android:selectable |
|
Whether the Preference is selectable. |
android:shouldDisableView |
|
Whether the view of this Preference should be disabled when
this Preference is disabled. |
android:summary |
|
The summary for the Preference in a PreferenceActivity screen. |
android:title |
|
The title for the Preference in a PreferenceActivity screen. |
android:widgetLayout |
|
The layout for the controllable widget portion of a Preference. |
Public Constructors
Public Methods
Protected Methods
callChangeListener,
compareTo,
findPreferenceInHierarchy,
getContext,
getDependency,
getEditor,
getIntent,
getKey,
getLayoutResource,
getOnPreferenceChangeListener,
getOnPreferenceClickListener,
getOrder,
getPersistedBoolean,
getPersistedFloat,
getPersistedInt,
getPersistedLong,
getPersistedString,
getPreferenceManager,
getSharedPreferences,
getShouldDisableView,
getSummary,
getTitle,
getView,
getWidgetLayoutResource,
hasKey,
isEnabled,
isPersistent,
isSelectable,
notifyChanged,
notifyDependencyChange,
notifyHierarchyChanged,
onAttachedToActivity,
onAttachedToHierarchy,
onBindView,
onClick,
onCreateView,
onDependencyChanged,
onGetDefaultValue,
onPrepareForRemoval,
onRestoreInstanceState,
onSaveInstanceState,
onSetInitialValue,
persistBoolean,
persistFloat,
persistInt,
persistLong,
persistString,
restoreHierarchyState,
saveHierarchyState,
setDefaultValue,
setDependency,
setEnabled,
setIntent,
setKey,
setLayoutResource,
setOnPreferenceChangeListener,
setOnPreferenceClickListener,
setOrder,
setPersistent,
setSelectable,
setShouldDisableView,
setSummary,
setSummary,
setTitle,
setTitle,
setWidgetLayoutResource,
shouldCommit,
shouldDisableDependents,
shouldPersist,
toString
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
XML Attributes
android:ringtoneType
Which ringtone type(s) to show in the picker.
Must be one or more (separated by '|') of the following constant values.
Constant | Value | Description |
ringtone | 1 | Ringtones. |
notification | 2 | Notification sounds. |
alarm | 4 | Alarm sounds. |
all | 7 | All available ringtone sounds. |
This corresponds to the global attribute resource symbol ringtoneType.
android:showDefault
Whether to show an item for a default sound.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol showDefault.
android:showSilent
Whether to show an item for 'Silent'.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol showSilent.
Public Constructors
public
RingtonePreference(Context context)
Public Methods
public
int
getRingtoneType()
Returns the sound type(s) that are shown in the picker.
Returns
- The sound type(s) that are shown in the picker.
public
boolean
getShowDefault()
Returns whether to a show an item for the default sound/ringtone.
Returns
- Whether to show an item for the default sound/ringtone.
public
boolean
getShowSilent()
Returns whether to a show an item for 'Silent'.
Returns
- Whether to show an item for 'Silent'.
public
boolean
onActivityResult(int requestCode, int resultCode, Intent data)
See Activity's onActivityResult.
public
void
setRingtoneType(int type)
Sets the sound type(s) that are shown in the picker.
Parameters
type
| The sound type(s) that are shown in the picker. |
public
void
setShowDefault(boolean showDefault)
Sets whether to show an item for the default sound/ringtone. The default
to use will be deduced from the sound type(s) being shown.
Parameters
showDefault
| Whether to show the default or not. |
public
void
setShowSilent(boolean showSilent)
Sets whether to show an item for 'Silent'.
Parameters
showSilent
| Whether to show 'Silent'. |
Protected Methods
protected
void
onAttachedToHierarchy(PreferenceManager preferenceManager)
Called when this preference has been attached to a preference hierarchy.
Make sure to call the super implementation.
Parameters
preferenceManager
| The preference manager of the hierarchy.
|
protected
void
onClick()
Processes a click on the preference. This includes saving the value to
the
SharedPreferences. However, the overridden method should
call
callChangeListener(Object) to make sure the client wants to
update the preference's state with the new value.
protected
Object
onGetDefaultValue(TypedArray a, int index)
Called when
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 getString(int).
Parameters
a
| The set of attributes. |
index
| The index of the default value attribute. |
Returns
- The default value of this preference type.
protected
void
onPrepareRingtonePickerIntent(Intent ringtonePickerIntent)
Prepares the intent to launch the ringtone picker. This can be modified
to adjust the parameters of the ringtone picker.
Parameters
ringtonePickerIntent
| The ringtone picker intent that can be
modified by putting extras.
|
protected
Uri
onRestoreRingtone()
Called when the chooser is about to be shown and the current ringtone
should be marked. Can return null to not mark any ringtone.
By default, this restores the previous ringtone URI from the persistent
storage.
Returns
- The ringtone to be marked as the current ringtone.
protected
void
onSaveRingtone(Uri ringtoneUri)
Called when a ringtone is chosen.
By default, this saves the ringtone URI to the persistent storage as a
string.
Parameters
ringtoneUri
| The chosen ringtone's Uri. Can be null.
|
protected
void
onSetInitialValue(boolean restorePersistedValue, Object defaultValueObj)
Implement this to set the initial value of the Preference. If the
restoreValue flag is true, you should restore the value from the shared
preferences. If false, you should set (and possibly store to shared
preferences if
shouldPersist()) to defaultValue.
This may not always be called. One example is if it should not persist
but there is no default value given.
Parameters
restorePersistedValue
| Whether to restore the persisted value
(true), or use the given default value (false). |
defaultValueObj
| The default value. Only use if restoreValue is false.
|