Bug 765069 - Swipe tabs off screen at the velocity they were swiped. r=mbrubeck
authorWes Johnston <wjohnston@mozilla.com>
Thu, 14 Jun 2012 16:50:58 -0700
changeset 96756 2448a35540d21117f54b9592dd2b3c0d83549525
parent 96755 35c79f50d85f2a53cf46c56ab5a436395c9a3b28
child 96757 4bf6b709f383a02efdc46db7d1f82de63fb5d582
push id22934
push useremorley@mozilla.com
push dateFri, 15 Jun 2012 12:37:14 +0000
treeherdermozilla-central@892f95753777 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs765069
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 765069 - Swipe tabs off screen at the velocity they were swiped. r=mbrubeck
mobile/android/base/TabsTray.java
--- a/mobile/android/base/TabsTray.java
+++ b/mobile/android/base/TabsTray.java
@@ -38,17 +38,19 @@ public class TabsTray extends LinearLayo
     private Context mContext;
 
     private static ListView mList;
     private TabsAdapter mTabsAdapter;
     private boolean mWaitingForClose;
 
     private GestureDetector mGestureDetector;
     private TabSwipeGestureListener mListener;
-    private static final int SWIPE_CLOSE_VELOCITY = 1000;
+    // Minimum velocity swipe that will close a tab, in inches/sec
+    private static final int SWIPE_CLOSE_VELOCITY = 5;
+    // Time to animate non-flicked tabs of screen, in milliseconds
     private static final int MAX_ANIMATION_TIME = 250;
     private static enum DragDirection {
         UNKNOWN,
         HORIZONTAL,
         VERTICAL
     }
 
     private static final String ABOUT_HOME = "about:home";
@@ -277,16 +279,19 @@ public class TabsTray extends LinearLayo
             pa.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
                 public void onPropertyAnimationStart() { }
                 public void onPropertyAnimationEnd() {
                     Tabs tabs = Tabs.getInstance();
                     Tab tab = tabs.getTab(tabId);
                     tabs.closeTab(tab);
                 }
             });
+        } else if (x != 0 && mWaitingForClose) {
+          // if this asked us to close, but we were already doing it just bail out
+          return;
         }
         pa.start();
     }
 
     private class TabSwipeGestureListener extends SimpleOnGestureListener {
         private View mList = null;
         private View mView = null;
         private PointF start = null;
@@ -366,19 +371,23 @@ public class TabsTray extends LinearLayo
             return false;
         }
 
         @Override
         public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
             if (mView == null || Tabs.getInstance().getCount() == 1)
                 return false;
 
+            // velocityX is in pixels/sec. divide by pixels/inch to compare it with swipe velocity
             if (Math.abs(velocityX)/GeckoAppShell.getDpi() > SWIPE_CLOSE_VELOCITY) {
+                // is this is a swipe, we want to continue the row moving at the swipe velocity
                 float d = (velocityX > 0 ? 1 : -1) * mView.getWidth();
-                animateTo(mView, (int)d, (int)(d/velocityX));
+                // convert the velocity (px/sec) to ms by taking the distance
+                // multiply by 1000 to convert seconds to milliseconds
+                animateTo(mView, (int)d, (int)((d + mView.getScrollX())*1000/velocityX));
             }
 
             return false; 
         }
 
         private View findViewAt(int x, int y) {
             if (mList == null)
                 return null;