Java Code Examples for android.view.MotionEvent#getRawY()
The following examples show how to use
android.view.MotionEvent#getRawY() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ECardFlow.java From ECardFlow with MIT License | 6 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: if (isSwitching) { return false; } mInterLastX = (int) event.getRawX(); mInterLastY = (int) event.getRawY(); break; case MotionEvent.ACTION_MOVE: return !isExpanding; case MotionEvent.ACTION_UP: mLastX = 0; mLastY = 0; mInterLastX = 0; mInterLastY = 0; hasReset = true; } return super.onInterceptTouchEvent(event); }
Example 2
Source File: TableFixHeaders.java From SqliteLookup with Apache License 2.0 | 6 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent event) { boolean intercept = false; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { int x2 = Math.abs(currentX - (int) event.getRawX()); int y2 = Math.abs(currentY - (int) event.getRawY()); if (x2 > touchSlop || y2 > touchSlop) { intercept = true; } break; } } return intercept; }
Example 3
Source File: DragScaleCircleView.java From DragScaleCircleView with Apache License 2.0 | 6 votes |
/** * Drag the circle view. * * @param event event * @param action action */ protected void drag(MotionEvent event, int action) { switch (action) { case MotionEvent.ACTION_MOVE: float dx = event.getRawX() - mLastX; float dy = event.getRawY() - mLastY; float touchX = event.getX(); float touchY = event.getY(); switch (mDragDirection) { case CENTER: center(dx, dy); break; case SIDE: side(touchX, touchY, touchX + dx, touchY + dy); break; } mLastX = (int) event.getRawX(); mLastY = (int) event.getRawY(); break; case MotionEvent.ACTION_UP: mDragDirection = 0; break; } }
Example 4
Source File: FloatingLabelSpinner.java From FloatingLabelSpinner with Apache License 2.0 | 6 votes |
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: is_moving = false; down_x = event.getRawX(); down_y = event.getRawY(); break; case MotionEvent.ACTION_MOVE: if (!is_moving && (Math.abs(event.getRawX() - down_x) > touch_slop || Math.abs(event.getRawY() - down_y) > touch_slop)) { is_moving = true; } break; case MotionEvent.ACTION_UP: if (!is_moving) { performClick(); } break; } return true; }
Example 5
Source File: SimpleClickListener.java From imsdk-android with MIT License | 6 votes |
public boolean inRangeOfView(View view, MotionEvent ev) { int[] location = new int[2]; if (view == null || !view.isShown()) { return false; } view.getLocationOnScreen(location); int x = location[0]; int y = location[1]; if (ev.getRawX() < x || ev.getRawX() > (x + view.getWidth()) || ev.getRawY() < y || ev.getRawY() > (y + view.getHeight())) { return false; } return true; }
Example 6
Source File: TestButton.java From android-art-res with Apache License 2.0 | 5 votes |
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(MotionEvent event) { int x = (int) event.getRawX(); int y = (int) event.getRawY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { break; } case MotionEvent.ACTION_MOVE: { int deltaX = x - mLastX; int deltaY = y - mLastY; Log.d(TAG, "move, deltaX:" + deltaX + " deltaY:" + deltaY); int translationX = (int)ViewHelper.getTranslationX(this) + deltaX; int translationY = (int)ViewHelper.getTranslationY(this) + deltaY; ViewHelper.setTranslationX(this, translationX); ViewHelper.setTranslationY(this, translationY); break; } case MotionEvent.ACTION_UP: { break; } default: break; } mLastX = x; mLastY = y; return true; }
Example 7
Source File: DraggableOverlay.java From brailleback with Apache License 2.0 | 5 votes |
private void drag(MotionEvent event) { if (!mDragging) { return; } switch (mWindowParams.gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mWindowParams.y = (int) (mDragOrigin - event.getRawY()); break; case Gravity.TOP: mWindowParams.y = (int) (event.getRawY() - mDragOrigin); break; } setParams(mWindowParams); }
Example 8
Source File: LRecyclerView.java From luckly_recyclerview with MIT License | 5 votes |
@Override public boolean onTouchEvent(MotionEvent e) { if (mLatesY == -1) { mLatesY = e.getRawY(); } switch (e.getAction()) { case MotionEvent.ACTION_DOWN: mLatesY = e.getRawY(); break; case MotionEvent.ACTION_MOVE: float distanceY = e.getRawY() - mLatesY; mLatesY = e.getRawY(); if (isOnTop() && mCanRefresh) { mHeaderView.onAcionMove(distanceY); //下拉状态的时候,就不调用下面的方法 if (mHeaderView.getVisibleHeight() > 0 && mHeaderView.getState() < HeaderView.STATE_REFRESHING) { return false; } } break; default: mLatesY = -1; if (mHeaderView.releaseAction() && mCanRefresh && isOnTop()) { if (mOnRefreshListener != null) { mOnRefreshListener.onRefresh(); } } break; } return super.onTouchEvent(e); }
Example 9
Source File: SegmentedView.java From segmentedview with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: inTapRegion = true; mStartX = event.getRawX(); mStartY = event.getRawY(); break; case MotionEvent.ACTION_MOVE: int dx = (int) (event.getRawX() - mStartX); int dy = (int) (event.getRawY() - mStartY); int distance = dx * dx + dy * dy; if (distance > mTouchSlop) { inTapRegion = false; } break; case MotionEvent.ACTION_UP: if (inTapRegion) { int[] loc = new int[2]; getLocationOnScreen(loc); mCurrentIndex = (int) (mStartX - loc[0]) / mItemWidth; if (mListener != null) { mListener.onSelected(mCurrentIndex, mTexts[mCurrentIndex]); } invalidate(); } break; default: break; } return true; }
Example 10
Source File: EdgeSwipeEventFilter.java From delion with Apache License 2.0 | 5 votes |
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { final float x = e2.getX() * mPxToDp; final float y = e2.getY() * mPxToDp; final float tx = (e2.getRawX() - e1.getRawX()) * mPxToDp; final float ty = (e2.getRawY() - e1.getRawY()) * mPxToDp; final float vx = velocityX * mPxToDp; final float vy = velocityY * mPxToDp; flingOccurred(x, y, tx, ty, vx, vy); return false; }
Example 11
Source File: MyViewPager.java From Dainty with Apache License 2.0 | 5 votes |
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(MotionEvent ev) { switch (ev.getAction()){ case MotionEvent.ACTION_DOWN: frameLayout= WebPageHelper.webpagelist.get(getCurrentItem()).getInnerContainer(); measureWidth=frameLayout.getMeasuredWidth(); measureHeight=frameLayout.getMeasuredHeight(); point_x = ev.getRawX(); point_y = ev.getRawY(); left = frameLayout.getLeft(); right = frameLayout.getRight(); bottom = frameLayout.getBottom(); break; case MotionEvent.ACTION_MOVE: float mov_x = ev.getRawX() - point_x; float mov_y = ev.getRawY() - point_y; Log.d("trr","mov_y"+mov_y); if(Math.abs(mov_x) < Math.abs(mov_y)&&canDel&&mov_y<frameLayout.getWidth()/4){ frameLayout.measure(MeasureSpec.makeMeasureSpec(measureWidth,MeasureSpec.AT_MOST),MeasureSpec.makeMeasureSpec(measureHeight,MeasureSpec.AT_MOST)); frameLayout.layout(left, (int) mov_y, right, bottom + (int) mov_y); } break; case MotionEvent.ACTION_UP: Log.d("trr","frameLayout:"+frameLayout .getTop()); if(Math.abs(frameLayout.getTop())>frameLayout.getWidth()/2){ EventBus.getDefault().post(new WebDeleteEvent(frameLayout.getTop())); }else { ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(frameLayout,"translationY",frameLayout.getTop(),0); objectAnimator.setDuration(400).start(); frameLayout.measure(MeasureSpec.makeMeasureSpec(measureWidth,MeasureSpec.AT_MOST),MeasureSpec.makeMeasureSpec(measureHeight,MeasureSpec.AT_MOST)); frameLayout.layout(left,0,right,bottom); } } gestureDetector.onTouchEvent(ev); return super.onTouchEvent(ev); }
Example 12
Source File: DragSortListView.java From chromadoze with GNU General Public License v3.0 | 5 votes |
private void saveTouchCoords(MotionEvent ev) { int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action != MotionEvent.ACTION_DOWN) { mLastX = mX; mLastY = mY; } mX = (int) ev.getX(); mY = (int) ev.getY(); if (action == MotionEvent.ACTION_DOWN) { mLastX = mX; mLastY = mY; } mOffsetX = (int) ev.getRawX() - mX; mOffsetY = (int) ev.getRawY() - mY; }
Example 13
Source File: RefreshRecyclerView.java From ReadMark with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent e) { //正在刷新或者正在回滚,不作为 if(mCurrentRefreshStatus == REFRESH_STATUS_REFRESHING || isAutoScroll){ //Log.e(TAG, "在刷新状态进入"); return true; }else if(!canScrollUp()){/*!canScrollUp()*/ //直到能滑动的时候才记录按下点 if(isTmpFirstDown){ mFingerDownY = (int) e.getRawY(); isTmpFirstDown = false; } switch (e.getAction()){ case MotionEvent.ACTION_MOVE: // 解决下拉刷新自动滚动问题 /*if(mCurrentDrag){ scrollToPosition(0); }*/ //计算距离 int distanceY = (int) ((e.getRawY() - mFingerDownY) * mDragIndex); if(distanceY > 0){ int marginTop = - mRefreshViewHeight + distanceY; //更新头部位置并更新状态 setRefreshViewMarginTop(marginTop); //更新状态并回调 updateRefreshStatus(marginTop); mCurrentDrag = true; return false; } break; } } //mCurrentRefreshStatus = REFRESH_STATUS_NORMAL; return super.onTouchEvent(e); }
Example 14
Source File: DragSortGridView.java From MissZzzReader with Apache License 2.0 | 5 votes |
@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (hasSendDragMsg) { hasSendDragMsg = false; handler.removeMessages(0x123); } if (isDragable && mCopyView != null) {// 可以拖动,实现跟随手指的拖动效果 // /// 2015/11/27补充修正跟随手指移动方法,适用于当本控件在drag时同时滚动的情况 if (lastLocation == null) { lastLocation = new float[]{e1.getRawX(), e1.getRawY()}; } distanceX = lastLocation[0] - e2.getRawX(); distanceY = lastLocation[1] - e2.getRawY(); lastLocation[0] = e2.getRawX(); lastLocation[1] = e2.getRawY(); // //////// mCopyView.setX(mCopyView.getX() - distanceX); mCopyView.setY(mCopyView.getY() - distanceY); mCopyView.invalidate(); int to = eventToPosition(e2); if (to != currentDragPosition && to >= headDragPosition && to < mChildCount - footDragPosition) { onDragPositionChange(currentDragPosition, to); } } return true; }
Example 15
Source File: OuterLayout.java From dragqueen with Apache License 2.0 | 5 votes |
private boolean isQueenTarget(MotionEvent event) { int[] queenLocation = new int[2]; mQueenButton.getLocationOnScreen(queenLocation); int upperLimit = queenLocation[1] + mQueenButton.getMeasuredHeight(); int lowerLimit = queenLocation[1]; int y = (int) event.getRawY(); return (y > lowerLimit && y < upperLimit); }
Example 16
Source File: MeJoystick.java From Makeblock-App-For-Android with MIT License | 4 votes |
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: lastX = (int) event.getRawX(); lastY = (int) event.getRawY(); originX = lastX; originY = lastY; lastTime = System.currentTimeMillis(); break; case MotionEvent.ACTION_MOVE: int dx = (int) event.getRawX() - lastX; int dy = (int) event.getRawY() - lastY; int left = v.getLeft() + dx; int top = v.getTop() + dy; if(left<0) left=0; if(left>200) left=200; if(top<0) top=0; if(top>200) top=200; FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)v.getLayoutParams(); params.gravity = Gravity.LEFT|Gravity.TOP; params.topMargin = top; params.leftMargin = left; if(top!=lastTop || left!=lastLeft){ v.setLayoutParams(params); lastX = (int) event.getRawX(); lastY = (int) event.getRawY(); long time= System.currentTimeMillis(); if((time-lastTime)>100){ sendXY(left,top); lastTime = time; } lastTop = top; lastLeft = left; } break; case MotionEvent.ACTION_UP: left = 100;//v.getLeft() + dx; top = 100;//v.getTop() + dy; params = (FrameLayout.LayoutParams)v.getLayoutParams(); params.gravity = Gravity.LEFT|Gravity.TOP; params.topMargin = initTop; params.leftMargin = initLeft; sendXY(left,top); v.setLayoutParams(params); break; } return true; }
Example 17
Source File: DynamicListLayout.java From dynamiclistview with MIT License | 4 votes |
@Override public boolean onTouch(View v, MotionEvent event) { if (!initialized) checkHeaderAndFooter(); gesture.onTouchEvent(event); if (!isAvailableStatus()) return super.onTouchEvent(event); switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_UP: break; case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_DOWN: firstTouch(event); break; case MotionEvent.ACTION_MOVE: mScrollWatcher.setEvent(event, mDynamicListViewListener); if (mNeedFirstTouch) firstTouch(event); mPullingOnTouchMove = true; if (mIsNowPullingDown || mIsNowPullingUp) { pull(event); return true; } if (mDynamicListView.reachedListTop() && (mPullingTouchYPosition - (int) event.getRawY() < 0) && Math.abs(mPullingTouchYPosition - (int) event.getRawY()) > mMinPullingLength) { mIsNowPullingUp = false; mIsNowPullingDown = true; firstTouch(event); mIsFirstPulling = true; } else if (mDynamicListView.reachedListBottom() && (mPullingTouchYPosition - (int) event.getRawY() > 0) && Math.abs(mPullingTouchYPosition - (int) event.getRawY()) > mMinPullingLength) { mIsNowPullingDown = false; mIsNowPullingUp = true; firstTouch(event); mIsFirstPulling = true; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsFirstPulling = false; mScrollWatcher.init(); mPullingOnTouchMove = false; mNeedFirstTouch = true; if (mIsNowPullingDown || mIsNowPullingUp) { if (mPullingState == PullingStatus.ON) { if (mDynamicListViewListener != null) mDynamicListViewListener.onRelease(this, mDynamicListView, mIsNowPullingDown ? PullingMode.TOP : PullingMode.BOTTOM, mPullingState); else close(); mPullingState = PullingStatus.OFF; } else if (mPullingState == PullingStatus.OFF) { close(); } } else { } break; } return false; }
Example 18
Source File: XListView.java From Conquer with Apache License 2.0 | 4 votes |
@Override public boolean onTouchEvent(MotionEvent ev) { if (mLastY == -1) { mLastY = ev.getRawY(); } switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mLastY = ev.getRawY(); break; case MotionEvent.ACTION_MOVE: final float deltaY = ev.getRawY() - mLastY; mLastY = ev.getRawY(); if (getFirstVisiblePosition() == 0 && (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) { // the first item is showing, header has shown or pull down. updateHeaderHeight(deltaY / OFFSET_RADIO); invokeOnScrolling(); } else if (mEnablePullLoad && (getLastVisiblePosition() == mTotalItemCount - 1) && (mFooterView.getBottomMargin() > 0 || deltaY < 0)) { // last item, already pulled up or want to pull up. updateFooterHeight(-deltaY / OFFSET_RADIO); } break; default: mLastY = -1; // reset if (getFirstVisiblePosition() == 0) { // invoke refresh if (mEnablePullRefresh && mHeaderView.getVisiableHeight() > mHeaderViewHeight) { mPullRefreshing = true; mHeaderView.setState(XListViewHeader.STATE_REFRESHING); if (mListViewListener != null) { mListViewListener.onRefresh(); } } resetHeaderHeight(); } else if (getLastVisiblePosition() == mTotalItemCount - 1) { // invoke load more. if (mEnablePullLoad) { if (mFooterView.getBottomMargin() > PULL_LOAD_MORE_DELTA) { startLoadMore(); } resetFooterHeight(); } } break; } return super.onTouchEvent(ev); }
Example 19
Source File: DragGridView.java From Social with Apache License 2.0 | 4 votes |
@Override public boolean dispatchTouchEvent(MotionEvent ev) { switch(ev.getAction()){ case MotionEvent.ACTION_DOWN: //使用Handler延迟dragResponseMS执行mLongClickRunnable mHandler.postDelayed(mLongClickRunnable, dragResponseMS); mDownX = (int) ev.getX(); mDownY = (int) ev.getY(); //根据按下的X,Y坐标获取所点击item的position mDragPosition = pointToPosition(mDownX, mDownY); if(mDragPosition == AdapterView.INVALID_POSITION){ return super.dispatchTouchEvent(ev); } //根据position获取该item所对应的View mStartDragItemView = getChildAt(mDragPosition - getFirstVisiblePosition()); //下面这几个距离大家可以参考我的博客上面的图来理解下 mPoint2ItemTop = mDownY - mStartDragItemView.getTop(); mPoint2ItemLeft = mDownX - mStartDragItemView.getLeft(); mOffset2Top = (int) (ev.getRawY() - mDownY); mOffset2Left = (int) (ev.getRawX() - mDownX); //获取DragGridView自动向上滚动的偏移量,小于这个值,DragGridView向下滚动 mDownScrollBorder = getHeight() /4; //获取DragGridView自动向下滚动的偏移量,大于这个值,DragGridView向上滚动 mUpScrollBorder = getHeight() * 3/4; //开启mDragItemView绘图缓存 mStartDragItemView.setDrawingCacheEnabled(true); //获取mDragItemView在缓存中的Bitmap对象 mDragBitmap = Bitmap.createBitmap(mStartDragItemView.getDrawingCache()); //这一步很关键,释放绘图缓存,避免出现重复的镜像 mStartDragItemView.destroyDrawingCache(); break; case MotionEvent.ACTION_MOVE: int moveX = (int)ev.getX(); int moveY = (int) ev.getY(); //如果我们在按下的item上面移动,只要不超过item的边界我们就不移除mRunnable if(!isTouchInItem(mStartDragItemView, moveX, moveY)){ mHandler.removeCallbacks(mLongClickRunnable); } break; case MotionEvent.ACTION_UP: mHandler.removeCallbacks(mLongClickRunnable); mHandler.removeCallbacks(mScrollRunnable); break; } return super.dispatchTouchEvent(ev); }
Example 20
Source File: SwipeViewLayout.java From UltimateSwipeTool with Apache License 2.0 | 4 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!isSwipeEnabled()) { return false; } if (mClickToClose && getOpenStatus() == Status.Open && isTouchOnSurface(ev)) { return true; } for (SwipeDenier denier : mSwipeDeniers) { if (denier != null && denier.shouldDenySwipe(ev)) { return false; } } switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mDragHelper.processTouchEvent(ev); mIsBeingDragged = false; sX = ev.getRawX(); sY = ev.getRawY(); //if the swipe is in middle state(scrolling), should intercept the touch if (getOpenStatus() == Status.Middle) { mIsBeingDragged = true; } break; case MotionEvent.ACTION_MOVE: boolean beforeCheck = mIsBeingDragged; checkCanDrag(ev); if (mIsBeingDragged) { ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } if (!beforeCheck && mIsBeingDragged) { //let children has one chance to catch the touch, and request the swipe not intercept //useful when swipeLayout wrap a swipeLayout or other gestural layout return false; } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: mIsBeingDragged = false; mDragHelper.processTouchEvent(ev); break; default://handle other action, such as ACTION_POINTER_DOWN/UP mDragHelper.processTouchEvent(ev); } return mIsBeingDragged; }