[Android] Fix touch events in RTL mode

habib kazemi git at videolan.org
Tue Jun 6 13:32:27 CEST 2017


vlc-android | branch: master | habib kazemi <kazemihabib1996 at gmail.com> | Fri Jun  2 23:42:16 2017 +0430| [b9d29e158f8acaf7500b55ecc6392b619fe79688] | committer: Geoffrey Métais

Fix touch events in RTL mode

Reverse seek touch direction and
reverse the location BrightnessTouch and VolumeTouch

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/b9d29e158f8acaf7500b55ecc6392b619fe79688
---

 .../vlc/gui/video/VideoPlayerActivity.java         | 26 ++++++++++++++--------
 1 file changed, 17 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 047bd0025..47115def8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -185,6 +185,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     private int mPresentationDisplayId = -1;
     private Uri mUri;
     private boolean mAskResume = true;
+    private boolean mIsRtl;
     private ScaleGestureDetector mScaleGestureDetector;
     private GestureDetectorCompat mDetector = null;
 
@@ -494,6 +495,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             mCurrentSize = mSettings.getInt(PreferencesActivity.VIDEO_RATIO, SURFACE_BEST_FIT);
         }
         mMedialibrary = VLCApplication.getMLInstance();
+        mIsRtl = AndroidUtil.isJellyBeanMR1OrLater && TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
     }
 
     @Override
@@ -868,7 +870,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             ItemTouchHelper.Callback callback =  new SwipeDragItemTouchHelperCallback(mPlaylistAdapter);
             ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
             touchHelper.attachToRecyclerView(mPlaylist);
-            if (AndroidUtil.isJellyBeanMR1OrLater && TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL) {
+            if (mIsRtl) {
                 mPlaylistPrevious.setImageResource(R.drawable.ic_playlist_next_circle);
                 mPlaylistNext.setImageResource(R.drawable.ic_playlist_previous_circle);
             }
@@ -2133,19 +2135,25 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                             return false;
                         mTouchY = event.getRawY();
                         mTouchX = event.getRawX();
-                        // Volume (Up or Down - Right side)
-                        if ((mTouchControls & TOUCH_FLAG_AUDIO_VOLUME) != 0 && (int)mTouchX > (4 * mScreen.widthPixels / 7f)){
-                            doVolumeTouch(y_changed);
+                        // (Up or Down - Right side) LTR: Volume RTL: Brightness
+                        if ((mTouchControls & (!mIsRtl ? TOUCH_FLAG_AUDIO_VOLUME : TOUCH_FLAG_BRIGHTNESS)) != 0 && (int)mTouchX > (4 * mScreen.widthPixels / 7f)){
+                            if (!mIsRtl)
+                                doVolumeTouch(y_changed);
+                            else
+                                doBrightnessTouch(y_changed);
                             hideOverlay(true);
                         }
-                        // Brightness (Up or Down - Left side)
-                        if ((mTouchControls & TOUCH_FLAG_BRIGHTNESS) != 0 && (int)mTouchX < (3 * mScreen.widthPixels / 7f)){
-                            doBrightnessTouch(y_changed);
+                        // (Up or Down - Left side) LTR: Brightness RTL: Volume
+                        if ((mTouchControls & (!mIsRtl ? TOUCH_FLAG_BRIGHTNESS : TOUCH_FLAG_AUDIO_VOLUME)) != 0 && (int)mTouchX < (3 * mScreen.widthPixels / 7f)){
+                            if(!mIsRtl)
+                                doBrightnessTouch(y_changed);
+                            else
+                                doVolumeTouch(y_changed);
                             hideOverlay(true);
                         }
                     } else {
                         // Seek (Right or Left move)
-                        doSeekTouch(Math.round(delta_y), xgesturesize, false);
+                        doSeekTouch(Math.round(delta_y), mIsRtl ? -xgesturesize : xgesturesize , false);
                     }
                 } else {
                     mTouchY = event.getRawY();
@@ -2162,7 +2170,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                 sendMouseEvent(MotionEvent.ACTION_UP, 0, xTouch, yTouch);
                 // Seek
                 if (mTouchAction == TOUCH_SEEK)
-                    doSeekTouch(Math.round(delta_y), xgesturesize, true);
+                    doSeekTouch(Math.round(delta_y), mIsRtl ? -xgesturesize : xgesturesize , true);
                 mTouchX = -1f;
                 mTouchY = -1f;
                 break;



More information about the Android mailing list