List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java
private TouchableUrlSpan getPressedSpan(Spannable spannable, MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); x -= getPaddingLeft();//w w w . j av a 2 s. co m y -= getPaddingTop(); x += getScrollX(); y += getScrollY(); int line = layout.getLineForVertical(y); int off = layout.getOffsetForHorizontal(line, x); TouchableUrlSpan[] link = spannable.getSpans(off, off, TouchableUrlSpan.class); TouchableUrlSpan touchedSpan = null; if (link.length > 0) { touchedSpan = link[0]; } return touchedSpan; }
From source file:com.albedinsky.android.ui.HorizontalPullHelper.java
/** */// www . j a v a2s. co m @Override boolean shouldStartPull(MotionEvent event) { switch (mState) { case STATE_PULLING_AT_START: return (mMode & PullController.START) != 0 && mTouchLastX < event.getX(); case STATE_PULLING_AT_END: return (mMode & PullController.END) != 0 && mTouchLastX > event.getX(); } return false; }
From source file:br.com.cybereagle.androidwidgets.view.PagerContainer.java
@Override public boolean onTouchEvent(MotionEvent ev) { //We capture any touches not already handled by the ViewPager // to implement scrolling from a touch outside the pager bounds. switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: initialTouch.x = (int) ev.getX(); initialTouch.y = (int) ev.getY(); default:// w w w . j a v a 2 s .c om ev.offsetLocation(center.x - initialTouch.x, center.y - initialTouch.y); break; } return pager.dispatchTouchEvent(ev); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewWithMiniKeyboard.java
@Override public boolean onTouchEvent(@NonNull MotionEvent me) { if (getMiniKeyboard() != null && mMiniKeyboardPopup.isShowing()) { final int miniKeyboardX = (int) me.getX(); final int miniKeyboardY = (int) me.getY(); final int action = MotionEventCompat.getActionMasked(me); MotionEvent translated = generateMiniKeyboardMotionEvent(action, miniKeyboardX, miniKeyboardY, me.getEventTime());/* w ww. ja va 2s . co m*/ getMiniKeyboard().onTouchEvent(translated); translated.recycle(); return true; } return super.onTouchEvent(me); }
From source file:com.cssweb.android.view.FTrendView.java
public void touchesEnded(MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); if (x < axisLabelWidth || x > width) return;/*from w ww . j av a 2 s .c o m*/ if (y < this.axisLabelHeight || y > height - this.axisLabelHeight) return; isTouched = false; if (isTouchMoved == false) { isTouchMoved = false; isTrackStatus = !isTrackStatus; if (isTrackStatus) {//?? if (x > axisLabelWidth && x < width) trackLineV = x; int idx = (int) ((x - axisLabelWidth) / SPACE); if (idx < dataLen && idx >= 0) { isTrackNumber = begin + idx; trackLineV = (int) (axisLabelWidth + idx * SPACE); } else { if (idx < 0) { isTrackNumber = 0; trackLineV = axisLabelWidth; } if (idx >= dataLen) { isTrackNumber = dataLen - 1; trackLineV = (int) (axisLabelWidth + (dataLen - 1) * SPACE); } } } } /** * ?Android SDK api * invalidate ?View */ this.invalidate(); }
From source file:com.albedinsky.android.support.ui.HorizontalPullHelper.java
/** *///from w ww . jav a 2 s.co m @Override void dispatchPullInitiated(MotionEvent event) { super.dispatchPullInitiated(event); switch (mState) { case STATE_PULLING_AT_START: this.mExpandingPull = mTouchLastX <= event.getX(); case STATE_PULLING_AT_END: this.mExpandingPull = mTouchLastX > event.getX(); } this.mTouchLastX = event.getX(); }
From source file:com.cssweb.android.view.FTrendView.java
public void touchesMoved(MotionEvent event) { currentPositionX = event.getX(); currentPositionY = event.getY();// ww w.jav a2s. c o m float deltaX = startPositionX - currentPositionX; float deltaY = startPositionY - currentPositionY; if (Math.abs(deltaX) < 8 && Math.abs(deltaY) < 8) { isTouchMoved = false; } else { isTouchMoved = true; } if (isTrackStatus) { double sep = SPACE; int idx = (int) ((currentPositionX - axisLabelWidth) / sep); if (idx < dataLen && idx >= 0) { if (currentPositionX >= axisLabelWidth || currentPositionX <= width) { trackLineV = (int) (axisLabelWidth + idx * SPACE); } isTrackNumber = begin + idx; if (isTrackNumber >= dataLen) { isTrackNumber = dataLen - 1; } } else { if (idx < 0) { idx = 0; isTrackNumber = begin + idx; trackLineV = axisLabelWidth; } if (idx >= dataLen) { isTrackNumber = dataLen - 1; trackLineV = (int) (axisLabelWidth + (dataLen - 1) * SPACE); } } } /** * ?Android SDK api * invalidate ?View */ this.invalidate(); }
From source file:com.baoyz.dribble.widget.SwipeHoverLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { int actionMasked = MotionEventCompat.getActionMasked(ev); boolean flag = false; switch (actionMasked) { case MotionEvent.ACTION_DOWN: mDownX = (int) ev.getX(); mGestureDetector.onTouchEvent(ev); break;/* w ww .j av a 2s. co m*/ case MotionEvent.ACTION_MOVE: if (Math.abs(ev.getX() - mDownX) > mTouchSlop) flag = true; break; } return flag; }
From source file:com.app.gongza.libs.view.scrollablelayout.ScrollableLayout.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { float currentX = ev.getX(); float currentY = ev.getY(); float deltaY; int shiftX = (int) Math.abs(currentX - mDownX); int shiftY = (int) Math.abs(currentY - mDownY); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mDisallowIntercept = false;//from w w w. j ava 2s. c o m needCheckUpdown = true; updown = true; mDownX = currentX; mDownY = currentY; mLastY = currentY; checkIsClickHead((int) currentY, mHeadHeight, getScrollY()); checkIsClickHeadExpand((int) currentY, mHeadHeight, getScrollY()); initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); mScroller.forceFinished(true); break; case MotionEvent.ACTION_MOVE: if (mDisallowIntercept) { break; } initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); deltaY = mLastY - currentY; if (needCheckUpdown) { if (shiftX > mTouchSlop && shiftX > shiftY) { needCheckUpdown = false; updown = false; } else if (shiftY > mTouchSlop && shiftY > shiftX) { needCheckUpdown = false; updown = true; } } if (updown && shiftY > mTouchSlop && shiftY > shiftX && (!isSticked() || mHelper.isTop() || isClickHeadExpand)) { if (childViewPager != null) { childViewPager.requestDisallowInterceptTouchEvent(true); } scrollBy(0, (int) (deltaY + 0.5)); } mLastY = currentY; break; case MotionEvent.ACTION_UP: if (updown && shiftY > shiftX && shiftY > mTouchSlop) { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); float yVelocity = -mVelocityTracker.getYVelocity(); boolean dislowChild = false; if (Math.abs(yVelocity) > mMinimumVelocity) { mDirection = yVelocity > 0 ? DIRECTION.UP : DIRECTION.DOWN; if ((mDirection == DIRECTION.UP && isSticked()) || (!isSticked() && getScrollY() == 0 && mDirection == DIRECTION.DOWN)) { dislowChild = true; } else { mScroller.fling(0, getScrollY(), 0, (int) yVelocity, 0, 0, -Integer.MAX_VALUE, Integer.MAX_VALUE); mScroller.computeScrollOffset(); mLastScrollerY = getScrollY(); invalidate(); } } if (!dislowChild && (isClickHead || !isSticked())) { int action = ev.getAction(); ev.setAction(MotionEvent.ACTION_CANCEL); boolean dispathResult = super.dispatchTouchEvent(ev); ev.setAction(action); return dispathResult; } } break; default: break; } super.dispatchTouchEvent(ev); return true; }
From source file:com.cssweb.android.view.FTrendView.java
public void touchesBegan(MotionEvent event) { isTouched = true; isTouchMoved = false; startPositionX = event.getX(); startPositionY = event.getY(); }