|
|
@@ -0,0 +1,67 @@
|
|
|
+package kr.co.zumo.app.lifeplus.view.screen.main;
|
|
|
+
|
|
|
+import android.view.MotionEvent;
|
|
|
+
|
|
|
+/**
|
|
|
+ * TouchEventWithDirection
|
|
|
+ * <pre>
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @author 하세미
|
|
|
+ * @version 1.0
|
|
|
+ * @history 하세미 [2018-12-13] [최초 작성]
|
|
|
+ * @since 2018-12-13
|
|
|
+ */
|
|
|
+public class TouchEventWithDirection {
|
|
|
+
|
|
|
+ public static final String DIRECTION_NONE = "none";
|
|
|
+ public static final String DIRECTION_UP = "up";
|
|
|
+ public static final String DIRECTION_DOWN = "down";
|
|
|
+ public static final String DIRECTION_RIGHT = "right";
|
|
|
+ public static final String DIRECTION_LEFT = "left";
|
|
|
+
|
|
|
+ private String direction;
|
|
|
+ private int oldX;
|
|
|
+ private int oldY;
|
|
|
+
|
|
|
+ public String getDirection(MotionEvent e) {
|
|
|
+ direction = DIRECTION_NONE;
|
|
|
+ int action = e.getAction();
|
|
|
+ switch (action) {
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
+ oldX = (int) e.getX();
|
|
|
+ oldY = (int) e.getY();
|
|
|
+ break;
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
+ int newX = (int) e.getX();
|
|
|
+ int newY = (int) e.getY();
|
|
|
+
|
|
|
+ int dx = oldX - newX;
|
|
|
+ int dy = oldY - newY;
|
|
|
+
|
|
|
+ // Use dx and dy to determine the direction of the move
|
|
|
+ if (Math.abs(dx) > Math.abs(dy)) {
|
|
|
+ if (dx > 0) {
|
|
|
+ direction = DIRECTION_RIGHT;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ direction = DIRECTION_LEFT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (dy > 0) {
|
|
|
+ direction = DIRECTION_DOWN;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ direction = DIRECTION_UP;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ // nothing
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return direction;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|