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: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 w  ww  . j a va2s  . 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:cardstream.CardActionButton.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        setPressed(true);//from w ww. j a v a  2 s . c  om
        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:com.akingyin.librarys.widgets.XSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        xDistance = yDistance = 0f;/*from   ww  w .  j av  a2s .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);
}

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//w w  w .j  a v  a2s  . c  o m
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                moveToMainActivity();
            }
            return true;
        }
    });

}

From source file:de.madvertise.android.sdk.MadvertiseImageView.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mImageAd.handleClick();//from  w  ww  .j  a v a2 s  . c o m
        return true;
    }
    return super.dispatchTouchEvent(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 w ww .  j a  v a 2 s  .  co 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:com.aprz.easy_iosched.ui.widget.MultiSwipeRefreshLayout.java

/**
 * @return false if the scrolled horizontal distance is bigger than the vertical one
 *///from w  ww  . j a v  a 2s. c om
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mStartGestureX = event.getX();
        mStartGestureY = event.getY();
        mHorizontalScrollDetected = false;
        break;

    case MotionEvent.ACTION_MOVE:
        mHorizontalScrollDetected = Math.abs(event.getX() - mStartGestureX) > Math
                .abs(event.getY() - mStartGestureY);
        if (mHorizontalScrollDetected) {
            return false;
        }
        break;
    }

    return super.onInterceptTouchEvent(event);
}

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

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onInterceptTouchEvent(event);
    }/*w w w  . jav  a 2  s.co  m*/

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        try {
            return super.onInterceptTouchEvent(event);
        } catch (Exception e) {
        }
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

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

@Override
public boolean onTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onTouchEvent(event);
    }/*from w w  w .j a  v a  2s  . c  om*/

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        try {
            return super.onTouchEvent(event);
        } catch (Exception e) {

        }
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onTouchEvent(event);
        }
    }

    return false;
}

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 . j a  v  a 2 s  . 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;
}