Java Code Examples for android.view.MotionEvent#ACTION_POINTER_INDEX_SHIFT

The following examples show how to use android.view.MotionEvent#ACTION_POINTER_INDEX_SHIFT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HorizontalScrollView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
            MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(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;
        mLastMotionX = (int) ev.getX(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
Example 2
Source File: ScrollView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
            MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(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) ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
Example 3
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
            MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(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;
        mLastMotionX = mDownMotionX = ev.getX(newPointerIndex);
        mLastMotionY = ev.getY(newPointerIndex);
        mLastMotionXRemainder = 0;
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
Example 4
Source File: MotionEventBuilder.java    From android-test with Apache License 2.0 6 votes vote down vote up
/** Returns a MotionEvent with the provided data or reasonable defaults. */
public MotionEvent build() {
  if (pointerPropertiesList.size() == 0) {
    setPointer(0, 0);
  }
  if (actionIndex != -1) {
    action = action | (actionIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
  }
  return MotionEvent.obtain(
      downTime,
      eventTime,
      action,
      pointerPropertiesList.size(),
      pointerPropertiesList.toArray(new PointerProperties[pointerPropertiesList.size()]),
      pointerCoordsList.toArray(new MotionEvent.PointerCoords[pointerCoordsList.size()]),
      metaState,
      buttonState,
      xPrecision,
      yPrecision,
      deviceId,
      edgeFlags,
      source,
      flags);
}
 
Example 5
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 5 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
	final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
	final int pointerId = ev.getPointerId(pointerIndex);
	if (pointerId == mActivePointerId) {
		final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
		mMotionX = (int) ev.getX(newPointerIndex);
		mMotionY = (int) ev.getY(newPointerIndex);
		mMotionCorrection = 0;
		mActivePointerId = ev.getPointerId(newPointerIndex);
	}
}
 
Example 6
Source File: VersionedGestureDetector.java    From PicturePicker with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = ev.getPointerId(0);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            final int pointerId = ev.getPointerId(pointerIndex);
            if (pointerId == mActivePointerId) {
                // This was our active pointer going up. Choose a new
                // active pointer and adjust accordingly.
                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                mActivePointerId = ev.getPointerId(newPointerIndex);
                mLastTouchX = ev.getX(newPointerIndex);
                mLastTouchY = ev.getY(newPointerIndex);
            }
            break;
    }

    mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
    return super.onTouchEvent(ev);
}
 
Example 7
Source File: MultitouchActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
	int action = event.getAction() & MotionEvent.ACTION_MASK;
	int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
	pointerCount = event.getPointerCount();

	int actionId = event.getPointerId(pointerIndex);
	Log.d("greenrobot", "MotionEvent - pointer ID:  " + actionId
			+ ", action: " + mapActionCodeToString(action)
			+ ", pointer count: " + pointerCount);
	if (actionId < MAX_POINTERS) {
		lastActions[actionId] = action;
	}

	for (int i = 0; i < pointerCount; i++) {
		int pointerId = event.getPointerId(i);
		if (pointerId < MAX_POINTERS) {
			points[pointerId] = new PointF(event.getX(i), event.getY(i));
			if (action == MotionEvent.ACTION_MOVE) {
				lastActions[pointerId] = action;
			}
		}
	}

	touchView.invalidate();
	return true;
}
 
Example 8
Source File: VersionedGestureDetector.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
	final int action = ev.getAction();
	switch (action & MotionEvent.ACTION_MASK) {
		case MotionEvent.ACTION_DOWN:
			mActivePointerId = ev.getPointerId(0);
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			mActivePointerId = INVALID_POINTER_ID;
			break;
		case MotionEvent.ACTION_POINTER_UP:
			final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
			final int pointerId = ev.getPointerId(pointerIndex);
			if (pointerId == mActivePointerId) {
				// This was our active pointer going up. Choose a new
				// active pointer and adjust accordingly.
				final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
				mActivePointerId = ev.getPointerId(newPointerIndex);
				mLastTouchX = ev.getX(newPointerIndex);
				mLastTouchY = ev.getY(newPointerIndex);
			}
			break;
	}

	mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
	return super.onTouchEvent(ev);
}
 
Example 9
Source File: VersionedGestureDetector.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
	final int action = ev.getAction();
	switch (action & MotionEvent.ACTION_MASK) {
		case MotionEvent.ACTION_DOWN:
			mActivePointerId = ev.getPointerId(0);
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			mActivePointerId = INVALID_POINTER_ID;
			break;
		case MotionEvent.ACTION_POINTER_UP:
			final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
			final int pointerId = ev.getPointerId(pointerIndex);
			if (pointerId == mActivePointerId) {
				// This was our active pointer going up. Choose a new
				// active pointer and adjust accordingly.
				final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
				mActivePointerId = ev.getPointerId(newPointerIndex);
				mLastTouchX = ev.getX(newPointerIndex);
				mLastTouchY = ev.getY(newPointerIndex);
			}
			break;
	}

	mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
	return super.onTouchEvent(ev);
}
 
Example 10
Source File: VersionedGestureDetector.java    From monolog-android with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
	final int action = ev.getAction();
	switch (action & MotionEvent.ACTION_MASK) {
		case MotionEvent.ACTION_DOWN:
			mActivePointerId = ev.getPointerId(0);
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			mActivePointerId = INVALID_POINTER_ID;
			break;
		case MotionEvent.ACTION_POINTER_UP:
			final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
			final int pointerId = ev.getPointerId(pointerIndex);
			if (pointerId == mActivePointerId) {
				// This was our active pointer going up. Choose a new
				// active pointer and adjust accordingly.
				final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
				mActivePointerId = ev.getPointerId(newPointerIndex);
				mLastTouchX = ev.getX(newPointerIndex);
				mLastTouchY = ev.getY(newPointerIndex);
			}
			break;
	}

	mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
	return super.onTouchEvent(ev);
}
 
Example 11
Source File: VersionedGestureDetector.java    From school_shop with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
	final int action = ev.getAction();
	switch (action & MotionEvent.ACTION_MASK) {
		case MotionEvent.ACTION_DOWN:
			mActivePointerId = ev.getPointerId(0);
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			mActivePointerId = INVALID_POINTER_ID;
			break;
		case MotionEvent.ACTION_POINTER_UP:
			final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
			final int pointerId = ev.getPointerId(pointerIndex);
			if (pointerId == mActivePointerId) {
				// This was our active pointer going up. Choose a new
				// active pointer and adjust accordingly.
				final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
				mActivePointerId = ev.getPointerId(newPointerIndex);
				mLastTouchX = ev.getX(newPointerIndex);
				mLastTouchY = ev.getY(newPointerIndex);
			}
			break;
	}

	mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
	return super.onTouchEvent(ev);
}
 
Example 12
Source File: Util.java    From PhotoViewer with Apache License 2.0 4 votes vote down vote up
static int getPointerIndex(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
Example 13
Source File: Compat.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static int getPointerIndexHoneyComb(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
Example 14
Source File: MotionEventUtils.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
 * 指定したMotionEventのactionをACTION_XXX形式の文字列に変換する
 * MotionEvent#actionToStringがAPI>=19なので後方互換性のためにバックポート
 * @param event
 * @return
 */
public static String getActionString(@NonNull final MotionEvent event) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		return MotionEvent.actionToString(event.getActionMasked());
	} else {
		final int action = event.getActionMasked();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			return "ACTION_DOWN";
		case MotionEvent.ACTION_UP:
			return "ACTION_UP";
		case MotionEvent.ACTION_CANCEL:
			return "ACTION_CANCEL";
		case MotionEvent.ACTION_OUTSIDE:
			return "ACTION_OUTSIDE";
		case MotionEvent.ACTION_MOVE:
			return "ACTION_MOVE";
		case MotionEvent.ACTION_HOVER_MOVE:
			return "ACTION_HOVER_MOVE";
		case MotionEvent.ACTION_SCROLL:
			return "ACTION_SCROLL";
		case MotionEvent.ACTION_HOVER_ENTER:
			return "ACTION_HOVER_ENTER";
		case MotionEvent.ACTION_HOVER_EXIT:
			return "ACTION_HOVER_EXIT";
		case MotionEvent.ACTION_BUTTON_PRESS:
			return "ACTION_BUTTON_PRESS";
		case MotionEvent.ACTION_BUTTON_RELEASE:
			return "ACTION_BUTTON_RELEASE";
		}

		final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK)
			>> MotionEvent.ACTION_POINTER_INDEX_SHIFT;

		switch (action & MotionEvent.ACTION_MASK) {
		case MotionEvent.ACTION_POINTER_DOWN:
			return "ACTION_POINTER_DOWN(" + index + ")";
		case MotionEvent.ACTION_POINTER_UP:
			return "ACTION_POINTER_UP(" + index + ")";
		default:
			return Integer.toString(action);
		}
	}
}
 
Example 15
Source File: Compat.java    From Dashboard with MIT License 4 votes vote down vote up
@TargetApi(VERSION_CODES.HONEYCOMB)
private static int getPointerIndexHoneyComb(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
Example 16
Source File: Util.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
static int getPointerIndex(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
Example 17
Source File: FlingCardListener.java    From SwipeCardView with Apache License 2.0 4 votes vote down vote up
@Override
  public boolean onTouch(View view, MotionEvent event) {
  	
  	try {
       switch (event.getAction() & MotionEvent.ACTION_MASK) {
           case MotionEvent.ACTION_DOWN:

                  // remove the listener because 'onAnimationEnd' will still be called if we cancel the animation.
                  this.frame.animate().setListener(null);
                  this.frame.animate().cancel();

                  resetAnimCanceled = true;

               // Save the ID of this pointer
               mActivePointerId = event.getPointerId(0);
               final float x = event.getX(mActivePointerId);
               final float y = event.getY(mActivePointerId);					
	
               // Remember where we started
               aDownTouchX = x;
               aDownTouchY = y;
               // to prevent an initial jump of the magnifier, aposX and aPosY must
               // have the values from the magnifier frame
                  aPosX = frame.getX();
                  aPosY = frame.getY();
	
               if (y < objectH/2) {
                   touchPosition = TOUCH_ABOVE;
               } else {
                   touchPosition = TOUCH_BELOW;
               }
               break;

           case MotionEvent.ACTION_POINTER_DOWN:
               break;
	
           case MotionEvent.ACTION_POINTER_UP:
               // Extract the index of the pointer that left the touch sensor
               final int pointerIndex = (event.getAction() &
                       MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
               final int pointerId = event.getPointerId(pointerIndex);
               if (pointerId == mActivePointerId) {
                   // This was our active pointer going up. Choose a new
                   // active pointer and adjust accordingly.
                   final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                   mActivePointerId = event.getPointerId(newPointerIndex);
               }
               break;
           case MotionEvent.ACTION_MOVE:
	
               // Find the index of the active pointer and fetch its position
               final int pointerIndexMove = event.findPointerIndex(mActivePointerId);
               final float xMove = event.getX(pointerIndexMove);
               final float yMove = event.getY(pointerIndexMove);
               
               // from http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
               // Calculate the distance moved
               final float dx = xMove - aDownTouchX;
               final float dy = yMove - aDownTouchY;
	
               // Move the frame
               aPosX += dx;
               aPosY += dy;
	
               // calculate the rotation degrees
               float distObjectX = aPosX - objectX;
               float rotation = BASE_ROTATION_DEGREES * 2f * distObjectX / parentWidth;
               if (touchPosition == TOUCH_BELOW) {
                   rotation = -rotation;
               }
	
               // in this area would be code for doing something with the view as the frame moves.
                  if (isNeedSwipe) {
                      frame.setX(aPosX);
                      frame.setY(aPosY);
                      frame.setRotation(rotation);
                      mFlingListener.onScroll(getScrollProgress(), getScrollXProgressPercent());
                  }
               break;

              case MotionEvent.ACTION_UP:
              case MotionEvent.ACTION_CANCEL:
                  //mActivePointerId = INVALID_POINTER_ID;
                  int pointerCount = event.getPointerCount();
                  int activePointerId = Math.min(mActivePointerId, pointerCount - 1);
                  aTouchUpX = event.getX(activePointerId);
                  mActivePointerId = INVALID_POINTER_ID;
                  resetCardViewOnStack(event);
               break;

       }
  	} catch (Exception e) {
	e.printStackTrace();
}

      return true;
  }
 
Example 18
Source File: Compat.java    From zen4android with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static int getPointerIndexHoneyComb(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
Example 19
Source File: Compat.java    From Album with Apache License 2.0 4 votes vote down vote up
public static int getPointerIndex(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
Example 20
Source File: Util.java    From giffun with Apache License 2.0 4 votes vote down vote up
static int getPointerIndex(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}