Cherish: Allow doubletap/longpress power to toggle torch [2/2]

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
ezio84
2022-09-24 11:37:44 +07:00
committed by Hưng Phan
parent 4f1a57e28d
commit aa4ad58e36
4 changed files with 46 additions and 0 deletions

View File

@@ -51,6 +51,7 @@ import com.cherish.settings.preferences.SystemSettingListPreference;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import android.provider.SearchIndexableResource;
import android.widget.Toast;
import java.util.List;
import java.util.ArrayList;
@@ -71,11 +72,13 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String UDFPS_CATEGORY = "udfps_category";
private static final String TORCH_POWER_BUTTON_GESTURE = "torch_power_button_gesture";
private ListPreference mLockClockStyles;
private PreferenceCategory mUdfpsCategory;
private Context mContext;
private ListPreference mTorchPowerButton;
@Override
public void onCreate(Bundle icicle) {
@@ -98,6 +101,14 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
if (!UdfpsUtils.hasUdfpsSupport(getContext())) {
prefSet.removePreference(mUdfpsCategory);
}
// screen off torch
mTorchPowerButton = (ListPreference) findPreference(TORCH_POWER_BUTTON_GESTURE);
int mTorchPowerButtonValue = Settings.System.getInt(resolver,
Settings.System.TORCH_POWER_BUTTON_GESTURE, 0);
mTorchPowerButton.setValue(Integer.toString(mTorchPowerButtonValue));
mTorchPowerButton.setSummary(mTorchPowerButton.getEntry());
mTorchPowerButton.setOnPreferenceChangeListener(this);
}
@Override
@@ -107,6 +118,15 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mTorchPowerButton) {
int mTorchPowerButtonValue = Integer.valueOf((String) newValue);
int index = mTorchPowerButton.findIndexOfValue((String) newValue);
mTorchPowerButton.setSummary(
mTorchPowerButton.getEntries()[index]);
Settings.System.putInt(resolver, Settings.System.TORCH_POWER_BUTTON_GESTURE,
mTorchPowerButtonValue);
return true;
}
return false;
}