CMActions: add support for fingerprint gesture
This commit is contained in:
@@ -26,8 +26,6 @@ import android.util.Log;
|
||||
|
||||
import com.cyanogenmod.settings.device.ServiceWrapper.LocalBinder;
|
||||
|
||||
import org.cyanogenmod.internal.util.FileUtils;
|
||||
|
||||
public class BootCompletedReceiver extends BroadcastReceiver {
|
||||
static final String TAG = "CMActions";
|
||||
private ServiceWrapper mServiceWrapper;
|
||||
@@ -38,13 +36,7 @@ public class BootCompletedReceiver extends BroadcastReceiver {
|
||||
|
||||
// Restore nodes to saved preference values
|
||||
for (String pref : Constants.sButtonPrefKeys) {
|
||||
String value = Constants.isPreferenceEnabled(context, pref) ? "1" : "0";
|
||||
String node = Constants.sBooleanNodePreferenceMap.get(pref);
|
||||
|
||||
if (!FileUtils.writeLine(node, value)) {
|
||||
Log.w(TAG, "Write to node " + node +
|
||||
" failed while restoring saved preference values");
|
||||
}
|
||||
Constants.writePreference(context, pref);
|
||||
}
|
||||
|
||||
context.startService(new Intent(context, ServiceWrapper.class));
|
||||
|
||||
@@ -128,6 +128,9 @@ public class CMActionsSettings {
|
||||
mFlipToMuteEnabled = sharedPreferences.getBoolean(GESTURE_FLIP_TO_MUTE_KEY, false);
|
||||
} else if (GESTURE_LIFT_TO_SILENCE_KEY.equals(key)) {
|
||||
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 {
|
||||
updated = false;
|
||||
}
|
||||
|
||||
@@ -22,15 +22,32 @@ import java.util.Map;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.cyanogenmod.internal.util.FileUtils;
|
||||
|
||||
public class Constants {
|
||||
|
||||
private static final String TAG = "CMActions";
|
||||
|
||||
// Swap keys
|
||||
public static final String FP_HOME_KEY = "fp_home";
|
||||
|
||||
// Swap nodes
|
||||
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
|
||||
public static final Map<String, String> sBooleanNodePreferenceMap = new HashMap<>();
|
||||
|
||||
@@ -39,15 +56,50 @@ public class Constants {
|
||||
|
||||
public static final String[] sButtonPrefKeys = {
|
||||
FP_HOME_KEY,
|
||||
FP_KEYS,
|
||||
FP_KEY_HOLD,
|
||||
FP_KEY_RIGHT,
|
||||
FP_KEY_LEFT,
|
||||
};
|
||||
|
||||
static {
|
||||
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_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) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
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.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.Preference;
|
||||
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 {
|
||||
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
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Reference in New Issue
Block a user