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: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 v  a  2 s .  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);//  w  ww .  j a  va2s .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: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;/* w  w w  .  j a v a2 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:cn.limc.androidcharts.event.SlipGestureDetector.java

public boolean onTouchEvent(MotionEvent event) {
    int pointers = event.getPointerCount();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // ?//  w w  w. j  a v  a  2s .  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.  ja  v a 2 s .c  om*/
        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.edu.zafu.easemob.CoverFlowLib.VelocityViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    // give all the events to the gesture detector. I'm returning true here so the viewpager doesn't
    // get any events at all, I'm sure you could adjust this to make that not true.
    mGestureDetector.onTouchEvent(event);

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        downX = event.getX();/*ww  w  .  j  a v a 2s .  c o m*/
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        onUp(event.getX() - downX);
    }
    return true;
}

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;//  w ww  . j a  v  a2s. 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: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 va 2 s . co m*/

    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:cn.kylinhuang.play.view.CommonGestures.java

public boolean onTouchEvent(MotionEvent event) {
    if (mListener == null)
        return false;

    if (null == event)
        return false;

    if (mTapGestureDetector.onTouchEvent(event))
        return true;

    if (event.getPointerCount() > 1) {
        try {//ww  w  .  j  av  a  2s  .c o  m
            if (mScaleDetector != null && mScaleDetector.onTouchEvent(event))
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if (mDoubleTapGestureDetector.onTouchEvent(event))
        return true;

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        mListener.onGestureEnd();
        break;
    }

    return true;
}

From source file:com.ppdl.microphone.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    sp.edit().remove(Constant.EXTRA_INFILE).commit(); // infile?PCM?????

    Button recordButton = (Button) findViewById(R.id.buttonRecord);
    recordButton.setOnTouchListener(new View.OnTouchListener() {

        @Override/*from w  w w  .  j  a v  a 2  s. c  om*/
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                startRecording();
                Toast.makeText(MainActivity.this, "Start Recording", Toast.LENGTH_SHORT).show();
                break;

            case MotionEvent.ACTION_UP:
                stopRecording();
                v.performClick();
                Toast.makeText(MainActivity.this, "Stop Recording", Toast.LENGTH_SHORT).show();
                break;

            default:
                break;
            }
            return false;
        }
    });

    Button playButton = (Button) findViewById(R.id.buttonPlay);
    playButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startPlaying();
        }
    });

    Button stopButton = (Button) findViewById(R.id.buttonStop);
    stopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            stopPlaying();
        }
    });

    Button recognizeButton = (Button) findViewById(R.id.buttonRecognize);
    recognizeButton.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Toast.makeText(MainActivity.this, "Start Recognizing", Toast.LENGTH_SHORT).show();
                speechRecognizer.cancel();
                Intent intent = new Intent();
                bindParams(intent);
                intent.putExtra("vad", "touch");
                speechRecognizer.startListening(intent);
                break;

            case MotionEvent.ACTION_UP:
                v.performClick();
                Toast.makeText(MainActivity.this, "Stop Recognizing", Toast.LENGTH_SHORT).show();
                speechRecognizer.stopListening();
                break;

            default:
                break;
            }
            return false;
        }
    });

    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));
    speechRecognizer.setRecognitionListener(mRecognitionListner);
}