Permalink
Browse files

Reverse drawer direction if openDrawer/closeDrawer is called whilst m…

…oving.

Currently when openDrawer or closeDrawer is called whilst the drawer is moving,
the calls are ignored. This patch reverses the direction of the drawer if
openDrawer/closeDrawer is called whilst the drawer is moving.

Signed-off-by: Eddie Ringle <eddie@eringle.net>
  • Loading branch information...
1 parent 1a44042 commit e7f795c0fbe553186b043e70f82b20a9e3526a67 @laurencedawson laurencedawson committed with Jan 12, 2013
Showing with 18 additions and 7 deletions.
  1. +18 −7 src/com/github/eddieringle/android/libs/undergarment/widgets/DrawerGarment.java
@@ -113,6 +113,8 @@
private ViewGroup mDrawerContent;
+ private Runnable mDrawOpenRunnable, mDrawCloseRunnable;
+
private VelocityTracker mVelocityTracker;
private IDrawerCallbacks mDrawerCallbacks;
@@ -519,12 +521,16 @@ public void toggleDrawer() {
}
public void openDrawer(final boolean animate) {
- if (mDrawerOpened || mDrawerMoving) {
+ if(mDrawerMoving){
+ mScrollerHandler.removeCallbacks(mDrawCloseRunnable);
+ mScrollerHandler.removeCallbacks(mDrawOpenRunnable);
+ }
+
+ if (mDrawerOpened) {
return;
}
mDrawerContent.setVisibility(VISIBLE);
-
mDrawerMoving = true;
final int widthPixels = getResources().getDisplayMetrics().widthPixels;
@@ -538,7 +544,7 @@ public void openDrawer(final boolean animate) {
0, animate ? SCROLL_DURATION : 0);
}
- mScrollerHandler.post(new Runnable() {
+ mDrawOpenRunnable = new Runnable() {
@Override
public void run() {
final boolean scrolling = mScroller.computeScrollOffset();
@@ -562,15 +568,19 @@ public void run() {
mScrollerHandler.post(this);
}
}
- });
+ };
+ mScrollerHandler.post(mDrawOpenRunnable);
}
public void openDrawer() {
openDrawer(true);
}
public void closeDrawer(final boolean animate) {
- if (!mDrawerOpened || mDrawerMoving) {
+ if(mDrawerMoving){
+ mScrollerHandler.removeCallbacks(mDrawCloseRunnable);
+ mScrollerHandler.removeCallbacks(mDrawOpenRunnable);
+ } else if (!mDrawerOpened) {
return;
}
@@ -580,7 +590,7 @@ public void closeDrawer(final boolean animate) {
mScroller.startScroll(mDecorOffsetX, 0, -mDecorOffsetX, 0,
animate ? SCROLL_DURATION : 0);
- mScrollerHandler.post(new Runnable() {
+ mDrawCloseRunnable = new Runnable() {
@Override
public void run() {
final boolean scrolling = mScroller.computeScrollOffset();
@@ -605,7 +615,8 @@ public void run() {
mScrollerHandler.post(this);
}
}
- });
+ };
+ mScrollerHandler.post(mDrawCloseRunnable);
}
public void closeDrawer() {

0 comments on commit e7f795c

Please sign in to comment.