[Android] Fix touch events in RTL mode

habib kazemi git at videolan.org
Tue Jun 6 10:18:54 CEST 2017


vlc-android | branch: master | habib kazemi <kazemihabib1996 at gmail.com> | Fri Jun  2 23:42:16 2017 +0430| [5a16b7dc97361d87f8e50160957653be3cc58715] | 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/5a16b7dc97361d87f8e50160957653be3cc58715
---

 .../vlc/gui/video/VideoPlayerActivity.java         | 27 ++++++++++++++--------
 1 file changed, 18 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..7f75d0d98 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);
             }
@@ -2058,6 +2060,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
 
     @Override
     public boolean onTouchEvent(MotionEvent event) {
+        final boolean rtl = AndroidUtil.isJellyBeanMR1OrLater && TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
         if (mService == null)
             return false;
         if (mDetector == null) {
@@ -2133,19 +2136,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 +2171,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