[Android] Nicer touch behaviour for volume and brightness

Geoffrey Métais git at videolan.org
Mon Nov 3 16:53:19 CET 2014


vlc-ports/android | branch: 1.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Nov  3 13:00:12 2014 +0100| [ad6c44216e5cbf69ede5eb7415a8cf4bd83495dc] | committer: Jean-Baptiste Kempf

Nicer touch behaviour for volume and brightness

(cherry picked from commit a8084723282b45dc275d12ca12d77cca276e80f9)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 .../vlc/gui/video/VideoPlayerActivity.java         |   27 ++++++++++++--------
 1 file changed, 16 insertions(+), 11 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 0f71175..6e317ca 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -213,7 +213,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     private int mAudioMax;
     private OnAudioFocusChangeListener mAudioFocusListener;
     private boolean mMute = false;
-    private int mVol, mVolSave;
+    private int mVolSave;
+    private float mVol;
 
     //Touch Events
     private static final int TOUCH_NONE = 0;
@@ -1332,6 +1333,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
             // No volume/brightness action if coef < 2 or a secondary display is connected
             //TODO : Volume action when a secondary display is connected
             if (coef > 2 && mPresentation == null) {
+                mTouchY = event.getRawY();
+                mTouchX = event.getRawX();
                 // Volume (Up or Down - Right side)
                 if (!mEnableBrightnessGesture || (int)mTouchX > (screen.widthPixels / 2)){
                     doVolumeTouch(y_changed);
@@ -1346,9 +1349,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                 // Nexus), gestures can't be made without activating the UI.
                 if(AndroidDevices.hasNavBar())
                     showOverlay();
+            } else {
+                // Seek (Right or Left move)
+                doSeekTouch(coef, xgesturesize, false);
             }
-            // Seek (Right or Left move)
-            doSeekTouch(coef, xgesturesize, false);
             break;
 
         case MotionEvent.ACTION_UP:
@@ -1411,9 +1415,10 @@ 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) {
+        float delta = - ((y_changed * 2f / mSurfaceYDisplayRange) * mAudioMax);
+        mVol += delta;
+        int vol = (int) Math.min(Math.max(mVol, 0), mAudioMax);
+        if (delta != 0f) {
             setAudioVolume(vol);
         }
     }
@@ -1426,14 +1431,14 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
 
     private void updateMute () {
         if (!mMute) {
-            mVolSave = mVol;
+            mVolSave = Float.floatToIntBits(mVol);
             mMute = true;
             mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
             showInfo(R.string.sound_off,1000);
         } else {
             mVol = mVolSave;
             mMute = false;
-            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mVol, 0);
+            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, Float.floatToIntBits(mVol), 0);
             showInfo(R.string.sound_on,1000);
         }
     }
@@ -1458,10 +1463,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_BRIGHTNESS)
             return;
         if (mIsFirstBrightnessGesture) initBrightnessTouch();
-        mTouchAction = TOUCH_BRIGHTNESS;
+            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;
+        // Set delta : 2f is arbitrary for now, it possibly will change in the future
+        float delta = - y_changed / mSurfaceYDisplayRange * 2f;
 
         changeBrightness(delta);
     }



More information about the Android mailing list