Example usage for android.support.v4.view MotionEventCompat ACTION_MASK

List of usage examples for android.support.v4.view MotionEventCompat ACTION_MASK

Introduction

In this page you can find the example usage for android.support.v4.view MotionEventCompat ACTION_MASK.

Prototype

int ACTION_MASK

To view the source code for android.support.v4.view MotionEventCompat ACTION_MASK.

Click Source Link

Document

Synonym for MotionEvent#ACTION_MASK .

Usage

From source file:Main.java

public static String byteToHexString(byte[] b) {
    StringBuffer hexString = new StringBuffer();
    for (byte b2 : b) {
        String hex = Integer.toHexString(b2 & MotionEventCompat.ACTION_MASK);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }/*  w w  w .jav  a2 s.  co  m*/
        hexString.append(hex.toLowerCase());
    }
    return hexString.toString();
}

From source file:Main.java

public static String toHexString(byte[] bytes) {
    StringBuilder hexString = new StringBuilder();
    for (byte b : bytes) {
        String str = Integer.toHexString(b & MotionEventCompat.ACTION_MASK);
        while (str.length() < 2) {
            str = "0" + str;
        }/* www  .  jav  a2 s .  c o  m*/
        hexString.append(str);
    }
    return hexString.toString();
}

From source file:Main.java

public static int inetAddressToInt(InetAddress inetaddress) throws IllegalArgumentException {
    byte[] abyte0 = inetaddress.getAddress();
    if (abyte0.length == 4) {
        return ((((abyte0[3] & MotionEventCompat.ACTION_MASK) << 24)
                | ((abyte0[2] & MotionEventCompat.ACTION_MASK) << 16))
                | ((abyte0[1] & MotionEventCompat.ACTION_MASK) << 8))
                | (abyte0[0] & MotionEventCompat.ACTION_MASK);
    }//from  w ww  .  j av  a 2  s .co m
    throw new IllegalArgumentException("Not an IPv4 address");
}

From source file:Main.java

public static String computeMD5(byte[] input) {
    try {/*  www . j av  a 2s  .  com*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(input, TYPE_NOT_CONNECTED, input.length);
        byte[] md5bytes = md.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = TYPE_NOT_CONNECTED; i < md5bytes.length; i += TYPE_WIFI) {
            String hex = Integer.toHexString(md5bytes[i] & MotionEventCompat.ACTION_MASK);
            if (hex.length() == TYPE_WIFI) {
                hexString.append('0');
            }
            hexString.append(hex);
        }
        return hexString.toString();
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.ppamorim.SlapBar.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    int actionMasked = MotionEventCompat.getActionMasked(ev);
    if ((actionMasked & MotionEventCompat.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        activePointerId = MotionEventCompat.getPointerId(ev, actionMasked);
    }//  ww w.j a va2 s .  co m
    if (activePointerId == INVALID_POINTER) {
        return false;
    }
    dragHelper.processTouchEvent(ev);
    return isViewHit(dragView, (int) ev.getX(), (int) ev.getY());
}

From source file:com.focosee.qingshow.widget.MVerticalViewPager.java

public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }/* w w w.j  a va2s  . c o m*/
    mVelocityTracker.addMovement(event);

    float currentY = event.getRawY();
    switch (event.getAction() & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mLastY = currentY;
        mMoved = false;
        break;
    case MotionEvent.ACTION_MOVE:
        mMoved = true;
        break;
    case MotionEvent.ACTION_UP:
        if (mMoved) {
            mVelocityTracker.computeCurrentVelocity(1000);
            int velocity = (int) mVelocityTracker.getYVelocity();
            float moveDistance = currentY - mLastY;
            int nextPage = mCurrentPage;
            if (moveDistance < 0 && Math.abs(moveDistance) >= SCROLL_PERCENTAGE * mSinglePageHeight
                    || velocity < 0 && Math.abs(velocity) > MIN_FLING_VELOCITY) {
                ++nextPage;
            } else if (moveDistance > 0 && Math.abs(moveDistance) >= SCROLL_PERCENTAGE * mSinglePageHeight
                    || velocity > 0 && Math.abs(velocity) > MIN_FLING_VELOCITY) {
                --nextPage;
            }
            setCurrentItem(nextPage);
        }
        break;
    }
    return true;
}

From source file:com.tjych.swip.vertical_t.VerticalViewPager.java

public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }/*  w  ww.  j  ava  2s .  c  o m*/
    mVelocityTracker.addMovement(event);

    float currentY = event.getRawY();
    float currentX = event.getRawX();
    switch (event.getAction() & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mLastY = currentY;
        mLastX = currentX;
        mMoved = false;
        return false;
    case MotionEvent.ACTION_MOVE:
        float x = event.getRawX() - mLastX;
        float y = event.getRawY() - mLastY;

        System.out.println(x + " : " + y);

        if (Math.abs(x) > Math.abs(y)) {
            // getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        } else {
            mMoved = true;
            return true;
        }

    case MotionEvent.ACTION_UP:
        x = event.getRawX() - mLastX;
        y = event.getRawY() - mLastY;
        System.out.println(x + " : " + y);
        if (Math.abs(x) > Math.abs(y)) {
            // getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
        if (mMoved) {
            mVelocityTracker.computeCurrentVelocity(1000);
            int velocity = (int) mVelocityTracker.getYVelocity();
            float moveDistance = currentY - mLastY;
            int nextPage = mCurrentPage;
            if (moveDistance < 0 && Math.abs(moveDistance) >= SCROLL_PERCENTAGE * mSinglePageHeight
                    || velocity < 0 && Math.abs(velocity) > MIN_FLING_VELOCITY) {
                ++nextPage;
            } else if (moveDistance > 0 && Math.abs(moveDistance) >= SCROLL_PERCENTAGE * mSinglePageHeight
                    || velocity > 0 && Math.abs(velocity) > MIN_FLING_VELOCITY) {
                --nextPage;
            }
            setCurrentItem(nextPage);
        }
        return true;
    }
    return true;
}

From source file:com.vincestyling.traversaless_testcase.TopTabIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev))
        return true;
    if (mViewPager == null)
        return false;

    final int count = getCount();
    if (count == 0)
        return false;

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();// www  . j a  v a  2  s  .co m
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (isFakeDragging() || beginFakeDrag()) {
                fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            Rect areaRect = new Rect();
            areaRect.left = getPaddingLeft();
            areaRect.right = getWidth() - getPaddingRight();
            areaRect.top = getPaddingTop();
            areaRect.bottom = getHeight() - getPaddingBottom();

            int btnWidth = areaRect.width() / count;

            for (int pos = 0; pos < count; pos++) {
                RectF tabRect = new RectF(areaRect);
                tabRect.left += pos * btnWidth;
                tabRect.right = tabRect.left + btnWidth;

                if (tabRect.contains(ev.getX(), ev.getY())) {
                    setCurrentItem(pos);
                    return true;
                }
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (isFakeDragging())
            endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:io.github.whataa.picer.widget.DragPinnerLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    final float x = ev.getX();
    final float y = ev.getY();
    boolean isBarHit = isBarHit((int) x, (int) y);
    // process the TouchEvent only when the bar or the visible content being touched.
    if (isBarHit || isContentVisibleHit((int) x, (int) y)) {
        dragHelper.processTouchEvent(ev);// TODO BUG ?
    }/* w  w  w . j a v  a 2  s. c o m*/
    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        initX = x;
        initY = y;
        break;
    // switch show/hide state.
    case MotionEvent.ACTION_UP:
        final float dx = x - initX;
        final float dy = y - initY;
        final int slop = dragHelper.getTouchSlop();
        if (dx * dx + dy * dy < slop * slop && isBarHit) {
            if (mDragOffset == 0) {
                hide();
            } else {
                show();
            }
        }
        break;
    }

    return true;
}

From source file:com.android.ex.photo.PhotoViewPager.java

/**
 * {@inheritDoc}//from   w w  w  . j ava 2s .  c  om
 * <p>
 * We intercept touch event intercepts so we can prevent switching views when the
 * current view is internally scrollable.
 */
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final InterceptType intercept = (mListener != null) ? mListener.onTouchIntercept(mActivatedX, mActivatedY)
            : InterceptType.NONE;
    final boolean ignoreScrollLeft = (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT);
    final boolean ignoreScrollRight = (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT);

    // Only check ability to page if we can't scroll in one / both directions
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mActivePointerId = INVALID_POINTER;
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        if (ignoreScrollLeft || ignoreScrollRight) {
            final int activePointerId = mActivePointerId;
            if (activePointerId == INVALID_POINTER) {
                // If we don't have a valid id, the touch down wasn't on content.
                break;
            }

            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
            final float x = MotionEventCompat.getX(ev, pointerIndex);

            if (ignoreScrollLeft && ignoreScrollRight) {
                mLastMotionX = x;
                return false;
            } else if (ignoreScrollLeft && (x > mLastMotionX)) {
                mLastMotionX = x;
                return false;
            } else if (ignoreScrollRight && (x < mLastMotionX)) {
                mLastMotionX = x;
                return false;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        mLastMotionX = ev.getX();
        // Use the raw x/y as the children can be located anywhere and there isn't a
        // single offset that would be meaningful
        mActivatedX = ev.getRawX();
        mActivatedY = ev.getRawY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP: {
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            // Our active pointer going up; select a new active pointer
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        break;
    }
    }

    return super.onInterceptTouchEvent(ev);
}