Example usage for android.view MotionEvent getAction

List of usage examples for android.view MotionEvent getAction

Introduction

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

Prototype

public final int getAction() 

Source Link

Document

Return the kind of action being performed.

Usage

From source file:Main.java

/**
 * View Scale Animation/*from   w w w .  j av a  2  s .c  o m*/
 * <p/>
 * Scale value {@link AnimUtils#SCALE}
 *
 * @param targetView
 */
public static void pushScaleAnimation(View targetView) {
    targetView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            pushScale(v, event.getAction(), SCALE, SCALE);
            return false;
        }
    });
}

From source file:Main.java

/**
 * View Scale Animation/* www  . j a  v  a2 s  . c om*/
 *
 * @param targetView
 * @param scaleX     toScaleX and fromScaleX
 * @param scaleY     toScaleY and fromScaleY
 */
public static void pushScaleAnimation(View targetView, final float scaleX, final float scaleY) {
    targetView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            pushScale(v, event.getAction(), scaleX, scaleY);
            return false;
        }
    });
}

From source file:Main.java

public static void handleAutoCloseKeyboard(boolean isAutoCloseKeyboard, View currentFocusView,
        MotionEvent motionEvent, Object dialogOrActivity) {
    if (isAutoCloseKeyboard && motionEvent.getAction() == MotionEvent.ACTION_DOWN && currentFocusView != null
            && (currentFocusView instanceof EditText) && dialogOrActivity != null) {
        int[] leftTop = { 0, 0 };
        currentFocusView.getLocationInWindow(leftTop);
        int left = leftTop[0];
        int top = leftTop[1];
        int bottom = top + currentFocusView.getHeight();
        int right = left + currentFocusView.getWidth();
        if (!(motionEvent.getX() > left && motionEvent.getX() < right && motionEvent.getY() > top
                && motionEvent.getY() < bottom)) {
            if (dialogOrActivity instanceof Dialog) {
                closeKeyboard((Dialog) dialogOrActivity);
            } else if (dialogOrActivity instanceof Activity) {
                closeKeyboard((Activity) dialogOrActivity);
            }// w w w. j a v a  2  s  .c o  m
        }
    }
}

From source file:Main.java

private static MotionEvent transformEventOld(MotionEvent e, Matrix m) {
    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();

    // Copy the x and y coordinates into an array, map them, and copy back.
    float[] xy = new float[pointerCoords.length * 2];
    for (int i = 0; i < pointerCount; i++) {
        xy[2 * i] = pointerCoords[i].x;//from w w w . j  a v a2s .co  m
        xy[2 * i + 1] = pointerCoords[i].y;
    }
    m.mapPoints(xy);
    for (int i = 0; i < pointerCount; i++) {
        pointerCoords[i].x = xy[2 * i];
        pointerCoords[i].y = xy[2 * i + 1];
        pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation);
    }

    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords,
            metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags);

    return n;
}

From source file:Main.java

private static MotionEvent transformEventOld(MotionEvent e, Matrix m) {
    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();
    // Copy the x and y coordinates into an array, map them, and copy back.
    float[] xy = new float[pointerCoords.length * 2];
    for (int i = 0; i < pointerCount; i++) {
        xy[2 * i] = pointerCoords[i].x;/*w  w  w . j  av  a 2 s. com*/
        xy[2 * i + 1] = pointerCoords[i].y;
    }
    m.mapPoints(xy);
    for (int i = 0; i < pointerCount; i++) {
        pointerCoords[i].x = xy[2 * i];
        pointerCoords[i].y = xy[2 * i + 1];
        pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation);
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords,
            metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}

From source file:Main.java

public static JSONObject CreateJSonObjectFromMotionEvent(MotionEvent e) throws JSONException {
    JSONObject jObj = new JSONObject();
    jObj.put("downTime", e.getDownTime());
    jObj.put("eventTime", e.getEventTime());
    jObj.put("action", e.getAction());
    jObj.put("pointerCount", e.getPointerCount());
    jObj.put("metaState", e.getMetaState());
    jObj.put("buttonState", e.getButtonState());
    jObj.put("xPrecision", e.getXPrecision());
    jObj.put("yPrecision", e.getYPrecision());
    jObj.put("deviceId", e.getDeviceId());
    jObj.put("edgeFlags", e.getEdgeFlags());
    jObj.put("source", e.getSource());
    jObj.put("flags", e.getFlags());

    for (int i = 0; i < e.getPointerCount(); i++) {
        PointerProperties prop = new PointerProperties();
        e.getPointerProperties(i, prop);

        PointerCoords coords = new PointerCoords();
        e.getPointerCoords(i, coords);//from www  .j  a v a  2s.c  om

        JSONObject pointer = JObjFromPointer(prop, coords);
        jObj.accumulate("pointers", pointer);
    }

    return jObj;
}

From source file:Main.java

public static void setOnTouchBackgroundEffect(View view) {
    view.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (!(v.getBackground() instanceof TransitionDrawable))
                return false;

            TransitionDrawable transition = (TransitionDrawable) v.getBackground();

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                transition.startTransition(500);
                break;
            case MotionEvent.ACTION_HOVER_EXIT:
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                transition.reverseTransition(500);
                break;
            }/*w ww.j  a  v  a 2 s .  c o  m*/

            return false;
        }
    });
}

From source file:Main.java

public static void inspectEvent(MotionEvent e) {
    if (e == null)
        return;//from  w ww  .j  a v  a  2 s. co m

    final int pointerCount = e.getPointerCount();

    Log.d(TAG, "Input: event time: " + e.getEventTime());
    for (int p = 0; p < pointerCount; p++) {
        Log.d(TAG, "Input:  pointer:" + e.getPointerId(p) + " x:" + e.getX(p) + " y:" + e.getY(p) + " action:"
                + e.getAction());
    }
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

public static void setClearAction(final EditText target) {
    target.setOnTouchListener(new View.OnTouchListener() {
        final int RIGHT = 2;

        @Override//from w w w.  ja  v  a2s  .  c  o m
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                int leftEdgeOfRightDrawable = view.getRight()
                        - target.getCompoundDrawables()[RIGHT].getBounds().width();
                // when EditBox has padding, adjust leftEdge like
                // leftEdgeOfRightDrawable -= getResources().getDimension(R.dimen.edittext_padding_left_right);
                if (event.getRawX() >= leftEdgeOfRightDrawable) {
                    // clicked on clear icon
                    target.setText("");
                    target.clearFocus();
                    return false;
                }
            }
            return false;
        }
    });
}

From source file:Main.java

public static MotionEvent hoverMotionEventAtPosition(View view, int action, int xPercent, int yPercent) {
    MotionEvent ev = motionEventAtPosition(view, action, xPercent, yPercent);

    MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[1];
    pointerProperties[0] = new MotionEvent.PointerProperties();

    MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1];
    pointerCoords[0] = new MotionEvent.PointerCoords();
    pointerCoords[0].x = ev.getX();/*from   w  w  w. j a  va2 s  .  c  om*/
    pointerCoords[0].y = ev.getY();

    return MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), 1, pointerProperties,
            pointerCoords, ev.getMetaState(), 0, ev.getXPrecision(), ev.getYPrecision(), ev.getDeviceId(),
            ev.getEdgeFlags(), InputDevice.SOURCE_CLASS_POINTER, ev.getFlags());
}