* Returns true if event was triggered by a mouse.
*/
public static boolean isMouseEvent(MotionEvent e) {
- return isMouseType(e.getToolType(0));
- }
-
- /**
- * Returns true if event was triggered by a finger or stylus touch.
- */
- public static boolean isTouchEvent(MotionEvent e) {
- return isTouchType(e.getToolType(0));
- }
-
- /**
- * Returns true if event was triggered by a mouse.
- */
- public static boolean isMouseType(int toolType) {
+ int toolType = e.getToolType(0);
return toolType == MotionEvent.TOOL_TYPE_MOUSE;
}
/**
* Returns true if event was triggered by a finger or stylus touch.
*/
- public static boolean isTouchType(int toolType) {
- return toolType == MotionEvent.TOOL_TYPE_FINGER
- || toolType == MotionEvent.TOOL_TYPE_STYLUS;
- }
-
- /**
- * Returns true if event was triggered by a finger or stylus touch.
- */
public static boolean isActionDown(MotionEvent e) {
return e.getActionMasked() == MotionEvent.ACTION_DOWN;
}
* of related code.
*/
public interface InputEvent extends AutoCloseable {
- boolean isTouchEvent();
boolean isMouseEvent();
boolean isPrimaryButtonPressed();
boolean isSecondaryButtonPressed();
}
@Override
- public boolean isTouchEvent() {
- return Events.isTouchEvent(mEvent);
- }
-
- @Override
public boolean isMouseEvent() {
return Events.isMouseEvent(mEvent);
}
new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
- try (MotionInputEvent event = MotionInputEvent.obtain(e, view)) {
+ try (InputEvent event = MotionInputEvent.obtain(e, view)) {
return handleEvent(event);
}
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
if (Events.isMouseEvent(e)) {
- try (MotionInputEvent event = MotionInputEvent.obtain(e, view)) {
+ try (InputEvent event = MotionInputEvent.obtain(e, view)) {
processInputEvent(event);
}
}
mSelection = selection;
}
- private boolean handleEvent(MotionInputEvent e) {
+ private boolean handleEvent(InputEvent e) {
// Don't start, or extend bands on right click.
if (e.isSecondaryButtonPressed()) {
return false;
}
}
- boolean shouldStart(MotionInputEvent e) {
+ boolean shouldStart(InputEvent e) {
return !isActive()
&& e.isActionDown() // the initial button press
&& mAdapter.getItemCount() > 0