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

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
ezio84
2017-09-03 19:13:15 +02:00
committed by Hưng Phan
parent 726a8edddc
commit 08476c3827
4 changed files with 46 additions and 1 deletions

View File

@@ -12,4 +12,16 @@
limitations under the License.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- 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>

View File

@@ -161,4 +161,11 @@
<string name="volume_rocker_music_controls_title">Music control</string>
<string name="volume_rocker_music_controls_summary">Long press volume buttons to switch tracks while screen off</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>

View File

@@ -36,6 +36,12 @@
android:defaultValue="false"
android:disableDependentsState="true" />
</PreferenceCategory>
<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" />
</PreferenceScreen>

View File

@@ -31,7 +31,7 @@ import androidx.preference.PreferenceScreen;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.SwitchPreference;
import android.provider.Settings;
import android.widget.Toast;
import com.android.settings.R;
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
@@ -52,6 +52,9 @@ import java.util.List;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class ButtonSettings extends ActionFragment implements OnPreferenceChangeListener {
private static final String TORCH_POWER_BUTTON_GESTURE = "torch_power_button_gesture";
private ListPreference mTorchPowerButton;
@Override
public void onCreate(Bundle icicle) {
@@ -61,10 +64,27 @@ public class ButtonSettings extends ActionFragment implements OnPreferenceChange
final Resources res = getResources();
final ContentResolver resolver = getActivity().getContentResolver();
final PreferenceScreen prefScreen = getPreferenceScreen();
// 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);
}
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;
}