[Android] [PATCH 11/12] dvd nav with Gamepad controllers

Geoffrey Métais geoffrey.metais at gmail.com
Mon Nov 17 17:06:49 CET 2014


---
 .../vlc/gui/video/VideoPlayerActivity.java         | 76 +++++++++++++---------
 1 file changed, 44 insertions(+), 32 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 395aee8..e0779cb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -722,40 +722,44 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     @TargetApi(12) //only active for Android 3.1+
     public boolean dispatchGenericMotionEvent(MotionEvent event){
 
-        InputDevice mInputDevice = event.getDevice();
-
-        float x = AndroidDevices.getCenteredAxis(event, mInputDevice,
-                MotionEvent.AXIS_X);
-        float y = AndroidDevices.getCenteredAxis(event, mInputDevice,
-                MotionEvent.AXIS_Y);
-        float z = AndroidDevices.getCenteredAxis(event, mInputDevice,
-                MotionEvent.AXIS_Z);
-        float rz = AndroidDevices.getCenteredAxis(event, mInputDevice,
-                MotionEvent.AXIS_RZ);
-
-        if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY){
-            if (Math.abs(x) > 0.3){
-                seek(x > 0.0f ? 10000 : -10000);
-                mLastMove = System.currentTimeMillis();
-            } else if (Math.abs(y) > 0.3){
-                if (mIsFirstBrightnessGesture)
-                    initBrightnessTouch();
-                changeBrightness(-y/10f);
-                mLastMove = System.currentTimeMillis();
-            } else if (Math.abs(rz) > 0.3){
-                mVol = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
-                int delta = -(int) ((rz / 7) * mAudioMax);
-                int vol = (int) Math.min(Math.max(mVol + delta, 0), mAudioMax);
-                setAudioVolume(vol);
-                mLastMove = System.currentTimeMillis();
-            }
-        }
-        return true;
+		InputDevice mInputDevice = event.getDevice();
+
+		float x = AndroidDevices.getCenteredAxis(event, mInputDevice,
+				MotionEvent.AXIS_X);
+		float y = AndroidDevices.getCenteredAxis(event, mInputDevice,
+				MotionEvent.AXIS_Y);
+		float z = AndroidDevices.getCenteredAxis(event, mInputDevice,
+				MotionEvent.AXIS_Z);
+		float rz = AndroidDevices.getCenteredAxis(event, mInputDevice,
+				MotionEvent.AXIS_RZ);
+
+		if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY){
+			if (Math.abs(x) > 0.3){
+				if (AndroidDevices.hasTsp()) {
+                    seek(x > 0.0f ? 10000 : -10000);
+                } else
+                    navigateDvdMenu(x > 0.0f ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT);
+			} else if (Math.abs(y) > 0.3){
+				if (AndroidDevices.hasTsp()) {
+                    if (mIsFirstBrightnessGesture)
+                        initBrightnessTouch();
+                    changeBrightness(-y / 10f);
+                } else
+                    navigateDvdMenu(x > 0.0f ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN);
+			} else if (Math.abs(rz) > 0.3){
+				mVol = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+				int delta = -(int) ((rz / 7) * mAudioMax);
+				int vol = (int) Math.min(Math.max(mVol + delta, 0), mAudioMax);
+				setAudioVolume(vol);
+			}
+            mLastMove = System.currentTimeMillis();
+		}
+		return true;
     }
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
-        showOverlay();
+        showOverlayTimeout(OVERLAY_TIMEOUT);
         switch (keyCode) {
         case KeyEvent.KEYCODE_F:
         case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
@@ -772,7 +776,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         case KeyEvent.KEYCODE_MEDIA_PAUSE:
         case KeyEvent.KEYCODE_SPACE:
         case KeyEvent.KEYCODE_BUTTON_A:
-            doPlayPause();
+            if (mIsNavMenu)
+                return navigateDvdMenu(keyCode);
+            else
+                doPlayPause();
             return true;
         case KeyEvent.KEYCODE_V:
         case KeyEvent.KEYCODE_BUTTON_Y:
@@ -795,7 +802,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
             return true;
         case KeyEvent.KEYCODE_VOLUME_MUTE:
         case KeyEvent.KEYCODE_BUTTON_X:
-            updateMute();
+            if (mIsNavMenu)
+                return navigateDvdMenu(keyCode);
+            else
+                updateMute();
             return true;
         case KeyEvent.KEYCODE_S:
         case KeyEvent.KEYCODE_MEDIA_STOP:
@@ -832,6 +842,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                 return true;
             case KeyEvent.KEYCODE_DPAD_CENTER:
             case KeyEvent.KEYCODE_ENTER:
+            case KeyEvent.KEYCODE_BUTTON_X:
+            case KeyEvent.KEYCODE_BUTTON_A:
                 mLibVLC.playerNavigate(LibVLC.INPUT_NAV_ACTIVATE);
                 return true;
             default:
-- 
1.9.1



More information about the Android mailing list