List of usage examples for android.view MotionEvent ACTION_MOVE
int ACTION_MOVE
To view the source code for android.view MotionEvent ACTION_MOVE.
Click Source Link
From source file:com.suan.weclient.fragment.mass.VoiceFragment.java
private void initWidgets() { recordLayout = (RelativeLayout) view.findViewById(R.id.voice_record_start); recordLayout.setOnTouchListener(new View.OnTouchListener() { @Override//from w w w.ja va2s . com public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: recordLayout.setSelected(true); if (!isRecord) { startRecord(); } break; case MotionEvent.ACTION_MOVE: recordLayout.setSelected(true); if (!isRecord) { startRecord(); } break; default: recordLayout.setSelected(false); if (isRecord) { stopRecord(); } break; } return true; } }); }
From source file:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java
@Override public boolean onTouchEvent(MotionEvent event) { if (onPageSelectedListener != null) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: int position = hitTest(event.getX()); if (position >= 0) { onPageSelectedListener.onPageStripSelected(position); }/*from w w w . j a v a 2s .co m*/ return true; } } return super.onTouchEvent(event); }
From source file:ca.psiphon.ploggy.FragmentSelfStatusDetails.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.self_status_details, container, false); mFragmentComposeMessage = new FragmentComposeMessage(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); transaction.add(R.id.fragment_self_status_details_compose_message, mFragmentComposeMessage).commit(); mScrollView = (ScrollView) view.findViewById(R.id.self_status_details_scroll_view); mAvatarImage = (ImageView) view.findViewById(R.id.self_status_details_avatar_image); mNicknameText = (TextView) view.findViewById(R.id.self_status_details_nickname_text); mFingerprintText = (TextView) view.findViewById(R.id.self_status_details_fingerprint_text); mMessagesList = (ListView) view.findViewById(R.id.self_status_details_messages_list); mLocationLabel = (TextView) view.findViewById(R.id.self_status_details_location_label); mLocationStreetAddressLabel = (TextView) view .findViewById(R.id.self_status_details_location_street_address_label); mLocationStreetAddressText = (TextView) view .findViewById(R.id.self_status_details_location_street_address_text); mLocationCoordinatesLabel = (TextView) view .findViewById(R.id.self_status_details_location_coordinates_label); mLocationCoordinatesText = (TextView) view.findViewById(R.id.self_status_details_location_coordinates_text); mLocationPrecisionLabel = (TextView) view.findViewById(R.id.self_status_details_location_precision_label); mLocationPrecisionText = (TextView) view.findViewById(R.id.self_status_details_location_precision_text); mLocationTimestampLabel = (TextView) view.findViewById(R.id.self_status_details_location_timestamp_label); mLocationTimestampText = (TextView) view.findViewById(R.id.self_status_details_location_timestamp_text); // TODO: use header/footer of listview instead of hack embedding of listview in scrollview // from: http://stackoverflow.com/questions/4490821/scrollview-inside-scrollview/11554823#11554823 mScrollView.setOnTouchListener(new View.OnTouchListener() { @Override//from w ww .j av a2 s . c o m public boolean onTouch(View view, MotionEvent event) { mMessagesList.requestDisallowInterceptTouchEvent(false); return false; } }); mMessagesList.setOnTouchListener(new View.OnTouchListener() { private float downX, downY; @Override public boolean onTouch(View view, MotionEvent event) { // We want to capture vertical scrolling motions for use by // the messages list, but we don't want to capture horizontal // swiping that should be used to switch tabs. So we're going // to decide based on whether the move looks more X-ish or Y-ish. if (event.getAction() == MotionEvent.ACTION_DOWN) { downX = event.getX(); downY = event.getY(); // Make sure the parent is allowed to intercept. view.getParent().requestDisallowInterceptTouchEvent(false); } else if (event.getAction() == MotionEvent.ACTION_MOVE) { float deltaX = downX - event.getX(); float deltaY = downY - event.getY(); if (Math.abs(deltaY) > Math.abs(deltaX)) { // Looks like a Y-ish scroll attempt. Disallow parent from intercepting. view.getParent().requestDisallowInterceptTouchEvent(true); } } return false; } }); try { mMessageAdapter = new MessageAdapter(getActivity(), MessageAdapter.Mode.SELF_MESSAGES); mMessagesList.setAdapter(mMessageAdapter); } catch (Utils.ApplicationError e) { Log.addEntry(LOG_TAG, "failed to load self messages"); } show(view); // Refresh the message list every 5 seconds. This updates "time ago" displays. // TODO: event driven redrawing? mRefreshUIExecutor = new Utils.FixedDelayExecutor(new Runnable() { @Override public void run() { show(); } }, 5000); Events.register(this); return view; }
From source file:com.app.gongza.libs.view.scrollablelayout.ScrollableLayout.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { float currentX = ev.getX(); float currentY = ev.getY(); float deltaY; int shiftX = (int) Math.abs(currentX - mDownX); int shiftY = (int) Math.abs(currentY - mDownY); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mDisallowIntercept = false;/*from ww w . j av a2s .co m*/ needCheckUpdown = true; updown = true; mDownX = currentX; mDownY = currentY; mLastY = currentY; checkIsClickHead((int) currentY, mHeadHeight, getScrollY()); checkIsClickHeadExpand((int) currentY, mHeadHeight, getScrollY()); initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); mScroller.forceFinished(true); break; case MotionEvent.ACTION_MOVE: if (mDisallowIntercept) { break; } initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); deltaY = mLastY - currentY; if (needCheckUpdown) { if (shiftX > mTouchSlop && shiftX > shiftY) { needCheckUpdown = false; updown = false; } else if (shiftY > mTouchSlop && shiftY > shiftX) { needCheckUpdown = false; updown = true; } } if (updown && shiftY > mTouchSlop && shiftY > shiftX && (!isSticked() || mHelper.isTop() || isClickHeadExpand)) { if (childViewPager != null) { childViewPager.requestDisallowInterceptTouchEvent(true); } scrollBy(0, (int) (deltaY + 0.5)); } mLastY = currentY; break; case MotionEvent.ACTION_UP: if (updown && shiftY > shiftX && shiftY > mTouchSlop) { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); float yVelocity = -mVelocityTracker.getYVelocity(); boolean dislowChild = false; if (Math.abs(yVelocity) > mMinimumVelocity) { mDirection = yVelocity > 0 ? DIRECTION.UP : DIRECTION.DOWN; if ((mDirection == DIRECTION.UP && isSticked()) || (!isSticked() && getScrollY() == 0 && mDirection == DIRECTION.DOWN)) { dislowChild = true; } else { mScroller.fling(0, getScrollY(), 0, (int) yVelocity, 0, 0, -Integer.MAX_VALUE, Integer.MAX_VALUE); mScroller.computeScrollOffset(); mLastScrollerY = getScrollY(); invalidate(); } } if (!dislowChild && (isClickHead || !isSticked())) { int action = ev.getAction(); ev.setAction(MotionEvent.ACTION_CANCEL); boolean dispathResult = super.dispatchTouchEvent(ev); ev.setAction(action); return dispathResult; } } break; default: break; } super.dispatchTouchEvent(ev); return true; }
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 ww . j a va 2 s . c om 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.bobomee.android.recyclerviewhelper.fastscroll.FastScroller.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: if (event.getX() < handle.getX() - ViewCompat.getPaddingStart(handle)) return false; if (currentAnimator != null) currentAnimator.cancel();/* ww w.ja v a2s.c om*/ handle.setSelected(true); mOnScrollStateChange.onFastScrollerStateChange(true); showBubble(); case MotionEvent.ACTION_MOVE: float y = event.getY(); setBubbleAndHandlePosition(y); onScrollPosition(y); return true; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: handle.setSelected(false); mOnScrollStateChange.onFastScrollerStateChange(false); hideBubble(); return true; } return super.onTouchEvent(event); }
From source file:com.chengmeng.tools.views.slidepage.ScrollableLayout.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { float currentX = ev.getX(); float currentY = ev.getY(); float deltaY; int shiftX = (int) Math.abs(currentX - mDownX); int shiftY = (int) Math.abs(currentY - mDownY); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: is_touching = 0;/* w ww . j a v a 2s . c o m*/ mDisallowIntercept = false; needCheckUpdown = true; updown = true; mDownX = currentX; mDownY = currentY; mLastY = currentY; checkIsClickHead((int) currentY, mHeadHeight, getScrollY()); checkIsClickHeadExpand((int) currentY, mHeadHeight, getScrollY()); initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); mScroller.forceFinished(true); break; case MotionEvent.ACTION_MOVE: is_touching++; if (mDisallowIntercept) { break; } initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); deltaY = mLastY - currentY; if (needCheckUpdown) { if (shiftX > mTouchSlop && shiftX > shiftY) { needCheckUpdown = false; updown = false; } else if (shiftY > mTouchSlop && shiftY > shiftX) { needCheckUpdown = false; updown = true; } } if (updown && shiftY > mTouchSlop && shiftY > shiftX && (!isSticked() || mHelper.isTop() || isClickHeadExpand)) { if (childViewPager != null) { childViewPager.requestDisallowInterceptTouchEvent(true); } scrollBy(0, (int) (deltaY + 0.5)); } mLastY = currentY; break; case MotionEvent.ACTION_UP: if (updown && shiftY > shiftX && shiftY > mTouchSlop) { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); float yVelocity = -mVelocityTracker.getYVelocity(); boolean dislowChild = false; if (Math.abs(yVelocity) > mMinimumVelocity) { mDirection = yVelocity > 0 ? DIRECTION.UP : DIRECTION.DOWN; if ((mDirection == DIRECTION.UP && isSticked()) || (!isSticked() && getScrollY() == 0 && mDirection == DIRECTION.DOWN)) { dislowChild = true; } else { mScroller.fling(0, getScrollY(), 0, (int) yVelocity, 0, 0, -Integer.MAX_VALUE, Integer.MAX_VALUE); mScroller.computeScrollOffset(); mLastScrollerY = getScrollY(); invalidate(); } } if (!dislowChild && (isClickHead || !isSticked())) { int action = ev.getAction(); ev.setAction(MotionEvent.ACTION_CANCEL); boolean dispathResult = super.dispatchTouchEvent(ev); ev.setAction(action); return dispathResult; } } break; default: break; } super.dispatchTouchEvent(ev); return true; }
From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean isIntercepted = super.onInterceptTouchEvent(ev); int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mDownX = mLastX = (int) ev.getX(); mDownY = (int) ev.getY(); isIntercepted = false;//w w w. ja va 2 s .c o m break; case MotionEvent.ACTION_MOVE: int disX = (int) (ev.getX() - mDownX); int disY = (int) (ev.getY() - mDownY); isIntercepted = Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY); break; case MotionEvent.ACTION_UP: isIntercepted = false; if (isMenuOpen() && mSwipeCurrentHorizontal.isClickOnContentView(getWidth(), ev.getX())) { smoothCloseMenu(); isIntercepted = true; } break; case MotionEvent.ACTION_CANCEL: isIntercepted = false; if (!mScroller.isFinished()) mScroller.abortAnimation(); break; } return isIntercepted; }
From source file:gov.sfmta.sfpark.AnnotationsOverlay.java
@Override public boolean onTouchEvent(MotionEvent e, MapView mapView) { int fingers = e.getPointerCount(); int action = e.getAction(); Log.v(TAG, "onTouchEvent " + action); if (action == MotionEvent.ACTION_DOWN) { isPinch = false;/*from w w w. ja v a 2 s. com*/ } if (action == MotionEvent.ACTION_MOVE && fingers == 2) { isPinch = true; } if (popupView != null) { MainScreenActivity.mapView.removeView(popupView); popupView = null; } return super.onTouchEvent(e, mapView); }
From source file:com.arthurpitman.common.SlidingPanel.java
@Override public boolean onTouchEvent(MotionEvent event) { float y = event.getY(); int action = event.getActionMasked(); int pointerId = event.getPointerId(event.getActionIndex()); switch (action) { case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_DOWN: startTouchY = y;/*from w ww . j a va2 s . c o m*/ startTouchScrollY = getScrollY(); // if touch didn't occur on the actual control, ignore it float touchBoundary = viewHeight - collapsedHeight - startTouchScrollY; if (y < touchBoundary) { return false; } // start tracking velocity if (velocityTracker == null) { velocityTracker = VelocityTracker.obtain(); } else { velocityTracker.clear(); } velocityTracker.addMovement(event); break; case MotionEvent.ACTION_MOVE: // determine if a valid touch has started if (Math.abs(y - startTouchY) > touchSlop) { touchState = TOUCH_STARTED; } if (velocityTracker != null) { velocityTracker.addMovement(event); } // scroll as appropriate if (touchState == TOUCH_STARTED) { final int scrollDelta = (int) (startTouchY - y); scrollTo(0, Math.max(0, Math.min(viewHeight, startTouchScrollY + scrollDelta))); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: if (touchState == TOUCH_STARTED) { final int currentScrollY = getScrollY(); // get velocity float velocity = 0; if (velocityTracker != null) { velocityTracker.computeCurrentVelocity(1000); velocity = VelocityTrackerCompat.getYVelocity(velocityTracker, pointerId); velocityTracker.recycle(); velocityTracker = null; } // snap to final scroll position int target = startTouchScrollY; if ((Math.abs(velocity) > minimumflingVelocity) || (Math.abs(y - startTouchY) > (viewHeight / 2))) { if (velocity < 0) { target = viewHeight; } else { target = 0; } } scroller.startScroll(0, currentScrollY, 0, target - currentScrollY); invalidate(); touchState = TOUCH_NONE; } break; } return true; }