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;
private boolean mHandlingSwipeButton = false;
private View mHandledSwipeView = null;
private float mHandledSwipeViewLastDelta = 0;
+ private float mSwipeStartX = 0;
private float mSwipeStartY = 0;
private ProcessingService mBoundService;
return mSelectedImageUri;
}
- public void setHandlesSwipeForView(View view, float startY) {
+ public void setHandlesSwipeForView(View view, float startX, float startY) {
if (view != null) {
mHandlingSwipeButton = true;
} else {
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();
}
}
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;
}
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;