Example usage for android.view MotionEvent ACTION_MASK

List of usage examples for android.view MotionEvent ACTION_MASK

Introduction

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

Prototype

int ACTION_MASK

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

Click Source Link

Document

Bit mask of the parts of the action code that are the action itself.

Usage

From source file:com.example.libwidgettv.bak.AbsListView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    View v;//from w w w.j  a v  a 2s  .  c  om

    if (mFastScroller != null) {
        boolean intercepted = mFastScroller.onInterceptTouchEvent(ev);
        if (intercepted) {
            return true;
        }
    }

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        int touchMode = mTouchMode;
        if (touchMode == TOUCH_MODE_OVERFLING || touchMode == TOUCH_MODE_OVERSCROLL) {
            mMotionCorrection = 0;
            return true;
        }

        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        mActivePointerId = ev.getPointerId(0);

        int motionPosition = findMotionRow(y);
        if (touchMode != TOUCH_MODE_FLING && motionPosition >= 0) {
            // User clicked on an actual view (and was not stopping a
            // fling).
            // Remember where the motion event started
            v = getChildAt(motionPosition - mFirstPosition);
            mMotionViewOriginalTop = v.getTop();
            mMotionX = x;
            mMotionY = y;
            mMotionPosition = motionPosition;
            mTouchMode = TOUCH_MODE_DOWN;
            clearScrollingCache();
        }
        mLastY = Integer.MIN_VALUE;
        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);
        if (touchMode == TOUCH_MODE_FLING) {
            return true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
            int pointerIndex = ev.findPointerIndex(mActivePointerId);
            if (pointerIndex == -1) {
                pointerIndex = 0;
                mActivePointerId = ev.getPointerId(pointerIndex);
            }
            final int y = (int) ev.getY(pointerIndex);
            initVelocityTrackerIfNotExists();
            mVelocityTracker.addMovement(ev);
            if (startScrollIfNeeded(y)) {
                return true;
            }
            break;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mTouchMode = TOUCH_MODE_REST;
        mActivePointerId = INVALID_POINTER;
        recycleVelocityTracker();
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        break;
    }
    }

    return false;
}

From source file:com.wb.launcher3.Page.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    mPointCount = ev.getPointerCount();//added by zxa 1018 for adjust brightness

    //Log.i("zwb", "zhangwuba ------ luancher dispatchTouchEvent");

    boolean enable = (Settings.Secure.getInt(mContext.getContentResolver(), "tyd_gesture_launcher", 1) == 1);
    boolean gesture = false;

    if (mPointCount == 2) {
        int x1 = (int) ev.getX(0);
        int y1 = (int) ev.getY(0);

        int x2 = (int) ev.getX(1);
        int y2 = (int) ev.getY(1);

        x1Down = x1;/*  w w w  .  j a v  a 2  s. com*/
        x2Down = x2;
        y1Down = y1;
        y2Down = y2;

        xyD = (int) FloatMath.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        //Log.i("zwb", "zhangwuba ------  xyD = " + xyD);
    }

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        //Log.i("xyz", "ACTION_DOWN");
        tempX = 0;
        tempY = 0;
        mOldY = ev.getY();
        mOldX = ev.getX();

        // mMode = DRAG;
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        mLastMultiDownDistance = getDistance(ev);
        //mMode = ZOOM;
        break;
    case MotionEvent.ACTION_UP:
        //added by zxa 1018 for multi touch panel  adjust screen light  start
        if (enable) {
            closebrightnessDialog();
        }
        //added by zxa 1018 for multi touch panel  adjust screen light  end
        //mMode = NONE;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        //added by zxa 1018 for multi touch panel  adjust screen light  start
        if (enable) {
            closebrightnessDialog();
        }
        //mMode = NONE;
        break;
    case MotionEvent.ACTION_MOVE:
        int scrollLength = xyD - temp;
        temp = xyD;
        if (enable && Math.abs(scrollLength) < 5 && y1Down != (int) mOldY) {
            adjustBrightness(ev, mPointCount);
        }
        /* if (mMode == ZOOM) {
        double currentLength = getDistance(ev);
        float length = (float) (currentLength - mLastMultiDownDistance);
        if (length < SHOW_WORKSPACE_PREVIEW_THRESHOLD) {
            onMultiZoomIn(length);
        } else {
            onMultiZoomOut(length);
        }
         }*/
        break;
    }

    /*  if (mMode == ZOOM) {
    return true;
      }*/

    return super.dispatchTouchEvent(ev);
}

From source file:com.appunite.list.AbsHorizontalListView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    View v;/*from   www .  j a  v  a 2  s  . co  m*/

    if (mPositionScroller != null) {
        mPositionScroller.stop();
    }

    if (!mIsAttached) {
        // Something isn't right.
        // Since we rely on being attached to get data set change notifications,
        // don't risk doing anything where we might try to resync and find things
        // in a bogus state.
        return false;
    }

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        int touchMode = mTouchMode;
        if (touchMode == TOUCH_MODE_OVERFLING || touchMode == TOUCH_MODE_OVERSCROLL) {
            mMotionCorrection = 0;
            return true;
        }

        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        mActivePointerId = ev.getPointerId(0);

        int motionPosition = findMotionCol(x);
        if (touchMode != TOUCH_MODE_FLING && motionPosition >= 0) {
            // User clicked on an actual view (and was not stopping a fling).
            // Remember where the motion event started
            v = getChildAt(motionPosition - mFirstPosition);
            mMotionViewOriginalLeft = v.getLeft();
            mMotionX = x;
            mMotionY = y;
            mMotionPosition = motionPosition;
            mTouchMode = TOUCH_MODE_DOWN;
            clearScrollingCache();
        }
        mLastX = Integer.MIN_VALUE;
        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);
        if (touchMode == TOUCH_MODE_FLING) {
            return true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
            int pointerIndex = ev.findPointerIndex(mActivePointerId);
            if (pointerIndex == -1) {
                pointerIndex = 0;
                mActivePointerId = ev.getPointerId(pointerIndex);
            }
            final int x = (int) ev.getX(pointerIndex);
            initVelocityTrackerIfNotExists();
            mVelocityTracker.addMovement(ev);
            if (startScrollIfNeeded(x)) {
                return true;
            }
            break;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mTouchMode = TOUCH_MODE_REST;
        mActivePointerId = INVALID_POINTER;
        recycleVelocityTracker();
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        break;
    }
    }

    return false;
}

From source file:com.appunite.list.AbsListView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    View v;/*from  w w  w  .ja va 2 s. c o  m*/

    if (mPositionScroller != null) {
        mPositionScroller.stop();
    }

    if (!mIsAttached) {
        // Something isn't right.
        // Since we rely on being attached to get data set change notifications,
        // don't risk doing anything where we might try to resync and find things
        // in a bogus state.
        return false;
    }

    if (mFastScroller != null) {
        boolean intercepted = mFastScroller.onInterceptTouchEvent(ev);
        if (intercepted) {
            return true;
        }
    }

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        int touchMode = mTouchMode;
        if (touchMode == TOUCH_MODE_OVERFLING || touchMode == TOUCH_MODE_OVERSCROLL) {
            mMotionCorrection = 0;
            return true;
        }

        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        mActivePointerId = ev.getPointerId(0);

        int motionPosition = findMotionRow(y);
        if (touchMode != TOUCH_MODE_FLING && motionPosition >= 0) {
            // User clicked on an actual view (and was not stopping a fling).
            // Remember where the motion event started
            v = getChildAt(motionPosition - mFirstPosition);
            mMotionViewOriginalTop = v.getTop();
            mMotionX = x;
            mMotionY = y;
            mMotionPosition = motionPosition;
            mTouchMode = TOUCH_MODE_DOWN;
            clearScrollingCache();
        }
        mLastY = Integer.MIN_VALUE;
        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);
        if (touchMode == TOUCH_MODE_FLING) {
            return true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
            int pointerIndex = ev.findPointerIndex(mActivePointerId);
            if (pointerIndex == -1) {
                pointerIndex = 0;
                mActivePointerId = ev.getPointerId(pointerIndex);
            }
            final int y = (int) ev.getY(pointerIndex);
            initVelocityTrackerIfNotExists();
            mVelocityTracker.addMovement(ev);
            if (startScrollIfNeeded(y)) {
                return true;
            }
            break;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mTouchMode = TOUCH_MODE_REST;
        mActivePointerId = INVALID_POINTER;
        recycleVelocityTracker();
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        break;
    }
    }

    return false;
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

private void createClickableSearch() {
    new Handler().postDelayed(new Runnable() {
        @Override/*from  w  ww .j ava  2  s .co m*/
        public void run() {
            FrameLayout content = (FrameLayout) findViewById(R.id.search_dummy);

            View search = new View(Launcher.this);

            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    mQsb.getHeight());
            params.topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 28,
                    getResources().getDisplayMetrics());

            search.setLayoutParams(params);

            search.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (!disableSearch()) {
                        if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
                            v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                        }
                    }

                    return disableSearch();
                }
            });
            search.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    startSearch("", false, new Bundle(), new Rect());
                }
            });

            content.addView(search);
        }
    }, 1000);

}

From source file:xyz.klinker.blur.launcher3.Launcher.java

private void createClickableSearch(final int tryNumber) {
    new Handler().postDelayed(new Runnable() {
        @Override/*from   w ww  . j  a  v  a 2  s  .c  o  m*/
        public void run() {
            FrameLayout content = (FrameLayout) findViewById(R.id.search_dummy);

            View search = new View(Launcher.this);

            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    mQsb.getHeight());
            params.topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 28,
                    getResources().getDisplayMetrics());

            search.setLayoutParams(params);

            search.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (!disableSearch()) {
                        if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
                            v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                        }
                    }

                    return disableSearch();
                }
            });
            search.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    showGlobalSearchOverlay();
                    //startSearch("", false, new Bundle(), new Rect());
                }
            });

            try {
                content.addView(search);
            } catch (Exception e) {
                if (tryNumber <= 3) {
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            createClickableSearch(tryNumber + 1);
                        }
                    }, 2000);
                }
            }
        }
    }, 1000);

}