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:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(@NonNull MotionEvent event) { ensureTarget();/* w ww . j av a 2 s . co m*/ if (!isEnabled() || canChildScrollUp() || isRefreshing()) { return false; } final int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(event, 0); mFirstTouchDownPointY = getMotionEventY(event, mActivePointerId); break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { return false; } final float currentY = getMotionEventY(event, mActivePointerId); if (currentY == -1) { return false; } if (mFirstTouchDownPointY == -1) { mFirstTouchDownPointY = currentY; } final float yDiff = currentY - mFirstTouchDownPointY; // State is changed to drag if over slop if (yDiff > ViewConfiguration.get(getContext()).getScaledTouchSlop() && !isRefreshing()) { mCircleView.makeProgressTransparent(); return true; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mActivePointerId = INVALID_POINTER; break; } return false; }
From source file:com.audionote.widget.SlideSwitch.java
@Override public boolean onTouchEvent(MotionEvent event) { if (slideable == false) return super.onTouchEvent(event); int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: eventStartX = (int) event.getRawX(); break;/*from w w w .j av a 2s . com*/ case MotionEvent.ACTION_MOVE: eventLastX = (int) event.getRawX(); diffX = eventLastX - eventStartX; int tempX = diffX + frontRect_left_begin; tempX = (tempX > max_left ? max_left : tempX); tempX = (tempX < min_left ? min_left : tempX); if (tempX >= min_left && tempX <= max_left) { frontRect_left = tempX; alpha = (int) (255 * (float) tempX / (float) max_left); invalidateView(); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: int wholeX = (int) (event.getRawX() - eventStartX); frontRect_left_begin = frontRect_left; boolean toRight; toRight = (frontRect_left_begin > max_left / 2 ? true : false); if (Math.abs(wholeX) < 3) { toRight = !toRight; } moveToDest(toRight); break; default: Log.d("motion", action + ""); break; } return true; }
From source file:com.acceleratedio.pac_n_zoom.AnimActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_anm); orgnlImageView = (ImageView) findViewById(R.id.imageView); orgnlImageView.setMaxHeight(800);// ww w.j av a2s . c o m orgnlImageView.setMaxWidth(600); crt_ctx = this; BitmapFactory.Options bmp_opt = new BitmapFactory.Options(); bmp_opt.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT; // - Now we need to set the GUI ImageView data with data read from the picked file. DcodRszdBmpFil dcodRszdBmpFil = new DcodRszdBmpFil(); Bitmap bmp = dcodRszdBmpFil.DcodRszdBmpFil(SelectImageActivity.orgFil, bmp_opt); // Now we need to set the GUI ImageView data with the orginal file selection. orgnlImageView.setImageBitmap(bmp); orgnl_iv_wdth = bmp.getWidth(); orgnl_iv_hght = bmp.getHeight(); final RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo); scaleGestureDetector = new ScaleGestureDetector(this, new simpleOnScaleGestureListener()); orgnlImageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getPointerCount() > 1 || flgInScale) { scaleGestureDetector.onTouchEvent(event); return true; } int end_hrz; int end_vrt; final int pointerIndex; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: pointerIndex = MotionEventCompat.getActionIndex(event); bgn_hrz = (int) MotionEventCompat.getX(event, pointerIndex); bgn_vrt = (int) MotionEventCompat.getY(event, pointerIndex); String log_str = "Beginning coordinates: Horz = " + String.valueOf(bgn_hrz) + "; Vert = " + String.valueOf(bgn_vrt); Log.d("OnTouchListener", log_str); orlp = (RelativeLayout.LayoutParams) orgnlImageView.getLayoutParams(); bgn_top = (int) orlp.topMargin; bgn_lft = (int) orlp.leftMargin; // To prevent an initial jump of the magnifier, aposX and aPosY must // have the values from the magnifier frame if (aPosX == 0) aPosX = orgnlImageView.getX(); if (aPosY == 0) aPosY = orgnlImageView.getY(); break; case MotionEvent.ACTION_MOVE: pointerIndex = MotionEventCompat.getActionIndex(event); float crt_hrz = MotionEventCompat.getX(event, pointerIndex); float crt_vrt = MotionEventCompat.getY(event, pointerIndex); final float dx = crt_hrz - bgn_hrz; final float dy = crt_vrt - bgn_vrt; aPosX += dx; aPosY += dy; orgnlImageView.setX(aPosX); orgnlImageView.setY(aPosY); log_str = "Current Position: Horz = " + String.valueOf(crt_hrz) + "; Vert = " + String.valueOf(crt_vrt); Log.d("OnTouchListener", log_str); break; case MotionEvent.ACTION_UP: pointerIndex = MotionEventCompat.getActionIndex(event); end_hrz = (int) MotionEventCompat.getX(event, pointerIndex); end_vrt = (int) MotionEventCompat.getY(event, pointerIndex); } rel_anm_lo.invalidate(); return true; } }); sav_anm_btn = (Button) findViewById(R.id.sav_btn); sav_anm_btn.setOnClickListener(new View.OnClickListener() { public void onClick(View vw) { onClickFlg = 1; RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo); rel_anm_lo.removeView(vw); Bitmap tnBmp = getWrtBmp("thumbnail", rel_anm_lo, 40); tnBmp.recycle(); int vw_nmbr = anmViews.size(); for (int vw_mbr = 1; vw_mbr < vw_nmbr; vw_mbr += 1) { anim_view = anmViews.get(vw_mbr); if (anim_view != null) { Animation crt_anm = anim_view.getAnimation(); if (crt_anm != null) crt_anm.cancel(); anim_view.setAnimation(null); rel_anm_lo.removeView(anim_view); // Garbage collect the bitmap Drawable drawable = anim_view.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; Bitmap anim_bmp = bitmapDrawable.getBitmap(); anim_bmp.recycle(); } } } Bitmap orgnlImageBmp = getWrtBmp("bgimg", rel_anm_lo, 90); orgnlImageWdth = Integer.toString(orgnlImageBmp.getWidth()); orgnlImageHght = Integer.toString(orgnlImageBmp.getHeight()); anmViews.clear(); unbindDrawables(rel_anm_lo); ((RelativeLayout) rel_anm_lo).removeAllViews(); orgnlImageBmp.recycle(); crt_ctx = null; orgnlImageView = null; Intent intent = new Intent(AnimActivity.this, com.acceleratedio.pac_n_zoom.SaveAnmActivity.class); startActivity(intent); } }); progress = ProgressDialog.show(crt_ctx, "Loading the animation", "dialog message", true); GetRequest get_svg_img = new GetRequest(); get_svg_img.execute(""); }
From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); if (canChildScrollUp()) { // Fail fast if we're not in a state where a swipe is possible return super.onTouchEvent(ev); }/*from www. java 2 s. c o m*/ mVelocityTracker.addMovement(ev); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialTouchX = x; mInitialTouchY = mLastTouchY = y; mActivePointerId = ev.getPointerId(0); if (findChildUnder(mInitialTouchX, mInitialTouchY) == null && mClickOutsideListener != null) { mIsDragging = handled = true; } handled |= mCollapsibleHeight > 0; mScroller.abortAnimation(); } break; case MotionEvent.ACTION_MOVE: { int index = ev.findPointerIndex(mActivePointerId); if (index < 0) { Log.e(TAG, "Bad pointer id " + mActivePointerId + ", resetting"); index = 0; mActivePointerId = ev.getPointerId(0); mInitialTouchX = ev.getX(); mInitialTouchY = mLastTouchY = ev.getY(); } final float x = ev.getX(index); final float y = ev.getY(index); if (!mIsDragging) { final float dy = y - mInitialTouchY; if (Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null) { handled = mIsDragging = true; mLastTouchY = Math.max(mLastTouchY - mTouchSlop, Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop)); } } if (mIsDragging) { final float dy = y - mLastTouchY; performDrag(dy); } mLastTouchY = y; } break; case MotionEvent.ACTION_POINTER_DOWN: { final int pointerIndex = ev.getActionIndex(); final int pointerId = ev.getPointerId(pointerIndex); mActivePointerId = pointerId; mInitialTouchX = ev.getX(pointerIndex); mInitialTouchY = mLastTouchY = ev.getY(pointerIndex); } break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); } break; case MotionEvent.ACTION_UP: { mIsDragging = false; if (!mIsDragging && findChildUnder(mInitialTouchX, mInitialTouchY) == null && findChildUnder(ev.getX(), ev.getY()) == null) { if (mClickOutsideListener != null) { mClickOutsideListener.onClick(this); resetTouch(); return true; } } if (mOpenOnClick && Math.abs(ev.getX() - mInitialTouchX) < mTouchSlop && Math.abs(ev.getY() - mInitialTouchY) < mTouchSlop) { smoothScrollTo(0, 0); return true; } mVelocityTracker.computeCurrentVelocity(1000); final float yvel = mVelocityTracker.getYVelocity(mActivePointerId); if (Math.abs(yvel) > mMinFlingVelocity) { smoothScrollTo(yvel < 0 ? 0 : mCollapsibleHeight, yvel); } else { smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0); } resetTouch(); } break; case MotionEvent.ACTION_CANCEL: { if (mIsDragging) { smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0); } resetTouch(); return true; } } return handled || (action == MotionEvent.ACTION_MOVE && mCollapseOffset > 0); }
From source file:it.angrydroids.epub3reader.TextSelectionSupport.java
@Override public boolean onTouch(View v, MotionEvent event) { final Context ctx = mActivity; float xPoint = getDensityIndependentValue(event.getX(), ctx) / getDensityIndependentValue(mScale, ctx); float yPoint = getDensityIndependentValue(event.getY(), ctx) / getDensityIndependentValue(mScale, ctx); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: final String startTouchUrl = String.format("javascript:android.selection.startTouch(%f, %f);", xPoint, yPoint);//from w w w . ja v a2 s .c om mLastTouchX = xPoint; mLastTouchY = yPoint; mWebView.loadUrl(startTouchUrl); break; case MotionEvent.ACTION_UP: if (!mScrolling) { endSelectionMode(); // // Fixes 4.4 double selection // See: // http://stackoverflow.com/questions/20391783/how-to-avoid-default-selection-on-long-press-in-android-kitkat-4-4 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return false; } } mScrollDiffX = 0; mScrollDiffY = 0; mScrolling = false; // // Fixes 4.4 double selection // See: // http://stackoverflow.com/questions/20391783/how-to-avoid-default-selection-on-long-press-in-android-kitkat-4-4 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return true; } break; case MotionEvent.ACTION_MOVE: mScrollDiffX += (xPoint - mLastTouchX); mScrollDiffY += (yPoint - mLastTouchY); mLastTouchX = xPoint; mLastTouchY = yPoint; if (Math.abs(mScrollDiffX) > SCROLLING_THRESHOLD || Math.abs(mScrollDiffY) > SCROLLING_THRESHOLD) { mScrolling = true; } break; } return false; }
From source file:cn.com.hgh.view.SlideSwitch.java
@Override public boolean onTouchEvent(MotionEvent event) { if (slideable == false) return super.onTouchEvent(event); int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: eventStartX = (int) event.getRawX(); break;/*from ww w . j a v a 2s .c om*/ case MotionEvent.ACTION_MOVE: // eventLastX = (int) event.getRawX(); // diffX = eventLastX - eventStartX; // int tempX = diffX + frontRect_left_begin; // tempX = (tempX > max_left ? max_left : tempX); // tempX = (tempX < min_left ? min_left : tempX); // if (tempX >= min_left && tempX <= max_left) { // frontRect_left = tempX; // alpha = (int) (255 * (float) tempX / (float) max_left); // invalidateView(); // } break; case MotionEvent.ACTION_UP: int wholeX = (int) (event.getRawX() - eventStartX); frontRect_left_begin = frontRect_left; toRight = (frontRect_left_begin > max_left / 2 ? true : false); if (Math.abs(wholeX) < 3) { toRight = !toRight; } //x?? float eventx = event.getX(); if (isOpen) { //? if (eventx < width / 2) { // switchBusinessStatus(); switchStatus(); } } else { //? if (eventx > width / 2) { // switchBusinessStatus(); switchStatus(); } } break; default: break; } return true; }
From source file:com.intel.xdk.multitouch.MultiTouch.java
public void queueMultitouchData(String js, int id, int maskedAction) { //Log.i("[appMobi]", "queueMultitouchData:"+js); if (maskedAction == MotionEvent.ACTION_POINTER_DOWN || maskedAction == MotionEvent.ACTION_DOWN) { //touchstart: create list //this.multitouchMap.put(id, new ArrayList<String>()); } else if (maskedAction == MotionEvent.ACTION_POINTER_UP || maskedAction == MotionEvent.ACTION_UP) { //touchend: remove list this.multitouchMap.remove(id); } else if (maskedAction == MotionEvent.ACTION_MOVE) { //touchmove: flush stale touchmove events and and update list String stale = this.multitouchMap.get(id); this.multitouchQueue.remove(stale); this.multitouchMap.put(id, js); }/*from w w w. java 2 s.com*/ this.multitouchQueue.add(js); }
From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mCanPickRange) { return super.onInterceptTouchEvent(ev); }/*from ww w . ja va2 s . c om*/ if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (Config.DEBUG) { Log.i(TAG, "OITE: DOWN"); } mInitialDownX = ev.getX(); mInitialDownY = ev.getY(); if (mCheckForLongPress == null) { mCheckForLongPress = new CheckForLongPress(); } postDelayed(mCheckForLongPress, ViewConfiguration.getLongPressTimeout()); } else if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) { if (Config.DEBUG) { Log.i(TAG, "OITE: (UP || CANCEL)"); } if (mCheckForLongPress != null) { removeCallbacks(mCheckForLongPress); } mIsLongPressed = false; mInitialDownX = -1; mInitialDownY = -1; } else if (ev.getAction() == MotionEvent.ACTION_MOVE) { if (Config.DEBUG) { Log.i(TAG, "OITE: MOVE"); } if (!isStillALongPress((int) ev.getX(), (int) ev.getY())) { if (Config.DEBUG) { Log.i(TAG, "OITE: MOVED TOO MUCH, CANCELLING CheckForLongPress Runnable"); } if (mCheckForLongPress != null) { removeCallbacks(mCheckForLongPress); } } } return mIsLongPressed || super.onInterceptTouchEvent(ev); }
From source file:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { float currentTouchY = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mLastTouchY = currentTouchY;//from www . j ava2 s .com break; case MotionEvent.ACTION_MOVE: float differentY = currentTouchY - mLastTouchY; if (Math.abs(differentY) > mTouchSlop) { if (!isHeaderViewCompleteInvisible() || (isContentViewToTop() && isHeaderViewCompleteInvisible() && mIsInControl)) { mLastTouchY = currentTouchY; return true; } } break; } return super.onInterceptTouchEvent(ev); }
From source file:com.cocarechina.pullrefreshview.layout.FlingLayout.java
/******************************************************************/ @Override/*from w w w.ja v a 2 s . co m*/ public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tepmY = downY = y; tepmX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } lastY = ev.getY(); Log.v("lastY", moveY + ""); break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tepmX = ev.getX(pointerIndex); tepmY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } //????? int dataX = (int) (mx - tepmX); int dataY = (int) (my - tepmY); tepmX = mx; tepmY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 //?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { //?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);//? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { //0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { //?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } Log.v("flingLayout", "ev.getY()" + ev.getY() + " --- lastY " + lastY); if (ev.getY() - lastY > 5) { if (monScrollHeadListener != null) { monScrollHeadListener.onScrollBottom(); } } else if (ev.getY() - lastY < -10) { if (monScrollHeadListener != null) { monScrollHeadListener.onScrollTop(); } } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tepmY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }