Allow doubletap/longpress power to toggle torch [2/2]
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -161,4 +161,12 @@
|
||||
|
||||
<!--Volume keys -->
|
||||
<string name="volume_rocker_wake_summary">Pressing the volume keys will wake your device</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>
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
android:title="@string/volume_rocker_wake_title"
|
||||
android:defaultValue="false" />
|
||||
</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>
|
||||
@@ -31,17 +31,14 @@ 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.android.settings.SettingsPreferenceFragment;
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
import com.cherish.settings.preferences.SecureSettingSwitchPreference;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.util.hwkeys.ActionConstants;
|
||||
import com.android.internal.util.hwkeys.ActionUtils;
|
||||
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
import com.cherish.settings.preferences.ActionFragment;
|
||||
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
@@ -52,6 +49,9 @@ import java.util.List;
|
||||
public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String TORCH_POWER_BUTTON_GESTURE = "torch_power_button_gesture";
|
||||
|
||||
private ListPreference mTorchPowerButton;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -61,10 +61,27 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -76,26 +93,7 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.cherish_settings_button);
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.cherish_settings_button;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user