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 9fb7d1d563
commit fb3d2e57b3
4 changed files with 46 additions and 0 deletions

View File

@@ -249,4 +249,17 @@
<item>3</item> <item>3</item>
<item>4</item> <item>4</item>
</string-array> </string-array>
<!-- Torch Power button gestures -->
<string-array name="torch_power_button_gesture_entries">
<item>@string/torch_power_button_gesture_none</item>
<item>@string/torch_power_button_gesture_dt</item>
<item>@string/torch_power_button_gesture_lp</item>
</string-array>
<string-array name="torch_power_button_gesture_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources> </resources>

View File

@@ -521,4 +521,11 @@
<string name="bluetooth_battery_title">Bluetooth battery status</string> <string name="bluetooth_battery_title">Bluetooth battery status</string>
<string name="bluetooth_battery_summary">Display battery status for the connected bluetooth device, if available</string> <string name="bluetooth_battery_summary">Display battery status for the connected bluetooth device, if available</string>
<!-- Torch Power button gestures -->
<string name="torch_power_button_gesture_title">Toggle torch when screen off</string>
<string name="torch_power_button_gesture_none">Disabled</string>
<string name="torch_power_button_gesture_dt">Double tap power button (slower single tap response), Disables double power tap for camera.</string>
<string name="torch_power_button_gesture_dt_toast">Jump to camera gesture is now disabled</string>
<string name="torch_power_button_gesture_lp">Long press power button</string>
</resources> </resources>

View File

@@ -27,6 +27,12 @@
android:summary="@string/double_tap_sleep_lockscreen_summary" android:summary="@string/double_tap_sleep_lockscreen_summary"
android:defaultValue="true" /> android:defaultValue="true" />
<ListPreference
android:key="torch_power_button_gesture"
android:title="@string/torch_power_button_gesture_title"
android:entries="@array/torch_power_button_gesture_entries"
android:entryValues="@array/torch_power_button_gesture_values" />
<com.cherish.settings.preferences.SecureSettingSwitchPreference <com.cherish.settings.preferences.SecureSettingSwitchPreference
android:key="power_menu_hide_on_secure" android:key="power_menu_hide_on_secure"
android:title="@string/power_menu_hide_on_secure_title" android:title="@string/power_menu_hide_on_secure_title"

View File

@@ -51,6 +51,7 @@ import com.cherish.settings.preferences.SystemSettingListPreference;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -60,11 +61,13 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener { Preference.OnPreferenceChangeListener {
private static final String UDFPS_CATEGORY = "udfps_category"; private static final String UDFPS_CATEGORY = "udfps_category";
private static final String TORCH_POWER_BUTTON_GESTURE = "torch_power_button_gesture";
private ListPreference mLockClockStyles; private ListPreference mLockClockStyles;
private PreferenceCategory mUdfpsCategory; private PreferenceCategory mUdfpsCategory;
private Context mContext; private Context mContext;
private ListPreference mTorchPowerButton;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
@@ -89,6 +92,14 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
if (!UdfpsUtils.hasUdfpsSupport(getContext())) { if (!UdfpsUtils.hasUdfpsSupport(getContext())) {
prefSet.removePreference(mUdfpsCategory); 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 @Override
@@ -98,6 +109,15 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver(); 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; return false;
} }