Settings: Add option to cycle through ringer modes [2/2]

* @mickaelmendes50 : Adapt to Android 12, 13

Signed-off-by: rituj <ritujbeniwal@gmail.com>
Change-Id: If4a387a9f8a465d33b25b87b0360fa20f1cee7de
This commit is contained in:
rituj
2020-07-27 18:23:45 +05:30
committed by Joey
parent 9ae7f8fe5f
commit 9fab4f5616
3 changed files with 26 additions and 0 deletions

View File

@@ -262,4 +262,8 @@
<!-- Enforce DNS for VPN -->
<string name="vpn_enforce_dns_title">Disable for VPN</string>
<string name="vpn_enforce_dns_summary">Disable the private DNS when connected to a VPN\nWill restore upon disconnecting</string>
<!-- Cycle through ringer modes gesture -->
<string name="prevent_ringing_option_cycle">Cycle through modes</string>
<string name="prevent_ringing_option_cycle_summary">On (cycle through modes)</string>
</resources>

View File

@@ -47,6 +47,8 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
@VisibleForTesting
static final String KEY_MUTE = "prevent_ringing_option_mute";
static final String KEY_CYCLE = "prevent_ringing_option_cycle";
private final String PREF_KEY_VIDEO = "gesture_prevent_ringing_video";
private final String KEY = "gesture_prevent_ringing_category";
private final Context mContext;
@@ -57,6 +59,7 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
SelectorWithWidgetPreference mVibratePref;
@VisibleForTesting
SelectorWithWidgetPreference mMutePref;
SelectorWithWidgetPreference mCyclePref;
private SettingObserver mSettingObserver;
@@ -78,6 +81,9 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
mPreferenceCategory = screen.findPreference(getPreferenceKey());
mVibratePref = makeRadioPreference(KEY_VIBRATE, R.string.prevent_ringing_option_vibrate);
mMutePref = makeRadioPreference(KEY_MUTE, R.string.prevent_ringing_option_mute);
if (!mContext.getResources().getBoolean(com.android.internal.R.bool.config_hasAlertSlider)) {
mCyclePref = makeRadioPreference(KEY_CYCLE, R.string.prevent_ringing_option_cycle);
}
if (mPreferenceCategory != null) {
mSettingObserver = new SettingObserver(mPreferenceCategory);
@@ -115,19 +121,29 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_VIBRATE);
final boolean isVibrate = preventRingingSetting == Settings.Secure.VOLUME_HUSH_VIBRATE;
final boolean isMute = preventRingingSetting == Settings.Secure.VOLUME_HUSH_MUTE;
final boolean isCycle = preventRingingSetting == Settings.Secure.VOLUME_HUSH_CYCLE;
if (mVibratePref != null && mVibratePref.isChecked() != isVibrate) {
mVibratePref.setChecked(isVibrate);
}
if (mMutePref != null && mMutePref.isChecked() != isMute) {
mMutePref.setChecked(isMute);
}
if (mCyclePref != null && mCyclePref.isChecked() != isCycle) {
mCyclePref.setChecked(isCycle);
}
if (preventRingingSetting == Settings.Secure.VOLUME_HUSH_OFF) {
mVibratePref.setEnabled(false);
mMutePref.setEnabled(false);
if (mCyclePref != null) {
mCyclePref.setEnabled(false);
}
} else {
mVibratePref.setEnabled(true);
mMutePref.setEnabled(true);
if (mCyclePref != null) {
mCyclePref.setEnabled(true);
}
}
}
@@ -152,6 +168,8 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
return Settings.Secure.VOLUME_HUSH_MUTE;
case KEY_VIBRATE:
return Settings.Secure.VOLUME_HUSH_VIBRATE;
case KEY_CYCLE:
return Settings.Secure.VOLUME_HUSH_CYCLE;
default:
return Settings.Secure.VOLUME_HUSH_OFF;
}

View File

@@ -16,6 +16,7 @@
package com.android.settings.gestures;
import static android.provider.Settings.Secure.VOLUME_HUSH_CYCLE;
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;
@@ -102,6 +103,9 @@ public class PreventRingingParentPreferenceController extends TogglePreferenceCo
case VOLUME_HUSH_MUTE:
summary = mContext.getText(R.string.prevent_ringing_option_mute_summary);
break;
case VOLUME_HUSH_CYCLE:
summary = mContext.getText(R.string.prevent_ringing_option_cycle_summary);
break;
// VOLUME_HUSH_OFF
default:
summary = mContext.getText(R.string.switch_off_text);