List of usage examples for android.view MotionEvent getY
public final float getY()
From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mCanPickRange) { return super.onInterceptTouchEvent(ev); }//from w ww . j ava 2 s . c o m 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:com.acious.android.paginationseekbar.PaginationSeekBar.java
private void updateDragging(MotionEvent ev) { setHotspot(ev.getX(), ev.getY()); int x = (int) ev.getX(); Rect oldBounds = mThumb.getBounds(); int halfThumb = oldBounds.width() / 2; int addedThumb = mAddedTouchBounds; int newX = x - mDragOffset + halfThumb; int left = getPaddingLeft() + halfThumb + addedThumb; int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb); if (newX < left) { newX = left;//w w w . j a v a2s. c o m } else if (newX > right) { newX = right; } int available = right - left; float scale = (float) (newX - left) / (float) available; if (isRtl()) { scale = 1f - scale; } int progress = Math.round((scale * (mMax - mMin)) + mMin); setProgress(progress, true); }
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
protected void applyMapViewLongPressListener(MapView mapView) { final MapView finalMapView = mapView; final GestureDetector gd = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { @Override//from w ww. j a v a 2 s . com public void onLongPress(MotionEvent e) { //Log.i("CityBikes","LONG PRESS!"); Projection astral = finalMapView.getProjection(); GeoPoint center = astral.fromPixels((int) e.getX(), (int) e.getY()); locator.lockCenter(center); } @Override public boolean onDoubleTap(MotionEvent e) { // TODO Auto-generated method stub //Log.i("CityBikes","Double tap!"); Projection astral = finalMapView.getProjection(); GeoPoint center = astral.fromPixels((int) e.getX(), (int) e.getY()); locator.lockCenter(center); return super.onDoubleTap(e); } }); mapView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent ev) { return gd.onTouchEvent(ev); } }); }
From source file:com.pitchedapps.primenumbercalculator.Calculator.java
License:asdf
void addOnTouchListener(View view) { Button button = (Button) view; button.setOnTouchListener(new View.OnTouchListener() { @Override/*from www . j a va2 s . c o m*/ public boolean onTouch(View v, MotionEvent e) { x = (int) e.getX() + v.getLeft(); y = (int) e.getY() + v.getTop(); return false; } }); }
From source file:com.pitchedapps.primenumbercalculator.Calculator.java
License:asdf
void addOnTouchListenerText(View view) { TextView text = (TextView) view;/* w w w . j av a 2 s. co m*/ text.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { x = (int) e.getX() + v.getLeft(); y = (int) e.getY() + v.getTop(); return false; } }); }
From source file:com.am.pullview.swiperefresh.SwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;// w w w .j a v a 2s .c om mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } updateContentOffsetTop((int) (offsetTop)); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } else { updatePositionTimeout(); } mPrevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }
From source file:cn.sdgundam.comicatsdgo.extension.SwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;// w w w .j ava 2 s. c o m mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } updateContentOffsetTop((int) (offsetTop)); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } // else { // updatePositionTimeout(); // } mPrevY = event.getY(); } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; updatePositionImmediately(); } break; } return handled; }
From source file:com.bxbxbai.zhuanlan.ui.widget.SwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;// www. j ava 2 s . co m mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } updateContentOffsetTop(); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } else { updatePositionTimeout(); } mPrevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }
From source file:co.dift.ui.SwipeToAction.java
/** Private methods **/ private void init() { gestureDetector = new GestureDetectorCompat(recyclerView.getContext(), new GestureDetector.SimpleOnGestureListener() { @Override/*ww w. j ava 2 s . co m*/ public void onLongPress(MotionEvent e) { logger.d("onLongPress called!"); if (touchedViewHolder != null) { swipeListener.onLongClick(touchedViewHolder.getItemData()); } } @Override public boolean onSingleTapUp(MotionEvent e) { logger.d("onSingleTapUp called!"); if (touchedViewHolder != null) { swipeListener.onClick(touchedViewHolder.getItemData()); return true; } return super.onSingleTapUp(e); } }); recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) { gestureDetector.onTouchEvent(ev); switch (ev.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { // starting point downX = ev.getX(); downY = ev.getY(); downTime = new Date().getTime(); // which item are we touching resolveItem(downX, downY); break; } case MotionEvent.ACTION_UP: { upX = ev.getX(); upY = ev.getY(); upTime = new Date().getTime(); resolveState(); break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float dx = x - downX; if (!shouldMove(dx)) break; // current position. moving only over x-axis frontViewLastX = frontViewX + dx + (dx > 0 ? -getRevealThreshold() : getRevealThreshold()); // logger.d("dx: %f, frontViewLastX: %f", dx, frontViewLastX); if (maxSwipeXPosition != null) { if (frontViewLastX > 0 && frontViewLastX > maxSwipeXPosition) { frontViewLastX = maxSwipeXPosition; } else if (frontViewLastX <= -maxSwipeXPosition) { frontViewLastX = -maxSwipeXPosition; } } frontView.setX(frontViewLastX); if (frontViewLastX > 0) { revealRight(); } else { revealLeft(); } break; } case MotionEvent.ACTION_CANCEL: { resolveState(); break; } } return false; } @Override public void onTouchEvent(RecyclerView rv, MotionEvent e) { logger.d("onTouchEvent called"); } @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { logger.d("onRequestDisallowInterceptTouchEvent called"); } }); }
From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;/* www . j a va2 s .c om*/ mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) {//? // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) {//?? // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } //content???? updateContentOffsetTop((int) (offsetTop * mResistance)); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } else { updatePositionTimeout(); } mPrevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }