本文整理汇总了Java中android.view.MotionEvent.getButtonState方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getButtonState方法的具体用法?Java MotionEvent.getButtonState怎么用?Java MotionEvent.getButtonState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getButtonState方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
// Give everything to the gesture detector
boolean retValue = false;
if (event.getButtonState() == MotionEvent.BUTTON_SECONDARY) return retValue;
retValue = mGestureDetector.onTouchEvent(event);
// Check if finger is upped after scrolling
if (mGestureDetectorScrolling && (event.getAction() == MotionEvent.ACTION_UP)) {
if(DBG) Log.d(TAG, "ACTION_UP end of scrolling");
mGestureDetectorScrolling = false;
// Center to the front cover
float targetScroll = mLayout.getScrollingPositionToCenterThisCover( mLayout.getFrontCoverIndex());
mAnimHandler.startScrollingAnimPosition(targetScroll, AnimHandler.SPEED_FAST);
}
return retValue;
}
示例2: process
import android.view.MotionEvent; //导入方法依赖的package包/类
public void process(final MotionEvent event)
{
//Log.i("SDL", "Got motion event, type " + (int)(event.getAction()) + " X " + (int)event.getX() + " Y " + (int)event.getY() + " buttons " + buttonState + " source " + event.getSource());
int buttonStateNew = event.getButtonState();
if( buttonStateNew != buttonState )
{
for( int i = 1; i <= MotionEvent.BUTTON_FORWARD; i *= 2 )
{
if( (buttonStateNew & i) != (buttonState & i) )
DemoGLSurfaceView.nativeMouseButtonsPressed(i, ((buttonStateNew & i) == 0) ? 0 : 1);
}
if( (buttonStateNew & MotionEvent.BUTTON_STYLUS_PRIMARY) != (buttonState & MotionEvent.BUTTON_STYLUS_PRIMARY) )
DemoGLSurfaceView.nativeMouseButtonsPressed(2, ((buttonStateNew & MotionEvent.BUTTON_STYLUS_PRIMARY) == 0) ? 0 : 1);
if( (buttonStateNew & MotionEvent.BUTTON_STYLUS_SECONDARY) != (buttonState & MotionEvent.BUTTON_STYLUS_SECONDARY) )
DemoGLSurfaceView.nativeMouseButtonsPressed(4, ((buttonStateNew & MotionEvent.BUTTON_STYLUS_SECONDARY) == 0) ? 0 : 1);
buttonState = buttonStateNew;
}
super.process(event);
}
示例3: 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;
}
示例4: performButtonActionOnTouchDown
import android.view.MotionEvent; //导入方法依赖的package包/类
@TargetApi(14)
protected boolean performButtonActionOnTouchDown(MotionEvent event) {
if (VERSION.SDK_INT < 14 || (event.getButtonState() & 2) == 0 || !showContextMenu(event.getX(), event.getY(), event.getMetaState())) {
return false;
}
return true;
}
示例5: performButtonActionOnTouchDown
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* 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;
}
示例6: onRowTouch
import android.view.MotionEvent; //导入方法依赖的package包/类
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;
}
示例7: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if(DBG) Log.d(TAG, "onTouchEvent e = "+event);
// Check if finger is "upped" after scrolling
if (event.getButtonState() == MotionEvent.BUTTON_SECONDARY) return false;
if ((mLabelScrolling!=0) && (event.getAction() == MotionEvent.ACTION_UP)) {
// Check if the scrolling has been far enough or if the label must go back to original position
if (Math.abs(mLabelScrolling)<getWidth()/6) { //MAGICAL
// Go back to original position
Log.d(TAG, "onTouchEvent: reseting the label scrolling");
mLayout.scrollGlobalLabel(0);
requestRender();
} else {
// Change content
Log.d(TAG, "onTouchEvent: label has been scrolled far enough, change content!");
final int direction = (mLabelScrolling<0)?-1:+1;
// Start the animation removing the current content
mAnimHandler.stopAllAnimations();
mAnimHandler.startTranslationOutAnimation( 1.1f, new float[] {direction*TRANSLATION_SPEED_X, TRANSLATION_SPEED_Y, TRANSLATION_SPEED_Z},
new Runnable() {
public void run() {
changeContent(direction);
};
});
}
// We must make sure that a content change is not triggered by a onFling callback
// For that purpose we keep a reference to the current event, which is the same than e2 for onFling (same data, not same instance)
mContentChangeEvent = event;
// Reset label scrolling
mLabelScrolling = 0;
// consume the event so that it is not taken into account by the onFling
return true;
}
// Some stuff may have to be done in the mother class
return super.onTouchEvent(event);
}
示例8: 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;
}
示例9: onTouch
import android.view.MotionEvent; //导入方法依赖的package包/类
public boolean onTouch(View v, MotionEvent event) {
if (isTVMenuDisplayed) mLastTouchEventTime = event.getEventTime();
if(mControllerViewLeft!=null){
View overlay = mControllerViewLeft.findViewById(R.id.help_overlay);
if(event.getAction()==KeyEvent.ACTION_DOWN&&overlay!=null&&overlay.getVisibility()==View.VISIBLE){
sendOverlayFadeOut(0);
return true;
}
}
if (mControllerView == null)
return false;
if(isTVMenuDisplayed){
showTVMenu(false);
return false;
}
if(mIsLocked){
showUnlockInstructions(true);
return true;
}
if (mActionBarShowing && event.getY() < mActionBarHeight) {
mWindow.superDispatchTouchEvent(event);
return true;
}
if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY)!=0) return false;
if (event.getAction() != MotionEvent.ACTION_UP) {
return true;
}
int flags = FLAG_SIDE_ALL_EXCEPT_UNLOCK_INSTRUCTIONS;
if (!mVolumeBarEnabled) {
flags &= ~FLAG_SIDE_VOLUME_BAR;
}
if (mIsStopped || !Player.sPlayer.isInPlaybackState()) {
flags &= ~(FLAG_SIDE_CONTROL_BAR);
}
toggleMediaControlsVisiblity(flags);
switchMode(false);
return true;
}
示例10: isStylusButtonPressed
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* 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);
}