Cherish: Add DND & Rate settings to flash on call [3/3]

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Ido Ben-Hur
2020-06-13 03:31:47 +03:00
committed by Hưng Phan
parent 3525d519fc
commit d63a98a86c
3 changed files with 69 additions and 6 deletions

View File

@@ -40,6 +40,13 @@ import java.util.List;
public class NotificationSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener{
private static final String INCALL_VIB_OPTIONS = "incall_vib_options";
private static final String PREF_FLASH_ON_CALL = "flashlight_on_call";
private static final String PREF_FLASH_ON_CALL_DND = "flashlight_on_call_ignore_dnd";
private static final String PREF_FLASH_ON_CALL_RATE = "flashlight_on_call_rate";
private SystemSettingListPreference mFlashOnCall;
private SystemSettingSwitchPreference mFlashOnCallIgnoreDND;
private CustomSeekBarPreference mFlashOnCallRate;
private Preference mChargingLeds;
@Override
public void onCreate(Bundle icicle) {
@@ -55,6 +62,24 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
prefScreen.removePreference(incallVibCategory);
}
mFlashOnCallRate = (CustomSeekBarPreference)
findPreference(PREF_FLASH_ON_CALL_RATE);
int value = Settings.System.getInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL_RATE, 1);
mFlashOnCallRate.setValue(value);
mFlashOnCallRate.setOnPreferenceChangeListener(this);
mFlashOnCallIgnoreDND = (SystemSettingSwitchPreference)
findPreference(PREF_FLASH_ON_CALL_DND);
value = Settings.System.getInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL, 0);
mFlashOnCallIgnoreDND.setVisible(value > 1);
mFlashOnCallRate.setVisible(value != 0);
mFlashOnCall = (SystemSettingListPreference)
findPreference(PREF_FLASH_ON_CALL);
mFlashOnCall.setOnPreferenceChangeListener(this);
mChargingLeds = (Preference) findPreference("charging_light");
if (mChargingLeds != null
&& !getResources().getBoolean(
@@ -66,6 +91,20 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final ContentResolver resolver = getActivity().getContentResolver();
if (preference == mFlashOnCall) {
int value = Integer.parseInt((String) newValue);
Settings.System.putInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL, value);
mFlashOnCallIgnoreDND.setVisible(value > 1);
mFlashOnCallRate.setVisible(value != 0);
return true;
} else if (preference == mFlashOnCallRate) {
int value = (Integer) newValue;
Settings.System.putInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL_RATE, value);
return true;
}
return false;
}