[Android] video: don't mix touch actions

Sébastien Toque git at videolan.org
Fri Sep 6 21:12:59 CEST 2013


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Fri Sep  6 16:36:23 2013 +0200| [519d9dd4dbe57a46b62f9cce75f9c3ed29c5df61] | committer: Sébastien Toque

video: don't mix touch actions

For instance start with volume change, and end up with an unwanted seek

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=519d9dd4dbe57a46b62f9cce75f9c3ed29c5df61
---

 .../vlc/gui/video/VideoPlayerActivity.java         |   29 ++++++++++++++------
 1 file changed, 20 insertions(+), 9 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 e3e4412..40aa1ce 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -177,8 +177,12 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     private AudioManager mAudioManager;
     private int mAudioMax;
 
-    //Volume Or Brightness
-    private boolean mIsAudioOrBrightnessChanged;
+    //Touch Events
+    private static final int TOUCH_NONE = 0;
+    private static final int TOUCH_VOLUME = 1;
+    private static final int TOUCH_BRIGHTNESS = 2;
+    private static final int TOUCH_SEEK = 3;
+    private int mTouchAction;
     private int mSurfaceYDisplayRange;
     private float mTouchY, mTouchX, mVol;
 
@@ -900,7 +904,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
             // Audio
             mTouchY = event.getRawY();
             mVol = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
-            mIsAudioOrBrightnessChanged = false;
+            mTouchAction = TOUCH_NONE;
             // Seek
             mTouchX = event.getRawX();
             break;
@@ -929,7 +933,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
 
         case MotionEvent.ACTION_UP:
             // Audio or Brightness
-            if (!mIsAudioOrBrightnessChanged) {
+            if ( mTouchAction == TOUCH_NONE) {
                 if (!mShowing) {
                     showOverlay();
                 } else {
@@ -940,7 +944,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
             doSeekTouch(coef, xgesturesize, true);
             break;
         }
-        return mIsAudioOrBrightnessChanged;
+        return mTouchAction != TOUCH_NONE;
     }
 
     private void doSeekTouch(float coef, float gesturesize, boolean seek) {
@@ -948,6 +952,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         if (mEnableWheelbar || coef > 0.5 || Math.abs(gesturesize) < 1)
             return;
 
+        if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_SEEK)
+            return;
+        mTouchAction = TOUCH_SEEK;
+
         // Always show seekbar when searching
         if (!mShowing) showOverlay();
 
@@ -975,12 +983,13 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     }
 
     private void doVolumeTouch(float y_changed) {
+        if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_VOLUME)
+            return;
         int delta = -(int) ((y_changed / mSurfaceYDisplayRange) * mAudioMax);
         int vol = (int) Math.min(Math.max(mVol + delta, 0), mAudioMax);
         if (delta != 0) {
-            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
-                    vol, 0);
-            mIsAudioOrBrightnessChanged = true;
+            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, 0);
+            mTouchAction = TOUCH_VOLUME;
             showInfo(getString(R.string.volume) + '\u00A0' + Integer.toString(vol),1000);
         }
     }
@@ -1002,8 +1011,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     }
 
     private void doBrightnessTouch(float y_changed) {
+        if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_BRIGHTNESS)
+            return;
         if (mIsFirstBrightnessGesture) initBrightnessTouch();
-        mIsAudioOrBrightnessChanged = true;
+        mTouchAction = TOUCH_BRIGHTNESS;
 
         // Set delta : 0.07f is arbitrary for now, it possibly will change in the future
         float delta = - y_changed / mSurfaceYDisplayRange * 0.07f;



More information about the Android mailing list