當前位置: 首頁>>代碼示例>>Java>>正文


Java MotionEvent.BUTTON_PRIMARY屬性代碼示例

本文整理匯總了Java中android.view.MotionEvent.BUTTON_PRIMARY屬性的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.BUTTON_PRIMARY屬性的具體用法?Java MotionEvent.BUTTON_PRIMARY怎麽用?Java MotionEvent.BUTTON_PRIMARY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.BUTTON_PRIMARY屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onGenericMotion

public boolean onGenericMotion(View v, MotionEvent event) {
    if(!isTVMenuDisplayed){
        if (DBG)
            Log.d(TAG, "onGenericMotion : event=" + event);
        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M&&event.getActionButton()==MotionEvent.BUTTON_PRIMARY) //
            return false;
        int action = event.getAction();

        if (action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_MOVE || action == MotionEvent.ACTION_HOVER_EXIT) {
            // Ignore events sent by the remote control when it is in pointer mode
            return false;
        }

        show(FLAG_SIDE_ALL_EXCEPT_UNLOCK_INSTRUCTIONS, 3000);

        return true;
    }
    return false;
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:19,代碼來源:PlayerController.java

示例2: mouseEventToJavaModifiers

/**
 * Takes an android mouse event and produces a Java InputEvent modifiers int which can be
 * passed to vt320.
 * @param mouseEvent The {@link MotionEvent} which should be a mouse click or release.
 * @return A Java InputEvent modifier int. See
 * http://docs.oracle.com/javase/7/docs/api/java/awt/event/InputEvent.html
 */
@TargetApi(14)
private static int mouseEventToJavaModifiers(MotionEvent mouseEvent) {
	if (MotionEventCompat.getSource(mouseEvent) != InputDevice.SOURCE_MOUSE) return 0;

	int mods = 0;

	// See http://docs.oracle.com/javase/7/docs/api/constant-values.html
	int buttonState = mouseEvent.getButtonState();
	if ((buttonState & MotionEvent.BUTTON_PRIMARY) != 0)
		mods |= 16;
	if ((buttonState & MotionEvent.BUTTON_SECONDARY) != 0)
		mods |= 8;
	if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0)
		mods |= 4;

	// Note: Meta and Ctrl are intentionally swapped here to keep logic in vt320 simple.
	int meta = mouseEvent.getMetaState();
	if ((meta & KeyEvent.META_META_ON) != 0)
		mods |= 2;
	if ((meta & KeyEvent.META_SHIFT_ON) != 0)
		mods |= 1;
	if ((meta & KeyEvent.META_CTRL_ON) != 0)
		mods |= 4;

	return mods;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:33,代碼來源:TerminalTextViewOverlay.java

示例3: onMouseEvent

/**
 * @param event
 * @param bridge
 * @return True if the event is handled.
 */
@TargetApi(14)
private boolean onMouseEvent(MotionEvent event, TerminalBridge bridge) {
	int row = (int) Math.floor(event.getY() / bridge.charHeight);
	int col = (int) Math.floor(event.getX() / bridge.charWidth);
	int meta = event.getMetaState();
	boolean shiftOn = (meta & KeyEvent.META_SHIFT_ON) != 0;
	vt320 vtBuffer = (vt320) bridge.buffer;
	boolean mouseReport = vtBuffer.isMouseReportEnabled();

	// MouseReport can be "defeated" using the shift key.
	if (!mouseReport || shiftOn) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			if (event.getButtonState() == MotionEvent.BUTTON_TERTIARY) {
				// Middle click pastes.
				pasteClipboard();
				return true;
			}

			// Begin "selection mode"

			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
				closeSelectionActionMode();
			}
		} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
			// In the middle of selection.

			if (selectionActionMode == null) {
				selectionActionMode = startActionMode(new TextSelectionActionModeCallback());
			}

			int selectionStart = getSelectionStart();
			int selectionEnd = getSelectionEnd();

			if (selectionStart > selectionEnd) {
				int tempStart = selectionStart;
				selectionStart = selectionEnd;
				selectionEnd = tempStart;
			}

			currentSelection = getText().toString().substring(selectionStart, selectionEnd);
		}
	} else if (event.getAction() == MotionEvent.ACTION_DOWN) {
		terminalView.viewPager.setPagingEnabled(false);
		vtBuffer.mousePressed(
				col, row, mouseEventToJavaModifiers(event));
		return true;
	} else if (event.getAction() == MotionEvent.ACTION_UP) {
		terminalView.viewPager.setPagingEnabled(true);
		vtBuffer.mouseReleased(col, row);
		return true;
	} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
		int buttonState = event.getButtonState();
		int button = (buttonState & MotionEvent.BUTTON_PRIMARY) != 0 ? 0 :
				(buttonState & MotionEvent.BUTTON_SECONDARY) != 0 ? 1 :
						(buttonState & MotionEvent.BUTTON_TERTIARY) != 0 ? 2 : 3;
		vtBuffer.mouseMoved(
				button,
				col,
				row,
				(meta & KeyEvent.META_CTRL_ON) != 0,
				(meta & KeyEvent.META_SHIFT_ON) != 0,
				(meta & KeyEvent.META_META_ON) != 0);
		return true;
	}

	return false;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:72,代碼來源:TerminalTextViewOverlay.java

示例4: onResolvePointerIcon

/**
 * Adds support for different mouse pointer icons depending on document state and mouse position
 */
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    int icon = PointerIcon.TYPE_DEFAULT;
    Layer l = mCurrentLayer;
    float x = event.getX() - getViewportX();
    float y = event.getY() - getViewportY();

    if (mMode == MODE_LAYER_DRAG || mMode == MODE_LAYER_PRE_DRAG) {
        icon = PointerIcon.TYPE_GRABBING;
    } else {
        if (l != null) {
            if (inPointTouchRadius(x, y, l.getTopLeft())
                    || inPointTouchRadius(x, y, l.getBottomRight())) {
                icon = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW;
            } else if (inPointTouchRadius(x, y, l.getTopRight())
                    || inPointTouchRadius(x, y, l.getBottomLeft())) {
                icon = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW;
            } else if (inPointTouchRadius(x, y, l.getMidTop())
                    || inPointTouchRadius(x, y, l.getMidBottom())) {
                icon = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW;
            } else if (inPointTouchRadius(x, y, l.getMidLeft())
                    || inPointTouchRadius(x, y, l.getMidRight())) {
                icon = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW;
            } else if (l.inBounds(x, y)) {
                switch (event.getActionMasked()) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_MOVE:
                        // Only change to hand if this is a primary button click
                        if (event.getActionButton() == MotionEvent.BUTTON_PRIMARY) {
                            icon = PointerIcon.TYPE_GRABBING;
                        } else {
                            icon = PointerIcon.TYPE_DEFAULT;
                        }
                        break;
                    case MotionEvent.ACTION_HOVER_MOVE:
                        icon = PointerIcon.TYPE_GRAB;
                        break;
                    case MotionEvent.ACTION_UP:
                    default:
                        if (event.getActionButton() == MotionEvent.BUTTON_PRIMARY) {
                            icon = PointerIcon.TYPE_GRAB;
                        } else {
                            icon = PointerIcon.TYPE_DEFAULT;
                        }
                }
            }
        }
    }
    return PointerIcon.getSystemIcon(getContext(), icon);
}
 
開發者ID:google,項目名稱:spline,代碼行數:53,代碼來源:DocumentView.java


注:本文中的android.view.MotionEvent.BUTTON_PRIMARY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。