List of usage examples for android.view MotionEvent getActionMasked
public final int getActionMasked()
From source file:org.chromium.chrome.browser.omnibox.SuggestionView.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { // Whenever the suggestion dropdown is touched, we dispatch onGestureDown which is // used to let autocomplete controller know that it should stop updating suggestions. if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) mSuggestionDelegate.onGestureDown(); return super.dispatchTouchEvent(ev); }
From source file:com.android.mail.browse.ConversationContainer.java
private void forwardFakeMotionEvent(MotionEvent original, int newAction) { MotionEvent newEvent = MotionEvent.obtain(original); newEvent.setAction(newAction);/*from w ww . j a v a2 s. c o m*/ mWebView.onTouchEvent(newEvent); LogUtils.v(TAG, "in Container.OnTouch. fake: action=%d x/y=%f/%f pointers=%d", newEvent.getActionMasked(), newEvent.getX(), newEvent.getY(), newEvent.getPointerCount()); }
From source file:radu.pidroid.Controller.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { int action = motionEvent.getActionMasked(); switch (view.getId()) { case R.id.forwardsPowerImageView: //// w ww.j av a2 s.co m if (action == MotionEvent.ACTION_DOWN) { if (roverAccelerationState != ROVER_STOPPED && roverDirection != ROVER_FORWARDS) { roverAccelerationState = ROVER_STOPPED; mMessenger.updateRoverSpeed(roverSpeed = 0); } // if else { roverDirection = ROVER_FORWARDS; roverAccelerationState = ROVER_ACCELERATING; resetTimer(new roverSpeedTask()); } // else } // if else // if ((action == MotionEvent.ACTION_UP || !isTouchOnView(view, motionEvent)) && roverAccelerationState != ROVER_DECELERATING) { roverAccelerationState = ROVER_DECELERATING; resetTimer(new roverSpeedTask()); } // if break; case R.id.backwardsPowerImageView: // if (action == MotionEvent.ACTION_DOWN) { if (roverAccelerationState != ROVER_STOPPED && roverDirection != ROVER_BACKWARDS) { roverAccelerationState = ROVER_STOPPED; mMessenger.updateRoverSpeed(roverSpeed = 0); } // if else { roverDirection = ROVER_BACKWARDS; roverAccelerationState = ROVER_ACCELERATING; resetTimer(new roverSpeedTask()); } // else } // if else if ((action == MotionEvent.ACTION_UP || !isTouchOnView(view, motionEvent)) && roverAccelerationState != ROVER_DECELERATING) { roverAccelerationState = ROVER_DECELERATING; resetTimer(new roverSpeedTask()); } // if break; default: Log.e("OnTouch:", "wut?"); } // switch return true; }
From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java
@Override public boolean onTouch(@Nullable final View view, @NonNull final MotionEvent event) { if (mListViewWrapper.getAdapter() == null) { return false; }/* w w w . j a v a2 s. c o m*/ if (mVirtualListCount == -1 || mActiveSwipeCount == 0) { mVirtualListCount = mListViewWrapper.getCount() - mListViewWrapper.getHeaderViewsCount(); } if (mViewWidth < 2) { mViewWidth = mListViewWrapper.getListView().getWidth(); } boolean result; switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: result = handleDownEvent(view, event); break; case MotionEvent.ACTION_MOVE: result = handleMoveEvent(view, event); break; case MotionEvent.ACTION_CANCEL: result = handleCancelEvent(); break; case MotionEvent.ACTION_UP: result = handleUpEvent(event); break; default: result = false; } return result; }
From source file:com.marshalchen.ultimaterecyclerview.UltimateRecyclerView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (mCallbacks != null) { switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mFirstScroll = mDragging = true; mCallbacks.onDownMotionEvent(); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIntercepted = false;/*from w w w .j a va 2 s . c om*/ mDragging = false; mCallbacks.onUpOrCancelMotionEvent(mObservableScrollState); break; } } return super.onInterceptTouchEvent(ev); // if (mCallbacks != null) { // URLogs.d("ev---"+ev.getActionMasked()); // switch (ev.getActionMasked()) { // case MotionEvent.ACTION_DOWN: // // Whether or not motion events are consumed by children, // // flag initializations which are related to ACTION_DOWN events should be executed. // // Because if the ACTION_DOWN is consumed by children and only ACTION_MOVEs are // // passed to parent (this view), the flags will be invalid. // // Also, applications might implement initialization codes to onDownMotionEvent, // // so call it here. // mFirstScroll = mDragging = true; // mCallbacks.onDownMotionEvent(); // break; // } // } // return super.onInterceptTouchEvent(ev); }
From source file:com.android.mail.browse.ConversationContainer.java
/** * Touch slop code was copied from {@link ScrollView#onInterceptTouchEvent(MotionEvent)}. *//* w ww. j a v a 2 s . c om*/ @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mTouchInitialized) { mTouchInitialized = true; } // no interception when WebView handles the first DOWN if (mWebView.isHandlingTouch()) { return false; } boolean intercept = false; switch (ev.getActionMasked()) { case MotionEvent.ACTION_POINTER_DOWN: LogUtils.d(TAG, "Container is intercepting non-primary touch!"); intercept = true; mMissedPointerDown = true; requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_DOWN: mLastMotionY = ev.getY(); mActivePointerId = ev.getPointerId(0); break; case MotionEvent.ACTION_MOVE: final int pointerIndex = ev.findPointerIndex(mActivePointerId); final float y = ev.getY(pointerIndex); final int yDiff = (int) Math.abs(y - mLastMotionY); if (yDiff > mTouchSlop) { mLastMotionY = y; intercept = true; } break; } // LogUtils.v(TAG, "in Container.InterceptTouch. action=%d x/y=%f/%f pointers=%d result=%s", // ev.getActionMasked(), ev.getX(), ev.getY(), ev.getPointerCount(), intercept); return intercept; }
From source file:org.chromium.chrome.browser.ntp.NewTabPageView.java
/** * Sets up scrolling when snippets are disabled. It adds scroll and touch listeners to the * scroll view.//from w ww . jav a 2s .com */ private void initializeSearchBoxScrollHandling() { final Runnable mSnapScrollRunnable = new Runnable() { @Override public void run() { if (!mPendingSnapScroll) return; int scrollY = mScrollView.getScrollY(); int dividerTop = mMostVisitedLayout.getTop() - mNewTabPageLayout.getPaddingTop(); if (scrollY > 0 && scrollY < dividerTop) { mScrollView.smoothScrollTo(0, scrollY < (dividerTop / 2) ? 0 : dividerTop); } mPendingSnapScroll = false; } }; mScrollView.setOnScrollListener(new NewTabPageScrollView.OnScrollListener() { @Override public void onScrollChanged(int l, int t, int oldl, int oldt) { if (mPendingSnapScroll) { mScrollView.removeCallbacks(mSnapScrollRunnable); mScrollView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_DELAY_MS); } updateSearchBoxOnScroll(); } }); mScrollView.setOnTouchListener(new OnTouchListener() { @Override @SuppressLint("ClickableViewAccessibility") public boolean onTouch(View v, MotionEvent event) { mScrollView.removeCallbacks(mSnapScrollRunnable); if (event.getActionMasked() == MotionEvent.ACTION_CANCEL || event.getActionMasked() == MotionEvent.ACTION_UP) { mPendingSnapScroll = true; mScrollView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_DELAY_MS); } else { mPendingSnapScroll = false; } return false; } }); }
From source file:org.chromium.chrome.browser.ntp.NewTabPageView.java
/** * Sets up scrolling when snippets are enabled. It adds scroll listeners and touch listeners to * the RecyclerView.//from ww w . j a v a 2 s . c o m */ private void initializeSearchBoxRecyclerViewScrollHandling() { final Runnable mSnapScrollRunnable = new Runnable() { @Override public void run() { assert mPendingSnapScroll; mPendingSnapScroll = false; mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), getHeight()); } }; mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (mPendingSnapScroll) { mRecyclerView.removeCallbacks(mSnapScrollRunnable); mRecyclerView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_DELAY_MS); } updateSearchBoxOnScroll(); mRecyclerView.updatePeekingCardAndHeader(); } }); mRecyclerView.setOnTouchListener(new OnTouchListener() { @Override @SuppressLint("ClickableViewAccessibility") public boolean onTouch(View v, MotionEvent event) { mRecyclerView.removeCallbacks(mSnapScrollRunnable); if (event.getActionMasked() == MotionEvent.ACTION_CANCEL || event.getActionMasked() == MotionEvent.ACTION_UP) { mPendingSnapScroll = true; mRecyclerView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_DELAY_MS); } else { mPendingSnapScroll = false; } return false; } }); }
From source file:org.telegram.ui.Components.NumberPicker.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; }//w ww . jav a 2 s.co m if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_MOVE: { if (mIngonreMoveEvents) { break; } float currentMoveY = event.getY(); if (mScrollState != OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { int deltaDownY = (int) Math.abs(currentMoveY - mLastDownEventY); if (deltaDownY > mTouchSlop) { removeAllCallbacks(); onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); } } else { int deltaMoveY = (int) ((currentMoveY - mLastDownOrMoveEventY)); scrollBy(0, deltaMoveY); invalidate(); } mLastDownOrMoveEventY = currentMoveY; } break; case MotionEvent.ACTION_UP: { removeChangeCurrentByOneFromLongPress(); mPressedStateHelper.cancel(); VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumFlingVelocity); int initialVelocity = (int) velocityTracker.getYVelocity(); if (Math.abs(initialVelocity) > mMinimumFlingVelocity) { fling(initialVelocity); onScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); } else { int eventY = (int) event.getY(); int deltaMoveY = (int) Math.abs(eventY - mLastDownEventY); long deltaTime = event.getEventTime() - mLastDownEventTime; if (deltaMoveY <= mTouchSlop && deltaTime < ViewConfiguration.getTapTimeout()) { int selectorIndexOffset = (eventY / mSelectorElementHeight) - SELECTOR_MIDDLE_ITEM_INDEX; if (selectorIndexOffset > 0) { changeValueByOne(true); mPressedStateHelper.buttonTapped(PressedStateHelper.BUTTON_INCREMENT); } else if (selectorIndexOffset < 0) { changeValueByOne(false); mPressedStateHelper.buttonTapped(PressedStateHelper.BUTTON_DECREMENT); } } else { ensureScrollWheelAdjusted(); } onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } mVelocityTracker.recycle(); mVelocityTracker = null; } break; } return true; }
From source file:com.marshalchen.ultimaterecyclerview.UltimateRecyclerView.java
@Override public boolean onTouchEvent(MotionEvent ev) { URLogs.d("ev---" + ev); if (mCallbacks != null) { switch (ev.getActionMasked()) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIntercepted = false;/*from w ww. j a v a 2 s. com*/ mDragging = false; mCallbacks.onUpOrCancelMotionEvent(mObservableScrollState); break; case MotionEvent.ACTION_MOVE: if (mPrevMoveEvent == null) { mPrevMoveEvent = ev; } float diffY = ev.getY() - mPrevMoveEvent.getY(); mPrevMoveEvent = MotionEvent.obtainNoHistory(ev); if (getCurrentScrollY() - diffY <= 0) { // Can't scroll anymore. if (mIntercepted) { // Already dispatched ACTION_DOWN event to parents, so stop here. return false; } // Apps can set the interception target other than the direct parent. final ViewGroup parent; if (mTouchInterceptionViewGroup == null) { parent = (ViewGroup) getParent(); } else { parent = mTouchInterceptionViewGroup; } // Get offset to parents. If the parent is not the direct parent, // we should aggregate offsets from all of the parents. float offsetX = 0; float offsetY = 0; for (View v = this; v != null && v != parent; v = (View) v.getParent()) { offsetX += v.getLeft() - v.getScrollX(); offsetY += v.getTop() - v.getScrollY(); } final MotionEvent event = MotionEvent.obtainNoHistory(ev); event.offsetLocation(offsetX, offsetY); if (parent.onInterceptTouchEvent(event)) { mIntercepted = true; // If the parent wants to intercept ACTION_MOVE events, // we pass ACTION_DOWN event to the parent // as if these touch events just have began now. event.setAction(MotionEvent.ACTION_DOWN); // Return this onTouchEvent() first and set ACTION_DOWN event for parent // to the queue, to keep events sequence. post(new Runnable() { @Override public void run() { parent.dispatchTouchEvent(event); } }); return false; } // Even when this can't be scrolled anymore, // simply returning false here may cause subView's click, // so delegate it to super. return super.onTouchEvent(ev); } break; } } return super.onTouchEvent(ev); }