Skip to content

Commit

Permalink
bacon : Update Find7Parts add torch gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
spanish33 authored and h2o64 committed Nov 21, 2015
1 parent 0022692 commit db0d719
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Find7Parts/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<string name="double_tap_wake_summary_head">Un double appui sur l\'écran réveille l\'appareil</string>
<string name="camera_title_head">Appareil photo</string>
<string name="camera_summary_head">Dessiner un cercle pour démarrer l\'appareil photo</string>
<string name="torch_title_head">Torche</string>
<string name="torch_summary_head">Dessiner un V pour afficher la torche</string>
<string name="music_title_head">Musique</string>
<string name="music_summary_head">Utilises les gestes pour contrôler l\'avancement de la musique \n
• Les deux doigts verticallement pour play/pause\n
• Slide vers la gauche pour revenir à la musique précédente\n
• Slide vers la droite pour lancer la musique suivante</string>
<string name="torch_title_head">Torche</string>
<string name="torch_summary_head">Dessiner un V pour afficher la torche</string>
<string name="key_disabler_title_head">Utiliser la barre de navigation</string>
<string name="key_disabler_summary_head">Utilise la barre de navigation au lieu des buttons physiques</string>
<string name="offscreen_gestures_settings">Gestes d\'extinction d\'écran</string>
Expand Down
4 changes: 2 additions & 2 deletions Find7Parts/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<string name="double_tap_wake_summary_head">Effettua un doppio tocco sullo schermo per attivare il device</string>
<string name="camera_title_head">Fotocamera</string>
<string name="camera_summary_head">Disegna un \"O\" per attivare la fotocamera</string>
<string name="torch_title_head">Torcia</string>
<string name="torch_summary_head">Disegna una \"V\" per attivare la torcia</string>
<string name="music_title_head">Musica</string>
<string name="music_summary_head">Usando gesti per controllare lo stato di avanzamento della musica \n
• Le due dita in verticale per il play/pausa \n
• Far scorrere verso sinistra per tornare alla musica precedente \n
• Far scorrere verso destra per avviare il brano successivo</string>
<string name="torch_title_head">Torcia</string>
<string name="torch_summary_head">Disegna una \"V\" per attivare la torcia</string>
<string name="key_disabler_title_head">Utilizzare la barra di navigazione</string>
<string name="key_disabler_summary_head">Utilizzare la barra di navigazione, invece di tasti fisici</string>
</resources>
2 changes: 2 additions & 0 deletions Find7Parts/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<string name="double_tap_wake_summary_head">Double tap on screen will wake the device</string>
<string name="camera_title_head">Camera</string>
<string name="camera_summary_head">Draw a circle to start camera</string>
<string name="torch_title_head">Torch</string>
<string name="torch_summary_head">Draw a V to toggle torch</string>
<string name="music_title_head">Music</string>
<string name="music_summary_head">Use gestures to control music playback \n
• Two fingers vertically to play/pause\n
Expand Down
5 changes: 5 additions & 0 deletions Find7Parts/res/xml/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
android:summary="@string/camera_summary_head"
android:title="@string/camera_title_head" />

<CheckBoxPreference
android:key="torch"
android:summary="@string/torch_summary_head"
android:title="@string/torch_title_head" />

<CheckBoxPreference
android:key="music"
android:summary="@string/music_summary_head"
Expand Down
7 changes: 7 additions & 0 deletions Find7Parts/src/org/omnirom/device/DeviceSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class DeviceSettings extends PreferenceActivity {
//public static final String KEY_DISABLER = "key_disabler";
public static final String KEY_DOUBLE_TAP_SWITCH = "double_tap";
public static final String KEY_CAMERA_SWITCH = "camera";
public static final String KEY_TORCH_SWITCH = "torch";
public static final String KEY_MUSIC_SWITCH = "music";

private TwoStatePreference mDoubleTapSwitch;
private TwoStatePreference mCameraSwitch;
private TwoStatePreference mTorchSwitch;
private TwoStatePreference mMusicSwitch;
//private TwoStatePreference mKeyDisabler;

Expand All @@ -56,6 +58,11 @@ public void onCreate(Bundle savedInstanceState) {
mCameraSwitch.setChecked(CameraGestureSwitch.isEnabled(this));
mCameraSwitch.setOnPreferenceChangeListener(new CameraGestureSwitch());

mTorchSwitch = (TwoStatePreference) findPreference(KEY_TORCH_SWITCH);
mTorchSwitch.setEnabled(TorchGestureSwitch.isSupported());
mTorchSwitch.setChecked(TorchGestureSwitch.isEnabled(this));
mTorchSwitch.setOnPreferenceChangeListener(new TorchGestureSwitch());

mMusicSwitch = (TwoStatePreference) findPreference(KEY_MUSIC_SWITCH);
mMusicSwitch.setEnabled(MusicGestureSwitch.isSupported());
mMusicSwitch.setChecked(MusicGestureSwitch.isEnabled(this));
Expand Down
10 changes: 10 additions & 0 deletions Find7Parts/src/org/omnirom/device/KeyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public class KeyHandler implements DeviceKeyHandler {
// Supported scancodes
private static final int GESTURE_CIRCLE_SCANCODE = 250;
private static final int GESTURE_SWIPE_DOWN_SCANCODE = 251;
private static final int GESTURE_V_SCANCODE = 252;
private static final int GESTURE_LTR_SCANCODE = 253;
private static final int GESTURE_GTR_SCANCODE = 254;
private static final int KEY_DOUBLE_TAP = 255;

private static final int[] sSupportedGestures = new int[]{
GESTURE_CIRCLE_SCANCODE,
GESTURE_V_SCANCODE,
GESTURE_SWIPE_DOWN_SCANCODE,
GESTURE_LTR_SCANCODE,
GESTURE_GTR_SCANCODE,
Expand Down Expand Up @@ -93,6 +95,14 @@ public void handleMessage(Message msg) {
Intent intent = new Intent(action, null);
startActivitySafely(intent);
break;
case GESTURE_V_SCANCODE:
if (DEBUG) Log.i(TAG, "GESTURE_V_SCANCODE");
mGestureWakeLock.acquire(GESTURE_WAKELOCK_DURATION);
Intent torchIntent = new Intent("com.android.systemui.TOGGLE_FLASHLIGHT");
torchIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
UserHandle user = new UserHandle(UserHandle.USER_CURRENT);
mContext.sendBroadcastAsUser(torchIntent, user);
break;
case GESTURE_SWIPE_DOWN_SCANCODE:
dispatchMediaKeyWithWakeLockToMediaSession(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
break;
Expand Down
1 change: 1 addition & 0 deletions Find7Parts/src/org/omnirom/device/Startup.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Startup extends BroadcastReceiver {
public void onReceive(final Context context, final Intent bootintent) {
DoubleTapSwitch.restore(context);
CameraGestureSwitch.restore(context);
TorchGestureSwitch.restore(context);
MusicGestureSwitch.restore(context);
//KeyDisabler.restore(context);
}
Expand Down
66 changes: 66 additions & 0 deletions Find7Parts/src/org/omnirom/device/TorchGestureSwitch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2013 The OmniROM Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.omnirom.device;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceManager;

public class TorchGestureSwitch implements OnPreferenceChangeListener {

private static final String FILE = "/proc/touchpanel/flashlight_enable";

public static boolean isSupported() {
return Utils.fileWritable(FILE);
}

public static boolean isEnabled(Context context) {
boolean enabled = Utils.getFileValueAsBoolean(FILE, false);
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPrefs.getBoolean(DeviceSettings.KEY_TORCH_SWITCH, enabled);
}

/**
* Restore setting from SharedPreferences. (Write to kernel.)
* @param context The context to read the SharedPreferences from
*/
public static void restore(Context context) {
if (!isSupported()) {
return;
}

boolean enabled = isEnabled(context);
if(enabled)
Utils.writeValue(FILE, "1");
else
Utils.writeValue(FILE, "0");
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Boolean enabled = (Boolean) newValue;
if(enabled)
Utils.writeValue(FILE, "1");
else
Utils.writeValue(FILE, "0");
return true;
}

}

0 comments on commit db0d719

Please sign in to comment.