RingtonePreferencepublic class RingtonePreference extends Preference implements PreferenceManager.OnActivityResultListenerA {@link 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
{@link System#DEFAULT_RINGTONE_URI},
{@link System#DEFAULT_NOTIFICATION_URI}, or
{@link System#DEFAULT_ALARM_ALERT_URI}. If the user chooses the "Silent"
item, the saved string will be an empty string. |
Fields Summary |
---|
private static final String | TAG | private int | mRingtoneType | private boolean | mShowDefault | private boolean | mShowSilent | private int | mRequestCode |
Constructors Summary |
---|
public RingtonePreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)
super(context, attrs, defStyleAttr, defStyleRes);
final TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.RingtonePreference, defStyleAttr, defStyleRes);
mRingtoneType = a.getInt(com.android.internal.R.styleable.RingtonePreference_ringtoneType,
RingtoneManager.TYPE_RINGTONE);
mShowDefault = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showDefault,
true);
mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent,
true);
a.recycle();
| public RingtonePreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)
this(context, attrs, defStyleAttr, 0);
| public RingtonePreference(android.content.Context context, android.util.AttributeSet attrs)
this(context, attrs, com.android.internal.R.attr.ringtonePreferenceStyle);
| public RingtonePreference(android.content.Context context)
this(context, null);
|
Methods Summary |
---|
public int | getRingtoneType()Returns the sound type(s) that are shown in the picker.
return mRingtoneType;
| public boolean | getShowDefault()Returns whether to a show an item for the default sound/ringtone.
return mShowDefault;
| public boolean | getShowSilent()Returns whether to a show an item for 'Silent'.
return mShowSilent;
| public boolean | onActivityResult(int requestCode, int resultCode, android.content.Intent data)
if (requestCode == mRequestCode) {
if (data != null) {
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (callChangeListener(uri != null ? uri.toString() : "")) {
onSaveRingtone(uri);
}
}
return true;
}
return false;
| protected void | onAttachedToHierarchy(PreferenceManager preferenceManager)
super.onAttachedToHierarchy(preferenceManager);
preferenceManager.registerOnActivityResultListener(this);
mRequestCode = preferenceManager.getNextRequestCode();
| protected void | onClick()
// Launch the ringtone picker
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
onPrepareRingtonePickerIntent(intent);
PreferenceFragment owningFragment = getPreferenceManager().getFragment();
if (owningFragment != null) {
owningFragment.startActivityForResult(intent, mRequestCode);
} else {
getPreferenceManager().getActivity().startActivityForResult(intent, mRequestCode);
}
| protected java.lang.Object | onGetDefaultValue(android.content.res.TypedArray a, int index)
return a.getString(index);
| protected void | onPrepareRingtonePickerIntent(android.content.Intent ringtonePickerIntent)Prepares the intent to launch the ringtone picker. This can be modified
to adjust the parameters of the ringtone picker.
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
onRestoreRingtone());
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault);
if (mShowDefault) {
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
RingtoneManager.getDefaultUri(getRingtoneType()));
}
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent);
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, mRingtoneType);
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getTitle());
| protected android.net.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.
final String uriString = getPersistedString(null);
return !TextUtils.isEmpty(uriString) ? Uri.parse(uriString) : null;
| protected void | onSaveRingtone(android.net.Uri ringtoneUri)Called when a ringtone is chosen.
By default, this saves the ringtone URI to the persistent storage as a
string.
persistString(ringtoneUri != null ? ringtoneUri.toString() : "");
| protected void | onSetInitialValue(boolean restorePersistedValue, java.lang.Object defaultValueObj)
String defaultValue = (String) defaultValueObj;
/*
* This method is normally to make sure the internal state and UI
* matches either the persisted value or the default value. Since we
* don't show the current value in the UI (until the dialog is opened)
* and we don't keep local state, if we are restoring the persisted
* value we don't need to do anything.
*/
if (restorePersistedValue) {
return;
}
// If we are setting to the default value, we should persist it.
if (!TextUtils.isEmpty(defaultValue)) {
onSaveRingtone(Uri.parse(defaultValue));
}
| public void | setRingtoneType(int type)Sets the sound type(s) that are shown in the picker.
mRingtoneType = type;
| 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.
mShowDefault = showDefault;
| public void | setShowSilent(boolean showSilent)Sets whether to show an item for 'Silent'.
mShowSilent = showSilent;
|
|