Example usage for android.view MotionEvent ACTION_DOWN

List of usage examples for android.view MotionEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

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

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has started, the motion contains the initial starting location.

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";
    }/*from   ww  w  . jav  a 2s.  c om*/
    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  a2s .  co m*/
    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 ww.ja va  2s. co  m
    case MotionEvent.ACTION_MOVE:
        actionName = "ACTION_MOVE";
        break;
    case MotionEvent.ACTION_UP:
        actionName = "ACTION_UP";
        break;
    }
    return actionName;
}

From source file:Main.java

private static long dragStart(View view, float x, float y) {
    long downTime = SystemClock.uptimeMillis();
    sendAction(view, MotionEvent.ACTION_DOWN, downTime, x, y);
    return downTime;
}

From source file:Main.java

public static void handleTouches(ImageView button) {
    button.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent m) {
            if (m.getAction() == MotionEvent.ACTION_DOWN) {
                darkenImage((ImageView) v);
            } else if (m.getAction() == MotionEvent.ACTION_UP) {
                ((ImageView) v).setColorFilter(null);
            }/*  ww w .j a  va  2  s . c o  m*/
            return false;
        }
    });
}

From source file:Main.java

public static void setViewTouchHightlighted(final View view) {
    if (view == null) {
        return;//from   ww  w  .j  a  v a 2  s .c om
    }

    view.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                view.setBackgroundColor(Color.rgb(1, 175, 244));
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                view.setBackgroundColor(Color.rgb(255, 255, 255));
            }
            return false;
        }
    });
}

From source file:Main.java

public static void setKeyboardFocus(final EditText mEditText) {
    (new Handler()).postDelayed(new Runnable() {
        public void run() {
            mEditText.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0));
            mEditText.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0));
        }/*from w  w  w.ja v a 2 s  .  c om*/
    }, 100);
}

From source file:Main.java

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

        @Override//w  ww .j a v a 2s.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

/**
 * inject a image touch overley//from www.jav  a  2s .  c om
 * @param v
 * @param event
 */
public static boolean imageOverlay(View v, MotionEvent event) {
    ImageView view = (ImageView) v;
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        // overlay is black with transparency of 0x77 (119)
        view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
        view.invalidate();
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        // clear the overlay
        view.getDrawable().clearColorFilter();
        view.invalidate();
        break;
    }
    }
    return false;
}

From source file:Main.java

public static void setOnTouchScaleAnimation(View targetView, final float scaleX, final float scaleY) {
    targetView.setOnTouchListener(new View.OnTouchListener() {
        @Override/*from  www  . j  a v  a 2  s.com*/
        public boolean onTouch(View v, MotionEvent event) {
            final int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN: {
                ScaleAnimation anim = new ScaleAnimation(1.0f, scaleX, 1.0f, scaleY, v.getWidth() / 2,
                        v.getHeight() / 2);
                anim.setDuration(60);
                anim.setFillEnabled(true);
                anim.setFillAfter(true);
                v.startAnimation(anim);
                break;
            }
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP: {
                ScaleAnimation anim = new ScaleAnimation(scaleX, 1.0f, scaleY, 1.0f, v.getWidth() / 2,
                        v.getHeight() / 2);
                anim.setDuration(100);
                v.startAnimation(anim);
                break;
            }
            }
            return false;
        }
    });
}