当前位置: 首页>>代码示例>>Java>>正文


Java MotionEvent.getMetaState方法代码示例

本文整理汇总了Java中android.view.MotionEvent.getMetaState方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getMetaState方法的具体用法?Java MotionEvent.getMetaState怎么用?Java MotionEvent.getMetaState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.getMetaState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSingleTapUp

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onSingleTapUp(MotionEvent event) {
    if (adapter != null && currentTouchLayer != null) {
        int metaState = event.getMetaState();
        boolean isShiftPressed = (metaState & KeyEvent.META_SHIFT_ON) != 0;

        if (!currentTouchIsSecondaryButton
                || !(adapter.getCurrentLayer() instanceof SelectionGroup)
                || ((SelectionGroup) adapter.getCurrentLayer()).getLayers().size() < 2) {
            Layer selection = LayerUtils.selectionFrom(
                    adapter.getCurrentLayer(), currentTouchLayer, isShiftPressed);
            adapter.setCurrentLayer(selection);
        }

        if (currentTouchIsSecondaryButton) {
            currentTouchView.showContextMenu(event.getX(), event.getY());
        }
    }

    return true;
}
 
开发者ID:google,项目名称:spline,代码行数:22,代码来源:LayerRowCallbacks.java

示例2: mouseEventToJavaModifiers

import android.view.MotionEvent; //导入方法依赖的package包/类
/**
 * 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,代码行数:34,代码来源:TerminalTextViewOverlay.java

示例3: onGenericMotionEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                // Handle mouse (or ext. device) by shifting the page depending on the scroll
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }
                if (hscroll != 0 || vscroll != 0) {
                    boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:31,代码来源:PagedView.java

示例4: onMouseEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
/**
 * @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,代码行数:73,代码来源:TerminalTextViewOverlay.java


注:本文中的android.view.MotionEvent.getMetaState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。