From 46779c8fa11d0dfe5ca5a1e82b17c57036db2f27 Mon Sep 17 00:00:00 2001 From: Yunus Emre Şeker Date: Mon, 3 Oct 2016 18:55:39 +0300 Subject: minor fix for fr translation --- cmactions/res/values-fr/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmactions/res/values-fr/strings.xml b/cmactions/res/values-fr/strings.xml index 2e54b81..0c2b0ca 100644 --- a/cmactions/res/values-fr/strings.xml +++ b/cmactions/res/values-fr/strings.xml @@ -41,8 +41,8 @@ Dessinez un \"M\" pour activer le mode \"Silencieux\" Tracez une ligne vers le bas Tracez une ligne verticale vers le bas pour activer la Torche - Tracez une ligne vers le haut - Tracez une ligne verticale vers le haut pour activer la Torche + Tracez une ligne vers le haut + Tracez une ligne verticale vers le haut pour activer la Torche -- cgit v1.2.3 From a69af6ca790c5677fc6a49176ccbeb55e260eb14 Mon Sep 17 00:00:00 2001 From: Yunus Emre Şeker Date: Wed, 5 Oct 2016 00:24:52 +0300 Subject: CMActions updated All gestures added & gesture ui updated --- cmactions/res/values-fr/arrays.xml | 31 ---- cmactions/res/values-fr/strings.xml | 49 ++--- cmactions/res/values-ru/arrays.xml | 31 ---- cmactions/res/values-ru/strings.xml | 50 ++--- cmactions/res/values/arrays.xml | 22 +-- cmactions/res/values/strings.xml | 58 +++--- cmactions/res/xml/touchscreen_panel.xml | 92 ++++++--- .../settings/device/BootCompletedReceiver.java | 22 --- .../settings/device/CMActionsService.java | 44 ----- .../settings/device/CMActionsSettings.java | 205 --------------------- .../settings/device/GestureController.java | 128 +++++++++++++ .../settings/device/ServiceWrapper.java | 65 ------- .../settings/device/SwitchPlusPreference.java | 125 +++++++++++++ .../device/TouchscreenGestureSettings.java | 107 +++++------ .../settings/device/UpdatedStateNotifier.java | 21 --- .../settings/device/utils/FileUtils.java | 23 +++ .../cyanogenmod/settings/device/KeyHandler.java | 18 +- 17 files changed, 497 insertions(+), 594 deletions(-) delete mode 100644 cmactions/res/values-fr/arrays.xml delete mode 100644 cmactions/res/values-ru/arrays.xml delete mode 100644 cmactions/src/com/cyanogenmod/settings/device/CMActionsService.java delete mode 100644 cmactions/src/com/cyanogenmod/settings/device/CMActionsSettings.java create mode 100644 cmactions/src/com/cyanogenmod/settings/device/GestureController.java delete mode 100644 cmactions/src/com/cyanogenmod/settings/device/ServiceWrapper.java create mode 100644 cmactions/src/com/cyanogenmod/settings/device/SwitchPlusPreference.java delete mode 100644 cmactions/src/com/cyanogenmod/settings/device/UpdatedStateNotifier.java diff --git a/cmactions/res/values-fr/arrays.xml b/cmactions/res/values-fr/arrays.xml deleted file mode 100644 index 0310fad..0000000 --- a/cmactions/res/values-fr/arrays.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - Désactivé - Réveiller - Dévérouiller - Lecture/Pause - Piste suivante - Piste précédente - Appareil photo - Lampe de poche - Do Not Disturb Mode - Normal Mode - Mute Mode - - - - disabled - wakeUp - unlock - play - next - prev - camera - flashlight - doNotDisturb - normal - mute - - - diff --git a/cmactions/res/values-fr/strings.xml b/cmactions/res/values-fr/strings.xml index 0c2b0ca..0f38736 100644 --- a/cmactions/res/values-fr/strings.xml +++ b/cmactions/res/values-fr/strings.xml @@ -1,5 +1,4 @@ - - Extras Retour Haptique Vibrer quand un geste est détecté + + + Désactivé + Réveiller + Dévérouiller + Lecture/Pause + Piste suivante + Piste précédente + Appareil photo + Lampe de poche + Do Not Disturb Mode + Normal Mode + Mute Mode + diff --git a/cmactions/res/values-ru/arrays.xml b/cmactions/res/values-ru/arrays.xml deleted file mode 100644 index 090c945..0000000 --- a/cmactions/res/values-ru/arrays.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - Выключено - Будить - Разблокировать - Воспризв./Пауза - Следующий Трек - Предыдущий Трек - Запустить камеру - Настройка вспышки - Режим Не беспокоить - Обычный режим - Беззвучный режим - - - - disabled - wakeUp - unlock - play - next - prev - camera - flashlight - doNotDisturb - normal - mute - - - diff --git a/cmactions/res/values-ru/strings.xml b/cmactions/res/values-ru/strings.xml index c5c439b..0a1cc34 100644 --- a/cmactions/res/values-ru/strings.xml +++ b/cmactions/res/values-ru/strings.xml @@ -18,35 +18,43 @@ Управление жестами - Использовать жесты, когда экран выключен + Use gestures while the screen is off Жесты выключенного экрана Включить управление жестами Доступные жесты + Двойной тап - Пробуждение двойным тапом - Нарисуйте \"C\" - Нарисуйте \"C\" для активации камеры - Нарисуйте \"Z\" - Нарисуйте \"Z\" для Воспроизв./Паузы - Свайп влево - Свайп влево - предыдущий трек - Свайп вправо - Свайп вправо - следующий трек - Нарисуйте \"S\" - Нарисуйте \"S\" для активации режима \"Не беспокоить\" - Нарисуйте \"W\" - Нарисуйте \"W\" для активации нормального режима - Нарисуйте \"M\" - Нарисуйте \"M\" для активации режима \"Без звука\" - Нарисуйте черту вниз - Нарисуйте вертикальную черту вниз для активации фонарика - Нарисуйте черту вверх - Нарисуйте вертикальную черту вверх для активации фонарика - + Музыка + Музыка + Фонарик + Swipe Up + + Нарисуйте \"c\" + Нарисуйте \"z\" + Нарисуйте \"s\" + Нарисуйте \"w\" + Нарисуйте \"o\" + Нарисуйте \"v\" + Нарисуйте \"e\" + Нарисуйте \"m\" + Дополнительные настройки Вибрация Использовать вбирацию при обработке жеста + + Выключено + Будить + Разблокировать + Воспризв./Пауза + Следующий Трек + Предыдущий Трек + Запустить камеру + Настройка вспышки + Обычный режим + Обычный режим + Беззвучный режим + diff --git a/cmactions/res/values/arrays.xml b/cmactions/res/values/arrays.xml index 4ebbd52..8982cb4 100644 --- a/cmactions/res/values/arrays.xml +++ b/cmactions/res/values/arrays.xml @@ -1,21 +1,19 @@ - Disabled - Wake Up - Unlock - Play/Pause - Next Song - Previous Song - Launch Camera - Toggle Flashlight - Do Not Disturb Mode - Normal Mode - Mute Mode + @string/wakeUp + @string/unlock + @string/play + @string/next + @string/prev + @string/camera + @string/flashlight + @string/doNotDisturbMode + @string/normalMode + @string/muteMode - disabled wakeUp unlock play diff --git a/cmactions/res/values/strings.xml b/cmactions/res/values/strings.xml index 22a34f6..a19d76b 100644 --- a/cmactions/res/values/strings.xml +++ b/cmactions/res/values/strings.xml @@ -1,5 +1,4 @@ - - - Gestures - Gesture shortcuts Use gestures while the screen is off @@ -25,30 +22,45 @@ Screen Off Gestures Enable Screen Gestures Available Gestures + Double Tap - Double Tap to Wake-Up device - Draw \"C\" - Draw a \"C\" to activate Camera - Draw \"Z\" - Draw an \"Z\" to Play/Pause - Swipe Left - Swipe left to Prev Track - Swipe Right - Swipe right to Next Track - Draw \"S\" - Draw a \"S\" to activate \"Do Not Disturb\" Mode - Draw \"W\" - Draw a \"W\" to activate \"Normal\" Mode - Draw \"M\" - Draw a \"M\" to activate \"Mute\" Mode - Swipe Down - Draw a vertical line down to activate Flashlight - Swipe Up - Draw a vertical line down to activate Flashlight + Swipe Left + Swipe Right + Swipe Down + Swipe Up + + Draw \"c\" + Draw \"z\" + Draw \"s\" + Draw \"w\" + Draw \"o\" + Draw \"v\" + Draw \"e\" + Draw \"m\" + + + + Draw \"<\" + Draw \">\" + Draw \"ʌ\" Extras Haptic feedback Vibrate when a gesture is detected + + + Disabled + Wake Up + Unlock + Play/Pause + Next Track + Previous Track + Launch Camera + Toggle Flashlight + Do Not Disturb Mode + Normal Mode + Mute Mode + diff --git a/cmactions/res/xml/touchscreen_panel.xml b/cmactions/res/xml/touchscreen_panel.xml index c64c3bb..4ab1481 100644 --- a/cmactions/res/xml/touchscreen_panel.xml +++ b/cmactions/res/xml/touchscreen_panel.xml @@ -24,41 +24,87 @@ - - - - - - - - + + + + + + + + - + - - + + + + + + + diff --git a/cmactions/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java b/cmactions/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java index eb9e233..2862fd9 100644 --- a/cmactions/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java +++ b/cmactions/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java @@ -16,8 +16,6 @@ package com.cyanogenmod.settings.device; -import com.cyanogenmod.settings.device.ServiceWrapper.LocalBinder; - import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -27,35 +25,15 @@ import android.content.ServiceConnection; import android.os.IBinder; import android.util.Log; -import com.cyanogenmod.settings.device.utils.FileUtils; - public class BootCompletedReceiver extends BroadcastReceiver { static final String TAG = "CMActions"; - private ServiceWrapper mServiceWrapper; @Override public void onReceive(final Context context, Intent intent) { Log.d(TAG, "Booting"); enableComponent(context, TouchscreenGestureSettings.class.getName()); - context.startService(new Intent(context, ServiceWrapper.class)); - // Set sane default, for whatever reason gesture_mode loads with garbage at boot - FileUtils.writeAsByte(CMActionsSettings.TOUCHSCREEN_GESTURE_MODE_NODE, 256); } - private ServiceConnection serviceConnection = new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName className, IBinder service) { - LocalBinder binder = (LocalBinder) service; - mServiceWrapper = binder.getService(); - mServiceWrapper.start(); - } - - @Override - public void onServiceDisconnected(ComponentName className) { - mServiceWrapper = null; - } - }; - private void enableComponent(Context context, String component) { ComponentName name = new ComponentName(context, component); PackageManager pm = context.getPackageManager(); diff --git a/cmactions/src/com/cyanogenmod/settings/device/CMActionsService.java b/cmactions/src/com/cyanogenmod/settings/device/CMActionsService.java deleted file mode 100644 index 3c09037..0000000 --- a/cmactions/src/com/cyanogenmod/settings/device/CMActionsService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2015 The CyanogenMod Project - * - * 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. - */ - -package com.cyanogenmod.settings.device; - -import android.app.IntentService; -import android.content.Context; -import android.content.Intent; -import android.provider.Settings; -import android.util.Log; - -import java.util.List; -import java.util.LinkedList; - - -public class CMActionsService extends IntentService { - private static final String TAG = "CMActions"; - private final Context mContext; - - public CMActionsService(Context context) { - super("CMActionService"); - mContext = context; - Log.d(TAG, "Starting"); - CMActionsSettings cmActionsSettings = new CMActionsSettings(context ); - } - - @Override - protected void onHandleIntent(Intent intent) { - } -} - diff --git a/cmactions/src/com/cyanogenmod/settings/device/CMActionsSettings.java b/cmactions/src/com/cyanogenmod/settings/device/CMActionsSettings.java deleted file mode 100644 index d566f58..0000000 --- a/cmactions/src/com/cyanogenmod/settings/device/CMActionsSettings.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod Project - * Copyright (C) 2016 faust93 adaptation for Meizu PRO5 FTS Driver - * - * 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. - */ - -package com.cyanogenmod.settings.device; - -import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; - -import android.util.Log; - -import com.cyanogenmod.settings.device.utils.FileUtils; - -public class CMActionsSettings { - private static final String TAG = "CMActions"; - - // Preference keys - public static final String TOUCHSCREEN_GESTURE_CONTROL_KEY = "touchscreen_gesture_control"; - public static final String TOUCHSCREEN_DOUBLETAP_KEY = "160_enabled"; - public static final String TOUCHSCREEN_C_GESTURE_KEY = "193_enabled"; - public static final String TOUCHSCREEN_Z_GESTURE_KEY = "202_enabled"; - public static final String TOUCHSCREEN_LTR_GESTURE_KEY = "176_enabled"; - public static final String TOUCHSCREEN_GTR_GESTURE_KEY = "177_enabled"; - public static final String TOUCHSCREEN_S_GESTURE_KEY = "s_enabled"; - public static final String TOUCHSCREEN_W_GESTURE_KEY = "194_enabled"; - public static final String TOUCHSCREEN_M_GESTURE_KEY = "195_enabled"; - public static final String TOUCHSCREEN_YDOWN_GESTURE_KEY = "179_enabled"; - - - public static final String TOUCHSCREEN_GESTURE_HAPTIC_FEEDBACK = - "touchscreen_gesture_haptic_feedback"; - - // Proc nodes - public static final String TOUCHSCREEN_GESTURE_MODE_NODE = "/sys/devices/platform/mx-gs/gesture_control"; - - // Key Masks - public static final int KEY_MASK_DTP_CONTROL = 0x200; - public static final int KEY_MASK_GESTURE_DTP = 0x1000000; - - public static final int KEY_MASK_SWIPE_CONTROL = 0x400; - public static final int KEY_MASK_GESTURE_YDOWN = 0x4000000; - public static final int KEY_MASK_GESTURE_LTR = 0x1000000; - public static final int KEY_MASK_GESTURE_GTR = 0x2000000; - - public static final int KEY_MASK_GESTURE_CONTROL = 0x300; - public static final int KEY_MASK_GESTURE_C = 0x2000000; - public static final int KEY_MASK_GESTURE_E = 0x4000000; - public static final int KEY_MASK_GESTURE_S = 0x14000000; - public static final int KEY_MASK_GESTURE_V = 0x1000000; - public static final int KEY_MASK_GESTURE_W = 0x8000000; - public static final int KEY_MASK_GESTURE_Z = 0x40000000; - public static final int KEY_MASK_GESTURE_O = 0x80000000; - public static final int KEY_MASK_GESTURE_M = 0x10000000; - - public static final int DISABLE_ALL_MASK = 0x100; - public static final int ENABLE_ALL_MASK = 0x1000100; - - private static boolean mIsGestureEnabled; - private static boolean mIsGesture_DTP_Enabled; - private static boolean mIsGesture_C_Enabled; - private static boolean mIsGesture_E_Enabled; - private static boolean mIsGesture_S_Enabled; - private static boolean mIsGesture_V_Enabled; - private static boolean mIsGesture_O_Enabled; - private static boolean mIsGesture_M_Enabled; - private static boolean mIsGesture_W_Enabled; - private static boolean mIsGesture_Z_Enabled; - private static boolean mIsGesture_YDOWN_Enabled; - private static boolean mIsGesture_LTR_Enabled; - private static boolean mIsGesture_GTR_Enabled; - - private final Context mContext; - - private static SharedPreferences.OnSharedPreferenceChangeListener mPrefListener; - - public CMActionsSettings(Context context) { - - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - loadPreferences(sharedPrefs); - - mPrefListener = new SharedPreferences.OnSharedPreferenceChangeListener() { - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - boolean updated = true; - if (TOUCHSCREEN_GESTURE_CONTROL_KEY.equals(key)) { - mIsGestureEnabled = sharedPreferences.getBoolean(TOUCHSCREEN_GESTURE_CONTROL_KEY, false); - Log.d(TAG, "prefChanged: gesture control " + mIsGestureEnabled); - TouchscreenGestureSettings.PrefFragment.gestureCat.setEnabled(areGesturesEnabled()); - } else if (TOUCHSCREEN_DOUBLETAP_KEY.equals(key)) { - mIsGesture_DTP_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_DOUBLETAP_KEY, false); - } else if (TOUCHSCREEN_C_GESTURE_KEY.equals(key)) { - mIsGesture_C_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_C_GESTURE_KEY, false); - } else if (TOUCHSCREEN_S_GESTURE_KEY.equals(key)) { - mIsGesture_S_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_S_GESTURE_KEY, false); - } else if (TOUCHSCREEN_W_GESTURE_KEY.equals(key)) { - mIsGesture_W_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_W_GESTURE_KEY, false); - } else if (TOUCHSCREEN_M_GESTURE_KEY.equals(key)) { - mIsGesture_M_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_M_GESTURE_KEY, false); - } else if (TOUCHSCREEN_Z_GESTURE_KEY.equals(key)) { - mIsGesture_Z_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_Z_GESTURE_KEY, false); - } else if (TOUCHSCREEN_YDOWN_GESTURE_KEY.equals(key)) { - mIsGesture_YDOWN_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_YDOWN_GESTURE_KEY, false); - } else if (TOUCHSCREEN_LTR_GESTURE_KEY.equals(key)) { - mIsGesture_LTR_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_LTR_GESTURE_KEY, false); - } else if (TOUCHSCREEN_GTR_GESTURE_KEY.equals(key)) { - mIsGesture_GTR_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_GTR_GESTURE_KEY, false); - } else if (TOUCHSCREEN_GESTURE_HAPTIC_FEEDBACK.equals(key)) { - //CMSettings.System.putInt(getContentResolver(),CMSettings.System.TOUCHSCREEN_GESTURE_HAPTIC_FEEDBACK, value ? 1 : 0); - final boolean val = sharedPreferences.getBoolean(TOUCHSCREEN_GTR_GESTURE_KEY, false); - } else { - updated = false; - } - if (updated) { - updateGestureMode(); - } - } - }; - - sharedPrefs.registerOnSharedPreferenceChangeListener(mPrefListener); - mContext = context; - } - - public static boolean areGesturesEnabled() { - Log.d(TAG, "Are gestures enabled:" + mIsGestureEnabled); - return mIsGestureEnabled; - } - - public static void loadPreferences(SharedPreferences sharedPreferences) { - mIsGestureEnabled = sharedPreferences.getBoolean(TOUCHSCREEN_GESTURE_CONTROL_KEY, false); - mIsGesture_DTP_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_DOUBLETAP_KEY, false); - mIsGesture_C_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_C_GESTURE_KEY, false); - mIsGesture_S_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_S_GESTURE_KEY, false); - mIsGesture_M_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_M_GESTURE_KEY, false); - mIsGesture_W_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_W_GESTURE_KEY, false); - mIsGesture_Z_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_Z_GESTURE_KEY, false); - mIsGesture_YDOWN_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_YDOWN_GESTURE_KEY, false); - mIsGesture_LTR_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_LTR_GESTURE_KEY, false); - mIsGesture_GTR_Enabled = sharedPreferences.getBoolean(TOUCHSCREEN_GTR_GESTURE_KEY, false); - - updateGestureMode(); - } - - - /* Use bitwise logic to set gesture_mode in kernel driver. - Check each if each key is enabled with & operator and KEY_MASK, - if enabled toggle the appropriate bit with ^ XOR operator */ - public static void updateGestureMode() { - int gesture_mode = 0; - // TODO Configure gesture control bits for better handling - - if (mIsGestureEnabled) { - FileUtils.writeAsByte(TOUCHSCREEN_GESTURE_MODE_NODE, ENABLE_ALL_MASK); - // TAP_CTR masking - gesture_mode = (gesture_mode ^ KEY_MASK_DTP_CONTROL); - if (mIsGesture_DTP_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_DTP); - Log.d(TAG, "Gesture mode DoubleTap: " + gesture_mode); - FileUtils.writeAsByte(TOUCHSCREEN_GESTURE_MODE_NODE, gesture_mode); - gesture_mode = 0; - // SWIPE_CTR masking - gesture_mode = (gesture_mode ^ KEY_MASK_SWIPE_CONTROL); - if (mIsGesture_YDOWN_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_YDOWN); - if (mIsGesture_LTR_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_LTR); - if (mIsGesture_GTR_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_GTR); - Log.d(TAG, "Gesture mode Swipe: " + gesture_mode); - FileUtils.writeAsByte(TOUCHSCREEN_GESTURE_MODE_NODE, gesture_mode); - gesture_mode = 0; - // UNICODE_CTR masking - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_CONTROL); - if (((gesture_mode & KEY_MASK_GESTURE_C) == 1) != mIsGesture_C_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_C); - if (((gesture_mode & KEY_MASK_GESTURE_S) == 1) != mIsGesture_S_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_S); - if (((gesture_mode & KEY_MASK_GESTURE_W) == 1) != mIsGesture_W_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_W); - if (((gesture_mode & KEY_MASK_GESTURE_M) == 1) != mIsGesture_M_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_M); - if (((gesture_mode & KEY_MASK_GESTURE_Z) == 1) != mIsGesture_Z_Enabled) - gesture_mode = (gesture_mode ^ KEY_MASK_GESTURE_Z); - } else { - gesture_mode = DISABLE_ALL_MASK; - } - Log.d(TAG, "finished gesture mode: " + gesture_mode); - FileUtils.writeAsByte(TOUCHSCREEN_GESTURE_MODE_NODE, gesture_mode); - } - -} - diff --git a/cmactions/src/com/cyanogenmod/settings/device/GestureController.java b/cmactions/src/com/cyanogenmod/settings/device/GestureController.java new file mode 100644 index 0000000..b262cf6 --- /dev/null +++ b/cmactions/src/com/cyanogenmod/settings/device/GestureController.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * Copyright (C) 2016 faust93 adaptation for Meizu PRO5 FTS Driver + * + * 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. + */ + +package com.cyanogenmod.settings.device; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import android.util.Log; +import android.util.SparseIntArray; + +import com.cyanogenmod.settings.device.utils.FileUtils; + +public class GestureController { + private static final String TAG = GestureController.class.getSimpleName(); + + public static final String TOUCHSCREEN_GESTURE_CONTROL_NODE = "/sys/devices/platform/mx-gs/gesture_control"; + public static final String TOUCHSCREEN_GESTURE_CONTROL_KEY = "touchscreen_gesture_control"; + + // M2Note gesture keys + public static final int DOUBLE_TAP = 0xA0; //160 + public static final int SWIPE_X_LEFT = 0xB0; //176 + public static final int SWIPE_X_RIGHT = 0xB1; + public static final int SWIPE_Y_UP = 0xB2; + public static final int SWIPE_Y_DOWN = 0xB3; + + public static final int UNICODE_E = 0xC0; // 192 + public static final int UNICODE_C = 0xC1; + public static final int UNICODE_W = 0xC2; + public static final int UNICODE_M = 0xC3; + public static final int UNICODE_O = 0xC4; + public static final int UNICODE_S = 0xC5; + public static final int UNICODE_V_UP = 0xC6; + public static final int UNICODE_V_DOWN = 0xC7; + public static final int UNICODE_V_L = 0xC8; + public static final int UNICODE_V_R = 0xC9; + public static final int UNICODE_Z = 0xCA; + + + public static final int GESTURES_DISABLED_MASK = 0x100; + public static final int GESTURES_ENABLED_MASK = 0x1000100; + + // Supported gesture keys and masks + public static SparseIntArray keysToMasks = new SparseIntArray(); + + static { + keysToMasks.put(DOUBLE_TAP, 0x000100); + + keysToMasks.put(SWIPE_X_LEFT, 0x000001); + keysToMasks.put(SWIPE_X_RIGHT, 0x000002); + keysToMasks.put(SWIPE_Y_DOWN, 0x000004); + keysToMasks.put(SWIPE_Y_UP, 0x000008); + + keysToMasks.put(UNICODE_E, 0x040000); + keysToMasks.put(UNICODE_C, 0x020000); + keysToMasks.put(UNICODE_M, 0x100000); + keysToMasks.put(UNICODE_O, 0x800000); + keysToMasks.put(UNICODE_S, 0x200000); + keysToMasks.put(UNICODE_V_UP, 0x010000); + keysToMasks.put(UNICODE_W, 0x080000); + keysToMasks.put(UNICODE_Z, 0x400000); + } + + private static SharedPreferences.OnSharedPreferenceChangeListener mPrefListener; + + public GestureController(final Context context) { + updateGestureControl(context); + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + mPrefListener = new SharedPreferences.OnSharedPreferenceChangeListener() { + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + updateGestureControl(context); + } + }; + sharedPrefs.registerOnSharedPreferenceChangeListener(mPrefListener); + + } + + public static void updateGestureControl(Context context) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + if (sharedPreferences.getBoolean(TOUCHSCREEN_GESTURE_CONTROL_KEY, false)) { + int gestureMask = 0x000000; + FileUtils.writeAsByte(TOUCHSCREEN_GESTURE_CONTROL_NODE, GESTURES_ENABLED_MASK); + for (int i = 0; i < keysToMasks.size(); i++) { + int key = keysToMasks.keyAt(i); + int mask = keysToMasks.get(key); + if (sharedPreferences.getBoolean(key + "_enabled", false)) + gestureMask += mask; + } + byte swipeMask = (byte) (gestureMask & 0xff); + FileUtils.writeByteArray(TOUCHSCREEN_GESTURE_CONTROL_NODE, new byte[]{swipeMask, 0, 4, 0}); + byte doubleTapMask = (byte) ((gestureMask >> 8) & 0xff); + FileUtils.writeByteArray(TOUCHSCREEN_GESTURE_CONTROL_NODE, new byte[]{doubleTapMask, 0, 2, 0}); + byte unicodeMask = (byte) ((gestureMask >> 16) & 0xff); + FileUtils.writeByteArray(TOUCHSCREEN_GESTURE_CONTROL_NODE, new byte[]{unicodeMask, 0, 3, 0}); + } else { + FileUtils.writeAsByte(TOUCHSCREEN_GESTURE_CONTROL_NODE, GESTURES_DISABLED_MASK); + } + } + + public static void masterSwitch(boolean enabled) { + if (enabled) { + Log.i(TAG, "Gestures enabled"); + FileUtils.writeAsByte(TOUCHSCREEN_GESTURE_CONTROL_NODE, GESTURES_ENABLED_MASK); + } else { + Log.i(TAG, "Gestures disabled"); + FileUtils.writeAsByte(TOUCHSCREEN_GESTURE_CONTROL_NODE, GESTURES_DISABLED_MASK); + } + } +} + + diff --git a/cmactions/src/com/cyanogenmod/settings/device/ServiceWrapper.java b/cmactions/src/com/cyanogenmod/settings/device/ServiceWrapper.java deleted file mode 100644 index 0a4b21c..0000000 --- a/cmactions/src/com/cyanogenmod/settings/device/ServiceWrapper.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2015 The CyanogenMod Project - * - * 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. - */ - -package com.cyanogenmod.settings.device; - -import android.content.Intent; -import android.os.Binder; -import android.os.Bundle; -import android.os.IBinder; -import android.util.Log; - -public class ServiceWrapper extends android.app.Service { - static final String TAG = "CMActions-ServiceWrapper"; - - private final IBinder mBinder = new LocalBinder(); - private CMActionsService mCmActionsService; - - public interface ServiceCallback { - void sendResults(int resultCode, Bundle b); - } - - public class LocalBinder extends Binder { - ServiceWrapper getService() { - // Return this instance of the service so clients can call public - // methods - return ServiceWrapper.this; - } - } - - @Override - public void onCreate() { - Log.i(TAG, "onCreate"); - super.onCreate(); - mCmActionsService = new CMActionsService(this); - } - - @Override - public IBinder onBind(Intent intent) { - Log.i(TAG, "onBind"); - return null; - } - - public void setCallback(ServiceCallback callback) { - } - - public void start() { - Log.i(TAG, "start"); - } - - public void stop() { - } -} diff --git a/cmactions/src/com/cyanogenmod/settings/device/SwitchPlusPreference.java b/cmactions/src/com/cyanogenmod/settings/device/SwitchPlusPreference.java new file mode 100644 index 0000000..acf7843 --- /dev/null +++ b/cmactions/src/com/cyanogenmod/settings/device/SwitchPlusPreference.java @@ -0,0 +1,125 @@ +package com.cyanogenmod.settings.device; + +import android.content.Context; +import android.preference.SwitchPreference; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Switch; + +/** + * Custom preference for handling a switch with a clickable preference area as well + * + * Source: https://gist.github.com/marchold/45e22839eb94aa14dfb5 + */ +public class SwitchPlusPreference extends SwitchPreference { + + // + // Public interface + // + + /** + * Sets listeners for the switch and the background container preference view cell + * + * @param listener A valid SwitchPlusClickListener + */ + public void setSwitchClickListener(SwitchPlusClickListener listener) { + this.listener = listener; + } + + private SwitchPlusClickListener listener = null; + + /** + * Interface gives callbacks in to both parts of the preference + */ + public interface SwitchPlusClickListener { + /** + * Called when the switch is switched + * + * @param preference + * @param isChecked + */ + public void onCheckedChanged(SwitchPlusPreference preference, boolean isChecked); + + /** + * Called when the preference view is clicked + * + * @param view + * @param preference + */ + public void onClick(View view, SwitchPlusPreference preference); + } + + public SwitchPlusPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public SwitchPlusPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public SwitchPlusPreference(Context context) { + super(context); + } + + + // + // Internal Functions + // + + /** + * Recursively go through view tree until we find an android.widget.Switch + * + * @param view Root view to start searching + * @return A Switch class or null + */ + private Switch findSwitchWidget(View view) { + if (view instanceof Switch) { + return (Switch) view; + } + if (view instanceof ViewGroup) { + ViewGroup viewGroup = (ViewGroup) view; + for (int i = 0; i < viewGroup.getChildCount(); i++) { + View child = viewGroup.getChildAt(i); + if (child instanceof ViewGroup) { + Switch result = findSwitchWidget(child); + if (result != null) return result; + } + if (child instanceof Switch) { + return (Switch) child; + } + } + } + return null; + } + + //Get a handle on the 2 parts of the switch preference and assign handlers to them + @Override + protected void onBindView(View view) { + super.onBindView(view); + final SwitchPlusPreference that = this; + + final Switch switchView = findSwitchWidget(view); + if (switchView != null) { + switchView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) + listener.onCheckedChanged(that, ((Switch) v).isChecked()); + } + }); + switchView.setChecked(getSharedPreferences().getBoolean(getKey(), false)); + switchView.setFocusable(true); + //switchView.setEnabled(true); + } + + + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) listener.onClick(v, that); + } + }); + } +} + diff --git a/cmactions/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java b/cmactions/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java index fed85fb..2945404 100644 --- a/cmactions/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java +++ b/cmactions/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java @@ -18,63 +18,33 @@ package com.cyanogenmod.settings.device; import android.app.ActionBar; import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; -import android.preference.ListPreference; import android.preference.Preference; -import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; -import android.util.Log; import android.view.MenuItem; +import android.view.View; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TouchscreenGestureSettings extends Activity { - // M2Note gesture codes - public static final int DOUBLE_TAP = 0xA0; //160 - public static final int SWIPE_X_LEFT = 0xB0; //176 - public static final int SWIPE_X_RIGHT = 0xB1; - public static final int SWIPE_Y_UP = 0xB2; - public static final int SWIPE_Y_DOWN = 0xB3; - - public static final int UNICODE_E = 0xC0; // 192 - public static final int UNICODE_C = 0xC1; - public static final int UNICODE_W = 0xC2; - public static final int UNICODE_M = 0xC3; - public static final int UNICODE_O = 0xC4; - public static final int UNICODE_S = 0xC5; - public static final int UNICODE_V_UP = 0xC6; - public static final int UNICODE_V_DOWN = 0xC7; - public static final int UNICODE_V_L = 0xC8; - public static final int UNICODE_V_R = 0xC9; - public static final int UNICODE_Z = 0xCA; - - private static final int[] supportedGesturesKeys = { - DOUBLE_TAP, - UNICODE_C, - UNICODE_Z, - SWIPE_X_LEFT, - SWIPE_X_RIGHT, - UNICODE_W, - UNICODE_M, - SWIPE_Y_DOWN - }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ActionBar actionBar = getActionBar(); - //actionBar.setTitle(getString(R.string.appName)); actionBar.setDisplayHomeAsUpEnabled(true); getFragmentManager().beginTransaction() - .replace(android.R.id.content, new PrefFragment()) + .replace(android.R.id.content, new GestureFragment()) .commit(); } @@ -92,11 +62,9 @@ public class TouchscreenGestureSettings extends Activity { return false; } - public static class PrefFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener { + public static class GestureFragment extends PreferenceFragment implements SwitchPlusPreference.SwitchPlusClickListener { - public static final String TAG = PrefFragment.class.getSimpleName(); - public static final String CATEGORY_GESTURES = "category_gestures"; - public static PreferenceCategory gestureCat; + public static final String TAG = GestureFragment.class.getSimpleName(); private SharedPreferences sharedPrefs; private String[] actionTitles; @@ -137,44 +105,51 @@ public class TouchscreenGestureSettings extends Activity { } actionTitles = actionTitlesList.toArray(new String[actionTitlesList.size()]); actionValues = actionValuesList.toArray(new String[actionValuesList.size()]); - for (int prefKey : supportedGesturesKeys) { - ListPreference preference = (ListPreference) findPreference(String.valueOf(prefKey)); - preference.setEntries(actionTitles); - preference.setEntryValues(actionValues); - preference.setOnPreferenceChangeListener(this); - String prefValue = sharedPrefs.getString(String.valueOf(prefKey), "disabled"); + for (int x = 0; x < GestureController.keysToMasks.size(); x++) { + int prefKey = GestureController.keysToMasks.keyAt(x); + SwitchPlusPreference preference = (SwitchPlusPreference) findPreference(String.valueOf(prefKey) + "_enabled"); + preference.setSwitchClickListener(this); + String prefValue = sharedPrefs.getString(String.valueOf(prefKey) + "_action", "disabled"); int i = actionValuesList.indexOf(prefValue); - if (i >= 0) { - preference.setSummary(actionTitles[i]); - preference.setValueIndex(i); - } + if (i >= 0) + preference.setSummaryOn(actionTitles[i]); + else + preference.setSummaryOn(" "); } - } - @Override - public void onResume() { - super.onResume(); - gestureCat = (PreferenceCategory) findPreference(CATEGORY_GESTURES); - if (gestureCat != null) { - gestureCat.setEnabled(CMActionsSettings.areGesturesEnabled()); - } + findPreference(GestureController.TOUCHSCREEN_GESTURE_CONTROL_KEY).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object o) { + boolean newValue = (boolean) o; + GestureController.masterSwitch(newValue); + return true; + } + }); } @Override - public void onStart() { - super.onStart(); + public void onCheckedChanged(SwitchPlusPreference preference, boolean isChecked) { + GestureController.updateGestureControl(getActivity()); } @Override - public boolean onPreferenceChange(Preference preference, Object o) { - String newValue = (String) o; - int i = actionValuesList.indexOf(newValue); - if (i >= 0) - preference.setSummary(actionTitles[i]); - sharedPrefs.edit().putBoolean(preference.getKey() + "_enabled", - !"disabled".equals(newValue)).apply(); - return true; + public void onClick(View view, final SwitchPlusPreference preference) { + if (!preference.isChecked()) return; + + String prefValue = sharedPrefs.getString(preference.getKey().replace("_enabled", "_action"), "disabled"); + int i = actionValuesList.indexOf(prefValue); + AlertDialog dialog = new AlertDialog.Builder(getActivity()).setSingleChoiceItems(actionTitles, i, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + preference.setSummaryOn(actionTitles[which]); + sharedPrefs.edit().putString(preference.getKey().replace("_enabled", "_action"), + actionValues[which]).apply(); + dialog.dismiss(); + } + }).create(); + dialog.show(); } } } + diff --git a/cmactions/src/com/cyanogenmod/settings/device/UpdatedStateNotifier.java b/cmactions/src/com/cyanogenmod/settings/device/UpdatedStateNotifier.java deleted file mode 100644 index 268b4bd..0000000 --- a/cmactions/src/com/cyanogenmod/settings/device/UpdatedStateNotifier.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2015 The CyanogenMod Project - * - * 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. - */ - -package com.cyanogenmod.settings.device; - -interface UpdatedStateNotifier { - public void updateState(); -} diff --git a/cmactions/src/com/cyanogenmod/settings/device/utils/FileUtils.java b/cmactions/src/com/cyanogenmod/settings/device/utils/FileUtils.java index 64ed3d6..e0ed400 100644 --- a/cmactions/src/com/cyanogenmod/settings/device/utils/FileUtils.java +++ b/cmactions/src/com/cyanogenmod/settings/device/utils/FileUtils.java @@ -75,6 +75,11 @@ public final class FileUtils { return true; } + /** + * Writes the given value as bytes into the given file + * + * @return true on success, false on failure + */ public static boolean writeAsByte(String fileName, int value) { byte[] bytes = ByteBuffer.allocate(4).putInt(value).array(); try { @@ -86,7 +91,25 @@ public final class FileUtils { Log.e(TAG, "Could not write to file " + fileName, e); return false; } + return true; + } + /** + * Writes the given byte array into the given file + * + * @return true on success, false on failure + */ + public static boolean writeByteArray(String fileName, byte[] bytes) { + try { + FileOutputStream fos = new FileOutputStream(fileName); + fos.write(bytes); + fos.flush(); + fos.close(); + } catch (IOException e) { + Log.e(TAG, "Could not write to file " + fileName, e); + return false; + } return true; } } + diff --git a/keyhandler/src/com/cyanogenmod/settings/device/KeyHandler.java b/keyhandler/src/com/cyanogenmod/settings/device/KeyHandler.java index 20c3199..303d12a 100644 --- a/keyhandler/src/com/cyanogenmod/settings/device/KeyHandler.java +++ b/keyhandler/src/com/cyanogenmod/settings/device/KeyHandler.java @@ -169,10 +169,10 @@ public class KeyHandler implements DeviceKeyHandler { @Override public void handleMessage(Message msg) { try { - int zenMode = 0; + boolean gestureHandled = true; int gestureData = (int) msg.obj; - String prefValue = getCMAStringPref(String.valueOf(gestureData)); - Log.i(TAG, "Handling gesture: " + gestureData + " action: " + prefValue); + String prefValue = getCMAStringPref(String.valueOf(gestureData) + "_action"); + Log.i(TAG, "Handling gesture: " + gestureData + " with action: " + prefValue); switch (prefValue) { case "wakeUp": mPowerManager.wakeUpWithProximityCheck(SystemClock.uptimeMillis()); @@ -237,24 +237,23 @@ public class KeyHandler implements DeviceKeyHandler { mPowerManager.wakeUp(SystemClock.uptimeMillis()); Intent appIntent = mPackageManager.getLaunchIntentForPackage(packageName); startActivitySafely(appIntent); + } else { + gestureHandled = false; } break; } - doHapticFeedback(); + if (gestureHandled) + doHapticFeedback(); } catch (Exception e) { Log.e(TAG, "Gesture EventHandler", e); } } } - private void setZenMode(int zenMode) { - Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, - zenMode); - } - public boolean handleKeyEvent(KeyEvent event) { boolean isHandled = false; + switch (event.getScanCode()) { case 102: // Home button event if (event.getAction() == KeyEvent.ACTION_DOWN) { @@ -401,3 +400,4 @@ public class KeyHandler implements DeviceKeyHandler { return Integer.valueOf(readSingleLine(f)); } } + -- cgit v1.2.3