List of usage examples for android.view MotionEvent obtain
static public MotionEvent obtain(long downTime, long eventTime, int action, float x, float y, int metaState)
From source file:cc.flydev.launcher.Folder.java
public void onDragOver(DragObject d) { final DragView dragView = d.dragView; final int scrollOffset = mScrollView.getScrollY(); final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null); r[0] -= getPaddingLeft();/*from w w w. j a v a2 s . c o m*/ r[1] -= getPaddingTop(); final long downTime = SystemClock.uptimeMillis(); final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0); if (!mAutoScrollHelper.isEnabled()) { mAutoScrollHelper.setEnabled(true); } final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv); translatedEv.recycle(); if (handled) { mReorderAlarm.cancelAlarm(); } else { mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell); if (isLayoutRtl()) { mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1; } if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) { mReorderAlarm.cancelAlarm(); mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); mReorderAlarm.setAlarm(REORDER_DELAY); mPreviousTargetCell[0] = mTargetCell[0]; mPreviousTargetCell[1] = mTargetCell[1]; mDragMode = DRAG_MODE_REORDER; } else { mDragMode = DRAG_MODE_NONE; } } }
From source file:com.llf.android.launcher3.Folder.java
@Override public void onDragOver(DragObject d) { final DragView dragView = d.dragView; final int scrollOffset = mScrollView.getScrollY(); final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null); r[0] -= getPaddingLeft();/*w w w . j av a 2 s . c o m*/ r[1] -= getPaddingTop(); final long downTime = SystemClock.uptimeMillis(); final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0); if (!mAutoScrollHelper.isEnabled()) { mAutoScrollHelper.setEnabled(true); } final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv); translatedEv.recycle(); if (handled) { mReorderAlarm.cancelAlarm(); } else { mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell); if (isLayoutRtl()) { mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1; } if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) { mReorderAlarm.cancelAlarm(); mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); mReorderAlarm.setAlarm(REORDER_DELAY); mPreviousTargetCell[0] = mTargetCell[0]; mPreviousTargetCell[1] = mTargetCell[1]; mDragMode = DRAG_MODE_REORDER; } else { mDragMode = DRAG_MODE_NONE; } } }
From source file:com.appunite.list.FastScroller.java
private void cancelFling() { // Cancel the list fling MotionEvent cancelFling = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0); mList.onTouchEvent(cancelFling);// w w w . j av a 2 s. co m cancelFling.recycle(); }
From source file:com.wb.launcher3.Folder.java
public void onDragOver(DragObject d) { final DragView dragView = d.dragView; final int scrollOffset = mScrollView.getScrollY(); final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null); r[0] -= getPaddingLeft();/*from w ww . j av a2 s.c om*/ r[1] -= getPaddingTop(); final long downTime = SystemClock.uptimeMillis(); final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0); if (!mAutoScrollHelper.isEnabled()) { mAutoScrollHelper.setEnabled(true); } final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv); translatedEv.recycle(); if (handled) { mReorderAlarm.cancelAlarm(); } else { mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell); if (isLayoutRtl()) { mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1; } if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) { mReorderAlarm.cancelAlarm(); mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); mReorderAlarm.setAlarm(REORDER_DELAY); mPreviousTargetCell[0] = mTargetCell[0]; mPreviousTargetCell[1] = mTargetCell[1]; mDragMode = DRAG_MODE_REORDER; } else { mDragMode = DRAG_MODE_NONE; } } //*/ }
From source file:com.cw.litenote.note.Note.java
@Override public void onBackPressed() { System.out.println("Note / _onBackPressed"); // web view can go back String tagStr = "current" + viewPager.getCurrentItem() + "linkWebView"; CustomWebView linkWebView = (CustomWebView) viewPager.findViewWithTag(tagStr); if (linkWebView.canGoBack()) { linkWebView.goBack();// ww w . j a v a2 s. c om } else if (isPictureMode()) { // dispatch touch event to show buttons long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis() + 100; float x = 0.0f; float y = 0.0f; // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState() int metaState = 0; MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, metaState); dispatchTouchEvent(event); event.recycle(); // in order to make sure ImageViewBackButton is effective to be clicked mPagerHandler = new Handler(); mPagerHandler.postDelayed(mOnBackPressedRun, 500); } else if (isTextMode()) { // back to view all mode setViewAllMode(); setOutline(act); } else { System.out.println("Note / _onBackPressed / view all mode"); stopAV(); finish(); } }
From source file:com.android.launcher3.Folder.java
public void onDragOver(DragObject d) { final DragView dragView = d.dragView; final int scrollOffset = mScrollView.getScrollY(); final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null); r[0] -= getPaddingLeft();/*from w w w .j av a2 s.co m*/ r[1] -= getPaddingTop(); final long downTime = SystemClock.uptimeMillis(); final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0); if (!mAutoScrollHelper.isEnabled()) { mAutoScrollHelper.setEnabled(true); } final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv); translatedEv.recycle(); if (handled) { mReorderAlarm.cancelAlarm(); } else { mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell); if (isLayoutRtl()) { mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1; } if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) { mReorderAlarm.cancelAlarm(); mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); mReorderAlarm.setAlarm(REORDER_DELAY); mPreviousTargetCell[0] = mTargetCell[0]; mPreviousTargetCell[1] = mTargetCell[1]; } } }
From source file:com.jzh.stuapp.view.MyViewPager.java
/** * Fake drag by an offset in pixels. You must have called * {@link #beginFakeDrag()} first.// w w w . j av a 2 s . c o m * * @param xOffset * Offset in pixels to drag by. * @see #beginFakeDrag() * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float scrollX = getScrollX() - xOffset; final int width = getWidth(); final int widthWithMargin = width + mPageMargin; final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin); final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin; if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); if (mOnPageChangeListener != null) { final int position = (int) scrollX / widthWithMargin; final int positionOffsetPixels = (int) scrollX % widthWithMargin; final float positionOffset = (float) positionOffsetPixels / widthWithMargin; mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:refresh.renyi.io.supperrefreshview.customview.VerticalViewPager.java
private void sendDownEvent() { System.out.println("sendDownEvent"); final MotionEvent last = mLastMoveEvent; if (last == null) return;/*from www.j ava 2s. c om*/ MotionEvent e = MotionEvent.obtain(last.getDownTime(), last.getEventTime(), MotionEvent.ACTION_DOWN, last.getX(), last.getY(), last.getMetaState()); dispatchTouchEventSupper(e); }
From source file:refresh.renyi.io.supperrefreshview.customview.VerticalViewPager.java
private void sendCancelEvent() { System.out.println("sendCancelEvent"); MotionEvent last = mLastMoveEvent;/* ww w . j a v a 2 s. c o m*/ MotionEvent e = MotionEvent.obtain(last.getDownTime(), last.getEventTime(), MotionEvent.ACTION_CANCEL, last.getX(), last.getY(), last.getMetaState()); dispatchTouchEventSupper(e); }
From source file:com.yao.zhihudaily.tool.LazyViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()//w w w .j a va2 s. co m * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float scrollX = getScrollX() - xOffset; final int width = getWidth(); final int widthWithMargin = width + mPageMargin; final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin); final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin; if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); if (mOnPageChangeListener != null) { final int position = (int) scrollX / widthWithMargin; final int positionOffsetPixels = (int) scrollX % widthWithMargin; final float positionOffset = (float) positionOffsetPixels / widthWithMargin; mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }