本文整理匯總了Java中android.view.MotionEvent.getActionMasked方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.getActionMasked方法的具體用法?Java MotionEvent.getActionMasked怎麽用?Java MotionEvent.getActionMasked使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getActionMasked方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
int action = ev.getActionMasked();
switch (action) {
case MotionEvent.ACTION_DOWN:
lastTouchY = (int) ev.getY();
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
isBeingDragged = true;
break;
case MotionEvent.ACTION_MOVE:
int y = (int) ev.getY();
int yDiff = Math.abs(y - lastTouchY);
if (yDiff > touchSlop) {
lastTouchY = y;
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
stopNestedScroll();
}
return super.onInterceptTouchEvent(ev);
}
示例2: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// 1. detector和mDragHelper判斷是否需要攔截
boolean yScroll = moveDetector.onTouchEvent(ev);
boolean shouldIntercept = false;
try {
shouldIntercept = mDragHelper.shouldInterceptTouchEvent(ev);
} catch (Exception e) {
}
// 2. 觸點按下的時候直接交給mDragHelper
int action = ev.getActionMasked();
if (action == MotionEvent.ACTION_DOWN) {
downState = getCurrentState();
mDragHelper.processTouchEvent(ev);
}
return shouldIntercept && yScroll;
}
示例3: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
* Handle touch event.
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
mDownKeyX = event.getX();
mDownKeyY = event.getY();
break;
case MotionEvent.ACTION_UP:
onKeyPressed(mBoxKeypad.findKeyPressed(mDownKeyX,
mDownKeyY,
event.getX(),
event.getY()));
break;
default:
return false;
}
return true;
}
示例4: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent e) {
// If there is a pending close task, remove it.
mHandler.removeCallbacks(mCloseRunnable);
boolean handled = mSwipeGestureDetector.onTouchEvent(e);
if (handled) return true;
if (e.getActionMasked() == MotionEvent.ACTION_UP) {
if (Math.abs(getTranslationX()) > mSwipeCommitDistance) {
runSwipeAnimation(DEFAULT_ANIMATION_DURATION_MS);
} else {
runResetAnimation(false);
}
mCanScrollListener.setCanScroll(true);
return true;
}
return super.onTouchEvent(e);
}
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:19,代碼來源:AccessibilityTabModelListItem.java
示例5: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent ev) {
if (!mTouchEnabled) return false;
// Action down would already have been handled in onInterceptTouchEvent
if (ev.getActionMasked() != MotionEvent.ACTION_DOWN) {
mGestureDetector.onTouchEvent(ev);
}
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException ex) {
// In JB MR0 and earlier, an ACTION_MOVE that is not preceded by an ACTION_DOWN event
// causes a crash. This can happen under normal circumstances (e.g. going back to the
// NTP while a finger is down on the screen) and should not crash. The most reliable way
// to prevent this crash is to catch the exception. http://crbug.com/293822
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1
&& ev.getActionMasked() == MotionEvent.ACTION_MOVE
&& "pointerIndex out of range".equals(ex.getMessage())) {
Log.d(TAG, "Ignoring pointerIndex out of range exception.");
return true;
}
throw ex;
}
}
示例6: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (downTime > 0 && System.currentTimeMillis() - downTime > INTERCEPT_TIME_SLOP) {
return true;
}
boolean shouldIntercept = mDragHelper.shouldInterceptTouchEvent(ev);
int action = ev.getActionMasked();
if (action == MotionEvent.ACTION_DOWN) {
mDragHelper.processTouchEvent(ev);
}
boolean moveFlag = moveDetector.onTouchEvent(ev);
if (moveFlag) {
if (null != moveAnchorThread) {
moveAnchorThread.interrupt();
moveAnchorThread = null;
}
if (null != draggingView && draggingView.isDraggable()) {
draggingView.startAnchorAnimation();
}
}
return shouldIntercept && moveFlag;
}
示例7: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.M &&
event.getActionMasked() == MotionEvent.ACTION_UP) {
// Android 6 occasionally throws a NullPointerException inside Editor.onTouchEvent()
// for ACTION_UP when attempting to display (uninitialised) text handles. The Editor
// and TextView IME interactions are quite complex, so I don't know how to properly
// work around this issue, but we can at least catch the NPE to prevent crashing
// the whole app.
// (Editor tries to make both selection handles visible, but in certain cases they haven't
// been initialised yet, causing the NPE. It doesn't bother to check the selection handle
// state, and making some other calls to ensure the handles exist doesn't seem like a
// clean solution either since I don't understand most of the selection logic. This implementation
// only seems to exist in Android 6, both Android 5 and 7 have different implementations.)
try {
return super.onTouchEvent(event);
} catch (NullPointerException ignored) {
// Ignore this (see above) - since we're now in an unknown state let's clear all selection
// (which is still better than an arbitrary crash that we can't control):
clearFocus();
return true;
}
} else {
return super.onTouchEvent(event);
}
}
示例8: dispatchTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
// Normally, touch event is dispatched to presentation view only if the phone is paired with
// a Cardboard viewer. This is annoying when we just want to quickly verify a Cardboard
// behavior. This allows us to trigger cardboard trigger event without pair to a Cardboard.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR_SHELL_DEV)
&& event.getActionMasked() == MotionEvent.ACTION_DOWN) {
nativeOnTriggerEvent(mNativeVrShell);
}
return super.dispatchTouchEvent(event);
}
示例9: getHistoricalEvents
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
* Get historical event. This is only applied to {@link MotionEvent#ACTION_MOVE}.
* For other types of motionEvent, historical event is meaningless.
* @param motionEvent motionEvent, which contains all pointers event in a period of time
* @return If motionEvent.getActionMasked()!=MotionEvent.ACTION_MOVE,
* this method will return an empty list.
* Otherwise this method will return the historical motionEvent, which may also be empty.
*/
private List<Map<String, Object>> getHistoricalEvents(MotionEvent motionEvent) {
List<Map<String, Object>> list = new ArrayList<>(motionEvent.getHistorySize());
if (motionEvent.getActionMasked() == MotionEvent.ACTION_MOVE) {
Map<String, Object> param;
for (int i = 0; i < motionEvent.getHistorySize(); i++) {
param = createFireEventParam(motionEvent, i,null);
list.add(param);
}
}
return list;
}
示例10: onTouch
import android.view.MotionEvent; //導入方法依賴的package包/類
public void onTouch(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
LayoutParams layoutParams = (LayoutParams) textureView.getLayoutParams();
if (layoutParams != null && event.getX() >= layoutParams.leftMargin && event.getY() >= layoutParams.topMargin && event.getX() <= layoutParams.leftMargin + layoutParams.width && event.getY() <= layoutParams.topMargin + layoutParams.height) {
setShowOriginal(true);
}
} else if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
setShowOriginal(false);
}
}
示例11: handleMotionEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean handleMotionEvent(MotionEvent event) {
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
int actionPointerIndex = event.getActionIndex();
int action = event.getActionMasked();
switch(action) {
case MotionEvent.ACTION_MOVE:
SDLJoystick joystick = getJoystick(event.getDeviceId());
if ( joystick != null ) {
for (int i = 0; i < joystick.axes.size(); i++) {
InputDevice.MotionRange range = joystick.axes.get(i);
/* Normalize the value to -1...1 */
float value = ( event.getAxisValue( range.getAxis(), actionPointerIndex) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
SDLActivity.onNativeJoy(joystick.device_id, i, value );
}
for (int i = 0; i < joystick.hats.size(); i+=2) {
int hatX = Math.round(event.getAxisValue( joystick.hats.get(i).getAxis(), actionPointerIndex ) );
int hatY = Math.round(event.getAxisValue( joystick.hats.get(i+1).getAxis(), actionPointerIndex ) );
SDLActivity.onNativeHat(joystick.device_id, i/2, hatX, hatY );
}
}
break;
default:
break;
}
}
return true;
}
示例12: onDoubleTapEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
if (e.getActionMasked() == MotionEvent.ACTION_UP) {
isDoubleTapping = true;
if (isCurrStepScale()) {
float scale = getNextStepValue() * laidOutScaleX;
animate2ZoomImage(scale, e.getX(), e.getY());
} else {
animate2ZoomImage(laidOutScaleX, e.getX(), e.getY());
scaleStepsIndex = 0;
}
return true;
}
return false;
}
示例13: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
if (cancelledOnTouchOutside && event.getActionMasked() == MotionEvent.ACTION_DOWN) {
ensureContent();
if (!isUnderView(content, event)) {
cancel();
}
}
// Always return true to avoid touch through
return true;
}
示例14: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent ev) {
final int action = ev.getActionMasked();
final int actionIndex = ev.getActionIndex();
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(ev);
switch (action){
case MotionEvent.ACTION_POINTER_DOWN:
mActivePointerId = ev.getPointerId(actionIndex);
mLastMotionX = ev.getX(actionIndex);
mLastMotionY = ev.getY(actionIndex);
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerId = ev.getPointerId(actionIndex);
if(pointerId==mActivePointerId){
final int newIndex = actionIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newIndex);
mLastMotionX = ev.getX(newIndex);
mLastMotionY = ev.getY(newIndex);
}
break;
//down時,已經將capture item定下來了。所以,後麵可以安心考慮event處理
case MotionEvent.ACTION_MOVE: {
final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
if (activePointerIndex == -1)
break;
final float x = ev.getX(activePointerIndex);
final float y = (int) ev.getY(activePointerIndex);
int deltaX = (int) (x - mLastMotionX);
if(mCaptureItem!=null && mCaptureItem.getTouchMode()== Mode.DRAG){
mLastMotionX = x;
mLastMotionY = y;
//對capture item進行拖拽
mCaptureItem.trackMotionScroll(deltaX);
}
break;
}
case MotionEvent.ACTION_UP:
if(mCaptureItem!=null){
Mode touchMode = mCaptureItem.getTouchMode();
if(touchMode== Mode.DRAG){
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
int xVel = (int) velocityTracker.getXVelocity(mActivePointerId);
mCaptureItem.fling(xVel);
}
}
cancel();
break;
case MotionEvent.ACTION_CANCEL:
if(mCaptureItem!=null)
mCaptureItem.revise();
cancel();
break;
}
}
示例15: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
// 決策是否需要攔截
int action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_DOWN:
downX = (int) event.getX();
downY = (int) event.getY();
lastX = event.getX();
scrollMode = MODE_IDLE;
if (null != animator) {
animator.cancel();
}
initVelocityTrackerIfNotExists();
mVelocityTracker.addMovement(event);
animatingView = null;
break;
case MotionEvent.ACTION_MOVE:
if (scrollMode == MODE_IDLE) {
float xDistance = Math.abs(downX - event.getX());
float yDistance = Math.abs(downY - event.getY());
if (xDistance > yDistance && xDistance > mTouchSlop) {
// 水平滑動,需要攔截
scrollMode = MODE_HORIZONTAL;
return true;
} else if (yDistance > xDistance && yDistance > mTouchSlop) {
// 垂直滑動
scrollMode = MODE_VERTICAL;
}
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
recycleVelocityTracker();
// ACTION_UP還能攔截,說明手指沒滑動,隻是一個click事件,同樣需要snap到特定位置
onRelease(event.getX(), 0);
break;
}
return false; // 默認都是不攔截的
}