CMActions: add support for fingerprint gesture
This commit is contained in:
37
cmactions/res/values/array.xml
Normal file
37
cmactions/res/values/array.xml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2017 Erfan Abdi
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<resources>
|
||||||
|
<string-array name="fp_keys_listArray">
|
||||||
|
<item>None</item>
|
||||||
|
<item>Home</item>
|
||||||
|
<item>Power</item>
|
||||||
|
<item>Back</item>
|
||||||
|
<item>Recents</item>
|
||||||
|
<item>Volume Up</item>
|
||||||
|
<item>Volume Down</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="fp_keys_listValues">
|
||||||
|
<item>0</item>
|
||||||
|
<item>102</item>
|
||||||
|
<item>116</item>
|
||||||
|
<item>158</item>
|
||||||
|
<item>580</item>
|
||||||
|
<item>115</item>
|
||||||
|
<item>114</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
||||||
@@ -58,11 +58,50 @@
|
|||||||
android:key="fp_key"
|
android:key="fp_key"
|
||||||
android:title="@string/fingerprint_title" >
|
android:title="@string/fingerprint_title" >
|
||||||
|
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="fp_home"
|
android:key="fp_home"
|
||||||
android:title="@string/fingerprint_as_home_title"
|
android:title="Fingerprint Gestures"
|
||||||
android:summary="@string/fingerprint_as_home_summary" />
|
android:summary="Use fingerprint gestures" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:dependency="fp_home"
|
||||||
|
android:title="Fingerprint Tap"
|
||||||
|
android:summary="Select action for single tap"
|
||||||
|
android:dialogTitle="Select action for single tap"
|
||||||
|
android:key="fp_keys"
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:entries="@array/fp_keys_listArray"
|
||||||
|
android:entryValues="@array/fp_keys_listValues" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:dependency="fp_home"
|
||||||
|
android:title="Fingerprint Long Press"
|
||||||
|
android:summary="Select action for long press"
|
||||||
|
android:dialogTitle="Select action for long press"
|
||||||
|
android:key="fp_key_hold"
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:entries="@array/fp_keys_listArray"
|
||||||
|
android:entryValues="@array/fp_keys_listValues" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:dependency="fp_home"
|
||||||
|
android:title="Fingerprint Swipe Left"
|
||||||
|
android:summary="Select action for swipe left"
|
||||||
|
android:dialogTitle="Select action for swipe left"
|
||||||
|
android:key="fp_key_left"
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:entries="@array/fp_keys_listArray"
|
||||||
|
android:entryValues="@array/fp_keys_listValues" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:dependency="fp_home"
|
||||||
|
android:title="Fingerprint Swipe Right"
|
||||||
|
android:summary="Select action for swipe right"
|
||||||
|
android:dialogTitle="Select action for swipe right"
|
||||||
|
android:key="fp_key_right"
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:entries="@array/fp_keys_listArray"
|
||||||
|
android:entryValues="@array/fp_keys_listValues" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.cyanogenmod.settings.device.ServiceWrapper.LocalBinder;
|
import com.cyanogenmod.settings.device.ServiceWrapper.LocalBinder;
|
||||||
|
|
||||||
import org.cyanogenmod.internal.util.FileUtils;
|
|
||||||
|
|
||||||
public class BootCompletedReceiver extends BroadcastReceiver {
|
public class BootCompletedReceiver extends BroadcastReceiver {
|
||||||
static final String TAG = "CMActions";
|
static final String TAG = "CMActions";
|
||||||
private ServiceWrapper mServiceWrapper;
|
private ServiceWrapper mServiceWrapper;
|
||||||
@@ -38,13 +36,7 @@ public class BootCompletedReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
// Restore nodes to saved preference values
|
// Restore nodes to saved preference values
|
||||||
for (String pref : Constants.sButtonPrefKeys) {
|
for (String pref : Constants.sButtonPrefKeys) {
|
||||||
String value = Constants.isPreferenceEnabled(context, pref) ? "1" : "0";
|
Constants.writePreference(context, pref);
|
||||||
String node = Constants.sBooleanNodePreferenceMap.get(pref);
|
|
||||||
|
|
||||||
if (!FileUtils.writeLine(node, value)) {
|
|
||||||
Log.w(TAG, "Write to node " + node +
|
|
||||||
" failed while restoring saved preference values");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.startService(new Intent(context, ServiceWrapper.class));
|
context.startService(new Intent(context, ServiceWrapper.class));
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ public class CMActionsSettings {
|
|||||||
mFlipToMuteEnabled = sharedPreferences.getBoolean(GESTURE_FLIP_TO_MUTE_KEY, false);
|
mFlipToMuteEnabled = sharedPreferences.getBoolean(GESTURE_FLIP_TO_MUTE_KEY, false);
|
||||||
} else if (GESTURE_LIFT_TO_SILENCE_KEY.equals(key)) {
|
} else if (GESTURE_LIFT_TO_SILENCE_KEY.equals(key)) {
|
||||||
mLiftToSilenceEnabled = sharedPreferences.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
|
mLiftToSilenceEnabled = sharedPreferences.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
|
||||||
|
} else if (Constants.FP_HOME_KEY.equals(key) || Constants.FP_KEYS.equals(key) || Constants.FP_KEY_HOLD.equals(key) || Constants.FP_KEY_LEFT.equals(key) || Constants.FP_KEY_RIGHT.equals(key)) {
|
||||||
|
Constants.writePreference(mContext, key);
|
||||||
|
updated = false;
|
||||||
} else {
|
} else {
|
||||||
updated = false;
|
updated = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,32 @@ import java.util.Map;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.cyanogenmod.internal.util.FileUtils;
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
|
private static final String TAG = "CMActions";
|
||||||
|
|
||||||
// Swap keys
|
// Swap keys
|
||||||
public static final String FP_HOME_KEY = "fp_home";
|
public static final String FP_HOME_KEY = "fp_home";
|
||||||
|
|
||||||
// Swap nodes
|
// Swap nodes
|
||||||
public static final String FP_HOME_NODE = "/sys/homebutton/enable";
|
public static final String FP_HOME_NODE = "/sys/homebutton/enable";
|
||||||
|
|
||||||
|
// List of keys
|
||||||
|
public static final String FP_KEYS = "fp_keys";
|
||||||
|
public static final String FP_KEY_HOLD = "fp_key_hold";
|
||||||
|
public static final String FP_KEY_LEFT = "fp_key_left";
|
||||||
|
public static final String FP_KEY_RIGHT = "fp_key_right";
|
||||||
|
|
||||||
|
// Keys nodes
|
||||||
|
public static final String FP_KEYS_NODE = "/sys/homebutton/key";
|
||||||
|
public static final String FP_KEY_HOLD_NODE = "/sys/homebutton/key_hold";
|
||||||
|
public static final String FP_KEY_LEFT_NODE = "/sys/homebutton/key_left";
|
||||||
|
public static final String FP_KEY_RIGHT_NODE = "/sys/homebutton/key_right";
|
||||||
|
|
||||||
// Holds <preference_key> -> <proc_node> mapping
|
// Holds <preference_key> -> <proc_node> mapping
|
||||||
public static final Map<String, String> sBooleanNodePreferenceMap = new HashMap<>();
|
public static final Map<String, String> sBooleanNodePreferenceMap = new HashMap<>();
|
||||||
|
|
||||||
@@ -39,15 +56,50 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String[] sButtonPrefKeys = {
|
public static final String[] sButtonPrefKeys = {
|
||||||
FP_HOME_KEY,
|
FP_HOME_KEY,
|
||||||
|
FP_KEYS,
|
||||||
|
FP_KEY_HOLD,
|
||||||
|
FP_KEY_RIGHT,
|
||||||
|
FP_KEY_LEFT,
|
||||||
};
|
};
|
||||||
|
|
||||||
static {
|
static {
|
||||||
sBooleanNodePreferenceMap.put(FP_HOME_KEY, FP_HOME_NODE);
|
sBooleanNodePreferenceMap.put(FP_HOME_KEY, FP_HOME_NODE);
|
||||||
|
sBooleanNodePreferenceMap.put(FP_KEYS, FP_KEYS_NODE);
|
||||||
|
sBooleanNodePreferenceMap.put(FP_KEY_HOLD, FP_KEY_HOLD_NODE);
|
||||||
|
sBooleanNodePreferenceMap.put(FP_KEY_LEFT, FP_KEY_LEFT_NODE);
|
||||||
|
sBooleanNodePreferenceMap.put(FP_KEY_RIGHT, FP_KEY_RIGHT_NODE);
|
||||||
sNodeDefaultMap.put(FP_HOME_KEY, false);
|
sNodeDefaultMap.put(FP_HOME_KEY, false);
|
||||||
|
sNodeDefaultMap.put(FP_KEYS, "0");
|
||||||
|
sNodeDefaultMap.put(FP_KEY_HOLD, "0");
|
||||||
|
sNodeDefaultMap.put(FP_KEY_LEFT, "0");
|
||||||
|
sNodeDefaultMap.put(FP_KEY_RIGHT, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPreferenceEnabled(Context context, String key) {
|
public static boolean isPreferenceEnabled(Context context, String key) {
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
return preferences.getBoolean(key, (Boolean) sNodeDefaultMap.get(key));
|
return preferences.getBoolean(key, (Boolean) sNodeDefaultMap.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String GetPreference(Context context, String key) {
|
||||||
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
return preferences.getString(key, (String) sNodeDefaultMap.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writePreference(Context context, String pref) {
|
||||||
|
|
||||||
|
String value = "1";
|
||||||
|
Log.e(TAG, "Write Pref: " + pref);
|
||||||
|
if (!pref.equals(FP_KEYS) && !pref.equals(FP_KEY_HOLD) && !pref.equals(FP_KEY_LEFT) && !pref.equals(FP_KEY_RIGHT))
|
||||||
|
value = isPreferenceEnabled(context, pref) ? "1" : "0";
|
||||||
|
else
|
||||||
|
value = GetPreference(context, pref);
|
||||||
|
|
||||||
|
String node = sBooleanNodePreferenceMap.get(pref);
|
||||||
|
Log.e(TAG, "Write " + value + " to node " + node);
|
||||||
|
|
||||||
|
if (!FileUtils.writeLine(node, value)) {
|
||||||
|
Log.w(TAG, "Write " + value + " to node " + node +
|
||||||
|
"failed while restoring saved preference values");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,16 +23,10 @@ import android.os.Bundle;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.PreferenceCategory;
|
import android.support.v7.preference.PreferenceCategory;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.cyanogenmod.internal.util.FileUtils;
|
|
||||||
import org.cyanogenmod.internal.util.ScreenType;
|
|
||||||
|
|
||||||
public class TouchscreenGesturePreferenceFragment extends PreferenceFragment {
|
public class TouchscreenGesturePreferenceFragment extends PreferenceFragment {
|
||||||
private SwitchPreference mFlipPref;
|
private SwitchPreference mFlipPref;
|
||||||
@@ -70,34 +64,6 @@ public class TouchscreenGesturePreferenceFragment extends PreferenceFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addPreferencesFromResource(int preferencesResId) {
|
|
||||||
super.addPreferencesFromResource(preferencesResId);
|
|
||||||
// Initialize node preferences
|
|
||||||
for (String pref : Constants.sBooleanNodePreferenceMap.keySet()) {
|
|
||||||
SwitchPreference b = (SwitchPreference) findPreference(pref);
|
|
||||||
if (b == null) continue;
|
|
||||||
b.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
String node = Constants.sBooleanNodePreferenceMap.get(preference.getKey());
|
|
||||||
if (!TextUtils.isEmpty(node)) {
|
|
||||||
Boolean value = (Boolean) newValue;
|
|
||||||
FileUtils.writeLine(node, value ? "1" : "0");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
String node = Constants.sBooleanNodePreferenceMap.get(pref);
|
|
||||||
if (new File(node).exists()) {
|
|
||||||
String curNodeValue = FileUtils.readOneLine(node);
|
|
||||||
b.setChecked(curNodeValue.equals("1"));
|
|
||||||
} else {
|
|
||||||
b.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|||||||
Reference in New Issue
Block a user