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

Commit b058221b authored by Yi-Ling Chuang's avatar Yi-Ling Chuang
Browse files

Add inline toggle for Prevent Ringing gesture.

- Fork sound_settings_v2 for dev.
- Replace Preference with PrimarySwitchPreference for the Prevent
Ringing entry.
- When the toggle is on, only show the status text without the on/off
info.
- Remove unused codes.

Bug: 174964721
Test: robotests
Change-Id: I990f5c778436c8058d4a5953c7f15a9a7eb580d8
parent 0f81257a
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -11666,11 +11666,9 @@
    <!-- Option for prevent ringing setting -->
    <string name="prevent_ringing_option_none">Do nothing</string>
    <!-- Summary for prevent ringing setting -->
    <string name="prevent_ringing_option_vibrate_summary">On (vibrate)</string>
    <string name="prevent_ringing_option_vibrate_summary">Vibrate</string>
    <!-- Summary for prevent ringing setting -->
    <string name="prevent_ringing_option_mute_summary">On (mute)</string>
    <!-- Summary for prevent ringing setting -->
    <string name="prevent_ringing_option_none_summary">Off</string>
    <string name="prevent_ringing_option_mute_summary">Mute</string>
    <!-- Title for detail page of wifi network [CHAR LIMIT=30] -->
    <string name="pref_title_network_details">Network details</string>
+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@
        settings:controller="com.android.settings.sound.MediaControlsParentPreferenceController"
        settings:keywords="@string/keywords_media_controls"/>

    <Preference
    <com.android.settings.widget.PrimarySwitchPreference
        android:key="gesture_prevent_ringing_sound"
        android:title="@string/gesture_prevent_ringing_sound_title"
        android:order="-107"
+251 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:title="@string/sound_settings"
    android:key="sound_settings"
    settings:keywords="@string/keywords_sounds"
    settings:initialExpandedChildrenCount="9">

    <!-- Remote volume group -->
    <PreferenceCategory
        android:key="remote_media_group"
        android:title=""
        android:order="-185"
        settings:allowDividerBelow="true"
        settings:controller="com.android.settings.notification.RemoteVolumeGroupController">
    </PreferenceCategory>

    <!-- Media volume -->
    <com.android.settings.notification.VolumeSeekBarPreference
        android:key="media_volume"
        android:icon="@drawable/ic_media_stream"
        android:title="@string/media_volume_option_title"
        android:order="-180"
        settings:controller="com.android.settings.notification.MediaVolumePreferenceController"/>

    <!-- Media output switcher -->
    <Preference
        android:key="media_output"
        android:title="@string/media_output_title"
        android:dialogTitle="@string/media_output_title"
        android:order="-175"
        settings:searchable="false"
        settings:controller="com.android.settings.sound.MediaOutputPreferenceController"/>

    <!-- Call volume -->
    <com.android.settings.notification.VolumeSeekBarPreference
        android:key="call_volume"
        android:icon="@drawable/ic_local_phone_24_lib"
        android:title="@string/call_volume_option_title"
        android:order="-170"
        settings:controller="com.android.settings.notification.CallVolumePreferenceController"/>

    <!-- Hands free profile output switcher -->
    <ListPreference
        android:key="take_call_on_output"
        android:title="@string/take_call_on_title"
        android:dialogTitle="@string/take_call_on_title"
        android:order="-165"
        settings:searchable="false"
        settings:controller="com.android.settings.sound.HandsFreeProfileOutputPreferenceController"/>

    <!-- Ring volume -->
    <com.android.settings.notification.VolumeSeekBarPreference
        android:key="ring_volume"
        android:icon="@drawable/ic_notifications"
        android:title="@string/ring_volume_option_title"
        android:order="-160"
        settings:controller="com.android.settings.notification.RingVolumePreferenceController"/>


    <!-- Alarm volume -->
    <com.android.settings.notification.VolumeSeekBarPreference
        android:key="alarm_volume"
        android:icon="@*android:drawable/ic_audio_alarm"
        android:title="@string/alarm_volume_option_title"
        android:order="-150"
        settings:controller="com.android.settings.notification.AlarmVolumePreferenceController"/>

    <!-- Notification volume -->
    <com.android.settings.notification.VolumeSeekBarPreference
        android:key="notification_volume"
        android:icon="@drawable/ic_notifications"
        android:title="@string/notification_volume_option_title"
        android:order="-140"
        settings:controller="com.android.settings.notification.NotificationVolumePreferenceController"/>

    <!-- Also vibrate for calls -->
    <Preference
        android:fragment="com.android.settings.sound.VibrateForCallsPreferenceFragment"
        android:key="vibrate_for_calls"
        android:title="@string/vibrate_when_ringing_title"
        android:order="-130"
        settings:controller="com.android.settings.sound.VibrateForCallsPreferenceController"
        settings:keywords="@string/keywords_vibrate_for_calls"/>

    <!-- Interruptions -->
    <com.android.settingslib.RestrictedPreference
        android:key="zen_mode"
        android:title="@string/zen_mode_settings_title"
        android:fragment="com.android.settings.notification.zen.ZenModeSettings"
        android:order="-120"
        settings:useAdminDisabledSummary="true"
        settings:keywords="@string/keywords_sounds_and_notifications_interruptions"
        settings:allowDividerAbove="true"
        settings:controller="com.android.settings.notification.zen.ZenModePreferenceController"/>

    <Preference
        android:key="media_controls_summary"
        android:title="@string/media_controls_title"
        android:fragment="com.android.settings.sound.MediaControlsSettings"
        android:order="-110"
        settings:controller="com.android.settings.sound.MediaControlsParentPreferenceController"
        settings:keywords="@string/keywords_media_controls"/>

    <com.android.settings.widget.PrimarySwitchPreference
        android:key="gesture_prevent_ringing_sound"
        android:title="@string/gesture_prevent_ringing_sound_title"
        android:order="-107"
        android:fragment="com.android.settings.gestures.PreventRingingGestureSettings"
        settings:controller="com.android.settings.gestures.PreventRingingParentPreferenceController"/>

    <!-- Phone ringtone -->
    <com.android.settings.DefaultRingtonePreference
        android:key="phone_ringtone"
        android:title="@string/ringtone_title"
        android:dialogTitle="@string/ringtone_title"
        android:summary="@string/summary_placeholder"
        android:ringtoneType="ringtone"
        android:order="-100"
        settings:keywords="@string/sound_settings"/>

    <!-- Default notification ringtone -->
    <com.android.settings.DefaultRingtonePreference
        android:key="notification_ringtone"
        android:title="@string/notification_ringtone_title"
        android:dialogTitle="@string/notification_ringtone_title"
        android:summary="@string/summary_placeholder"
        android:ringtoneType="notification"
        android:order="-90"/>

    <!-- Default alarm ringtone -->
    <com.android.settings.DefaultRingtonePreference
        android:key="alarm_ringtone"
        android:title="@string/alarm_ringtone_title"
        android:dialogTitle="@string/alarm_ringtone_title"
        android:summary="@string/summary_placeholder"
        android:persistent="false"
        android:ringtoneType="alarm"
        android:order="-80"/>

    <!-- Other sounds -->
    <PreferenceCategory
          android:key="other_sounds_and_vibrations_category"
          android:title="@string/other_sound_category_preference_title"
          android:order="-50">

        <!-- Dial pad tones -->
        <SwitchPreference
          android:key="dial_pad_tones"
          android:title="@string/dial_pad_tones_title"/>

        <!-- Screen locking sounds -->
        <SwitchPreference
          android:key="screen_locking_sounds"
          android:title="@string/screen_locking_sounds_title"/>

        <!-- Charging sounds -->
        <SwitchPreference
          android:key="charging_sounds"
          android:title="@string/charging_sounds_title"/>

        <!-- Docking sounds -->
        <SwitchPreference
          android:key="docking_sounds"
          android:title="@string/docking_sounds_title"/>

        <!-- Touch sounds -->
        <SwitchPreference
          android:key="touch_sounds"
          android:title="@string/touch_sounds_title"/>

        <!-- Vibrate on touch -->
        <SwitchPreference
          android:key="vibrate_on_touch"
          android:title="@string/vibrate_on_touch_title"
          android:summary="@string/vibrate_on_touch_summary"
          settings:keywords="@string/keywords_vibrate_on_touch"/>

        <!-- Dock speaker plays -->
        <DropDownPreference
          android:key="dock_audio_media"
          android:title="@string/dock_audio_media_title"
          android:summary="%s"/>

        <!-- Boot sounds -->
        <SwitchPreference
          android:key="boot_sounds"
          android:title="@string/boot_sounds_title"/>

        <!-- Emergency tone -->
        <DropDownPreference
          android:key="emergency_tone"
          android:title="@string/emergency_tone_title"
          android:summary="%s"/>
    </PreferenceCategory>

    <com.android.settings.widget.WorkOnlyCategory
        android:key="sound_work_settings_section"
        android:title="@string/sound_work_settings"
        android:order="100">

                <!-- Use the same sounds of the work profile -->
                <SwitchPreference
                    android:key="work_use_personal_sounds"
                    android:title="@string/work_use_personal_sounds_title"
                    android:summary="@string/work_use_personal_sounds_summary"
                    android:disableDependentsState="true"/>

                <!-- Work phone ringtone -->
                <com.android.settings.DefaultRingtonePreference
                    android:key="work_ringtone"
                    android:title="@string/work_ringtone_title"
                    android:dialogTitle="@string/work_alarm_ringtone_title"
                    android:ringtoneType="ringtone"
                    android:dependency="work_use_personal_sounds"/>

                <!-- Default work notification ringtone -->
                <com.android.settings.DefaultRingtonePreference
                    android:key="work_notification_ringtone"
                    android:title="@string/work_notification_ringtone_title"
                    android:dialogTitle="@string/work_alarm_ringtone_title"
                    android:ringtoneType="notification"
                    android:dependency="work_use_personal_sounds"/>

                <!-- Default work alarm ringtone -->
                <com.android.settings.DefaultRingtonePreference
                    android:key="work_alarm_ringtone"
                    android:title="@string/work_alarm_ringtone_title"
                    android:dialogTitle="@string/work_alarm_ringtone_title"
                    android:persistent="false"
                    android:ringtoneType="alarm"
                    android:dependency="work_use_personal_sounds"/>

    </com.android.settings.widget.WorkOnlyCategory>
</PreferenceScreen>
+102 −13
Original line number Diff line number Diff line
@@ -20,42 +20,131 @@ import static android.provider.Settings.Secure.VOLUME_HUSH_GESTURE;
import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE;
import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.widget.PrimarySwitchPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;

public class PreventRingingParentPreferenceController extends BasePreferenceController {
/** The controller manages the behaviour of the Prevent Ringing gesture setting. */
public class PreventRingingParentPreferenceController extends TogglePreferenceController
        implements LifecycleObserver, OnStart, OnStop {

    final String SECURE_KEY = VOLUME_HUSH_GESTURE;

    private PrimarySwitchPreference mPreference;
    private SettingObserver mSettingObserver;

    public PreventRingingParentPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
    public int getAvailabilityStatus() {
        return mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_volumeHushGestureEnabled)
                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
        mSettingObserver = new SettingObserver(mPreference);
    }

    @Override
    public CharSequence getSummary() {
        int value = Settings.Secure.getInt(
    public boolean isChecked() {
        final int preventRinging = Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.VOLUME_HUSH_GESTURE,
                Settings.Secure.VOLUME_HUSH_VIBRATE);
        return preventRinging != Settings.Secure.VOLUME_HUSH_OFF;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        final int preventRingingSetting = Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_VIBRATE);
        final int newRingingSetting = preventRingingSetting == Settings.Secure.VOLUME_HUSH_OFF
                ? Settings.Secure.VOLUME_HUSH_VIBRATE
                : preventRingingSetting;

        return Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.VOLUME_HUSH_GESTURE, isChecked
                        ? newRingingSetting
                        : Settings.Secure.VOLUME_HUSH_OFF);
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        final int value = Settings.Secure.getInt(
                mContext.getContentResolver(), SECURE_KEY, VOLUME_HUSH_VIBRATE);
        int summary;
        CharSequence summary;
        switch (value) {
            case VOLUME_HUSH_VIBRATE:
                summary = R.string.prevent_ringing_option_vibrate_summary;
                summary = mContext.getText(R.string.prevent_ringing_option_vibrate_summary);
                break;
            case VOLUME_HUSH_MUTE:
                summary = R.string.prevent_ringing_option_mute_summary;
                summary = mContext.getText(R.string.prevent_ringing_option_mute_summary);
                break;
            default:
                summary = R.string.prevent_ringing_option_none_summary;
                summary = null;
        }
        preference.setSummary(summary);
    }

    @Override
    public int getAvailabilityStatus() {
        return mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_volumeHushGestureEnabled)
                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }

    @Override
    public void onStart() {
        if (mSettingObserver != null) {
            mSettingObserver.register(mContext.getContentResolver());
            mSettingObserver.onChange(false, null);
        }
    }

    @Override
    public void onStop() {
        if (mSettingObserver != null) {
            mSettingObserver.unregister(mContext.getContentResolver());
        }
    }

    private class SettingObserver extends ContentObserver {
        private final Uri mVolumeHushGestureUri = Settings.Secure.getUriFor(
                Settings.Secure.VOLUME_HUSH_GESTURE);

        private final Preference mPreference;

        SettingObserver(Preference preference) {
            super(new Handler());
            mPreference = preference;
        }

        public void register(ContentResolver cr) {
            cr.registerContentObserver(mVolumeHushGestureUri, false, this);
        }

        public void unregister(ContentResolver cr) {
            cr.unregisterContentObserver(this);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            super.onChange(selfChange, uri);
            if (uri == null || mVolumeHushGestureUri.equals(uri)) {
                updateState(mPreference);
            }
        }
        return mContext.getText(summary);
    }
}
+0 −34
Original line number Diff line number Diff line
@@ -16,11 +16,7 @@

package com.android.settings.gestures;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.widget.Switch;

@@ -39,7 +35,6 @@ public class PreventRingingSwitchPreferenceController extends AbstractPreference

    private static final String KEY = "gesture_prevent_ringing_switch";
    private final Context mContext;
    private SettingObserver mSettingObserver;

    @VisibleForTesting
    SwitchBar mSwitch;
@@ -60,7 +55,6 @@ public class PreventRingingSwitchPreferenceController extends AbstractPreference
        if (isAvailable()) {
            LayoutPreference pref = screen.findPreference(getPreferenceKey());
            if (pref != null) {
                mSettingObserver = new SettingObserver(pref);
                pref.setOnPreferenceClickListener(preference -> {
                    int preventRinging = Settings.Secure.getInt(mContext.getContentResolver(),
                            Settings.Secure.VOLUME_HUSH_GESTURE,
@@ -113,32 +107,4 @@ public class PreventRingingSwitchPreferenceController extends AbstractPreference
                        ? newRingingSetting
                        : Settings.Secure.VOLUME_HUSH_OFF);
    }

    private class SettingObserver extends ContentObserver {
        private final Uri VOLUME_HUSH_GESTURE = Settings.Secure.getUriFor(
                Settings.Secure.VOLUME_HUSH_GESTURE);

        private final Preference mPreference;

        public SettingObserver(Preference preference) {
            super(new Handler());
            mPreference = preference;
        }

        public void register(ContentResolver cr) {
            cr.registerContentObserver(VOLUME_HUSH_GESTURE, false, this);
        }

        public void unregister(ContentResolver cr) {
            cr.unregisterContentObserver(this);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            super.onChange(selfChange, uri);
            if (uri == null || VOLUME_HUSH_GESTURE.equals(uri)) {
                updateState(mPreference);
            }
        }
    }
}
Loading