List of usage examples for android.support.v4.view MotionEventCompat getActionMasked
public static int getActionMasked(MotionEvent event)
From source file:com.lovejjfg.blogdemo.ui.BottomSheet.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { hasInteractedWithSheet = true;/*from w w w.j av a2s . c o m*/ if (isNestedScrolling) return false; /* prefer nested scrolling to dragging */ final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { sheetDragHelper.cancel(); return false; } return isDraggableViewUnder((int) ev.getX(), (int) ev.getY()) && (sheetDragHelper.shouldInterceptTouchEvent(ev)); }
From source file:com.wenhui.syncedListView.lib.SyncedListLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { boolean handle = gestureDetector.onTouchEvent(event); int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: Log.d(TAG, "touch mode " + mTouchMode); if (mTouchMode != TOUCH_MODE_FLING) { startAnimationInternal(DEFAULT_ANIMATION_DELAY); }/*w ww . j a va 2 s . co m*/ mTouchMode = TOUCH_MODE_REST; break; } return handle; }
From source file:com.taobao.luaview.view.viewpager.AutoScrollViewPager.java
/** * <ul>// w w w . ja v a 2s . com * if stopScrollWhenTouch is true * <li>if event is down, stop auto scroll.</li> * <li>if event is up, start auto scroll again.</li> * </ul> * * bugfix: ev.getAction() == MotionEvent.ACTION_CANCEL?,Action Cancel??? * */ @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (!canAutoScroll) { return super.dispatchTouchEvent(ev); } int action = MotionEventCompat.getActionMasked(ev); if (stopScrollWhenTouch) { if ((action == MotionEvent.ACTION_DOWN) && isAutoScroll) { isStopByTouch = true; stopAutoScroll(); } else if ((ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) && isStopByTouch) { startAutoScroll(); } } // if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT || slideBorderMode == SLIDE_BORDER_MODE_CYCLE) { // touchX = ev.getX(); // if (ev.getAction() == MotionEvent.ACTION_DOWN) { // downX = touchX; // } // int currentItem = getCurrentItem(); // PagerAdapter adapter = getAdapter(); // int pageCount = adapter == null ? 0 : adapter.getCount(); // /** // * current index is first one and slide to right or current index is last one and slide to left.<br/> // * if slide border mode is to parent, then requestDisallowInterceptTouchEvent false.<br/> // * else scroll to last one when current item is first one, scroll to first one when current item is last // * one. // */ // if ((currentItem == 0 && downX <= touchX) || (currentItem == pageCount - 1 && downX >= touchX)) { // if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) { // getParent().requestDisallowInterceptTouchEvent(false); // } else { // if (pageCount > 1) { // setCurrentItem(pageCount - currentItem - 1, false); // } //// getParent().requestDisallowInterceptTouchEvent(true); // } // return super.dispatchTouchEvent(ev); // } // } //// getParent().requestDisallowInterceptTouchEvent(true); return super.dispatchTouchEvent(ev); }
From source file:ayushi.view.adapter.ShoppingListAdapter.java
@Override public void onBindViewHolder(final ItemViewHolder holder, final int position) { holder.itemName.setText(productList.get(position).getItemName()); holder.itemDesc.setText(productList.get(position).getItemShortDesc()); String sellCostString = Money .rupees(BigDecimal.valueOf(Long.valueOf(productList.get(position).getSellMRP()))).toString() + " "; String buyMRP = Money.rupees(BigDecimal.valueOf(Long.valueOf(productList.get(position).getMRP()))) .toString();/*from w w w . j a v a 2 s .c om*/ String costString = sellCostString + buyMRP; holder.itemCost.setText(costString, BufferType.SPANNABLE); Spannable spannable = (Spannable) holder.itemCost.getText(); spannable.setSpan(new StrikethroughSpan(), sellCostString.length(), costString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mDrawableBuilder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().roundRect(10); drawable = mDrawableBuilder.build(String.valueOf(productList.get(position).getItemName().charAt(0)), mColorGenerator.getColor(productList.get(position).getItemName())); ImageUrl = productList.get(position).getImageURL(); holder.quanitity .setText(GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity()); Glide.with(context).load(ImageUrl).placeholder(drawable).error(drawable).animate(R.anim.base_slide_right_in) .centerCrop().into(holder.imagView); // Start a drag whenever the handle view it touched holder.imagView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { mDragStartListener.onStartDrag(holder); } return false; } }); holder.addItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).setQuantity(String.valueOf( Integer.valueOf( GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity()) + 1)); holder.quanitity.setText( GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity()); Utils.vibrate(context); ((ECartHomeActivity) context).updateCheckOutAmount( BigDecimal.valueOf(Long.valueOf( GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getSellMRP())), true); } }); holder.removeItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Integer.valueOf( GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity()) > 2) { GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).setQuantity(String.valueOf( Integer.valueOf(GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position) .getQuantity()) - 1)); holder.quanitity.setText( GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity()); ((ECartHomeActivity) context).updateCheckOutAmount(BigDecimal.valueOf(Long.valueOf( GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getSellMRP())), false); Utils.vibrate(context); } else if (Integer.valueOf( GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity()) == 1) { ((ECartHomeActivity) context).updateItemCount(false); ((ECartHomeActivity) context).updateCheckOutAmount(BigDecimal.valueOf(Long.valueOf( GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getSellMRP())), false); GlobaDataHolder.getGlobaDataHolder().getShoppingList().remove(position); if (Integer.valueOf(((ECartHomeActivity) context).getItemCount()) == 0) { MyCartFragment.updateMyCartFragment(false); } Utils.vibrate(context); } } }); }
From source file:com.josecalles.porridge.widget.BottomSheet.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { viewDragHelper.cancel();/* www. j a va 2 s . com*/ return false; } return isDraggableViewUnder((int) ev.getX(), (int) ev.getY()) && (viewDragHelper.shouldInterceptTouchEvent(ev) || super.onInterceptTouchEvent(ev)); }
From source file:android.support.v7.widget.ForwardingListener.java
/** * Observes motion events and determines when to start forwarding. * * @param srcEvent motion event in source view coordinates * @return true to start forwarding motion events, false otherwise */// w w w .jav a 2 s . c o m private boolean onTouchObserved(MotionEvent srcEvent) { final View src = mSrc; if (!src.isEnabled()) { return false; } final int actionMasked = MotionEventCompat.getActionMasked(srcEvent); switch (actionMasked) { case MotionEvent.ACTION_DOWN: mActivePointerId = srcEvent.getPointerId(0); if (mDisallowIntercept == null) { mDisallowIntercept = new DisallowIntercept(); } src.postDelayed(mDisallowIntercept, mTapTimeout); if (mTriggerLongPress == null) { mTriggerLongPress = new TriggerLongPress(); } src.postDelayed(mTriggerLongPress, mLongPressTimeout); break; case MotionEvent.ACTION_MOVE: final int activePointerIndex = srcEvent.findPointerIndex(mActivePointerId); if (activePointerIndex >= 0) { final float x = srcEvent.getX(activePointerIndex); final float y = srcEvent.getY(activePointerIndex); // Has the pointer moved outside of the view? if (!pointInView(src, x, y, mScaledTouchSlop)) { clearCallbacks(); // Don't let the parent intercept our events. src.getParent().requestDisallowInterceptTouchEvent(true); return true; } } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: clearCallbacks(); break; } return false; }
From source file:com.waz.zclient.pages.main.conversationlist.views.listview.SwipeListView.java
/** * onInterceptTouchEvent is not called on move even it returns false. (Bug?) * This function determines the hit element and the movement. *///w w w . j a v a 2 s. c om @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (viewWidth < 2) { viewWidth = getWidth(); } switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: touchState = TOUCH_STATE_REST; getHitChild(ev); break; case MotionEvent.ACTION_MOVE: if (touchState != TOUCH_STATE_REST) { super.dispatchTouchEvent(ev); } final float x = ev.getX(); final float y = ev.getY(); // make sure we hit an item if (targetView != null) { checkMotionDirection(x, y); } break; } return super.dispatchTouchEvent(ev); }
From source file:com.jakewharton.behavior.drawer.BehaviorDelegate.java
boolean onInterceptTouchEvent(MotionEvent ev) { boolean interceptForDrag = dragger.shouldInterceptTouchEvent(ev); boolean interceptForTap = false; switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { float x = ev.getX(); float y = ev.getY(); initialMotionX = x;// ww w. j a va 2s . c om initialMotionY = y; if (onScreen > 0) { View child = dragger.findTopChildUnder((int) x, (int) y); if (child != null && isContentView(child)) { interceptForTap = true; } } childrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { // If we cross the touch slop, don't perform the delayed peek for an edge touch. if (dragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { closeDrawers(true); childrenCanceledTouch = false; break; } } return interceptForDrag || interceptForTap || isPeeking || childrenCanceledTouch; }
From source file:com.idrv.coach.ui.view.LoopViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: case MotionEventCompat.ACTION_POINTER_DOWN: mHandler.removeMessages(AUTO_SCROLL_MESSAGE); break;/* w w w. j a v a 2s. com*/ case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_2_UP: case MotionEvent.ACTION_POINTER_3_UP: case MotionEvent.ACTION_CANCEL: mHandler.removeMessages(AUTO_SCROLL_MESSAGE); mHandler.sendEmptyMessageDelayed(AUTO_SCROLL_MESSAGE, delayTimeInMills); break; default: break; } return super.onTouchEvent(ev); }
From source file:com.github.ppamorim.cult.CultView.java
/** * Override method to intercept only touch events over the drag view and to cancel the drag when * the action associated to the MotionEvent is equals to ACTION_CANCEL or ACTION_UP. * * @param ev captured.//from w w w.j a va2 s .co m * @return true if the view is going to process the touch event or false if not. */ @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!isEnabled()) { return false; } switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: dragHelper.cancel(); return false; case MotionEvent.ACTION_DOWN: int index = MotionEventCompat.getActionIndex(ev); activePointerId = MotionEventCompat.getPointerId(ev, index); if (activePointerId == INVALID_POINTER) { return false; } default: dragHelper.processTouchEvent(ev); return dragHelper.shouldInterceptTouchEvent(ev); } }