Notification sound field updates
- Show default and silent options - Don't also update the default notification sound - Display a better summary in case the sound isn't in media store Change-Id: I42d537657a7bbddb8a1ce41fd03b8e5847899a82 Fixes: 36734113 Fixes: 36849670 Test: manual (silent sound, default sound, normal sound, private sound)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.RingtonePreference;
|
||||
|
||||
public class NotificationSoundPreference extends RingtonePreference {
|
||||
private Uri mRingtone;
|
||||
|
||||
public NotificationSoundPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Uri onRestoreRingtone() {
|
||||
return mRingtone;
|
||||
}
|
||||
|
||||
public void setRingtone(Uri ringtone) {
|
||||
mRingtone = ringtone;
|
||||
updateRingtoneName(mRingtone);
|
||||
}
|
||||
|
||||
private void updateRingtoneName(final Uri uri) {
|
||||
AsyncTask ringtoneNameTask = new AsyncTask<Object, Void, CharSequence>() {
|
||||
@Override
|
||||
protected CharSequence doInBackground(Object... params) {
|
||||
if (uri == null) {
|
||||
return getContext().getString(com.android.internal.R.string.ringtone_silent);
|
||||
} else if (RingtoneManager.isDefault(uri)) {
|
||||
return getContext().getString(R.string.notification_sound_default);
|
||||
} else if(ContentResolver.SCHEME_ANDROID_RESOURCE.equals(uri.getScheme())) {
|
||||
return getContext().getString(R.string.notification_unknown_sound_title);
|
||||
} else {
|
||||
return Ringtone.getTitle(getContext(), uri, false /* followSettingsUri */,
|
||||
true /* allowRemote */);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(CharSequence name) {
|
||||
setSummary(name);
|
||||
}
|
||||
};
|
||||
ringtoneNameTask.execute();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user