Cherish:Torch long press power: add with auto-off function

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Sam Mortimer
2018-08-30 16:09:26 +08:00
committed by Hưng Phan
parent cbe6fdc678
commit e208dd915d
5 changed files with 85 additions and 2 deletions

View File

@@ -3,17 +3,51 @@ package com.cherish.settings.fragments;
import com.android.internal.logging.nano.MetricsProto;
import android.os.Bundle;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.ListPreference;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
public class GestureSettings extends SettingsPreferenceFragment {
public class GestureSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String KEY_TORCH_LONG_PRESS_POWER_TIMEOUT =
"torch_long_press_power_timeout";
private ListPreference mTorchLongPressPowerTimeout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.cherish_settings_gestures);
mTorchLongPressPowerTimeout =
(ListPreference) findPreference(KEY_TORCH_LONG_PRESS_POWER_TIMEOUT);
mTorchLongPressPowerTimeout.setOnPreferenceChangeListener(this);
int TorchTimeout = Settings.System.getInt(getContentResolver(),
Settings.System.TORCH_LONG_PRESS_POWER_TIMEOUT, 0);
mTorchLongPressPowerTimeout.setValue(Integer.toString(TorchTimeout));
mTorchLongPressPowerTimeout.setSummary(mTorchLongPressPowerTimeout.getEntry());
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mTorchLongPressPowerTimeout) {
String TorchTimeout = (String) newValue;
int TorchTimeoutValue = Integer.parseInt(TorchTimeout);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.TORCH_LONG_PRESS_POWER_TIMEOUT, TorchTimeoutValue);
int TorchTimeoutIndex = mTorchLongPressPowerTimeout
.findIndexOfValue(TorchTimeout);
mTorchLongPressPowerTimeout
.setSummary(mTorchLongPressPowerTimeout.getEntries()[TorchTimeoutIndex]);
return true;
}
return false;
}
@Override