Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c98369d authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge "Notification sound field updates" into oc-dev am: b40a4590

am: cd8f4fb6

Change-Id: I8f8b5674339b044911ef6ed630c2d432cb7277cf
parents 5b67fa63 cd8f4fb6
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6364,6 +6364,12 @@
    <!-- Sound: Title for the option defining the default notification sound. [CHAR LIMIT=30] -->
    <string name="notification_ringtone_title">Default notification sound</string>
    <!-- Sound: Sound title for apps that have not provided a title. [CHAR LIMIT=30] -->
    <string name="notification_unknown_sound_title">App provided sound</string>
    <!-- Notification sound summary when chosen sound is the system default. -->
    <string name="notification_sound_default">Default notification sound</string>
    <!-- Sound: Title for the option defining the default alarm sound. [CHAR LIMIT=30] -->
    <string name="alarm_ringtone_title">Default alarm sound</string>
+5 −3
Original line number Diff line number Diff line
@@ -32,10 +32,12 @@
        android:title="@string/notification_importance_title" />

    <!-- Default ringtone -->
    <com.android.settings.notification.DefaultNotificationTonePreference
    <com.android.settings.notification.NotificationSoundPreference
        android:key="ringtone"
        android:title="@string/notification_ringtone_title"
        android:dialogTitle="@string/notification_ringtone_title"
        android:title="@string/notification_channel_sound_title"
        android:dialogTitle="@string/notification_channel_sound_title"
        android:showSilent="true"
        android:showDefault="true"
        android:ringtoneType="notification" />

    <!-- Vibration -->
+2 −4
Original line number Diff line number Diff line
@@ -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());
+54 −0
Original line number Diff line number Diff line
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();
    }
}