Merge "Update vibrator on/off status from accessibility settings menu"
This commit is contained in:
committed by
Android (Google) Code Review
commit
9495654926
@@ -106,6 +106,31 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasVibrationEnabledSetting() {
|
||||||
|
return !TextUtils.isEmpty(getVibrationEnabledSetting());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSettings(VibrationIntensityCandidateInfo candidate) {
|
||||||
|
boolean vibrationEnabled = candidate.getIntensity() != Vibrator.VIBRATION_INTENSITY_OFF;
|
||||||
|
if (hasVibrationEnabledSetting()) {
|
||||||
|
// Update vibration enabled setting
|
||||||
|
boolean wasEnabled = Settings.System.getInt(getContext().getContentResolver(),
|
||||||
|
getVibrationEnabledSetting(), 1) == 1;
|
||||||
|
if (vibrationEnabled != wasEnabled) {
|
||||||
|
Settings.System.putInt(getContext().getContentResolver(),
|
||||||
|
getVibrationEnabledSetting(), vibrationEnabled ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// There are two conditions that need to change the intensity.
|
||||||
|
// First: Vibration is enabled and we are changing its strength.
|
||||||
|
// Second: There is no setting to enable this vibration, change the intensity directly.
|
||||||
|
if (vibrationEnabled || !hasVibrationEnabledSetting()) {
|
||||||
|
// Update vibration intensity setting
|
||||||
|
Settings.System.putInt(getContext().getContentResolver(),
|
||||||
|
getVibrationIntensitySetting(), candidate.getIntensity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
@@ -185,11 +210,7 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
|
|||||||
Log.e(TAG, "Tried to set unknown intensity (key=" + key + ")!");
|
Log.e(TAG, "Tried to set unknown intensity (key=" + key + ")!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (candidate.getIntensity() != Vibrator.VIBRATION_INTENSITY_OFF ||
|
updateSettings(candidate);
|
||||||
TextUtils.isEmpty(getVibrationEnabledSetting())) {
|
|
||||||
Settings.System.putInt(getContext().getContentResolver(),
|
|
||||||
getVibrationIntensitySetting(), candidate.getIntensity());
|
|
||||||
}
|
|
||||||
onVibrationIntensitySelected(candidate.getIntensity());
|
onVibrationIntensitySelected(candidate.getIntensity());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user