Cherish:Torch long press power: add with auto-off function
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
8
res/drawable/ic_torch.xml
Normal file
8
res/drawable/ic_torch.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<vector android:height="24dp" android:viewportHeight="532"
|
||||||
|
android:viewportWidth="532.0038" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m289.449,100.379c-13.016,-12.98 -34.082,-12.98 -47.094,0l-17.93,17.934c-7.77,7.793 -13.742,17.195 -17.496,27.539l-34.793,96.324 -139.391,139.387c-21.105,21.152 -21.105,55.398 0,76.555l41.813,41.805c21.152,21.109 55.406,21.109 76.559,0l139.27,-139.262 96.637,-35.168c10.211,-3.734 19.5,-9.633 27.227,-17.297l17.945,-17.844c13.039,-12.973 13.098,-34.059 0.125,-47.098l-0.063,-0.063zM133.48,482.289c-11.406,11.383 -29.871,11.383 -41.281,0l-41.809,-41.813c-11.383,-11.406 -11.383,-29.875 0,-41.285l132.047,-132.047 83.332,82.852zM414.605,272.66 L396.66,290.512c-5.156,5.109 -11.359,9.043 -18.172,11.539l-91.941,33.457 -89.473,-88.965 33.313,-92.223c2.508,-6.898 6.492,-13.172 11.676,-18.375l17.934,-17.93c3.258,-3.266 8.547,-3.27 11.816,-0.012l0.008,0.012 142.801,142.801c3.262,3.266 3.262,8.559 0,11.828l-0.02,0.02zM414.605,272.66"/>
|
||||||
|
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m205.375,327.293c-4.867,-4.867 -12.762,-4.867 -17.633,0l-30.316,30.324c-4.77,4.883 -4.715,12.691 0.105,17.52 4.828,4.828 12.637,4.875 17.527,0.113l30.316,-30.324c4.871,-4.871 4.871,-12.762 0,-17.633zM205.375,327.293"/>
|
||||||
|
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m396.711,148.43c3.305,0.004 6.48,-1.309 8.816,-3.648l42.852,-42.855c4.711,-4.895 4.637,-12.66 -0.164,-17.461 -4.805,-4.805 -12.566,-4.879 -17.461,-0.172l-42.855,42.852c-3.566,3.563 -4.633,8.926 -2.703,13.59 1.93,4.656 6.473,7.695 11.516,7.695zM396.711,148.43"/>
|
||||||
|
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m499.48,176.902 l-42.855,13.391c-6.57,2.055 -10.238,9.051 -8.184,15.625 2.059,6.57 9.051,10.234 15.621,8.18l42.855,-13.391c6.574,-2.055 10.238,-9.051 8.184,-15.621 -2.055,-6.574 -9.051,-10.238 -15.621,-8.184zM499.48,176.902"/>
|
||||||
|
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m326.754,84.227c6.566,2.059 13.559,-1.59 15.617,-8.152l0.012,-0.031 13.387,-42.848c2.059,-6.578 -1.605,-13.57 -8.18,-15.621 -6.574,-2.055 -13.566,1.605 -15.621,8.176l-13.391,42.855c-2.055,6.574 1.605,13.57 8.176,15.621zM326.754,84.227"/>
|
||||||
|
</vector>
|
||||||
@@ -44,4 +44,20 @@
|
|||||||
<item>1</item>
|
<item>1</item>
|
||||||
<item>2</item>
|
<item>2</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="torch_long_press_power_timeout_entries" translatable="false">
|
||||||
|
<item>@string/torch_long_press_power_timeout_never</item>
|
||||||
|
<item>@string/torch_long_press_power_timeout_1min</item>
|
||||||
|
<item>@string/torch_long_press_power_timeout_2min</item>
|
||||||
|
<item>@string/torch_long_press_power_timeout_5min</item>
|
||||||
|
<item>@string/torch_long_press_power_timeout_10min</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="torch_long_press_power_timeout_values" translatable="false">
|
||||||
|
<item>0</item>
|
||||||
|
<item>60</item>
|
||||||
|
<item>120</item>
|
||||||
|
<item>300</item>
|
||||||
|
<item>600</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -137,4 +137,13 @@
|
|||||||
<string name="volume_key_cursor_control_off">Disabled</string>
|
<string name="volume_key_cursor_control_off">Disabled</string>
|
||||||
<string name="volume_key_cursor_control_on">Volume up/down moves cursor left/right</string>
|
<string name="volume_key_cursor_control_on">Volume up/down moves cursor left/right</string>
|
||||||
<string name="volume_key_cursor_control_on_reverse">Volume up/down moves cursor right/left</string>
|
<string name="volume_key_cursor_control_on_reverse">Volume up/down moves cursor right/left</string>
|
||||||
|
|
||||||
|
<string name="torch_long_press_power_gesture_title">Screen off power button torch</string>
|
||||||
|
<string name="torch_long_press_power_gesture_desc">Long press power button while the screen is off to turn on the flashlight</string>
|
||||||
|
<string name="torch_long_press_power_timeout_title">Automatically turn torch off</string>
|
||||||
|
<string name="torch_long_press_power_timeout_never">Never</string>
|
||||||
|
<string name="torch_long_press_power_timeout_1min">1 minute</string>
|
||||||
|
<string name="torch_long_press_power_timeout_2min">2 minutes</string>
|
||||||
|
<string name="torch_long_press_power_timeout_5min">5 minutes</string>
|
||||||
|
<string name="torch_long_press_power_timeout_10min">10 minutes</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -18,4 +18,20 @@
|
|||||||
android:title="@string/gestures_title"
|
android:title="@string/gestures_title"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||||
|
android:icon="@drawable/ic_torch"
|
||||||
|
android:key="torch_long_press_power_gesture"
|
||||||
|
android:title="@string/torch_long_press_power_gesture_title"
|
||||||
|
android:summary="@string/torch_long_press_power_gesture_desc"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="torch_long_press_power_timeout"
|
||||||
|
android:dialogTitle="@string/torch_long_press_power_timeout_title"
|
||||||
|
android:title="@string/torch_long_press_power_timeout_title"
|
||||||
|
android:summary="%s"
|
||||||
|
android:entries="@array/torch_long_press_power_timeout_entries"
|
||||||
|
android:entryValues="@array/torch_long_press_power_timeout_values"
|
||||||
|
android:dependency="torch_long_press_power_gesture"
|
||||||
|
android:persistent="false" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
@@ -3,17 +3,51 @@ package com.cherish.settings.fragments;
|
|||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
|
|
||||||
import android.os.Bundle;
|
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.R;
|
||||||
|
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
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
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.cherish_settings_gestures);
|
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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user