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

Commit f2b1fc1d authored by Danesh M's avatar Danesh M Committed by Gerrit Code Review
Browse files

Settings : Add volume link notification

Change-Id: I06027bc4f13c8a60b19a2b7ded73ce76da4e4f02

Tablets don't need to link volumes they don't have

This feature broke the notification volume slider in settings for
devices without telephony service (tablets) and isn't applicable
anyways since they don't have ringtone volume streams.

Change-Id: Ifff10ecd35b53f5fc08a36332814fb00d20b4350
parent d948c831
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -880,4 +880,5 @@
    <string name="category_misc">Miscellaneous</string>
    <string name="title_general">General</string>
    <string name="advanced">Advanced</string>
    <string name="link_volume_option_title">Link ringtone &amp; notification volumes</string>
</resources>
+5 −0
Original line number Diff line number Diff line
@@ -40,6 +40,11 @@
                android:icon="@*android:drawable/ic_audio_alarm"
                android:title="@string/alarm_volume_option_title" />

        <!-- Link Volume Notification -->
        <com.android.settings.cyanogenmod.SecureSettingSwitchPreference
                android:key="volume_link_notification"
                android:title="@string/link_volume_option_title" />

        <!-- Notification volume -->
        <com.android.settings.notification.VolumeSeekBarPreference
                android:key="notification_volume"
+31 −9
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
    private static final String KEY_VIBRATE_ON_TOUCH = "vibrate_on_touch";
    private static final String KEY_ZEN_ACCESS = "manage_zen_access";
    private static final String KEY_ZEN_MODE = "zen_mode";
    private static final String KEY_VOLUME_LINK_NOTIFICATION = "volume_link_notification";

    private static final String[] RESTRICTED_KEYS = {
        KEY_MEDIA_VOLUME,
@@ -123,7 +124,8 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
    private boolean mVoiceCapable;
    private Vibrator mVibrator;
    private AudioManager mAudioManager;
    private VolumeSeekBarPreference mRingOrNotificationPreference;
    private VolumeSeekBarPreference mRingPreference;
    private VolumeSeekBarPreference mNotificationPreference;

    private TwoStatePreference mIncreasingRing;
    private IncreasingRingVolumePreference mIncreasingRingVolume;
@@ -168,15 +170,12 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
        initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM,
                com.android.internal.R.drawable.ic_audio_alarm_mute);
        if (mVoiceCapable) {
            mRingOrNotificationPreference =
            mRingPreference =
                    initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING,
                            com.android.internal.R.drawable.ic_audio_ring_notif_mute);
            volumes.removePreference(volumes.findPreference(KEY_NOTIFICATION_VOLUME));
        } else {
            mRingOrNotificationPreference =
                    initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION,
                            com.android.internal.R.drawable.ic_audio_ring_notif_mute);
            volumes.removePreference(volumes.findPreference(KEY_RING_VOLUME));
            volumes.removePreference(volumes.findPreference(KEY_VOLUME_LINK_NOTIFICATION));
        }

        CMHardwareManager hardware = CMHardwareManager.getInstance(mContext);
@@ -202,6 +201,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
        refreshNotificationListeners();
        refreshZenAccess();
        lookupRingtoneNames();
        updateNotificationPreferenceState();
        mSettingsObserver.register(true);
        mReceiver.register(true);
        updateRingOrNotificationPreference();
@@ -243,8 +243,24 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
        return volumePref;
    }

    private void updateNotificationPreferenceState() {
        mNotificationPreference = initVolumePreference(KEY_NOTIFICATION_VOLUME,
                AudioManager.STREAM_NOTIFICATION,
                com.android.internal.R.drawable.ic_audio_ring_notif_mute);

        if (mVoiceCapable) {
            final boolean enabled = Settings.System.getInt(getContentResolver(),
                    Settings.Secure.VOLUME_LINK_NOTIFICATION, 1) == 1;

            if (mNotificationPreference != null) {
                boolean show = !enabled;
                mNotificationPreference.setEnabled(show);
            }
        }
    }

    private void updateRingOrNotificationPreference() {
        mRingOrNotificationPreference.showIcon(mSuppressor != null
        mRingPreference.showIcon(mSuppressor != null
                ? com.android.internal.R.drawable.ic_audio_ring_notif_mute
                : mRingerMode == AudioManager.RINGER_MODE_VIBRATE || wasRingerModeVibrate()
                ? com.android.internal.R.drawable.ic_audio_ring_notif_vibrate
@@ -267,11 +283,11 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
        final ComponentName suppressor = NotificationManager.from(mContext).getEffectsSuppressor();
        if (Objects.equals(suppressor, mSuppressor)) return;
        mSuppressor = suppressor;
        if (mRingOrNotificationPreference != null) {
        if (mRingPreference != null) {
            final String text = suppressor != null ?
                    mContext.getString(com.android.internal.R.string.muted_by,
                            getSuppressorCaption(suppressor)) : null;
            mRingOrNotificationPreference.setSuppressionText(text);
            mRingPreference.setSuppressionText(text);
        }
        updateRingOrNotificationPreference();
    }
@@ -503,6 +519,8 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
                Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS);
        private final Uri LOCK_SCREEN_SHOW_URI =
                Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS);
        private final Uri VOLUME_LINK_NOTIFICATION_URI =
                Settings.Secure.getUriFor(Settings.Secure.VOLUME_LINK_NOTIFICATION);

        public SettingsObserver() {
            super(mHandler);
@@ -515,6 +533,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
                cr.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI, false, this);
                cr.registerContentObserver(LOCK_SCREEN_PRIVATE_URI, false, this);
                cr.registerContentObserver(LOCK_SCREEN_SHOW_URI, false, this);
                cr.registerContentObserver(VOLUME_LINK_NOTIFICATION_URI, false, this);
            } else {
                cr.unregisterContentObserver(this);
            }
@@ -526,6 +545,9 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
            if (VIBRATE_WHEN_RINGING_URI.equals(uri)) {
                updateVibrateWhenRinging();
            }
            if (VOLUME_LINK_NOTIFICATION_URI.equals(uri)) {
                updateNotificationPreferenceState();
            }
        }
    }