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:com.dycody.android.idealnote.ListFragment.java

@Override
public void onViewTouchOccurred(MotionEvent ev) {
    Log.v(Constants.TAG, "Notes list: onViewTouchOccurred " + ev.getAction());
    commitPending();/*w  w  w  .j a va 2s  .co  m*/
}

From source file:com.androzic.vnspeech.MapFragment.java

@SuppressLint("ClickableViewAccessibility")
@Override/*from ww  w.j av  a2s .c o m*/
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        zoom100X = (int) event.getRawX();
        zoom100Y = (int) event.getRawY();
        zoomHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                zoom100X = 0;
                zoom100Y = 0;
            }
        }, 2000);
        break;
    case MotionEvent.ACTION_UP:
        int dx = Math.abs((int) event.getRawX() - zoom100X);
        int dy = (int) event.getRawY() - zoom100Y;
        int h = v.getHeight();
        int w = v.getWidth() >> 1;
        if (dy > h * 0.8 && dy < h * 2 && dx < w) {
            wait(new Waitable() {
                @Override
                public void waitFor() {
                    application.setZoom(1.);
                }
            });
            zoom100X = 0;
            zoom100Y = 0;
        }
        break;
    }
    return false;
}

From source file:cl.monsoon.s1next.widget.PhotoView.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    if (scaleGestureDetector == null || mGestureDetector == null) {
        // We're being destroyed; ignore any touch events
        return true;
    }//from  w w w .j  a  v  a 2 s. c om

    scaleGestureDetector.onTouchEvent(event);
    mGestureDetector.onTouchEvent(event);

    final int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (!mTranslateRunnable.mRunning) {
            snap();
        }

        break;
    }

    return true;
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
public boolean onTouchEvent(MotionEvent me) {
    try {//from  w ww  .j a v a 2s. c om
        killOnError(); // ?  ?

        //  ? x, y  
        float xPress = me.getX();
        float yPress = me.getY();

        // ?? ??  ?? ? ?? 
        if (me.getAction() == MotionEvent.ACTION_UP) {
            dataView.clickEvent(xPress, yPress);
        }

        return true;

    } catch (Exception ex) { //  
        //doError(ex);
        ex.printStackTrace();
        return super.onTouchEvent(me);
    }
}

From source file:com.scigames.registration.LoginActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    View v = getCurrentFocus();//from   www  .  j  a va  2 s  .c  o m
    Log.d(TAG, "CLICK DETECTED");
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    //        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
    //        v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    //        Window win = this.getWindow(); // in Activity's onCreate() for instance
    //        win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    //                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    boolean ret = super.dispatchTouchEvent(event);

    if (v instanceof EditText) {
        View w = getCurrentFocus();
        int scrcoords[] = new int[2];
        w.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + w.getLeft() - scrcoords[0];
        float y = event.getRawY() + w.getTop() - scrcoords[1];

        Log.d("Activity",
                "Touch event " + event.getRawX() + "," + event.getRawY() + " " + x + "," + y + " rect "
                        + w.getLeft() + "," + w.getTop() + "," + w.getRight() + "," + w.getBottom() + " coords "
                        + scrcoords[0] + "," + scrcoords[1]);
        if (event.getAction() == MotionEvent.ACTION_UP
                && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) {

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }
    }
    return ret;

}

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mCanSlide) {
        return super.onTouchEvent(ev);
    }//from   ww w  . j  a  va2  s. co m

    mDragHelper.processTouchEvent(ev);

    final int action = ev.getAction();
    boolean wantTouchEvents = true;

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (isDimmed(mSlideableView)) {
            final float x = ev.getX();
            final float y = ev.getY();
            final float dx = x - mInitialMotionX;
            final float dy = y - mInitialMotionY;
            final int slop = mDragHelper.getTouchSlop();
            if (dx * dx + dy * dy < slop * slop && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) {
                // Taps close a dimmed open pane.
                closePane(mSlideableView, 0);
                break;
            }
        }
        break;
    }
    }

    return wantTouchEvents;
}

From source file:com.android.volley.ui.PhotoView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mScaleGetureDetector == null || mGestureDetector == null) {
        // We're being destroyed; ignore any touch events
        return true;
    }// w w  w.j  a  va2  s  .c o m

    mScaleGetureDetector.onTouchEvent(event);
    mGestureDetector.onTouchEvent(event);
    final int action = event.getAction();

    switch (action) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (!mTranslateRunnable.mRunning) {
            snap();
        }
        break;
    }

    return true;
}

From source file:com.aidy.bottomdrawerlayout.DrawerLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    Log.i(TAG, "onTouchEvent()");
    mLeftDragger.processTouchEvent(ev);/*  w w w .j a va2 s.  c o  m*/
    mRightDragger.processTouchEvent(ev);

    final int action = ev.getAction();
    boolean wantTouchEvents = true;

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        Log.i(TAG, "onTouchEvent() -- ACTION_DOWN");
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }

    case MotionEvent.ACTION_UP: {
        Log.i(TAG, "onTouchEvent() -- ACTION_UP");
        final float x = ev.getX();
        final float y = ev.getY();
        boolean peekingOnly = true;
        final View touchedView = mLeftDragger.findTopChildUnder((int) x, (int) y);
        if (touchedView != null && isContentView(touchedView)) {
            final float dx = x - mInitialMotionX;
            final float dy = y - mInitialMotionY;
            final int slop = mLeftDragger.getTouchSlop();
            if (dx * dx + dy * dy < slop * slop) {
                // Taps close a dimmed open drawer but only if it isn't
                // locked open.
                final View openDrawer = findOpenDrawer();
                if (openDrawer != null) {
                    peekingOnly = getDrawerLockMode(openDrawer) == LOCK_MODE_LOCKED_OPEN;
                }
            }
        }
        closeDrawers(peekingOnly);
        mDisallowInterceptRequested = false;
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        Log.i(TAG, "onTouchEvent() -- ACTION_CANCEL");
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }
    }

    boolean result = wantTouchEvents;
    Log.i(TAG, "onTouchEvent() -- result = " + result);
    return result;
}

From source file:androidx.media.widget.VideoView2.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (DEBUG) {/*from ww w .j  ava 2 s.com*/
        Log.d(TAG, "onTouchEvent(). mCurrentState=" + mCurrentState + ", mTargetState=" + mTargetState);
    }
    if (ev.getAction() == MotionEvent.ACTION_UP && mMediaControlView != null) {
        if (!mIsMusicMediaType || mSizeType != SIZE_TYPE_FULL) {
            toggleMediaControlViewVisibility();
        }
    }

    return super.onTouchEvent(ev);
}

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction()
            & MotionEventCompat.ACTION_POINTER_INDEX_MASK) >> MotionEventCompat.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        // TODO: Make this decision more intelligent.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionY = (int) MotionEventCompat.getY(ev, newPointerIndex);
        mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();//from ww  w.  j a  v  a  2  s  .  co  m
        }
    }
}