List of usage examples for android.support.v4.view MotionEventCompat getActionMasked
public static int getActionMasked(MotionEvent event)
From source file:com.cndll.chgj.adapter.CaiPinListAdapter.java
@Override public void onBindViewHolder(final ItemViewHolder holder, final int position) { String isDiscount = ""; if (mitems.get(position).getIs_discount().equals("1")) { isDiscount = ":? "; } else {/* w w w. j a v a 2 s . c om*/ isDiscount = ":? "; } ((ListItemViewHolder) holder).info.setVisibility(View.VISIBLE); ((ListItemViewHolder) holder).price.setVisibility(View.VISIBLE); ((ListItemViewHolder) holder).name.setText(mitems.get(position).getName()); ((ListItemViewHolder) holder).price.setText(" " + mitems.get(position).getPrice()); ((ListItemViewHolder) holder).info.setText( isDiscount + "?: " + mitems.get(position).getCode() + " " + mitems.get(position).getMachine()); ((ListItemViewHolder) holder).name.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (onItemClick != null) { onItemClick.onItemClick(v, position); } } }); ((ListItemViewHolder) holder).revise.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (onItemClick != null) { onItemClick.onReEidetClick(v, position); } } }); // Start a drag whenever the handle view it touched ((ListItemViewHolder) holder).handleView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { mDragStartListener.onStartDrag(holder); } return false; } }); }
From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.touchguard.RecyclerViewTouchActionGuardManager.java
boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { if (!mEnabled) { return false; }//from w w w. j a v a2s. c om final int action = MotionEventCompat.getActionMasked(e); if (LOCAL_LOGV) { Timber.v("onInterceptTouchEvent() action = " + action); } switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: handleActionUpOrCancel(); break; case MotionEvent.ACTION_DOWN: handleActionDown(e); break; case MotionEvent.ACTION_MOVE: if (handleActionMove(rv, e)) { return true; } break; } return false; }
From source file:com.example.tt.pullrefresh.widget.SwipItemLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { sheetDragHelper.cancel();//w ww . j a va2 s. com getParent().requestDisallowInterceptTouchEvent(false); return false; } return isDraggableViewUnder((int) ev.getX(), (int) ev.getY()) && (sheetDragHelper.shouldInterceptTouchEvent(ev)); }
From source file:android.support.v7.widget.DropDownListView.java
/** * Handles forwarded events.//from w ww . ja va 2s. com * * @param activePointerId id of the pointer that activated forwarding * @return whether the event was handled */ public boolean onForwardedEvent(MotionEvent event, int activePointerId) { boolean handledEvent = true; boolean clearPressedItem = false; final int actionMasked = MotionEventCompat.getActionMasked(event); switch (actionMasked) { case MotionEvent.ACTION_CANCEL: handledEvent = false; break; case MotionEvent.ACTION_UP: handledEvent = false; // $FALL-THROUGH$ case MotionEvent.ACTION_MOVE: final int activeIndex = event.findPointerIndex(activePointerId); if (activeIndex < 0) { handledEvent = false; break; } final int x = (int) event.getX(activeIndex); final int y = (int) event.getY(activeIndex); final int position = pointToPosition(x, y); if (position == INVALID_POSITION) { clearPressedItem = true; break; } final View child = getChildAt(position - getFirstVisiblePosition()); setPressedItem(child, position, x, y); handledEvent = true; if (actionMasked == MotionEvent.ACTION_UP) { clickPressedItem(child, position); } break; } // Failure to handle the event cancels forwarding. if (!handledEvent || clearPressedItem) { clearPressedItem(); } // Manage automatic scrolling. if (handledEvent) { if (mScrollHelper == null) { mScrollHelper = new ListViewAutoScrollHelper(this); } mScrollHelper.setEnabled(true); mScrollHelper.onTouch(this, event); } else if (mScrollHelper != null) { mScrollHelper.setEnabled(false); } return handledEvent; }
From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.touchguard.RecyclerViewTouchActionGuardManager.java
boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { if (!mEnabled) { return false; }//w w w .jav a 2 s. c om final int action = MotionEventCompat.getActionMasked(e); if (LOCAL_LOGV) { Log.v(TAG, "onInterceptTouchEvent() action = " + action); } switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: handleActionUpOrCancel(); break; case MotionEvent.ACTION_DOWN: handleActionDown(e); break; case MotionEvent.ACTION_MOVE: if (handleActionMove(rv, e)) { return true; } break; } return false; }
From source file:com.github.ppamorim.library.DraggerView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!isEnabled()) { return false; }//from w ww .j a v a2 s . c om final int action = MotionEventCompat.getActionMasked(ev); switch (action) { 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: return dragHelper.shouldInterceptTouchEvent(ev); } }
From source file:com.telenav.expandablepager.SlidingContainer.java
private boolean translate(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); int stepSize = stopValues.size(); switch (action) { case MotionEvent.ACTION_DOWN: { startYCoordinate = ev.getRawY(); translated = 0;/*from w w w .j a v a 2 s . c o m*/ break; } case MotionEvent.ACTION_MOVE: { touchDelta = (startYCoordinate - ev.getRawY()); if (Math.abs(touchDelta) > slideThreshold) { float startingPointY, nextPointY, maxDiff, tempDelta, auxDelta = 0; tempDelta = touchDelta + (touchDelta < 0 ? 1 : -1) * slideThreshold; startingPointY = stopValues.get(stopValueIndex); if (!isUpwardGesture() && stopValueIndex >= 1) { nextPointY = stopValues.get(stopValueIndex - 1); maxDiff = nextPointY - stopValues.get(stopValueIndex); auxDelta = Math.min(-tempDelta, maxDiff); } else if (isUpwardGesture() && stopValueIndex < stepSize - 1) { nextPointY = stopValues.get(stopValueIndex + 1); maxDiff = nextPointY - stopValues.get(stopValueIndex); auxDelta = Math.max(-tempDelta, maxDiff); } float preTranslated = translated; translated = startingPointY + auxDelta; setTranslationY(translated); if (preTranslated != translated) notifySlideEvent(translated); return false; } return true; } case MotionEvent.ACTION_UP: { if (Math.abs(touchDelta) > slideThreshold) { if (!isUpwardGesture() && stopValueIndex > 0) stopValueIndex--; else if (isUpwardGesture() && stopValueIndex < stepSize - 1) stopValueIndex++; if (!stopValues.contains(translated)) { animate(stopValues.get(stopValueIndex)); } else onSettled(stopValueIndex); startYCoordinate = -1; touchDelta = 0; } break; } case MotionEvent.ACTION_CANCEL: { break; } case MotionEvent.ACTION_POINTER_UP: { break; } } return true; }
From source file:com.blogspot.holbohistorier.readonfree.BookView.java
protected void swipePage(View v, MotionEvent event, int book) { int action = MotionEventCompat.getActionMasked(event); switch (action) { case (MotionEvent.ACTION_DOWN): swipeOriginX = event.getX();/* ww w.ja va2 s . c om*/ swipeOriginY = event.getY(); break; case (MotionEvent.ACTION_UP): int quarterWidth = (int) (screenWidth * 0.25); float diffX = swipeOriginX - event.getX(); float diffY = swipeOriginY - event.getY(); float absDiffX = Math.abs(diffX); float absDiffY = Math.abs(diffY); if ((diffX > quarterWidth) && (absDiffX > absDiffY)) { try { navigator.goToNextChapter(index); } catch (Exception e) { errorMessage(getString(R.string.error_cannotTurnPage)); } } else if ((diffX < -quarterWidth) && (absDiffX > absDiffY)) { try { navigator.goToPrevChapter(index); } catch (Exception e) { errorMessage(getString(R.string.error_cannotTurnPage)); } } break; } }
From source file:android.support.design.widget.HeaderBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) { if (mTouchSlop < 0) { mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop(); }//from w ww .ja va 2s . c om switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { final int x = (int) ev.getX(); final int y = (int) ev.getY(); if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) { mLastMotionY = y; mActivePointerId = ev.getPointerId(0); ensureVelocityTracker(); } else { return false; } break; } case MotionEvent.ACTION_MOVE: { final int activePointerIndex = ev.findPointerIndex(mActivePointerId); if (activePointerIndex == -1) { return false; } final int y = (int) ev.getY(activePointerIndex); int dy = mLastMotionY - y; if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) { mIsBeingDragged = true; if (dy > 0) { dy -= mTouchSlop; } else { dy += mTouchSlop; } } if (mIsBeingDragged) { mLastMotionY = y; // We're being dragged so scroll the ABL scroll(parent, child, dy, getMaxDragOffset(child), 0); } break; } case MotionEvent.ACTION_UP: if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel); } // $FALLTHROUGH case MotionEvent.ACTION_CANCEL: { mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); } return true; }
From source file:com.rks.musicx.ui.adapters.QueueAdapter.java
@Override public void onBindViewHolder(QueueViewHolder holder, int position) { Song song = getItem(position);// ww w .ja v a2 s . co m int accentColor = Config.accentColor(getContext(), Helper.getATEKey(getContext())); if (mLayoutId == R.layout.song_list) { if (position == pos) { holder.itemView.setSelected(true); highLight(holder, accentColor, accentColor); } else { holder.itemView.setSelected(false); highLight(holder, Color.WHITE, Color.BLACK); } holder.SongTitle.setText(song.getTitle()); holder.SongArtist.setText(song.getArtist()); ArtworkUtils.ArtworkLoader(getContext(), 300, 600, song.getAlbum(), song.getAlbumId(), new palette() { @Override public void palettework(Palette palette) { } }, holder.queueArtwork); holder.menu.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_menu)); holder.queueArtwork.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { mDragStartListener.onStartDrag(holder); } return false; } }); if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) { holder.SongArtist.setTextColor(ContextCompat.getColor(getContext(), R.color.darkthemeTextColor)); holder.menu.getDrawable().setTint(Color.WHITE); } else { holder.menu.getDrawable().setTint(Color.WHITE); holder.SongArtist.setTextColor(Color.WHITE); if (Extras.getInstance().getPlayingViewTrack()) { holder.menu.getDrawable().setTint(ContextCompat.getColor(getContext(), R.color.MaterialGrey)); holder.SongArtist.setTextColor(Color.DKGRAY); } } } if (mLayoutId == R.layout.gridqueue) { ArtworkUtils.ArtworkLoader(getContext(), 300, 600, song.getAlbum(), song.getAlbumId(), new palette() { @Override public void palettework(Palette palette) { } }, holder.queueArtworkgrid); } }