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:com.androidexperiments.tunnelvision.SplashScreenActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splashscreen);

    ButterKnife.inject(this);

    mSplashVideo.setOnTouchListener(new View.OnTouchListener() {

        @Override//from   w  w w  .j a va  2s.  com
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                moveToMainActivity();
            }
            return true;
        }
    });

}

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

public boolean onTouchEvent(MotionEvent touchevent) {
    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        x1 = touchevent.getX();/* w  w w  .  ja  v a  2s.c o 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;
}

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.  ja  va  2s . c  om
        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);
}

From source file:cardstream.CardActionButton.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        setPressed(true);//  w  w w .  ja va  2s . c  o  m
        Log.d("", "click");
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            animate().scaleX(0.98f).scaleY(0.98f).setDuration(100)
                    .setInterpolator(new DecelerateInterpolator());
        } else {
            ViewCompat.setElevation(this, 8.f);
        }
        break;
    }
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        setPressed(false);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            animate().scaleX(1.f).scaleY(1.f).setDuration(50).setInterpolator(new BounceInterpolator());
        } else {
            ViewCompat.setElevation(this, 0.f);
        }
        break;
    }
    }

    return super.onTouchEvent(event);
}

From source file:co.uk.aging.mabel.places.placepicker.cardstream.CardActionButton.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        setPressed(true);/*from ww w.j  a  va 2s  .co  m*/
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            animate().scaleX(0.98f).scaleY(0.98f).setDuration(100)
                    .setInterpolator(new DecelerateInterpolator());
        } else {
            ViewCompat.setElevation(this, 8.f);
        }
        break;
    }
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        setPressed(false);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            animate().scaleX(1.f).scaleY(1.f).setDuration(50).setInterpolator(new BounceInterpolator());
        } else {
            ViewCompat.setElevation(this, 0.f);
        }
        break;
    }
    }

    return super.onTouchEvent(event);
}

From source file:com.android.audiorecorder.gallery.widget.GalleryViewPager.java

private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;/*from   ww w  . j  a va 2s  .  c o  m*/
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:cn.limc.androidcharts.event.SlipGestureDetector.java

public boolean onTouchEvent(MotionEvent event) {
    int pointers = event.getPointerCount();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // ?//from ww  w .ja v  a2 s  .c  o  m
    case MotionEvent.ACTION_DOWN:
        initalX = event.getX();
        if (pointers > 1) {
            touchMode = TOUCH_MODE_MULTI;
        } else {
            touchMode = TOUCH_MODE_SINGLE;
        }
        break;
    case MotionEvent.ACTION_UP:
        startPointA = null;
        startPointB = null;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        startPointA = null;
        startPointB = null;
    case MotionEvent.ACTION_POINTER_DOWN:
        olddistance = calcDistance(event);
        if (olddistance > MIN_DISTANCE) {
            touchMode = TOUCH_MODE_MULTI;
            startPointA = new PointF(event.getX(0), event.getY(0));
            startPointB = new PointF(event.getX(1), event.getY(1));
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (touchMode == TOUCH_MODE_SINGLE) {
            final float finalX = event.getX();
            // MotionEvent finalEvent = event;
            if (performLongClick) {
                return super.onTouchEvent(event);
            } else {
                if (finalX - initalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveRight((ISlipable) instance, event);
                    }
                } else if (initalX - finalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveLeft((ISlipable) instance, event);
                    }
                }
                initalX = finalX;
                // initalEvent = finalEvent;
                return true;
            }
        } else if (touchMode == TOUCH_MODE_MULTI) {
            newdistance = calcDistance(event);
            if (Math.abs(newdistance - olddistance) > MIN_DISTANCE) {
                if (onZoomGestureListener != null) {
                    if (newdistance > olddistance) {
                        onZoomGestureListener.onZoomIn((IZoomable) instance, event);
                    } else {
                        onZoomGestureListener.onZoomOut((IZoomable) instance, event);
                    }
                }
            }
            olddistance = newdistance;
            return true;
            // startPointA = new PointF(event.getX(), event.getY());
            // startPointB = new PointF(event.getX(1), event.getY(1));
        }
        break;
    }
    return super.onTouchEvent(event);
}

From source file:net.hoodalabs.cordova.plugins.touchevent.HoodalabsTouchEvent.java

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
        throws JSONException {

    if ("fireAt".equals(action)) {

        final float x = args.getInt(0);
        final float y = args.getInt(1);

        // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
        final int metaState = 0;

        final long timestamp = SystemClock.uptimeMillis();

        MotionEvent touchStart = MotionEvent.obtain(timestamp, timestamp + 50, MotionEvent.ACTION_DOWN, x, y,
                metaState);//  w  ww. j  a v  a  2 s  . co  m
        touchStart.setSource(InputDevice.SOURCE_TOUCHSCREEN);

        webView.dispatchTouchEvent(touchStart);

        MotionEvent touchEnd = MotionEvent.obtain(timestamp + 50, timestamp + 100, MotionEvent.ACTION_UP, x, y,
                metaState);
        touchEnd.setSource(InputDevice.SOURCE_TOUCHSCREEN);

        webView.dispatchTouchEvent(touchEnd);

        callbackContext.success(); // Thread-safe.
        return true;
    }

    return false;
}

From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java

@TargetApi(Build.VERSION_CODES.ECLAIR)
private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;/*from w  w  w. j av a2 s.  c  om*/
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:cn.iotguard.GalleryWidget.GalleryViewPager.java

private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        ////from  w w  w. ja v  a  2 s  . com
        if (GalleryFileActivity.ll_dibumenu != null
                && GalleryFileActivity.ll_dibumenu.getVisibility() == View.GONE) {
            GalleryFileActivity.ll_dibumenu.setVisibility(View.VISIBLE);
        }
        if (Show_bigpic2.ll_dibumenu != null && Show_bigpic2.ll_dibumenu.getVisibility() == View.GONE) {
            Show_bigpic2.ll_dibumenu.setVisibility(View.VISIBLE);
        }

        //
        if (GalleryFileActivity.timeCount != null) {
            GalleryFileActivity.timeCount.cancel();
        }
        GalleryFileActivity.timeCount = new TimeCount_pic_dibu(Millis.pic_dibus, 1000);
        GalleryFileActivity.timeCount.start();
        System.out.println("pic    ");
        if (Show_bigpic2.timeCount != null) {
            Show_bigpic2.timeCount.cancel();
        }
        Show_bigpic2.timeCount = new TimeCount_pic_dibu_showbigpic2(Millis.pic_dibus, 1000);
        Show_bigpic2.timeCount.start();

        break;
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}