[Android] Seek gesture : change progression formula and fix some bugs

Alexandre Perraud git at videolan.org
Tue Aug 14 18:17:02 CEST 2012


vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Tue Aug 14 18:08:47 2012 +0200| [8f164505a14086f22c75043f702025395479ad05] | committer: Jean-Baptiste Kempf

Seek gesture : change progression formula and fix some bugs

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 .../vlc/gui/video/VideoPlayerActivity.java         |   33 ++++++++++++++------
 1 file changed, 23 insertions(+), 10 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 3d1d625..ec7e91f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -637,6 +637,7 @@ public class VideoPlayerActivity extends Activity {
      * show/hide the overlay
      */
 
+    @SuppressWarnings("deprecation")
     @Override
     public boolean onTouchEvent(MotionEvent event) {
 
@@ -649,7 +650,6 @@ public class VideoPlayerActivity extends Activity {
         float x_changed = event.getRawX() - mTouchX;
         // coef is the gradient's move to determine a neutral zone
         float coef = Math.abs (y_changed / x_changed);
-        Log.i(TAG, "coef " + Float.toString(coef));
 
         switch (event.getAction()) {
 
@@ -690,16 +690,29 @@ public class VideoPlayerActivity extends Activity {
                 }
             }
             // Seek
-            // No seek action if coef > 0.5
-            if ((Math.abs(y_changed) < Math.abs(x_changed)) && (coef < 0.5)){
-                // Tools to get the screen size for the cubic progression
-                DisplayMetrics screen = new DisplayMetrics();
-                getWindowManager().getDefaultDisplay().getMetrics(screen);
-
-                // Size of the jump, 10 minutes max (600000) with a cubic progression
-                int jump = (int) (600000 * Math.pow(
-                        (x_changed / screen.widthPixels), 3));
+            // Tools to get the xdpi resolution for the cubic progression
+            DisplayMetrics screen = new DisplayMetrics();
+            getWindowManager().getDefaultDisplay().getMetrics(screen);
+
+            float gesturesize = (float) ((x_changed / screen.xdpi) * 2.54);
+            // No seek action if coef > 0.5 and gesturesize < 1cm
+            if ((Math.abs(y_changed) < Math.abs(x_changed))
+                    && (coef < 0.5)
+                    && (Math.abs(gesturesize) > 1)) {
+
+                // Size of the jump, 10 minutes max (600000), with a bi-cubic progression, for a 8cm gesture
+                int jump = (int) (Math.signum(gesturesize) * ((600000 * Math.pow((gesturesize / 8), 4)) + 3000));
+
+                // Adjust the jump
+                if ((jump > 0) && ((mLibVLC.getTime() + jump) > mLibVLC.getLength()))
+                    jump = (int) (mLibVLC.getLength() - mLibVLC.getTime());
+                if ((jump < 0) && ((mLibVLC.getTime() + jump) < 0))
+                    jump = (int) - mLibVLC.getTime();
+
+                //Jump !
                 mPlayerControlListener.onSeek(jump);
+
+                //Show the jump's size
                 showInfo(String.format("%s%ss", jump >= 0 ? "+" : "", Util.millisToString(jump)),1000);
             }
             break;



More information about the Android mailing list