List of usage examples for android.view MotionEvent ACTION_UP
int ACTION_UP
To view the source code for android.view MotionEvent ACTION_UP.
Click Source Link
From source file:com.ahutjw.indicator.TitlePageIndicator.java
@Override public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*from ww w.j a va 2s . com*/ if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } else { //Middle third if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:android.hqs.view.pager.indicator.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from ww w.j a va 2 s . c o m if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } else { //Middle third if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanSlide || !mIsSlidingEnabled) { return super.onTouchEvent(ev); }/*from w w w. j av a 2 s . co m*/ mDragHelper.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_UP: { final float x = ev.getX(); final float y = ev.getY(); final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mDragHelper.getTouchSlop(); View dragView = mDragView != null ? mDragView : mSlideableView; if (dx * dx + dy * dy < slop * slop && isDragViewUnder((int) x, (int) y)) { dragView.playSoundEffect(SoundEffectConstants.CLICK); if (!isExpanded() && !isAnchored()) { expandPane(mAnchorPoint); } else { collapsePane(); } break; } break; } } return wantTouchEvents; }
From source file:com.nps.micro.view.TestsSectionFragment.java
private void createSequenceChooser(View rootView) { final String[] sequencesArray = getResources().getStringArray(R.array.sequence_array); selectedSequences.clear();//from w ww . j ava 2 s .c o m selectedSequences.addAll(model.getSequencesAsStrings()); runButton.setEnabled(model.getSequences().length > 0); selectedSequencesListView = (DynamicListView) rootView.findViewById(R.id.selectedSequencesListView); selectedSequencesListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); selectedSequencesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedSequences); selectedSequencesListView.setListItems(selectedSequences); selectedSequencesListView.setAdapter(selectedSequencesAdapter); setListViewHeightBasedOnChildren(selectedSequencesListView); selectedSequencesListView.setOnTouchListener(new ListView.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: v.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: v.getParent().requestDisallowInterceptTouchEvent(false); break; } v.onTouchEvent(event); return true; } }); selectSequenceButton = (Button) rootView.findViewById(R.id.selectSequenceButton); selectSequenceButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { boolean[] checkedItems = new boolean[sequencesArray.length]; for (int i = 0; i < sequencesArray.length; i++) { if (selectedSequences.contains(sequencesArray[i])) { checkedItems[i] = true; } else { checkedItems[i] = false; } } new AlertDialog.Builder(getActivity()).setTitle(R.string.arhitecture) .setMultiChoiceItems(sequencesArray, checkedItems, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { String selectedArchitecture = sequencesArray[which]; if (isChecked) { selectedSequences.add(selectedArchitecture); } else if (selectedSequences.contains(selectedArchitecture)) { selectedSequences.remove(selectedArchitecture); } } }) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { runButton.setEnabled(!selectedSequences.isEmpty()); model.setSequences(selectedSequences); selectedSequencesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedSequences); selectedSequencesListView.setAdapter(selectedSequencesAdapter); setListViewHeightBasedOnChildren(selectedSequencesListView); } }).create().show(); } }); }
From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // Preserve the open state based on the last view that was touched. if (!mCanSlide && action == MotionEvent.ACTION_DOWN && getChildCount() > 1) { // After the first things will be slideable. final View secondChild = getChildAt(1); if (secondChild != null) { mPreservedOpenState = !mDragHelper.isViewUnder(secondChild, (int) ev.getX(), (int) ev.getY()); }/*from w w w .jav a 2s. co m*/ } if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel(); return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } boolean interceptTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; if (mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y) && isDimmed(mSlideableView)) { interceptTap = true; } break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int slop = mDragHelper.getTouchSlop(); View view = findViewAtPosition(this, (int) x, (int) y); if (adx > slop && ady > adx || view != null) { if (view != null) { Log.d(TAG, "touch on unscrollable view"); } mDragHelper.cancel(); mIsUnableToDrag = true; return false; } } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev); return interceptForDrag || interceptTap; }
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { SimpleMonthAdapter.CalendarDay calendarDay = getDayFromLocation(event.getX(), event.getY()); if (calendarDay != null) { onDayClick(calendarDay);/*w w w .j av a2 s.c om*/ } } return true; }
From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java
/** *//*from w w w . ja v a 2s. com*/ @Override @SuppressLint("NewApi") public boolean onTouchEvent(@NonNull MotionEvent event) { final boolean processed = super.onTouchEvent(event); final int progress = getProgress(); if (processed) { if (progress != mProgress) { this.handleProgressChange(progress); } this.ensureDecorator(); switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: if (mDecorator.hasPrivateFlag(PFLAG_DISCRETE_PREVIEW_ENABLED)) { this.revealDiscreteComponents(); } break; case MotionEvent.ACTION_MOVE: final Drawable background = getBackground(); if (background != null && mAnimations.shouldDraw() && UiConfig.MATERIALIZED) { // Cancel the revealed circle around the thumb. background.setHotspotBounds(0, 0, 0, 0); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDecorator.hasPrivateFlag(PFLAG_DISCRETE_PREVIEW_ENABLED)) { this.concealDiscreteComponents(); } break; } } return processed; }
From source file:android.support.v7.widget.SwitchCompat.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*from w w w . j a va2s.c o m*/ final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); if (isEnabled() && hitThumb(x, y)) { mTouchMode = TOUCH_MODE_DOWN; mTouchX = x; mTouchY = y; } break; } case MotionEvent.ACTION_MOVE: { switch (mTouchMode) { case TOUCH_MODE_IDLE: // Didn't target the thumb, treat normally. break; case TOUCH_MODE_DOWN: { final float x = ev.getX(); final float y = ev.getY(); if (Math.abs(x - mTouchX) > mTouchSlop || Math.abs(y - mTouchY) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; getParent().requestDisallowInterceptTouchEvent(true); mTouchX = x; mTouchY = y; return true; } break; } case TOUCH_MODE_DRAGGING: { final float x = ev.getX(); final int thumbScrollRange = getThumbScrollRange(); final float thumbScrollOffset = x - mTouchX; float dPos; if (thumbScrollRange != 0) { dPos = thumbScrollOffset / thumbScrollRange; } else { // If the thumb scroll range is empty, just use the // movement direction to snap on or off. dPos = thumbScrollOffset > 0 ? 1 : -1; } if (ViewUtils.isLayoutRtl(this)) { dPos = -dPos; } final float newPos = constrain(mThumbPosition + dPos, 0, 1); if (newPos != mThumbPosition) { mTouchX = x; setThumbPosition(newPos); } return true; } } break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { if (mTouchMode == TOUCH_MODE_DRAGGING) { stopDrag(ev); // Allow super class to handle pressed state, etc. super.onTouchEvent(ev); return true; } mTouchMode = TOUCH_MODE_IDLE; mVelocityTracker.clear(); break; } } return super.onTouchEvent(ev); }
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_HOVER_ENTER: // Fall-through to movement events. onEnter(event.getX(), event.getY()); case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_HOVER_MOVE: onMove(event.getX(), event.getY()); break;//w ww . j a va2 s . co m case MotionEvent.ACTION_UP: case MotionEvent.ACTION_HOVER_EXIT: onUp(event.getX(), event.getY()); break; default: // Don't handle other types of events. return false; } mHandler.onTouch(this, event); return true; }
From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { /*//from w w w .j ava 2s . c om * This method JUST determines whether we want to intercept the motion. * If we return true, onMotionEvent will be called and we do the actual * scrolling there. */ /* * Shortcut the most recurring case: the user is in the dragging * state and he is moving his finger. We want to intercept this * motion. */ final int action = ev.getAction(); if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { return true; } switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_MOVE: { /* * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check * whether the user has moved far enough from his original down touch. */ /* * Locally do absolute value. mLastMotionY is set to the y value * of the down event. */ final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { Log.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent"); break; } final int y = (int) MotionEventCompat.getY(ev, pointerIndex); final int yDiff = Math.abs(y - mLastMotionY); if (yDiff > mTouchSlop && (getNestedScrollAxes() & ViewCompat.SCROLL_AXIS_VERTICAL) == 0) { mIsBeingDragged = true; mLastMotionY = y; initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); mNestedYOffset = 0; final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } break; } case MotionEvent.ACTION_DOWN: { final int y = (int) ev.getY(); if (!inChild((int) ev.getX(), y)) { mIsBeingDragged = false; recycleVelocityTracker(); break; } /* * Remember location of down touch. * ACTION_DOWN always refers to pointer index 0. */ mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); /* * If being flinged and user touches the screen, initiate drag; * otherwise don't. mScroller.isFinished should be false when * being flinged. */ //mIsBeingDragged = !mScroller.isFinished(); mIsBeingDragged = false; startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: /* Release the drag */ mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; recycleVelocityTracker(); if (mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) { ViewCompat.postInvalidateOnAnimation(this); } stopNestedScroll(); break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } /* * The only time we want to intercept motion events is if we are in the * drag mode. */ return mIsBeingDragged; }