Example usage for android.view MotionEvent ACTION_MOVE

List of usage examples for android.view MotionEvent ACTION_MOVE

Introduction

In this page you can find the example usage for android.view MotionEvent ACTION_MOVE.

Prototype

int ACTION_MOVE

To view the source code for android.view MotionEvent ACTION_MOVE.

Click Source Link

Document

Constant for #getActionMasked : A change has happened during a press gesture (between #ACTION_DOWN and #ACTION_UP ).

Usage

From source file:Main.java

public static String eventToString(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        return "DOWN";
    case MotionEvent.ACTION_MOVE:
        return "MOVE";
    case MotionEvent.ACTION_UP:
        return "UP";
    case MotionEvent.ACTION_CANCEL:
        return "CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "OUTSIDE";
    case MotionEvent.ACTION_POINTER_DOWN:
        return "POINTER DOWN";
    case MotionEvent.ACTION_POINTER_UP:
        return "POINTER UP";
    }//w w  w .  j a v a 2 s .c  o m
    return "UNKNOWN";
}

From source file:Main.java

public static String getTouchAction(int actionId) {
    String actionName = "Unknow:id=" + actionId;
    switch (actionId) {
    case MotionEvent.ACTION_DOWN:
        actionName = "ACTION_DOWN";
        break;/*from  w ww . j  av  a 2 s  .  com*/
    case MotionEvent.ACTION_MOVE:
        actionName = "ACTION_MOVE";
        break;
    case MotionEvent.ACTION_UP:
        actionName = "ACTION_UP";
        break;
    case MotionEvent.ACTION_CANCEL:
        actionName = "ACTION_CANCEL";
        break;
    case MotionEvent.ACTION_OUTSIDE:
        actionName = "ACTION_OUTSIDE";
        break;
    }
    return actionName;
}

From source file:Main.java

public static String getActionName(int action) {
    String actionName = "";
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        actionName = "ACTION_DOWN";
        break;//from  w w w  .  j a  v  a  2s.c om
    case MotionEvent.ACTION_MOVE:
        actionName = "ACTION_MOVE";
        break;
    case MotionEvent.ACTION_UP:
        actionName = "ACTION_UP";
        break;
    }
    return actionName;
}

From source file:Main.java

public static void addTouchFeedback(final ImageView view) {
    view.setOnTouchListener(new View.OnTouchListener() {
        private Rect rect;

        @Override/*  ww  w.j  a  v a  2  s  .  co m*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                view.setColorFilter(Color.argb(50, 0, 0, 0));
                rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
                view.setColorFilter(Color.argb(0, 0, 0, 0));
            }
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                if (!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())) {
                    view.setColorFilter(Color.argb(0, 0, 0, 0));
                }
            }
            return false;
        }
    });
}

From source file:Main.java

public static String getMotionEventString(int action) {
    switch (action) {
    case (MotionEvent.ACTION_DOWN):
        return "action_down";
    case (MotionEvent.ACTION_UP):
        return "action_down";
    case (MotionEvent.ACTION_CANCEL):
        return "action_down";
    case (MotionEvent.ACTION_MOVE):
        return "action_move";
    case (MotionEvent.ACTION_OUTSIDE):
        return "action_outside";
    case (MotionEvent.ACTION_HOVER_ENTER):
        return "action_hover_enter";
    case (MotionEvent.ACTION_HOVER_EXIT):
        return "action_hover_exit";
    case (MotionEvent.ACTION_HOVER_MOVE):
        return "action_hover_move";
    case (MotionEvent.ACTION_MASK):
        return "action_mask";
    }//w ww .  ja v a  2  s.c o m
    return "unknown action event";
}

From source file:Main.java

/**
 * Gets the name of an action./*  www  .j a  va2  s.c o  m*/
 * 
 * @param action        The action being performed.
 * @param isMotionEvent Whether or not the action is a motion event.
 * 
 * @return The name of the action being performed.
 */
public static String getActionName(int action, boolean isMotionEvent) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        return "DOWN";
    case MotionEvent.ACTION_UP:
        return "UP";
    case MotionEvent.ACTION_MOVE:
        return isMotionEvent ? "MOVE" : "MULTIPLE";
    case MotionEvent.ACTION_CANCEL:
        return "CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "OUTSIDE";
    case MotionEvent.ACTION_POINTER_DOWN:
        return "POINTER_DOWN";
    case MotionEvent.ACTION_POINTER_UP:
        return "POINTER_UP";
    case MotionEvent.ACTION_HOVER_MOVE:
        return "HOVER_MOVE";
    case MotionEvent.ACTION_SCROLL:
        return "SCROLL";
    case MotionEvent.ACTION_HOVER_ENTER:
        return "HOVER_ENTER";
    case MotionEvent.ACTION_HOVER_EXIT:
        return "HOVER_EXIT";
    default:
        return "ACTION_" + Integer.toString(action);
    }
}

From source file:Main.java

public static List<MotionEvent> createMotionEvents(final AbsListView absListView, final float fromY,
        final float toY) {
    int x = (int) (absListView.getX() + absListView.getWidth() / 2);

    List<MotionEvent> results = new ArrayList<>();
    results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
            MotionEvent.ACTION_DOWN, x, fromY, 0));

    float diff = (toY - fromY) / 25;
    float y = fromY;
    for (int i = 0; i < 25; i++) {
        y += diff;/*from w ww .  jav  a2 s.  c  o  m*/
        results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                MotionEvent.ACTION_MOVE, x, y, 0));
    }
    results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
            MotionEvent.ACTION_UP, x, toY, 0));

    return results;
}

From source file:Main.java

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null)
        return;//from  ww w. j  a  va 2s .c o  m

    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
    int totalHeight = 0;
    View view = null;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        view = listAdapter.getView(i, view, listView);
        if (i == 0)
            view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));

        view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += view.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();

    listView.setOnTouchListener(new View.OnTouchListener() {
        // Setting on Touch Listener for handling the touch inside ScrollView
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                return true; // Indicates that this has been handled by you and will not be forwarded further.
            }
            return false;
        }
    });
}

From source file:Main.java

private static void dragTo(View view, float fromX, float toX, float fromY, float toY, int stepCount,
        long downTime) {
    float x = fromX;
    float y = fromY;
    float yStep = (toY - fromY) / stepCount;
    float xStep = (toX - fromX) / stepCount;
    for (int i = 0; i < stepCount; ++i) {
        y += yStep;//from   w w  w. ja  v a2s.c o  m
        x += xStep;
        sendAction(view, MotionEvent.ACTION_MOVE, downTime, x, y);
    }
}

From source file:com.akingyin.librarys.widgets.XSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        xDistance = yDistance = 0f;/*from w  w  w .  j  av a  2  s. c o m*/
        xLast = ev.getX();
        yLast = ev.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        final float curX = ev.getX();
        final float curY = ev.getY();

        xDistance += Math.abs(curX - xLast);
        yDistance += Math.abs(curY - yLast);
        xLast = curX;
        yLast = curY;

        if (xDistance > yDistance) {
            return false;
        }
    }

    return super.onInterceptTouchEvent(ev);
}