List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:chan.android.app.bitwise.util.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//w ww . j av a 2s .c om final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY()); switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mLastTouchX = ev.getX(); motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_DOWN; mBeginClick = true; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } mMotionPosition = motionPosition; invalidate(); 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 y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } updateSelectorState(); break; case MotionEvent.ACTION_CANCEL: mTouchMode = TOUCH_MODE_IDLE; updateSelectorState(); setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } if (mTopEdge != null) { mTopEdge.onRelease(); mBottomEdge.onRelease(); } mTouchMode = TOUCH_MODE_IDLE; break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); final int prevTouchMode = mTouchMode; if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; invalidate(); } else { mTouchMode = TOUCH_MODE_IDLE; } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { // TODO : handle mTouchMode = TOUCH_MODE_TAP; } else { mTouchMode = TOUCH_MODE_REST; } switch (prevTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight(); if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handlerTouch = getHandler(); if (handlerTouch != null) { handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(mDataChanged); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; } mBeginClick = false; updateSelectorState(); } break; } return true; }
From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java
/** * Handle touch events. One finger pans, and two finger pinch and zoom plus * panning.//from w w w.j av a 2 s.co m */ @Override public boolean onTouchEvent(MotionEvent event) { PointF vCenterEnd; float vDistEnd; // During non-interruptible anims, ignore all touch events if (anim != null && !anim.interruptible) { getParent().requestDisallowInterceptTouchEvent(true); return true; } else { anim = null; } // Abort if not ready if (vTranslate == null) { return true; } // Detect flings, taps and double taps if (detector == null || detector.onTouchEvent(event)) { return true; } int touchCount = event.getPointerCount(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_1_DOWN: case MotionEvent.ACTION_POINTER_2_DOWN: anim = null; getParent().requestDisallowInterceptTouchEvent(true); maxTouchCount = Math.max(maxTouchCount, touchCount); if (touchCount >= 2) { if (zoomEnabled) { // Start pinch to zoom. Calculate distance between touch // points and center point of the pinch. float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1)); scaleStart = scale; vDistStart = distance; vTranslateStart = new PointF(vTranslate.x, vTranslate.y); vCenterStart = new PointF((event.getX(0) + event.getX(1)) / 2, (event.getY(0) + event.getY(1)) / 2); } else { // Abort all gestures on second touch maxTouchCount = 0; } // Cancel long click timer handler.removeMessages(MESSAGE_LONG_CLICK); } else { // Start one-finger pan vTranslateStart = new PointF(vTranslate.x, vTranslate.y); vCenterStart = new PointF(event.getX(), event.getY()); // Start long click timer handler.sendEmptyMessageDelayed(MESSAGE_LONG_CLICK, 600); } return true; case MotionEvent.ACTION_MOVE: boolean consumed = false; if (maxTouchCount > 0) { if (touchCount >= 2) { // Calculate new distance between touch points, to scale and // pan relative to start values. vDistEnd = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1)); vCenterEnd = new PointF((event.getX(0) + event.getX(1)) / 2, (event.getY(0) + event.getY(1)) / 2); if (zoomEnabled && (distance(vCenterStart.x, vCenterEnd.x, vCenterStart.y, vCenterEnd.y) > 5 || Math.abs(vDistEnd - vDistStart) > 5 || isPanning)) { isZooming = true; isPanning = true; consumed = true; scale = Math.min(maxScale, (vDistEnd / vDistStart) * scaleStart); if (scale <= minScale()) { // Minimum scale reached so don't pan. Adjust start // settings so any expand will zoom in. vDistStart = vDistEnd; scaleStart = minScale(); vCenterStart = vCenterEnd; vTranslateStart = vTranslate; } else if (panEnabled) { // Translate to place the source image coordinate // that was at the center of the pinch at the start // at the center of the pinch now, to give // simultaneous pan + zoom. float vLeftStart = vCenterStart.x - vTranslateStart.x; float vTopStart = vCenterStart.y - vTranslateStart.y; float vLeftNow = vLeftStart * (scale / scaleStart); float vTopNow = vTopStart * (scale / scaleStart); vTranslate.x = vCenterEnd.x - vLeftNow; vTranslate.y = vCenterEnd.y - vTopNow; } else if (sRequestedCenter != null) { // With a center specified from code, zoom around // that point. vTranslate.x = (getWidth() / 2) - (scale * sRequestedCenter.x); vTranslate.y = (getHeight() / 2) - (scale * sRequestedCenter.y); } else { // With no requested center, scale around the image // center. vTranslate.x = (getWidth() / 2) - (scale * (sWidth() / 2)); vTranslate.y = (getHeight() / 2) - (scale * (sHeight() / 2)); } fitToBounds(true); refreshRequiredTiles(false); } } else if (!isZooming) { // One finger pan - translate the image. We do this // calculation even with pan disabled so click // and long click behaviour is preserved. float dx = Math.abs(event.getX() - vCenterStart.x); float dy = Math.abs(event.getY() - vCenterStart.y); if (dx > 5 || dy > 5 || isPanning) { consumed = true; vTranslate.x = vTranslateStart.x + (event.getX() - vCenterStart.x); vTranslate.y = vTranslateStart.y + (event.getY() - vCenterStart.y); float lastX = vTranslate.x; float lastY = vTranslate.y; fitToBounds(true); if (lastX == vTranslate.x || (lastY == vTranslate.y && dy > 10) || isPanning) { isPanning = true; } else if (dx > 5) { // Haven't panned the image, and we're at the left // or right edge. Switch to page swipe. maxTouchCount = 0; handler.removeMessages(MESSAGE_LONG_CLICK); getParent().requestDisallowInterceptTouchEvent(false); } if (!panEnabled) { vTranslate.x = vTranslateStart.x; vTranslate.y = vTranslateStart.y; getParent().requestDisallowInterceptTouchEvent(false); } refreshRequiredTiles(false); } } } if (consumed) { handler.removeMessages(MESSAGE_LONG_CLICK); invalidate(); return true; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_2_UP: handler.removeMessages(MESSAGE_LONG_CLICK); if (maxTouchCount > 0 && (isZooming || isPanning)) { if (isZooming && touchCount == 2) { // Convert from zoom to pan with remaining touch isPanning = true; vTranslateStart = new PointF(vTranslate.x, vTranslate.y); if (event.getActionIndex() == 1) { vCenterStart = new PointF(event.getX(0), event.getY(0)); } else { vCenterStart = new PointF(event.getX(1), event.getY(1)); } } if (touchCount < 3) { // End zooming when only one touch point isZooming = false; } if (touchCount < 2) { // End panning when no touch points isPanning = false; maxTouchCount = 0; } // Trigger load of tiles now required refreshRequiredTiles(true); return true; } if (touchCount == 1) { isZooming = false; isPanning = false; maxTouchCount = 0; } return true; } return super.onTouchEvent(event); }
From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { /*/*w w w . j a v a2 s .c o m*/ * 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. */ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; // Always take care of the touch gesture being complete. if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { // Release the drag. if (DEBUG) Log.v(TAG, "Intercept done!"); mIsBeingDragged = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } // Nothing more to do here if we have decided whether or not we // are dragging. if (action != MotionEvent.ACTION_DOWN) { if (mIsBeingDragged) { if (DEBUG) Log.v(TAG, "Intercept returning true!"); return true; } if (mIsUnableToDrag) { if (DEBUG) Log.v(TAG, "Intercept returning false!"); return false; } } switch (action) { 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); final float x = MotionEventCompat.getX(ev, pointerIndex); // BrantApps Change: Was final float xDiff = Math.abs(x - mLastMotionX); final float xDiff = Math.abs(x - mLastMotionX); final float y = MotionEventCompat.getY(ev, pointerIndex); // BrantApps Change: Renamed dx to dy and changed access from mLastMotionX to mLastMotionY final float dy = y - mLastMotionY; // BrantApps Change: Was final float yDiff = Math.abs(y - mLastMotionY); final float yDiff = Math.abs(dy); if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); // BrantApps Change: Replaced 4 uses in next two if blocks of mLastMotionX to mLastMotionY if (dy != 0 && !isGutterDrag(mLastMotionY, dy) && canScroll(this, false, (int) dy, (int) x, (int) y)) { // Nested view has scrollable area under this point. Let it be handled there. mInitialMotionY = mLastMotionY = y; mLastMotionY = y; mIsUnableToDrag = true; return false; } // BrantApps Change: Was if (xDiff > mTouchSlop && xDiff > yDiff) { if (yDiff > mTouchSlop && yDiff > xDiff) { if (DEBUG) Log.v(TAG, "Starting drag!"); mIsBeingDragged = true; setScrollState(SCROLL_STATE_DRAGGING); mLastMotionY = dy > 0 ? mInitialMotionY + mTouchSlop : mInitialMotionY - mTouchSlop; setScrollingCacheEnabled(true); } else { if (xDiff > mTouchSlop) { // BrantApps Change: Swapped uses of horizontal and vertical within comment // The finger has moved enough in the horizontal // direction to be counted as a drag... abort // any attempt to drag vertically, to work correctly // with children that have scrolling containers. if (DEBUG) Log.v(TAG, "Starting unable to drag!"); mIsUnableToDrag = true; } } if (mIsBeingDragged) { // Scroll to follow the motion event // BrantApps Change: Was if (performDrag(x)) { if (performDrag(y)) { ViewCompat.postInvalidateOnAnimation(this); } } break; } case MotionEvent.ACTION_DOWN: { /* * Remember location of down touch. * ACTION_DOWN always refers to pointer index 0. */ // BrantApps Change: Was mLastMotionX = mInitialMotionX = ev.getX(); mLastMotionX = ev.getX(); // BrantApps Change: Was mLastMotionY = ev.getY(); mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsUnableToDrag = false; mScroller.computeScrollOffset(); // BrantApps Change: Changed call to getFinalX() to getFinalY() and getCurrX() to getCurrY() if (mScrollState == SCROLL_STATE_SETTLING && Math.abs(mScroller.getFinalY() - mScroller.getCurrY()) > mCloseEnough) { // Let the user 'catch' the pager as it animates. mScroller.abortAnimation(); mPopulatePending = false; populate(); mIsBeingDragged = true; setScrollState(SCROLL_STATE_DRAGGING); } else { completeScroll(); mIsBeingDragged = false; } if (DEBUG) Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged + "mIsUnableToDrag=" + mIsUnableToDrag); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); /* * The only time we want to intercept motion events is if we are in the * drag mode. */ return mIsBeingDragged; }
From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (mFakeDragging) { // A fake drag is in progress already, ignore this real one // but still eat the touch events. // (It is likely that the user is multi-touching the screen.) return true; }/*from ww w .j a v a2 s. c o m*/ if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong to one of our // descendants. return false; } if (mAdapter == null || mAdapter.getCount() == 0) { // Nothing to present or scroll; nothing to touch. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); boolean needsInvalidate = false; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { mScroller.abortAnimation(); mPopulatePending = false; populate(); mIsBeingDragged = true; setScrollState(SCROLL_STATE_DRAGGING); // Remember where the motion event started // BrantApps Change: Was mLastMotionX = mInitialMotionX = ev.getX(); mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEvent.ACTION_MOVE: if (!mIsBeingDragged) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float xDiff = Math.abs(x - mLastMotionX); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mLastMotionY); if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); // BrantApps Change: Was if (xDiff > mTouchSlop && xDiff > yDiff) { if (yDiff > mTouchSlop && yDiff > xDiff) { if (DEBUG) Log.v(TAG, "Starting drag!"); mIsBeingDragged = true; // BrantApps Change: Was mLastMotionY = y - mInitialMotionY > 0 ? mInitialMotionY + mTouchSlop : mInitialMotionY - mTouchSlop; mLastMotionY = y - mInitialMotionY > 0 ? mInitialMotionY + mTouchSlop : mInitialMotionY - mTouchSlop; setScrollState(SCROLL_STATE_DRAGGING); setScrollingCacheEnabled(true); } } // Not else! Note that mIsBeingDragged can be set above. if (mIsBeingDragged) { // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); // BrantApps Change: Renamed x to y and changed call to getX() to getY() final float y = MotionEventCompat.getY(ev, activePointerIndex); needsInvalidate |= performDrag(y); } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); // BrantApps Change: Changed call to getXVelocity() to getYVelocity() int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); mPopulatePending = true; // BrantApps Change: Renamed width to height & scrollX to scrollY and changed method calls to get the values final int height = getHeight(); final int scrollY = getScrollY(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor; final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); // BrantApps Change: Renamed x to y and changed method call to get value final float y = MotionEventCompat.getY(ev, activePointerIndex); // BrantApps Change: Was final int totalDelta = (int) (x - mInitialMotionX); final int totalDelta = (int) (y - mInitialMotionY); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); mActivePointerId = INVALID_POINTER; endDrag(); needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease(); } break; case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged) { setCurrentItemInternal(mCurItem, true, true); mActivePointerId = INVALID_POINTER; endDrag(); needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease(); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); // BrantApps Change: Renamed x to y and changed method call to get value final float y = MotionEventCompat.getY(ev, index); // BrantApps Change: Was mLastMotionX = x; mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); // BrantApps Change: Was mLastMotionX = MotionEventCompat.getX(... mLastMotionY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } return true; }
From source file:com.ritesh.sevilla.EditDeliverAddressPhoneFields.VerifyPhoneFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.activity_edit_delivery_address, container, false); ButterKnife.bind(this, rootView); Appconstant.sh = getActivity().getSharedPreferences(Appconstant.MyPREFERENCES, Context.MODE_PRIVATE); User_ID = Appconstant.sh.getString("id", null); Log.e("User_ID from SharedPref :", "" + User_ID); /*textDotLoaderCountry = (DotLoader) rootView.findViewById(R.id.text_dot_loader_country); for (int i = 1; i < 4; i++) {// w w w . ja v a 2 s .c o m textDotLoaderCountry.postDelayed(new DotIncrementRunnable(3 + i, textDotLoaderCountry), i * 3000); } textDotLoaderState = (DotLoader) rootView.findViewById(R.id.text_dot_loader_state); for (int i = 1; i < 4; i++) { textDotLoaderState.postDelayed(new DotIncrementRunnable(3 + i, textDotLoaderState), i * 3000); } textDotLoaderCity = (DotLoader) rootView.findViewById(R.id.text_dot_loader_city); for (int i = 1; i < 4; i++) { textDotLoaderCity.postDelayed(new DotIncrementRunnable(3 + i, textDotLoaderCity), i * 3000); }*/ if (Utils.isConnected(getActivity())) { UserGetAddressJsontask task = new UserGetAddressJsontask(); task.execute(); } else { SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP).margin(15, 15) .backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please Your Internet Connectivity..!!")); } CPB_address_progressbar_circular = (CircularProgressBar) rootView .findViewById(R.id.cpb_address_progressbar_circular); // signupProgress.setVisibility(View.GONE); ((CircularProgressDrawable) CPB_address_progressbar_circular.getIndeterminateDrawable()).start(); updateValues(); /*%%%%%%%%%%%%%% Spinner Country (Start) %%%%%%%%%%%%%%*/ /*spinner click method and not clicked method for country (Start)*/ SP_user_country.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() { @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) { SP_user_country.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); /*Toast.makeText(getActivity(), "Position :" + " " + position + " Clicked " + "" + item, Toast.LENGTH_SHORT).show();*/ Log.e("Country Detail :", "Position :" + "" + position + "\t" + "ID :" + "" + id + "\t" + "Name :" + "" + item); /*android.support.design.widget.Snackbar.make(view, "Clicked " + item, android.support.design.widget.Snackbar.LENGTH_SHORT).show();*/ Get_user_country_SelectedValue = item; Str_get_user_country = item; Str_set_user_country = Str_get_user_country; long pos = id; int posi = position; Log.e("pos :", "" + pos); Log.e("posi ID:", "" + posi); GetSet_user_country_ID = String.valueOf(posi); Log.e("GetSet_user_country_ID :", "" + GetSet_user_country_ID); Log.e("Str_get_user_country :", "" + Str_get_user_country); Log.e("Str_set_user_country :", "" + Str_set_user_country); Log.e("Get_user_country_SelectedValue :", "" + Get_user_country_SelectedValue); if (Utils.isConnected(getActivity())) { UserStateListJsontask task = new UserStateListJsontask(); task.execute(); } else { SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please Your Internet Connectivity..!!")); } } }); SP_user_country.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() { @Override public void onNothingSelected(MaterialSpinner spinner) { /*Toast.makeText(getActivity(), "Please select Country First..!!", Toast.LENGTH_SHORT).show();*/ android.support.design.widget.Snackbar.make(spinner, "Please select Country First..!!", android.support.design.widget.Snackbar.LENGTH_SHORT).show(); } }); /*%%%%%%%%%%%%%% Spinner Country (End) %%%%%%%%%%%%%%*/ /*%%%%%%%%%%%%%% Spinner State (Start) %%%%%%%%%%%%%%*/ SP_user_state.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() { @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) { SP_user_state.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); /*Toast.makeText(getActivity(), "Position :" + " " + position + " Clicked " + "" + item, Toast.LENGTH_SHORT).show();*/ Log.e("State Detail :", "Position :" + "" + position + "\t" + "ID :" + "" + id + "\t" + "Name :" + "" + item); /*android.support.design.widget.Snackbar.make(view, "Clicked " + item, android.support.design.widget.Snackbar.LENGTH_SHORT).show();*/ Get_user_state_SelectedValue = item; Str_get_user_state = item; Str_set_user_state = Str_get_user_state; long pos = id; int posi = position; Log.e("pos :", "" + pos); Log.e("posi ID:", "" + posi); GetSet_user_state_ID = String.valueOf(posi); Log.e("GetSet_user_state_ID :", "" + GetSet_user_state_ID); Log.e("Str_get_user_state :", "" + Str_get_user_state); Log.e("Str_set_user_state :", "" + Str_set_user_state); if (Utils.isConnected(getActivity())) { UserCityListJsontask task = new UserCityListJsontask(); task.execute(); } else { SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please Your Internet Connectivity..!!")); } } }); SP_user_state.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() { @Override public void onNothingSelected(MaterialSpinner spinner) { /*Toast.makeText(getActivity(), "Please select Country First..!!", Toast.LENGTH_SHORT).show();*/ android.support.design.widget.Snackbar.make(spinner, "Please select State First..!!", android.support.design.widget.Snackbar.LENGTH_SHORT).show(); } }); /*%%%%%%%%%%%%%% Spinner State (End) %%%%%%%%%%%%%%*/ /*%%%%%%%%%%%%%% Spinner City (Start) %%%%%%%%%%%%%%*/ SP_user_city.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() { @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) { SP_user_city.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); /*Toast.makeText(getActivity(), "Position :" + " " + position + " Clicked " + "" + item, Toast.LENGTH_SHORT).show();*/ Log.e("City Detail :", "Position :" + "" + position + "\t" + "ID :" + "" + id + "\t" + "Name :" + "" + item); /*android.support.design.widget.Snackbar.make(view, "Clicked " + item, android.support.design.widget.Snackbar.LENGTH_SHORT).show();*/ Get_user_city_SelectedValue = item; Str_get_user_city = item; Str_set_user_city = Str_get_user_city; Log.e("Get_user_city_SelectedValue :", "" + Get_user_city_SelectedValue); Log.e("Str_get_user_city :", "" + Str_get_user_city); Log.e("Str_set_user_city :", "" + Str_set_user_city); } }); SP_user_city.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() { @Override public void onNothingSelected(MaterialSpinner spinner) { /*Toast.makeText(getActivity(), "Please select Country First..!!", Toast.LENGTH_SHORT).show();*/ android.support.design.widget.Snackbar.make(spinner, "Please select City First..!!", android.support.design.widget.Snackbar.LENGTH_SHORT).show(); } }); /*%%%%%%%%%%%%%% Spinner City (End) %%%%%%%%%%%%%%*/ CV_et_address_continue_payment.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { Str_set_user_f_name = ET_address_user_first_name.getText().toString().trim(); Str_set_user_l_name = ET_address_user_last_name.getText().toString().trim(); Str_set_user_street_address = ET_address_user_address.getText().toString().trim(); Str_set_user_phone = ET_address_phone.getText().toString().trim(); Str_set_user_phone_replace = Str_set_user_phone.replace(" ", ""); Str_set_user_zip_code = ET_address_user_zip_code.getText().toString().trim(); Log.e("Address Data :", "\n" + "Str_set_user_f_name :" + "" + Str_set_user_f_name + "\n" + "Str_set_user_l_name :" + "" + Str_set_user_l_name + "\n" + "Str_set_user_street_address :" + "" + Str_set_user_street_address + "\n" + "Str_set_user_phone :" + "" + Str_set_user_phone + "\n" + "Str_set_user_phone_replace :" + "" + Str_set_user_phone_replace + "\n" + "Str_set_user_zip_code :" + "" + Str_set_user_zip_code + "\n" + "Str_set_user_country :" + "" + Str_set_user_country + "\n" + "Str_set_user_state :" + "" + Str_set_user_state + "\n" + "Str_set_user_city :" + "" + Str_set_user_city + "\n"); if (event.getAction() == MotionEvent.ACTION_DOWN) { Log.e("Action ", "Down"); CV_et_address_continue_payment_click.setVisibility(View.VISIBLE); CV_et_address_continue_payment.setVisibility(View.GONE); v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // Toast.makeText(getApplicationContext(), "Add to cart Clicked", Toast.LENGTH_SHORT).show(); return true; } if (event.getAction() == MotionEvent.ACTION_MOVE) { Log.e("Action ", "Move"); CV_et_address_continue_payment_click.setVisibility(View.VISIBLE); CV_et_address_continue_payment.setVisibility(View.GONE); return true; } if (event.getAction() == MotionEvent.ACTION_UP) { Log.e("Action ", "Up"); CV_et_address_continue_payment_click.setVisibility(View.GONE); CV_et_address_continue_payment.setVisibility(View.VISIBLE); /*Intent MyCartPage = new Intent(GetDeliveryAddress.this, MyCartActivity.class); startActivity(MyCartPage);*/ if (Str_set_user_f_name.isEmpty()) { ISerror = true; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // v.playSoundEffect(SoundEffectConstants.CLICK); /**************** Start Animation ************** **/ YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_user_first_name); /**************** End Animation ****************/ /*Toast.makeText(getApplicationContext(), "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/ SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please enter your First Name")); } else if (Str_set_user_l_name.isEmpty()) { ISerror = true; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // v.playSoundEffect(SoundEffectConstants.CLICK); /**************** Start Animation ************** **/ YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_user_last_name); /**************** End Animation ****************/ /*Toast.makeText(getApplicationContext(), "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/ SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please enter your Last Name")); } else if (Str_set_user_street_address.isEmpty()) { ISerror = true; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // v.playSoundEffect(SoundEffectConstants.CLICK); /**************** Start Animation ************** **/ YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_user_address); /**************** End Animation ****************/ /*Toast.makeText(getApplicationContext(), "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/ SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please enter your Street Address")); } else if (Str_set_user_phone_replace.isEmpty()) { ISerror = true; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // v.playSoundEffect(SoundEffectConstants.CLICK); /**************** Start Animation ************** **/ YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_phone); /**************** End Animation ****************/ /*Toast.makeText(getApplicationContext(), "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/ SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please enter your Phone Number")); } else if (Str_set_user_country.isEmpty()) { ISerror = true; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // v.playSoundEffect(SoundEffectConstants.CLICK); /**************** Start Animation ************** **/ YoYo.with(Techniques.Tada).duration(700).playOn(SP_user_country); /**************** End Animation ****************/ /*Toast.makeText(getApplicationContext(), "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/ SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please select your Country")); } else if (Str_set_user_state.isEmpty()) { ISerror = true; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // v.playSoundEffect(SoundEffectConstants.CLICK); /**************** Start Animation ************** **/ YoYo.with(Techniques.Tada).duration(700).playOn(SP_user_state); /**************** End Animation ****************/ /*Toast.makeText(getApplicationContext(), "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/ SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please select your State")); } else if (Str_set_user_city.isEmpty()) { ISerror = true; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // v.playSoundEffect(SoundEffectConstants.CLICK); /**************** Start Animation ***************/ YoYo.with(Techniques.Tada).duration(700).playOn(SP_user_city); /**************** End Animation ****************/ /*Toast.makeText(getApplicationContext(), "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/ SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please select your City")); } else if (Str_set_user_zip_code.isEmpty()) { ISerror = true; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); // v.playSoundEffect(SoundEffectConstants.CLICK); /**************** Start Animation ************** **/ YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_user_zip_code); /**************** End Animation ****************/ /*Toast.makeText(getApplicationContext(), "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/ SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please enter your area code")); } else if (!ISerror) { // v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); /*Toast.makeText(getApplicationContext(), "Good", Toast.LENGTH_SHORT).show();*/ if (Utils.isConnected(getActivity())) { UserUpdateAddressJsontask task = new UserUpdateAddressJsontask(); task.execute(); } else { SnackbarManager .show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Please Your Internet Connectivity..!!")); } /* SnackbarManager.show( Snackbar.with(getActivity()) .position(Snackbar.SnackbarPosition.TOP) .margin(15, 15) .backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Good All Value Correct"));*/ // v.playSoundEffect(android.view.SoundEffectConstants.CLICK); } /*SnackbarManager.show( Snackbar.with(getActivity()) .position(Snackbar.SnackbarPosition.TOP) .margin(15, 15) .backgroundDrawable(R.drawable.snackbar_custom_layout) .text("Confirm Clicked")); */ return true; } return false; } }); initUI(rootView); return rootView; }
From source file:com.android.leanlauncher.LauncherTransitionable.java
public View.OnTouchListener getHapticFeedbackTouchListener() { if (mHapticFeedbackTouchListener == null) { mHapticFeedbackTouchListener = new View.OnTouchListener() { @Override//from w w w .j a v a 2 s.co m public boolean onTouch(View v, MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); } return false; } }; } return mHapticFeedbackTouchListener; }
From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/* w w w.jav a 2s . c o m*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: LogUtil.d("--------------onInterceptTouchEvent ACTION_DOWN---------"); mFirstDownY = ev.getRawY(); mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! mTouchMode = TOUCH_MODE_DRAGGING; reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, getFirstVisiblePosition(), getLastPosition()); 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 y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, getFirstVisiblePosition(), getLastPosition()); return true; } } } return false; }
From source file:com.airshiplay.framework.widget.MyViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (mFakeDragging) { // A fake drag is in progress already, ignore this real one // but still eat the touch events. // (It is likely that the user is multi-touching the screen.) return true; }//from w w w . j a v a2s. c o m if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong to one of our // descendants. return false; } if (mAdapter == null || mAdapter.getCount() == 0) { // Nothing to present or scroll; nothing to touch. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); boolean needsInvalidate = false; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { mScroller.abortAnimation(); mPopulatePending = false; populate(); mIsBeingDragged = true; setScrollState(SCROLL_STATE_DRAGGING); // Remember where the motion event started mLastMotionX = mInitialMotionX = ev.getX(); mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEvent.ACTION_MOVE: if (!mIsBeingDragged) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float xDiff = Math.abs(x - mLastMotionX); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mLastMotionY); if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); if (xDiff > mTouchSlop && xDiff > yDiff) { if (DEBUG) Log.v(TAG, "Starting drag!"); mIsBeingDragged = true; mLastMotionX = x - mInitialMotionX > 0 ? mInitialMotionX + mTouchSlop : mInitialMotionX - mTouchSlop; mLastMotionY = y; setScrollState(SCROLL_STATE_DRAGGING); setScrollingCacheEnabled(true); } } // Not else! Note that mIsBeingDragged can be set above. if (mIsBeingDragged) { // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); needsInvalidate |= performDrag(x); } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); mPopulatePending = true; final int width = getWidth(); final int scrollX = getScrollX(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor; final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final int totalDelta = (int) (x - mInitialMotionX); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); mActivePointerId = INVALID_POINTER; endDrag(); needsInvalidate = mLeftEdge.onRelease() | mRightEdge.onRelease(); } break; case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged) { scrollToItem(mCurItem, true, 0, false); mActivePointerId = INVALID_POINTER; endDrag(); needsInvalidate = mLeftEdge.onRelease() | mRightEdge.onRelease(); } 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: onSecondaryPointerUp(ev); mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } return true; }
From source file:com.android.backups.BackupStaggeredGridView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//from ww w . j a v a 2 s . com final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! mTouchMode = TOUCH_MODE_DRAGGING; setTouchMode(mTouchMode); 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 y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; setTouchMode(mTouchMode); return true; } } } return false; }
From source file:com.borqs.se.addobject.AddObjectViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { /*//from w w w.j a v a 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. */ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; // Always take care of the touch gesture being complete. if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { // Release the drag. mIsBeingDragged = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } // Nothing more to do here if we have decided whether or not we // are dragging. if (action != MotionEvent.ACTION_DOWN) { if (mIsBeingDragged) { return true; } if (mIsUnableToDrag) { return false; } } switch (action) { 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); final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastMotionX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mInitialMotionY); if (xDiff > mTouchSlop) { mIsBeingDragged = true; setScrollState(SCROLL_STATE_DRAGGING); mLastMotionX = dx > 0 ? mInitialMotionX + mTouchSlop : mInitialMotionX - mTouchSlop; mLastMotionY = y; setScrollingCacheEnabled(true); } else if (yDiff > mTouchSlop) { // The finger has moved enough in the vertical // direction to be counted as a drag... abort // any attempt to drag horizontally, to work correctly // with children that have scrolling containers. mIsUnableToDrag = true; } if (mIsBeingDragged) { // Scroll to follow the motion event if (performDrag(x)) { ViewCompat.postInvalidateOnAnimation(this); } } break; } case MotionEvent.ACTION_DOWN: { /* * Remember location of down touch. * ACTION_DOWN always refers to pointer index 0. */ mLastMotionX = mInitialMotionX = ev.getX(); mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsUnableToDrag = false; mScroller.computeScrollOffset(); if (mScrollState == SCROLL_STATE_SETTLING && Math.abs(mScroller.getFinalX() - mScroller.getCurrX()) > mCloseEnough) { // Let the user 'catch' the pager as it animates. mScroller.abortAnimation(); mPopulatePending = false; populate(); mIsBeingDragged = true; setScrollState(SCROLL_STATE_DRAGGING); } else { completeScroll(false); mIsBeingDragged = false; } break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); /* * The only time we want to intercept motion events is if we are in the * drag mode. */ return mIsBeingDragged; }