Merge "Keep consistency between sound and accessibility settings." into qt-dev
am: 6843e0247a
Change-Id: I21da5bf92dcdd6be217ddb9db4b0f81423f484c7
This commit is contained in:
@@ -36,6 +36,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
@@ -168,6 +169,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
private static final String ANIMATION_ON_VALUE = "1";
|
||||
private static final String ANIMATION_OFF_VALUE = "0";
|
||||
|
||||
static final String RAMPING_RINGER_ENABLED = "ramping_ringer_enabled";
|
||||
|
||||
private final Map<String, String> mLongPressTimeoutValueToTitleMap = new HashMap<>();
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
@@ -389,6 +392,15 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
: stateSummaryCombo;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static boolean isRampingRingerEnabled(final Context context) {
|
||||
return (Settings.Global.getInt(
|
||||
context.getContentResolver(),
|
||||
Settings.Global.APPLY_RAMPING_RINGER, 0) == 1)
|
||||
&& DeviceConfig.getBoolean(
|
||||
DeviceConfig.NAMESPACE_TELEPHONY, RAMPING_RINGER_ENABLED, false);
|
||||
}
|
||||
|
||||
private void handleToggleTextContrastPreferenceClick() {
|
||||
Settings.Secure.putInt(getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED,
|
||||
@@ -866,7 +878,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
Settings.System.RING_VIBRATION_INTENSITY,
|
||||
vibrator.getDefaultRingVibrationIntensity());
|
||||
if (Settings.System.getInt(context.getContentResolver(),
|
||||
Settings.System.VIBRATE_WHEN_RINGING, 0) == 0) {
|
||||
Settings.System.VIBRATE_WHEN_RINGING, 0) == 0 && !isRampingRingerEnabled(context)) {
|
||||
ringIntensity = Vibrator.VIBRATION_INTENSITY_OFF;
|
||||
}
|
||||
CharSequence ringIntensityString =
|
||||
|
@@ -29,7 +29,7 @@ public class RingVibrationIntensityPreferenceController
|
||||
|
||||
public RingVibrationIntensityPreferenceController(Context context) {
|
||||
super(context, PREF_KEY, Settings.System.RING_VIBRATION_INTENSITY,
|
||||
Settings.System.VIBRATE_WHEN_RINGING);
|
||||
Settings.System.VIBRATE_WHEN_RINGING, /* supportRampingRinger= */ true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -46,7 +46,11 @@ public class RingVibrationPreferenceFragment extends VibrationPreferenceFragment
|
||||
|
||||
@Override
|
||||
protected String getVibrationEnabledSetting() {
|
||||
return Settings.System.VIBRATE_WHEN_RINGING;
|
||||
if (AccessibilitySettings.isRampingRingerEnabled(getContext())) {
|
||||
return Settings.Global.APPLY_RAMPING_RINGER;
|
||||
} else {
|
||||
return Settings.System.VIBRATE_WHEN_RINGING;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -40,15 +40,17 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
|
||||
private final SettingObserver mSettingsContentObserver;
|
||||
private final String mSettingKey;
|
||||
private final String mEnabledKey;
|
||||
private final boolean mSupportRampingRinger;
|
||||
|
||||
private Preference mPreference;
|
||||
|
||||
public VibrationIntensityPreferenceController(Context context, String prefkey,
|
||||
String settingKey, String enabledKey) {
|
||||
String settingKey, String enabledKey, boolean supportRampingRinger) {
|
||||
super(context, prefkey);
|
||||
mVibrator = mContext.getSystemService(Vibrator.class);
|
||||
mSettingKey = settingKey;
|
||||
mEnabledKey = enabledKey;
|
||||
mSupportRampingRinger= supportRampingRinger;
|
||||
mSettingsContentObserver = new SettingObserver(settingKey) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
@@ -57,6 +59,11 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
|
||||
};
|
||||
}
|
||||
|
||||
public VibrationIntensityPreferenceController(Context context, String prefkey,
|
||||
String settingKey, String enabledKey) {
|
||||
this(context, prefkey, settingKey, enabledKey, /* supportRampingRinger= */ false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
@@ -80,10 +87,11 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
|
||||
public CharSequence getSummary() {
|
||||
final int intensity = Settings.System.getInt(mContext.getContentResolver(),
|
||||
mSettingKey, getDefaultIntensity());
|
||||
final boolean enabled = Settings.System.getInt(mContext.getContentResolver(),
|
||||
mEnabledKey, 1) == 1;
|
||||
final boolean enabled = (Settings.System.getInt(mContext.getContentResolver(),
|
||||
mEnabledKey, 1) == 1) ||
|
||||
(mSupportRampingRinger && AccessibilitySettings.isRampingRingerEnabled(mContext));
|
||||
return getIntensityString(mContext, enabled ? intensity : Vibrator.VIBRATION_INTENSITY_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
public static CharSequence getIntensityString(Context context, int intensity) {
|
||||
final boolean supportsMultipleIntensities = context.getResources().getBoolean(
|
||||
|
@@ -114,11 +114,20 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
|
||||
boolean vibrationEnabled = candidate.getIntensity() != Vibrator.VIBRATION_INTENSITY_OFF;
|
||||
if (hasVibrationEnabledSetting()) {
|
||||
// Update vibration enabled setting
|
||||
boolean wasEnabled = Settings.System.getInt(getContext().getContentResolver(),
|
||||
getVibrationEnabledSetting(), 1) == 1;
|
||||
final String vibrationEnabledSetting = getVibrationEnabledSetting();
|
||||
final boolean wasEnabled = TextUtils.equals(
|
||||
vibrationEnabledSetting, Settings.Global.APPLY_RAMPING_RINGER)
|
||||
? true
|
||||
: (Settings.System.getInt(
|
||||
getContext().getContentResolver(), vibrationEnabledSetting, 1) == 1);
|
||||
if (vibrationEnabled != wasEnabled) {
|
||||
Settings.System.putInt(getContext().getContentResolver(),
|
||||
getVibrationEnabledSetting(), vibrationEnabled ? 1 : 0);
|
||||
if (vibrationEnabledSetting.equals(Settings.Global.APPLY_RAMPING_RINGER)) {
|
||||
Settings.Global.putInt(getContext().getContentResolver(),
|
||||
vibrationEnabledSetting, 0);
|
||||
} else {
|
||||
Settings.System.putInt(getContext().getContentResolver(),
|
||||
vibrationEnabledSetting, vibrationEnabled ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
// There are two conditions that need to change the intensity.
|
||||
@@ -196,8 +205,12 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
|
||||
protected String getDefaultKey() {
|
||||
int vibrationIntensity = Settings.System.getInt(getContext().getContentResolver(),
|
||||
getVibrationIntensitySetting(), getDefaultVibrationIntensity());
|
||||
final boolean vibrationEnabled = Settings.System.getInt(getContext().getContentResolver(),
|
||||
getVibrationEnabledSetting(), 1) == 1;
|
||||
final String vibrationEnabledSetting = getVibrationEnabledSetting();
|
||||
final boolean vibrationEnabled = TextUtils.equals(
|
||||
vibrationEnabledSetting, Settings.Global.APPLY_RAMPING_RINGER)
|
||||
? true
|
||||
: (Settings.System.getInt(
|
||||
getContext().getContentResolver(), vibrationEnabledSetting, 1) == 1);
|
||||
if (!vibrationEnabled) {
|
||||
vibrationIntensity = Vibrator.VIBRATION_INTENSITY_OFF;
|
||||
}
|
||||
|
Reference in New Issue
Block a user