下面列出了android.view.MotionEvent#BUTTON_SECONDARY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public boolean onRowTouch(View view, MotionEvent event, LayerRowViewModel row) {
if (row != null) {
currentTouchLayer = row.getLayer();
}
currentTouchView = view;
detector.onTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
currentTouchIsSecondaryButton = event.getButtonState() == MotionEvent.BUTTON_SECONDARY;
}
return true;
}
/**
* Performs button-related actions during a touch down event.
*
* @param event
* The event.
* @return True if the down was consumed.
*
*/
@TargetApi(14)
protected boolean performButtonActionOnTouchDown( MotionEvent event ) {
if ( android.os.Build.VERSION.SDK_INT >= 14 ) {
if ( ( event.getButtonState() & MotionEvent.BUTTON_SECONDARY ) != 0 ) {
if ( showContextMenu( event.getX(), event.getY(), event.getMetaState() ) ) {
return true;
}
}
}
return false;
}
private boolean onTouchOrHoverEvent(MotionEvent event, boolean isTouch) {
final int buttonState = event.getButtonState();
int pressedButtons = buttonState & ~mOldButtonState;
mOldButtonState = buttonState;
if ((pressedButtons & MotionEvent.BUTTON_SECONDARY) != 0) {
// Advance color when the right mouse button or first stylus button
// is pressed.
advanceColor();
}
PaintMode mode;
if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0) {
// Splat paint when the middle mouse button or second stylus button is pressed.
mode = PaintMode.Splat;
} else if (isTouch || (buttonState & MotionEvent.BUTTON_PRIMARY) != 0) {
// Draw paint when touching or if the primary button is pressed.
mode = PaintMode.Draw;
} else {
// Otherwise, do not paint anything.
return false;
}
final int action = event.getActionMasked();
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE
|| action == MotionEvent.ACTION_HOVER_MOVE) {
final int N = event.getHistorySize();
final int P = event.getPointerCount();
for (int i = 0; i < N; i++) {
for (int j = 0; j < P; j++) {
paint(getPaintModeForTool(event.getToolType(j), mode),
event.getHistoricalX(j, i),
event.getHistoricalY(j, i),
event.getHistoricalPressure(j, i),
event.getHistoricalTouchMajor(j, i),
event.getHistoricalTouchMinor(j, i),
event.getHistoricalOrientation(j, i),
event.getHistoricalAxisValue(MotionEvent.AXIS_DISTANCE, j, i),
event.getHistoricalAxisValue(MotionEvent.AXIS_TILT, j, i));
}
}
for (int j = 0; j < P; j++) {
paint(getPaintModeForTool(event.getToolType(j), mode),
event.getX(j),
event.getY(j),
event.getPressure(j),
event.getTouchMajor(j),
event.getTouchMinor(j),
event.getOrientation(j),
event.getAxisValue(MotionEvent.AXIS_DISTANCE, j),
event.getAxisValue(MotionEvent.AXIS_TILT, j));
}
mCurX = event.getX();
mCurY = event.getY();
}
return true;
}
/**
* Identifies if the provided {@link MotionEvent} is a stylus with the primary stylus button
* pressed.
*
* @param event The event to check.
* @return Whether a stylus button press occurred.
*/
private static boolean isStylusButtonPressed(MotionEvent event) {
return event.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
&& ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY)
== MotionEvent.BUTTON_SECONDARY);
}
/**
* Identifies if the provided {@link MotionEvent} is a stylus with the primary stylus button
* pressed.
*
* @param event The event to check.
* @return Whether a stylus button press occurred.
*/
private static boolean isStylusButtonPressed(MotionEvent event) {
return event.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
&& ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY)
== MotionEvent.BUTTON_SECONDARY);
}