Java Code Examples for android.view.MotionEvent#BUTTON_SECONDARY

The following examples show how to use android.view.MotionEvent#BUTTON_SECONDARY . 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: LayerRowCallbacks.java    From spline with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: AbsHListView.java    From Klyph with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: TouchPaint.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
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;
}
 
Example 4
Source File: StylusEventHelper.java    From LaunchEnr with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: StylusEventHelper.java    From Trebuchet with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}