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


Java MotionEvent.getActionMasked方法代码示例

本文整理汇总了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);
}
 
开发者ID:marshi,项目名称:NestedWebView,代码行数:23,代码来源:NestedWebView.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:DragLayout.java

示例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;
}
 
开发者ID:kevalpatel2106,项目名称:PasscodeView,代码行数:22,代码来源:PinView.java

示例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;
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:26,代码来源:NewTabPageScrollView.java

示例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;
}
 
开发者ID:funnyzhaov,项目名称:Tribe,代码行数:25,代码来源:DraggableSquareView.java

示例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);

    }
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:28,代码来源:InlineAutocompleteEditText.java

示例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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:12,代码来源:VrShellImpl.java

示例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;
}
 
开发者ID:erguotou520,项目名称:weex-uikit,代码行数:20,代码来源:WXGesture.java

示例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);
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:11,代码来源:PhotoFilterView.java

示例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;
}
 
开发者ID:jomof,项目名称:cdep-android-studio-freetype-sample,代码行数:29,代码来源:SDLActivity.java

示例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;
}
 
开发者ID:xyzxqs,项目名称:XphotoView,代码行数:16,代码来源:XphotoView.java

示例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;
}
 
开发者ID:seven332,项目名称:Stage,代码行数:12,代码来源:DialogRootView.java

示例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;

    }
}
 
开发者ID:AndroidBoySC,项目名称:Mybilibili,代码行数:73,代码来源:SwipeItemLayout.java

示例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; // 默认都是不拦截的
}
 
开发者ID:yangchong211,项目名称:YCCardView,代码行数:45,代码来源:CardViewLayout.java


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