From 9737f3a18a8c302160e213afa30a4db710e41fb6 Mon Sep 17 00:00:00 2001 From: nicolasroard Date: Wed, 14 Aug 2013 11:14:47 -0700 Subject: [PATCH] Fix swiping in categories in landscape mode Change-Id: I58ecb212792e3e8432791ee29f8a0ef26a819362 --- .../gallery3d/filtershow/FilterShowActivity.java | 27 ++++++++++++++++++---- .../filtershow/category/CategoryView.java | 8 ++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index 28fd80930..43f132505 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -63,6 +63,7 @@ import com.android.gallery3d.data.LocalAlbum; import com.android.gallery3d.filtershow.cache.ImageLoader; import com.android.gallery3d.filtershow.category.Action; import com.android.gallery3d.filtershow.category.CategoryAdapter; +import com.android.gallery3d.filtershow.category.CategoryView; import com.android.gallery3d.filtershow.category.MainPanel; import com.android.gallery3d.filtershow.category.SwipableView; import com.android.gallery3d.filtershow.data.UserPresetsManager; @@ -168,6 +169,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL private boolean mHandlingSwipeButton = false; private View mHandledSwipeView = null; private float mHandledSwipeViewLastDelta = 0; + private float mSwipeStartX = 0; private float mSwipeStartY = 0; private ProcessingService mBoundService; @@ -1279,7 +1281,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL return mSelectedImageUri; } - public void setHandlesSwipeForView(View view, float startY) { + public void setHandlesSwipeForView(View view, float startX, float startY) { if (view != null) { mHandlingSwipeButton = true; } else { @@ -1288,25 +1290,42 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL mHandledSwipeView = view; int[] location = new int[2]; view.getLocationInWindow(location); + mSwipeStartX = location[0] + startX; mSwipeStartY = location[1] + startY; } public boolean dispatchTouchEvent (MotionEvent ev) { if (mHandlingSwipeButton) { + int direction = CategoryView.HORIZONTAL; + if (mHandledSwipeView instanceof CategoryView) { + direction = ((CategoryView) mHandledSwipeView).getOrientation(); + } if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) { float delta = ev.getY() - mSwipeStartY; - mHandledSwipeView.setTranslationY(delta); + float distance = mHandledSwipeView.getHeight(); + if (direction == CategoryView.VERTICAL) { + delta = ev.getX() - mSwipeStartX; + mHandledSwipeView.setTranslationX(delta); + distance = mHandledSwipeView.getWidth(); + } else { + mHandledSwipeView.setTranslationY(delta); + } delta = Math.abs(delta); - float transparency = Math.min(1, delta / mHandledSwipeView.getHeight()); + float transparency = Math.min(1, delta / distance); mHandledSwipeView.setAlpha(1.f - transparency); mHandledSwipeViewLastDelta = delta; } if (ev.getActionMasked() == MotionEvent.ACTION_CANCEL || ev.getActionMasked() == MotionEvent.ACTION_UP) { + mHandledSwipeView.setTranslationX(0); mHandledSwipeView.setTranslationY(0); mHandledSwipeView.setAlpha(1.f); mHandlingSwipeButton = false; - if (mHandledSwipeViewLastDelta > mHandledSwipeView.getHeight()) { + float distance = mHandledSwipeView.getHeight(); + if (direction == CategoryView.VERTICAL) { + distance = mHandledSwipeView.getWidth(); + } + if (mHandledSwipeViewLastDelta > distance) { ((SwipableView) mHandledSwipeView).delete(); } } diff --git a/src/com/android/gallery3d/filtershow/category/CategoryView.java b/src/com/android/gallery3d/filtershow/category/CategoryView.java index 7e7fc1751..1addbde30 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryView.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryView.java @@ -43,6 +43,7 @@ public class CategoryView extends IconView private int mSelectionStroke; private Paint mBorderPaint; private int mBorderStroke; + private float mStartTouchX = 0; private float mStartTouchY = 0; private float mDeleteSlope = 20; private int mSelectionColor = Color.WHITE; @@ -147,15 +148,20 @@ public class CategoryView extends IconView } if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { mStartTouchY = event.getY(); + mStartTouchX = event.getX(); } if (event.getActionMasked() == MotionEvent.ACTION_UP) { + setTranslationX(0); setTranslationY(0); } if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { float delta = event.getY() - mStartTouchY; + if (getOrientation() == CategoryView.VERTICAL) { + delta = event.getX() - mStartTouchX; + } if (Math.abs(delta) > mDeleteSlope) { FilterShowActivity activity = (FilterShowActivity) getContext(); - activity.setHandlesSwipeForView(this, mStartTouchY); + activity.setHandlesSwipeForView(this, mStartTouchX, mStartTouchY); } } return true; -- 2.11.0