diff options
| author | Mister Oyster <oysterized@gmail.com> | 2017-02-05 19:57:35 +0100 |
|---|---|---|
| committer | Mister Oyster <oysterized@gmail.com> | 2017-02-05 19:57:35 +0100 |
| commit | 16e6bbbc2e3ddea8ec8d229767cc45121fd8cd82 (patch) | |
| tree | 1ff10d387c0efab7ca16d3e8d9ad232823c33f33 /cmactions | |
initial commit
Diffstat (limited to 'cmactions')
22 files changed, 1199 insertions, 0 deletions
diff --git a/cmactions/Android.mk b/cmactions/Android.mk new file mode 100644 index 0000000..a098093 --- /dev/null +++ b/cmactions/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := CMActions +LOCAL_CERTIFICATE := platform +LOCAL_PRIVILEGED_MODULE := true + +LOCAL_PROGUARD_FLAG_FILES := proguard.flags + +include $(BUILD_PACKAGE) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/cmactions/AndroidManifest.xml b/cmactions/AndroidManifest.xml new file mode 100644 index 0000000..fbb36c9 --- /dev/null +++ b/cmactions/AndroidManifest.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.cyanogenmod.settings.device" + android:versionCode="1" + android:versionName="1.0" + android:sharedUserId="android.uid.system" + > + + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> + + <uses-sdk + android:minSdkVersion="23" + android:targetSdkVersion="23" /> + + <application + android:allowBackup="true" + android:label="@string/device_settings_app_name" + android:persistent="true" + android:icon="@mipmap/ic_launcher_settings" + android:theme="@android:style/Theme.Material.Settings" > + + <receiver android:name="com.cyanogenmod.settings.device.BootCompletedReceiver"> + <intent-filter> + <action android:name="android.intent.action.BOOT_COMPLETED" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </receiver> + + <!-- stub to ensure its loaded - DO NOT REMOVE --> + <activity android:name=".KeyHandler"/> + + <activity + android:excludeFromRecents="true" + android:name="CMActions" + android:launchMode="singleInstance" + android:screenOrientation="portrait" + android:windowAnimationStyle="@null"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + </intent-filter> + </activity> + + <activity + android:name=".TouchscreenGestureSettings" + android:label="@*cyanogenmod.platform:string/screen_gestures_panel_title"> + <intent-filter> + <action android:name="com.android.settings.action.EXTRA_SETTINGS" /> + </intent-filter> + <meta-data + android:name="com.android.settings.category" + android:value="com.android.settings.category.device" /> + <meta-data + android:name="com.android.settings.icon" + android:resource="@drawable/ic_settings_gestures" /> + </activity> + + </application> + +</manifest> diff --git a/cmactions/proguard.flags b/cmactions/proguard.flags new file mode 100644 index 0000000..def5066 --- /dev/null +++ b/cmactions/proguard.flags @@ -0,0 +1,3 @@ +-keep class org.cyanogenmod.CMActions.* { + *; +} diff --git a/cmactions/res/drawable/ic_settings_gestures.xml b/cmactions/res/drawable/ic_settings_gestures.xml new file mode 100644 index 0000000..95cdede --- /dev/null +++ b/cmactions/res/drawable/ic_settings_gestures.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + + <path + android:fillColor="@android:color/white" + android:pathData="M4.7,6.9c0.7-0.7,1.4-1.4,1.7-1.2c0.5,0.2,0,1-0.3,1.5c-0.2,0.4-2.8,3.9-2.8,6.3c0,1.3,0.5,2.3,1.3,3 +c0.7,0.6,1.7,0.7,2.6,0.5c1.1-0.3,1.9-1.4,3-2.8c1.2-1.5,2.8-3.4,4-3.4c1.6,0,1.6,1,1.7,1.8c-3.7,0.6-5.3,3.7-5.3,5.4 +s1.4,3.1,3.2,3.1c1.6,0,4.3-1.3,4.6-6.1H21v-2.5h-2.4c-0.1-1.7-1.1-4.2-4-4.2c-2.2,0-4.1,1.9-4.9,2.8c-0.6,0.7-2,2.5-2.3,2.7 +c-0.2,0.3-0.7,0.8-1.1,0.8c-0.4,0-0.7-0.8-0.4-1.9c0.3-1.1,1.4-2.9,1.8-3.5C8.5,8,9.1,7.2,9.1,5.9C9.1,3.7,7.4,3,6.6,3 +C5.3,3,4.1,4,3.9,4.3C3.5,4.6,3.2,4.9,3,5.2L4.7,6.9z +M13.9,18.6c-0.3,0-0.7-0.3-0.7-0.7c0-0.6,0.7-2.2,2.8-2.8 +C15.8,17.8,14.6,18.6,13.9,18.6z" /> +</vector> diff --git a/cmactions/res/mipmap-xhdpi/ic_launcher_settings.png b/cmactions/res/mipmap-xhdpi/ic_launcher_settings.png Binary files differnew file mode 100644 index 0000000..fa8c813 --- /dev/null +++ b/cmactions/res/mipmap-xhdpi/ic_launcher_settings.png diff --git a/cmactions/res/mipmap-xxhdpi/ic_launcher_settings.png b/cmactions/res/mipmap-xxhdpi/ic_launcher_settings.png Binary files differnew file mode 100644 index 0000000..3fa69e9 --- /dev/null +++ b/cmactions/res/mipmap-xxhdpi/ic_launcher_settings.png diff --git a/cmactions/res/mipmap-xxxhdpi/ic_launcher_settings.png b/cmactions/res/mipmap-xxxhdpi/ic_launcher_settings.png Binary files differnew file mode 100644 index 0000000..72946b7 --- /dev/null +++ b/cmactions/res/mipmap-xxxhdpi/ic_launcher_settings.png diff --git a/cmactions/res/values-es/strings.xml b/cmactions/res/values-es/strings.xml new file mode 100644 index 0000000..894726d --- /dev/null +++ b/cmactions/res/values-es/strings.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + Copyright (C) 2013-2014 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. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + + <!-- Gesture shortcuts --> + <string name="screen_gestures_panel_title">Atajos de gestos</string> + <string name="screen_gestures_panel_summary">Usar gestos cuando la pantalla está apagada</string> + + <string name="touchscreen_control_gesture_head">Gestos de Pantalla Apagada</string> + <string name="touchscreen_control_gesture_title">Activar Gestos de Pantalla</string> + <string name="gesture_category_title">Gestos Disponibles</string> + + <string name="touchscreen_dtp_gesture_title">Doble toque</string> + <string name="touchscreen_x_left_gesture_title">Deslizar a la izquierda</string> + <string name="touchscreen_x_right_gesture_title">Deslizar a la derecha</string> + <string name="touchscreen_y_down_gesture_title">Deslizar hacia abajo</string> + <string name="touchscreen_y_up_gesture_title">Deslizar hacia arriba</string> + + <string name="touchscreen_c_gesture_title">Dibujar \"c\"</string> + <string name="touchscreen_z_gesture_title">Dibujar \"z\"</string> + <string name="touchscreen_s_gesture_title">Dibujar \"s\"</string> + <string name="touchscreen_w_gesture_title">Dibujar \"w\"</string> + <string name="touchscreen_o_gesture_title">Dibujar \"o\"</string> + <string name="touchscreen_v_gesture_title">Dibujar \"v\"</string> + <string name="touchscreen_e_gesture_title">Dibujar \"e\"</string> + <string name="touchscreen_m_gesture_title">Dibujar \"m\"</string> + + <!-- unused --> + <!-- < equals to < and > equals to > --> + <string name="touchscreen_v_left_gesture_title">Dibujar \"<\"</string> + <string name="touchscreen_v_right_gesture_title">Dibujar \">\"</string> + <string name="touchscreen_v_down_gesture_title">Dibujar \"?\"</string> + + <!-- haptic feedback --> + <string name="touchscreen_extras">Extras</string> + <string name="haptic_feedback">Señal Táctil</string> + <string name="haptic_feedback_summary">Vibrar cuando se detecta el gesto</string> + + <!-- gesture actions --> + <string name="disabled">Desactivado</string> + <string name="wakeUp">Activar Pantalla</string> + <string name="unlock">Desbloquear</string> + <string name="play">Play/Pausa</string> + <string name="next">Pista Siguiente</string> + <string name="prev">Pista Anterior</string> + <string name="camera">Abrir Cámara</string> + <string name="flashlight">(Des)Activar Linterna</string> + <string name="doNotDisturbMode">Modo No Molestar</string> + <string name="normalMode">Modo Normal</string> + <string name="muteMode">Modo silencio</string> + +</resources> diff --git a/cmactions/res/values-fr/strings.xml b/cmactions/res/values-fr/strings.xml new file mode 100644 index 0000000..5c33f84 --- /dev/null +++ b/cmactions/res/values-fr/strings.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + Copyright (C) 2013-2014 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. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="device_settings_app_name">Gestes écran éteint</string> + + <!-- Gesture shortcuts --> + <string name="screen_gestures_panel_title">Gestes tactiles</string> + <string name="screen_gestures_panel_summary">Utilisez les gestes quand l\'écran est éteint</string> + + <string name="touchscreen_control_gesture_head">Gestes écran éteint</string> + <string name="touchscreen_control_gesture_title">Activer les Gestes</string> + <string name="gesture_category_title">Gestes disponible</string> + + <string name="touchscreen_dtp_gesture_title">Double Tape</string> + <string name="touchscreen_x_left_gesture_title">Glissez vers la gauche</string> + <string name="touchscreen_x_right_gesture_title">Glissez vers la droite</string> + <string name="touchscreen_y_down_gesture_title">Glissez vers le bas</string> + <string name="touchscreen_y_up_gesture_title">Glissez vers le haut</string> + + <string name="touchscreen_c_gesture_title">Dessinez \"c\"</string> + <string name="touchscreen_z_gesture_title">Dessinez \"z\"</string> + <string name="touchscreen_s_gesture_title">Dessinez \"s\"</string> + <string name="touchscreen_w_gesture_title">Dessinez \"w\"</string> + <string name="touchscreen_o_gesture_title">Dessinez \"o\"</string> + <string name="touchscreen_v_gesture_title">Dessinez \"v\"</string> + <string name="touchscreen_e_gesture_title">Dessinez \"e\"</string> + <string name="touchscreen_m_gesture_title">Dessinez \"m\"</string> + + <!-- haptic feedback --> + <string name="touchscreen_extras">Extras</string> + <string name="haptic_feedback">Retour Haptique</string> + <string name="haptic_feedback_summary">Vibrer quand un geste est détecté</string> + + <!-- gesture actions --> + <string name="disabled">Désactivé</string> + <string name="wakeUp">Réveiller</string> + <string name="unlock">Dévérouiller</string> + <string name="play">Lecture/Pause</string> + <string name="next">Piste suivante</string> + <string name="prev">Piste précédente</string> + <string name="camera">Appareil photo</string> + <string name="flashlight">Lampe de poche</string> + <string name="doNotDisturbMode">Do Not Disturb Mode</string> + <string name="normalMode">Normal Mode</string> + <string name="muteMode">Mute Mode</string> + +</resources> diff --git a/cmactions/res/values-it/strings.xml b/cmactions/res/values-it/strings.xml new file mode 100644 index 0000000..668274b --- /dev/null +++ b/cmactions/res/values-it/strings.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + Copyright (C) 2013-2014 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. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + + <!-- Gesture shortcuts --> + <string name="screen_gestures_panel_title">Scorciatoie gesture</string> + <string name="screen_gestures_panel_summary">Usa le gesture mentre lo schermo è spento</string> + + <string name="touchscreen_control_gesture_head">Gesture a schermo spento</string> + <string name="touchscreen_control_gesture_title">Abilita gesture</string> + <string name="gesture_category_title">Gesture disponibili</string> + + <string name="touchscreen_dtp_gesture_title">Doppio Tap</string> + <string name="touchscreen_x_left_gesture_title">Swipe a Sinistra</string> + <string name="touchscreen_x_right_gesture_title">Swipe a Destra</string> + <string name="touchscreen_y_down_gesture_title">Swipe in Basso</string> + <string name="touchscreen_y_up_gesture_title">Swipe in Alto</string> + + <string name="touchscreen_c_gesture_title">Disegna \"c\"</string> + <string name="touchscreen_z_gesture_title">Disegna \"z\"</string> + <string name="touchscreen_s_gesture_title">Disegna \"s\"</string> + <string name="touchscreen_w_gesture_title">Disegna \"w\"</string> + <string name="touchscreen_o_gesture_title">Disegna \"o\"</string> + <string name="touchscreen_v_gesture_title">Disegna \"v\"</string> + <string name="touchscreen_e_gesture_title">Disegna \"e\"</string> + <string name="touchscreen_m_gesture_title">Disegna \"m\"</string> + + <!-- unused --> + <!-- < equals to < and > equals to > --> + <string name="touchscreen_v_left_gesture_title">Disegna \"<\"</string> + <string name="touchscreen_v_right_gesture_title">Disegna \">\"</string> + <string name="touchscreen_v_down_gesture_title">Disegna \"ʌ\"</string> + + <!-- haptic feedback --> + <string name="touchscreen_extras">Extra</string> + <string name="haptic_feedback">Feedback aptico</string> + <string name="haptic_feedback_summary">Vibra quando una gesture è stata rilevata</string> + + <!-- gesture actions --> + <string name="disabled">Disabilitato</string> + <string name="wakeUp">Sveglia</string> + <string name="unlock">Sblocca</string> + <string name="play">Play/Pausa</string> + <string name="next">Traccia successiva</string> + <string name="prev">Traccia precedente</string> + <string name="camera">Avvia fotocamera</string> + <string name="flashlight">Accendi/Spegni torcia</string> + <string name="doNotDisturbMode">Modalità Non Disturbare</string> + <string name="normalMode">Modalità normale</string> + <string name="muteMode">Muto</string> + +</resources> + diff --git a/cmactions/res/values-ru/strings.xml b/cmactions/res/values-ru/strings.xml new file mode 100644 index 0000000..3dc5c7d --- /dev/null +++ b/cmactions/res/values-ru/strings.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2013-2014 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. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + + <string name="device_settings_app_name">Жесты выключенного экрана</string> + <!-- Gesture shortcuts --> + <string name="screen_gestures_panel_title">Управление жестами</string> + <string name="screen_gestures_panel_summary">Использовать жесты, когда экран выключен</string> + + <string name="touchscreen_control_gesture_head">Жесты выключенного экрана</string> + <string name="touchscreen_control_gesture_title">Включить управление жестами</string> + <string name="gesture_category_title">Доступные жесты</string> + + <string name="touchscreen_dtp_gesture_title">Двойной тап</string> + <string name="touchscreen_x_left_gesture_title">Проведите влево</string> + <string name="touchscreen_x_right_gesture_title">Проведите вправо</string> + <string name="touchscreen_y_down_gesture_title">Проведите вниз</string> + <string name="touchscreen_y_up_gesture_title">Проведите вверх</string> + + <string name="touchscreen_c_gesture_title">Нарисуйте \"c\"</string> + <string name="touchscreen_z_gesture_title">Нарисуйте \"z\"</string> + <string name="touchscreen_s_gesture_title">Нарисуйте \"s\"</string> + <string name="touchscreen_w_gesture_title">Нарисуйте \"w\"</string> + <string name="touchscreen_o_gesture_title">Нарисуйте \"o\"</string> + <string name="touchscreen_v_gesture_title">Нарисуйте \"v\"</string> + <string name="touchscreen_e_gesture_title">Нарисуйте \"e\"</string> + <string name="touchscreen_m_gesture_title">Нарисуйте \"m\"</string> + + <!-- haptic feedback --> + <string name="touchscreen_extras">Дополнительные настройки</string> + <string name="haptic_feedback">Вибрация</string> + <string name="haptic_feedback_summary">Использовать вибрацию при обработке жеста</string> + + <!-- gesture actions --> + <string name="disabled">Выключено</string> + <string name="wakeUp">Будить</string> + <string name="unlock">Разблокировать</string> + <string name="play">Воспризв./Пауза</string> + <string name="next">Следующий Трек</string> + <string name="prev">Предыдущий Трек</string> + <string name="camera">Запустить камеру</string> + <string name="flashlight">Настройка вспышки</string> + <string name="doNotDisturbMode">Обычный режим</string> + <string name="normalMode">Обычный режим</string> + <string name="muteMode">Беззвучный режим</string> + +</resources> diff --git a/cmactions/res/values/arrays.xml b/cmactions/res/values/arrays.xml new file mode 100644 index 0000000..8982cb4 --- /dev/null +++ b/cmactions/res/values/arrays.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string-array name="gesture_action_titles"> + <item>@string/wakeUp</item> + <item>@string/unlock</item> + <item>@string/play</item> + <item>@string/next</item> + <item>@string/prev</item> + <item>@string/camera</item> + <item>@string/flashlight</item> + <item>@string/doNotDisturbMode</item> + <item>@string/normalMode</item> + <item>@string/muteMode</item> + </string-array> + + <string-array name="gesture_action_values"> + <item>wakeUp</item> + <item>unlock</item> + <item>play</item> + <item>next</item> + <item>prev</item> + <item>camera</item> + <item>flashlight</item> + <item>doNotDisturb</item> + <item>normal</item> + <item>mute</item> + </string-array> + +</resources> diff --git a/cmactions/res/values/colors.xml b/cmactions/res/values/colors.xml new file mode 100644 index 0000000..c1f38af --- /dev/null +++ b/cmactions/res/values/colors.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<resources> + <!-- Palette colors referenced by top-level themes. --> + <color name="theme_primary">#ff263238</color> + <color name="theme_primary_dark">#ff21272b</color> + <color name="theme_accent">#ff009688</color> +</resources> diff --git a/cmactions/res/values/dimens.xml b/cmactions/res/values/dimens.xml new file mode 100644 index 0000000..133701d --- /dev/null +++ b/cmactions/res/values/dimens.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<resources> + <!-- ActionBar contentInsetStart --> + <dimen name="actionbar_subsettings_contentInsetStart">72dp</dimen> +</resources> diff --git a/cmactions/res/values/strings.xml b/cmactions/res/values/strings.xml new file mode 100644 index 0000000..6f66286 --- /dev/null +++ b/cmactions/res/values/strings.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + Copyright (C) 2013-2014 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. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + + <string name="device_settings_app_name">Off-Screen Gestures</string> + + <!-- Gesture shortcuts --> + <string name="screen_gestures_panel_title">Gesture shortcuts</string> + <string name="screen_gestures_panel_summary">Use gestures while the screen is off</string> + + <string name="touchscreen_control_gesture_head">Screen Off Gestures</string> + <string name="touchscreen_control_gesture_title">Enable Screen Gestures</string> + <string name="gesture_category_title">Available Gestures</string> + + <string name="touchscreen_dtp_gesture_title">Double Tap</string> + <string name="touchscreen_x_left_gesture_title">Swipe Left</string> + <string name="touchscreen_x_right_gesture_title">Swipe Right</string> + <string name="touchscreen_y_down_gesture_title">Swipe Down</string> + <string name="touchscreen_y_up_gesture_title">Swipe Up</string> + + <string name="touchscreen_c_gesture_title">Draw \"c\"</string> + <string name="touchscreen_z_gesture_title">Draw \"z\"</string> + <string name="touchscreen_s_gesture_title">Draw \"s\"</string> + <string name="touchscreen_w_gesture_title">Draw \"w\"</string> + <string name="touchscreen_o_gesture_title">Draw \"o\"</string> + <string name="touchscreen_v_gesture_title">Draw \"v\"</string> + <string name="touchscreen_e_gesture_title">Draw \"e\"</string> + <string name="touchscreen_m_gesture_title">Draw \"m\"</string> + + <!-- unused --> + <!-- < equals to < and > equals to > --> + <string name="touchscreen_v_left_gesture_title">Draw \"<\"</string> + <string name="touchscreen_v_right_gesture_title">Draw \">\"</string> + <string name="touchscreen_v_down_gesture_title">Draw \"ʌ\"</string> + + <!-- haptic feedback --> + <string name="touchscreen_extras">Extras</string> + <string name="haptic_feedback">Haptic feedback</string> + <string name="haptic_feedback_summary">Vibrate when a gesture is detected</string> + + <!-- gesture actions --> + <string name="disabled">Disabled</string> + <string name="wakeUp">Wake Up</string> + <string name="unlock">Unlock</string> + <string name="play">Play/Pause</string> + <string name="next">Next Track</string> + <string name="prev">Previous Track</string> + <string name="camera">Launch Camera</string> + <string name="flashlight">Toggle Flashlight</string> + <string name="doNotDisturbMode">Do Not Disturb Mode</string> + <string name="normalMode">Normal Mode</string> + <string name="muteMode">Mute Mode</string> + +</resources> + diff --git a/cmactions/res/values/styles.xml b/cmactions/res/values/styles.xml new file mode 100644 index 0000000..b013f16 --- /dev/null +++ b/cmactions/res/values/styles.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014-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. +--> +<resources> + <style name="Theme.Main" parent="@android:style/Theme.Material.Light.DarkActionBar"> + <item name="android:colorPrimary">@color/theme_primary</item> + <item name="android:colorPrimaryDark">@color/theme_primary_dark</item> + <item name="android:colorAccent">@color/theme_accent</item> + <!-- Redefine the ActionBar style for contentInsetStart --> + <item name="android:actionBarStyle">@style/Theme.ActionBar.SubSettings</item> + </style> + + <style name="Theme.ActionBar.SubSettings" parent="@android:style/Widget.Material.Light.ActionBar.Solid"> + <item name="android:contentInsetStart">@dimen/actionbar_subsettings_contentInsetStart</item> + </style> +</resources> diff --git a/cmactions/res/xml/touchscreen_panel.xml b/cmactions/res/xml/touchscreen_panel.xml new file mode 100644 index 0000000..4ab1481 --- /dev/null +++ b/cmactions/res/xml/touchscreen_panel.xml @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + 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. +--> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> + + <PreferenceCategory android:title="@string/touchscreen_control_gesture_head"> + + <SwitchPreference + android:key="touchscreen_gesture_control" + android:title="@string/touchscreen_control_gesture_title" /> + + </PreferenceCategory> + + <PreferenceCategory + android:dependency="touchscreen_gesture_control" + android:key="category_gestures" + android:title="@string/gesture_category_title"> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="wakeUp" + android:key="160_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_dtp_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="prev" + android:key="176_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_x_left_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="next" + android:key="177_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_x_right_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="unlock" + android:key="178_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_y_up_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="flashlight" + android:key="179_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_y_down_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="camera" + android:key="193_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_c_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="wakeUp" + android:key="192_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_e_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="normalMode" + android:key="194_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_w_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="muteMode" + android:key="195_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_m_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="wakeUp" + android:key="196_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_o_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="muteMode" + android:key="197_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_s_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="wakeUp" + android:key="198_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_v_gesture_title" /> + + <com.cyanogenmod.settings.device.SwitchPlusPreference + android:defaultValue="doNotDisturbMode" + android:key="202_enabled" + android:summaryOff=" " + android:title="@string/touchscreen_z_gesture_title" /> + </PreferenceCategory> + + <PreferenceCategory android:title="@string/touchscreen_extras"> + + <SwitchPreference + android:key="touchscreen_gesture_haptic_feedback" + android:summary="@string/haptic_feedback_summary" + android:title="@string/haptic_feedback" /> + + </PreferenceCategory> + +</PreferenceScreen> + diff --git a/cmactions/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java b/cmactions/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java new file mode 100644 index 0000000..c52ca65 --- /dev/null +++ b/cmactions/src/com/cyanogenmod/settings/device/BootCompletedReceiver.java @@ -0,0 +1,48 @@ +/* + * 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.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.util.Log; + +public class BootCompletedReceiver extends BroadcastReceiver { + static final String TAG = "CMActions"; + + @Override + public void onReceive(final Context context, Intent intent) { + Log.d(TAG, "Booting"); + enableComponent(context, TouchscreenGestureSettings.class.getName()); + GestureController.updateGestureControl(context); + } + + private void enableComponent(Context context, String component) { + ComponentName name = new ComponentName(context, component); + PackageManager pm = context.getPackageManager(); + if (pm.getComponentEnabledSetting(name) + == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { + pm.setComponentEnabledSetting(name, + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP); + } + } +} 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..2cef1a3 --- /dev/null +++ b/cmactions/src/com/cyanogenmod/settings/device/GestureController.java @@ -0,0 +1,112 @@ +/* + * 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); + } + + 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/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 new file mode 100644 index 0000000..2945404 --- /dev/null +++ b/cmactions/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java @@ -0,0 +1,155 @@ +/* + * 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.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.Preference; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; +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 { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final ActionBar actionBar = getActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + + getFragmentManager().beginTransaction() + .replace(android.R.id.content, new GestureFragment()) + .commit(); + } + + @Override + protected void onResume() { + super.onResume(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + onBackPressed(); + return true; + } + return false; + } + + public static class GestureFragment extends PreferenceFragment implements SwitchPlusPreference.SwitchPlusClickListener { + + public static final String TAG = GestureFragment.class.getSimpleName(); + + private SharedPreferences sharedPrefs; + private String[] actionTitles; + private String[] actionValues; + private List<String> actionTitlesList; + private List<String> actionValuesList; + private static final List<String> allowedSystemApps = new ArrayList<>(); + + static { + allowedSystemApps.add("com.android.dialer"); + allowedSystemApps.add("com.android.mms"); + allowedSystemApps.add("com.android.settings"); + allowedSystemApps.add("com.android.deskclock"); + allowedSystemApps.add("com.android.calculator2"); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.touchscreen_panel); + sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + + actionTitlesList = new ArrayList<>(); + actionValuesList = new ArrayList<>(); + actionTitles = this.getResources().getStringArray(R.array.gesture_action_titles); + actionValues = this.getResources().getStringArray(R.array.gesture_action_values); + actionTitlesList.addAll(Arrays.asList(actionTitles)); + actionValuesList.addAll(Arrays.asList(actionValues)); + + List<ApplicationInfo> packages = getActivity().getPackageManager() + .getInstalledApplications(PackageManager.GET_META_DATA); + for (ApplicationInfo appInfo : packages) { + if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 && + allowedSystemApps.indexOf(appInfo.packageName) == -1) + continue; + actionTitlesList.add(appInfo.loadLabel(getActivity().getPackageManager()).toString()); + actionValuesList.add("launch$" + appInfo.packageName); + } + actionTitles = actionTitlesList.toArray(new String[actionTitlesList.size()]); + actionValues = actionValuesList.toArray(new String[actionValuesList.size()]); + 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.setSummaryOn(actionTitles[i]); + else + preference.setSummaryOn(" "); + } + + 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 onCheckedChanged(SwitchPlusPreference preference, boolean isChecked) { + GestureController.updateGestureControl(getActivity()); + } + + @Override + 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/utils/FileUtils.java b/cmactions/src/com/cyanogenmod/settings/device/utils/FileUtils.java new file mode 100644 index 0000000..e0ed400 --- /dev/null +++ b/cmactions/src/com/cyanogenmod/settings/device/utils/FileUtils.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2013 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.utils; + +import android.util.Log; + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.nio.ByteBuffer; + +public final class FileUtils { + private static final String TAG = "FileUtils"; + + private FileUtils() { + // this class is not supposed to be instantiated + } + + /** + * Reads the first line of text from the given file + */ + public static String readOneLine(String fileName) { + String line = null; + BufferedReader reader = null; + + try { + reader = new BufferedReader(new FileReader(fileName), 512); + line = reader.readLine(); + } catch (IOException e) { + Log.e(TAG, "Could not read from file " + fileName, e); + } finally { + try { + if (reader != null) { + reader.close(); + } + } catch (IOException e) { + // ignored, not much we can do anyway + } + } + + return line; + } + + /** + * Writes the given value into the given file + * + * @return true on success, false on failure + */ + public static boolean writeLine(String fileName, String value) { + try { + FileOutputStream fos = new FileOutputStream(fileName); + fos.write(value.getBytes()); + fos.flush(); + fos.close(); + } catch (IOException e) { + Log.e(TAG, "Could not write to file " + fileName, e); + return false; + } + + 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 { + 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; + } + + /** + * 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; + } +} + |
