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.android.app.MediaPlaybackActivity.java
public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); TextView tv = textViewForContainer(v); if (tv == null) { return false; }/*from w w w. j ava2s. c o m*/ if (action == MotionEvent.ACTION_DOWN) { v.setBackgroundColor(0xff606060); mInitialX = mLastX = (int) event.getX(); mDraggingLabel = false; } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { v.setBackgroundColor(0); if (mDraggingLabel) { Message msg = mLabelScroller.obtainMessage(0, tv); mLabelScroller.sendMessageDelayed(msg, 1000); } } else if (action == MotionEvent.ACTION_MOVE) { if (mDraggingLabel) { int scrollx = tv.getScrollX(); int x = (int) event.getX(); int delta = mLastX - x; if (delta != 0) { mLastX = x; scrollx += delta; if (scrollx > mTextWidth) { // scrolled the text completely off the view to the left scrollx -= mTextWidth; scrollx -= mViewWidth; } if (scrollx < -mViewWidth) { // scrolled the text completely off the view to the right scrollx += mViewWidth; scrollx += mTextWidth; } tv.scrollTo(scrollx, 0); } return true; } int delta = mInitialX - (int) event.getX(); if (Math.abs(delta) > mTouchSlop) { // start moving mLabelScroller.removeMessages(0, tv); // Only turn ellipsizing off when it's not already off, because it // causes the scroll position to be reset to 0. if (tv.getEllipsize() != null) { tv.setEllipsize(null); } Layout ll = tv.getLayout(); // layout might be null if the text just changed, or ellipsizing // was just turned off if (ll == null) { return false; } // get the non-ellipsized line width, to determine whether scrolling // should even be allowed mTextWidth = (int) tv.getLayout().getLineWidth(0); mViewWidth = tv.getWidth(); if (mViewWidth > mTextWidth) { tv.setEllipsize(TruncateAt.END); v.cancelLongPress(); return false; } mDraggingLabel = true; tv.setHorizontalFadingEdgeEnabled(true); v.cancelLongPress(); return true; } } return false; }
From source file:com.commonsware.cwac.crossport.design.widget.BottomSheetBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { mIgnoreEvents = true;/*from w w w . ja va 2 s . c o m*/ return false; } int action = event.getActionMasked(); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchingScrollingChild = false; mActivePointerId = MotionEvent.INVALID_POINTER_ID; // Reset the ignore flag if (mIgnoreEvents) { mIgnoreEvents = false; return false; } break; case MotionEvent.ACTION_DOWN: int initialX = (int) event.getX(); mInitialY = (int) event.getY(); View scroll = mNestedScrollingChildRef != null ? mNestedScrollingChildRef.get() : null; if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; } mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID && !parent.isPointInChildBounds(child, initialX, mInitialY); break; } if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) { return true; } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. View scroll = mNestedScrollingChildRef.get(); return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY()) && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }
From source file:com.bolaa.medical.view.banner.CirclePageIndicator.java
public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from www . ja v a 2s .c o m if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { 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) { if (!mViewPager.isFakeDragging()) { mViewPager.beginFakeDrag(); } mLastMotionX = x; // tyl ?beginFakeDrag()false,pagermFakeDragging???, // ?isFakeDragging()?false??fakeDragBy() if (mViewPager != null && mViewPager.isFakeDragging()) { try { mViewPager.fakeDragBy(deltaX); } catch (NullPointerException e) { LogUtil.w(e); return true; } } } 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; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager != null && mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; 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:com.cubic9.android.droidglove.Main.java
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mYPointWhenDown = event.getY();/* w w w. ja v a2 s . co m*/ break; case MotionEvent.ACTION_MOVE: mYDiff = event.getY() - mYPointWhenDown; if (mYDiff < 0) { mYDiff = 0; mYPointWhenDown = event.getY(); } else if (mYDiff > 100) { mYDiff = 100; mYPointWhenDown = event.getY() - 100; } break; case MotionEvent.ACTION_UP: mYDiff = 0; break; default: break; } return true; }
From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanPickRange) { return super.onTouchEvent(ev); }//from w ww .ja v a2 s.c om // looks like the ViewPager wants to step in if (mCheckForLongPress != null) { removeCallbacks(mCheckForLongPress); } if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && (UP || CANCEL)"); } if (ev.getAction() == MotionEvent.ACTION_UP) { if (mDayPickerPagerAdapter != null) { mTempSelectedDate = mDayPickerPagerAdapter.resolveEndDateForRange((int) ev.getX(), (int) ev.getY(), getCurrentItem(), false); mDayPickerPagerAdapter.onDateRangeSelectionEnded(mTempSelectedDate); } } mIsLongPressed = false; mInitialDownX = -1; mInitialDownY = -1; mScrollingDirection = NOT_SCROLLING; if (mScrollerRunnable != null) { removeCallbacks(mScrollerRunnable); } //return true; } else if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_DOWN) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && DOWN"); } mScrollingDirection = NOT_SCROLLING; } else if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_MOVE) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && MOVE"); } int direction = resolveDirectionForScroll(ev.getX()); boolean directionChanged = mScrollingDirection != direction; if (directionChanged) { if (mScrollerRunnable != null) { removeCallbacks(mScrollerRunnable); } } if (mScrollerRunnable == null) { mScrollerRunnable = new ScrollerRunnable(); } mScrollingDirection = direction; if (mScrollingDirection == NOT_SCROLLING) { if (mDayPickerPagerAdapter != null) { mTempSelectedDate = mDayPickerPagerAdapter.resolveEndDateForRange((int) ev.getX(), (int) ev.getY(), getCurrentItem(), true); if (mTempSelectedDate != null) { mDayPickerPagerAdapter.onDateRangeSelectionUpdated(mTempSelectedDate); } } } else if (directionChanged) { // SCROLLING_LEFT || SCROLLING_RIGHT post(mScrollerRunnable); } } return mIsLongPressed || super.onTouchEvent(ev); }
From source file:com.test.hwautotest.emmagee.service.EmmageeService.java
/** * create a floating window to show real-time data. *//* w w w. j a v a 2 s. c o m*/ private void createFloatingWindow() { SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = shared.edit(); editor.putInt("float", 1); editor.commit(); windowManager = (WindowManager) getApplicationContext().getSystemService("window"); wmParams = ((MyApplication) getApplication()).getMywmParams(); wmParams.type = 2002; wmParams.flags |= 8; wmParams.gravity = Gravity.LEFT | Gravity.TOP; wmParams.x = 0; wmParams.y = 0; wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.format = 1; windowManager.addView(viFloatingWindow, wmParams); viFloatingWindow.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { x = event.getRawX(); y = event.getRawY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // state = MotionEvent.ACTION_DOWN; startX = x; startY = y; mTouchStartX = event.getX(); mTouchStartY = event.getY(); Log.d("startP", "startX" + mTouchStartX + "====startY" + mTouchStartY); break; case MotionEvent.ACTION_MOVE: // state = MotionEvent.ACTION_MOVE; updateViewPosition(); break; case MotionEvent.ACTION_UP: // state = MotionEvent.ACTION_UP; updateViewPosition(); // showImg();//? mTouchStartX = mTouchStartY = 0; break; } return true; } }); // btnWifi.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // try { // btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi); // String buttonText = (String) btnWifi.getText(); // String wifiText = getResources().getString( // R.string.openwifi); // if (buttonText.equals(wifiText)) { // wifiManager.setWifiEnabled(true); // btnWifi.setText(R.string.closewifi); // } else { // wifiManager.setWifiEnabled(false); // btnWifi.setText(R.string.openwifi); // } // } catch (Exception e) { // Toast.makeText(viFloatingWindow.getContext(), "?wifi", // Toast.LENGTH_LONG).show(); // Log.e(LOG_TAG, e.toString()); // } // } // }); //? imgClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub showMemi(); } }); }
From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { int actionMasked = MotionEventCompat.getActionMasked(event); switch (actionMasked) { case MotionEvent.ACTION_DOWN: mDownX = event.getX();//from ww w . ja va2 s .c o m mDisallowedParentIntercept = false; case MotionEvent.ACTION_MOVE: int x = (int) event.getX(); if (!mDisallowedParentIntercept && Math.abs(x - mDownX) > mScaledTouchSlop) { getParent().requestDisallowInterceptTouchEvent(true); mDisallowedParentIntercept = true; } Item item = findItemByPoint(x, (int) event.getY()); if (mTargetItem != item) { mTargetItem = item; if (item != null) { item.setSelected(!item.isSelected()); ItemState state = new ItemState(); state.item = item; state.isSelected = item.isSelected(); if (mItemState == null) { mItemState = state; } else { state.next = mItemState; mItemState = state; } } } break; case MotionEvent.ACTION_CANCEL: if (mItemState != null) { ItemState state = mItemState; while (state != null) { state.item.setSelected(!state.isSelected); state = state.next; } } case MotionEvent.ACTION_UP: requestLayout(); invalidate(); mTargetItem = null; if (mDisallowedParentIntercept) { getParent().requestDisallowInterceptTouchEvent(false); } mItemState = null; break; } return true; }
From source file:com.chauthai.overscroll.BouncyAdapter.java
private void initTouchListener() { mRecyclerView.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() { @Override/* w w w . jav a2s . c o m*/ public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { switch (e.getAction()) { case MotionEvent.ACTION_DOWN: mPrevTime = SystemClock.elapsedRealtime(); mShouldUseSpring = false; mSpringScroller.stopScroll(); mIsScrollBack = false; rv.stopScroll(); break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: onActionUp(); break; } mGestureOnIntercept = true; mGestureDetector.onTouchEvent(e); // return true so that RecyclerView won't scroll when the user scroll. // We scroll it using scrollBy(). return shouldInterceptTouch(); } @Override public void onTouchEvent(RecyclerView rv, MotionEvent e) { mGestureOnIntercept = false; mGestureDetector.onTouchEvent(e); switch (e.getAction()) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mGestureOnIntercept = true; onActionUp(); break; } } }); }
From source file:com.android.photos.views.GalleryThumbnailView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//from w ww. jav a 2 s .co m final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchX = ev.getX(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderX = 0; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! mTouchMode = TOUCH_MODE_DRAGGING; return true; } break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float x = MotionEventCompat.getX(ev, index); final float dx = x - mLastTouchX + mTouchRemainderX; final int deltaY = (int) dx; mTouchRemainderX = dx - deltaY; if (Math.abs(dx) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; return true; } } } return false; }
From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { mIgnoreEvents = true;/*from w w w .ja va 2 s. c o m*/ return false; } int action = MotionEventCompat.getActionMasked(event); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchingScrollingChild = false; mActivePointerId = MotionEvent.INVALID_POINTER_ID; // Reset the ignore flag if (mIgnoreEvents) { mIgnoreEvents = false; return false; } break; case MotionEvent.ACTION_DOWN: int initialX = (int) event.getX(); mInitialY = (int) event.getY(); for (WeakReference<View> scrollableView : scrollableViews) { View scroll = scrollableView.get(); if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; break; } } mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID && !parent.isPointInChildBounds(child, initialX, mInitialY); break; } if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) { return true; } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. boolean isPointInChildBounds = false; for (WeakReference<View> scrollableView : scrollableViews) { isPointInChildBounds = scrollableView.get() != null && parent.isPointInChildBounds(scrollableView.get(), (int) event.getX(), (int) event.getY()); if (isPointInChildBounds) { break; } } return action == MotionEvent.ACTION_MOVE && !mIgnoreEvents && mState != STATE_DRAGGING && !isPointInChildBounds && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }