Example usage for android.view MotionEvent ACTION_UP

List of usage examples for android.view MotionEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

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

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.

Usage

From source file:Main.java

public static void setOnTouchScaleAnimation(View targetView, final float scaleX, final float scaleY) {
    targetView.setOnTouchListener(new View.OnTouchListener() {
        @Override/* w ww  .  jav a2 s . c o m*/
        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;
        }
    });
}

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";
    }/*from w  w w .j a  va  2s  .  co m*/
    return "unknown action event";
}

From source file:Main.java

public static void setTextWithLinks(TextView textView, String htmlText) {
    setHtmlText(textView, htmlText);//from ww  w  . j  av  a  2  s  . co m
    textView.setOnTouchListener((v, event) -> {
        int action = event.getAction();
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
            int x = (int) event.getX();
            int y = (int) event.getY();

            TextView widget = (TextView) v;
            x -= widget.getTotalPaddingLeft();
            y -= widget.getTotalPaddingTop();

            x += widget.getScrollX();
            y += widget.getScrollY();

            Layout layout = widget.getLayout();
            int line = layout.getLineForVertical(y);
            int off = layout.getOffsetForHorizontal(line, x);

            ClickableSpan[] link = Spannable.Factory.getInstance().newSpannable(widget.getText()).getSpans(off,
                    off, ClickableSpan.class);

            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP) {
                    link[0].onClick(widget);
                }
                return true;
            }
        }
        return false;
    });
}

From source file:Main.java

public static void dispatchTouch(final View view, final long duration) {
    final long downTime = SystemClock.uptimeMillis();
    final long eventTime = SystemClock.uptimeMillis();
    final float x = view.getWidth() / 3;//0.0f;
    final float y = view.getHeight() / 3;//0.0f;
    // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
    final int metaState = 0;
    MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, metaState);

    // Dispatch touch event to view
    view.dispatchTouchEvent(motionEvent);

    new Handler().postDelayed(new Runnable() {
        @Override//from   w  w  w .  j a  va2  s. c  o  m
        public void run() {
            MotionEvent motionEvent = MotionEvent.obtain(downTime + duration, eventTime + duration,
                    MotionEvent.ACTION_UP, x, y, metaState);
            view.dispatchTouchEvent(motionEvent);
        }
    }, duration);
}

From source file:Main.java

public static void makeListViewWorkableInScollView(ListView lv) {
    lv.setOnTouchListener(new ListView.OnTouchListener() {

        @Override/*from  ww  w.j a  v a  2 s . com*/
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }

            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });
}

From source file:Main.java

/**
 * Gets the name of an action.// w  w w  .  j  a v a 2s  .  co 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 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;
            }/*ww w . ja  v a2 s  . co  m*/

            return false;
        }
    });
}

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 w  w .j a v a  2  s.  c om
        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

/**
 * push View ScaleAnimation//w  w  w .  j a  v a  2  s  . com
 *
 * @param targetView TargetView
 * @param action     MotionEventAction
 * @param scaleX
 * @param scaleY
 */
private static void pushScale(View targetView, int action, float scaleX, float scaleY) {
    if (action == MotionEvent.ACTION_DOWN) {
        // Touch Down
        ScaleAnimation anim = new ScaleAnimation(1.0f, scaleX, 1.0f, scaleY, targetView.getWidth() / 2,
                targetView.getHeight() / 2);
        anim.setDuration(DURATION);
        anim.setFillEnabled(true);
        anim.setFillAfter(true);
        targetView.startAnimation(anim);
    } else if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Touch Up
        ScaleAnimation anim = new ScaleAnimation(scaleX, 1.0f, scaleY, 1.0f, targetView.getWidth() / 2,
                targetView.getHeight() / 2);
        anim.setDuration(DURATION);
        anim.setFillEnabled(true);
        anim.setFillAfter(true);
        targetView.startAnimation(anim);
    }
}

From source file:projects.oss2015.cs.fundookid.Shoes.java

public boolean onTouchEvent(MotionEvent touchevent) {
    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        x1 = touchevent.getX();/*from ww  w  .  ja v a 2  s .co m*/
        y1 = touchevent.getY();
        break;
    }
    case MotionEvent.ACTION_UP: {
        x2 = touchevent.getX();
        y2 = touchevent.getY();

        //if left to right swipe event on screen
        if (x1 < x2) {
            if (mpCheer.isPlaying())
                mpCheer.stop();
            Intent i = new Intent(this, Colors.class);
            startActivity(i);
        }

        //if right to left swipe event on screen
        if (x1 > x2) {
            if (mpCheer.isPlaying())
                mpCheer.stop();
            Intent i = new Intent(this, Coat.class);
            startActivity(i);
        }

        break;
    }
    }
    return false;
}