Merge "Notification sound field updates" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b40a459031
@@ -21,7 +21,6 @@ import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.app.NotificationManager.IMPORTANCE_MIN;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
@@ -29,7 +28,6 @@ import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService.Ranking;
|
||||
@@ -63,7 +61,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
||||
|
||||
protected RestrictedSwitchPreference mLights;
|
||||
protected RestrictedSwitchPreference mVibrate;
|
||||
protected DefaultNotificationTonePreference mRingtone;
|
||||
protected NotificationSoundPreference mRingtone;
|
||||
protected RestrictedDropDownPreference mImportance;
|
||||
protected RestrictedSwitchPreference mPriority;
|
||||
protected RestrictedDropDownPreference mVisibilityOverride;
|
||||
@@ -102,7 +100,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
||||
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
|
||||
mLights = (RestrictedSwitchPreference) findPreference(KEY_LIGHTS);
|
||||
mVibrate = (RestrictedSwitchPreference) findPreference(KEY_VIBRATE);
|
||||
mRingtone = (DefaultNotificationTonePreference) findPreference(KEY_RINGTONE);
|
||||
mRingtone = (NotificationSoundPreference) findPreference(KEY_RINGTONE);
|
||||
|
||||
if (mPkgInfo != null && mChannel != null) {
|
||||
setupPriorityPref(mChannel.canBypassDnd());
|
||||
|
@@ -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