List of usage examples for android.os Handler removeCallbacks
public final void removeCallbacks(Runnable r)
From source file:org.lee.pulltorefresh.library.View.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*from w ww . j av a2s . co m*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY()); switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mLastTouchX = ev.getX(); motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_DOWN; mBeginClick = true; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } mMotionPosition = motionPosition; invalidate(); break; case MotionEvent.ACTION_MOVE: final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } updateSelectorState(); break; case MotionEvent.ACTION_CANCEL: mTouchMode = TOUCH_MODE_IDLE; updateSelectorState(); setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } if (mTopEdge != null) { mTopEdge.onRelease(); mBottomEdge.onRelease(); } mTouchMode = TOUCH_MODE_IDLE; break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); final int prevTouchMode = mTouchMode; if (Math.abs(velocity) > mFlingVelocity) { mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; invalidate(); } else { mTouchMode = TOUCH_MODE_IDLE; } if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) { // TODO : handle mTouchMode = TOUCH_MODE_TAP; } else { mTouchMode = TOUCH_MODE_REST; } switch (prevTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight(); if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handlerTouch = getHandler(); if (handlerTouch != null) { handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(mDataChanged); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; } mBeginClick = false; updateSelectorState(); } break; } return true; }
From source file:com.sintn.hera.client.widget.view.stagegered.ExtendableListView.java
private boolean onTouchUpTap(final MotionEvent event) { final int motionPosition = mMotionPosition; if (motionPosition >= 0) { final View child = getChildAt(motionPosition); if (child != null && !child.hasFocusable()) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); }//from w ww . j a v a2s. c om if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); // mResurrectToPosition = motionPosition; if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks( mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } mLayoutMode = LAYOUT_NORMAL; if (!mDataChanged && motionPosition >= 0 && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(); child.setPressed(true); setPressed(true); postDelayed(new Runnable() { public void run() { child.setPressed(false); setPressed(false); if (!mDataChanged) { post(performClick); } mTouchMode = TOUCH_MODE_IDLE; } }, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_IDLE; } return true; } else if (!mDataChanged && motionPosition >= 0 && mAdapter.isEnabled(motionPosition)) { post(performClick); } } } mTouchMode = TOUCH_MODE_IDLE; return true; }
From source file:mrfu.blurstaggered.lib.view.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*from www .j a va 2 s .c o m*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY()); switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mLastTouchX = ev.getX(); motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_DOWN; mBeginClick = true; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } mMotionPosition = motionPosition; invalidate(); break; case MotionEvent.ACTION_MOVE: final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; //TODO MrFu setTouchMode(TOUCH_MODE_DRAGGING); } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } updateSelectorState(); break; case MotionEvent.ACTION_CANCEL: mTouchMode = TOUCH_MODE_IDLE; updateSelectorState(); setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } if (mTopEdge != null) { mTopEdge.onRelease(); mBottomEdge.onRelease(); } mTouchMode = TOUCH_MODE_IDLE; setTouchMode(TOUCH_MODE_IDLE); break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); final int prevTouchMode = mTouchMode; if (Math.abs(velocity) > mFlingVelocity) { // TODO setTouchMode(TOUCH_MODE_FLINGING); mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; invalidate(); } else { mTouchMode = TOUCH_MODE_IDLE; setTouchMode(TOUCH_MODE_IDLE); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { // TODO : handle mTouchMode = TOUCH_MODE_TAP; } else { mTouchMode = TOUCH_MODE_REST; } switch (prevTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight(); if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handlerTouch = getHandler(); if (handlerTouch != null) { handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(mDataChanged); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; } mBeginClick = false; updateSelectorState(); } break; } return true; }
From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*from w ww .j a v a 2s.com*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY()); switch (action) { case MotionEvent.ACTION_DOWN: LogUtil.d("----------onTouch ACTION_DOWN-------------"); isOnTouch = true; mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mLastTouchX = ev.getX(); motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_DOWN; mBeginClick = true; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } mMotionPosition = motionPosition; invalidate(); break; case MotionEvent.ACTION_MOVE: //LogUtil.d("----------onTouch ACTION_MOVE-------------"); float currentY = ev.getRawY(); if (mMoveTouchListener != null) { if (currentY - mFirstDownY >= 30) { mMoveTouchListener.onMoveDown(); } else if (mFirstDownY - currentY >= 30) { mMoveTouchListener.onMoveUp(); } } mFirstDownY = currentY; isOnTouch = true; final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, getFirstVisiblePosition(), getLastPosition()); } updateSelectorState(); if (mFlingListener != null) { mFlingListener.onTouchFling(); } break; case MotionEvent.ACTION_CANCEL: // LogUtil.d("----------onTouch ACTION_CANCEL-------------"); isOnTouch = false; mTouchMode = TOUCH_MODE_IDLE; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); updateSelectorState(); setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } if (mTopEdge != null) { mTopEdge.onRelease(); mBottomEdge.onRelease(); } mTouchMode = TOUCH_MODE_IDLE; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); break; case MotionEvent.ACTION_UP: { //LogUtil.d("----------onTouch ACTION_UP-------------"); // LogUtil.d("TAG---------------onTouch ACTION_UP finish-----------" + mScroller.isFinished()); isOnTouch = false; mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); final int prevTouchMode = mTouchMode; if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mIsFling = true; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING, getFirstVisiblePosition(), getLastPosition()); invalidate(); } else { mIsFling = true; mTouchMode = TOUCH_MODE_IDLE; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { // TODO : handle mTouchMode = TOUCH_MODE_TAP; } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); } switch (prevTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight(); if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handlerTouch = getHandler(); if (handlerTouch != null) { handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(mDataChanged); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); } mBeginClick = false; updateSelectorState(); } break; } return true; }
From source file:com.dishes.views.stageredggridview.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (mFastScroller != null) { boolean intercepted = mFastScroller.onTouchEvent(ev); if (intercepted) { return true; }/*from www . j a va 2 s .c om*/ } mVelocityTracker.addMovement(ev); final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY()); switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mLastTouchX = ev.getX(); motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_DOWN; mBeginClick = true; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } mMotionPosition = motionPosition; invalidate(); break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } updateSelectorState(); } break; case MotionEvent.ACTION_CANCEL: mTouchMode = TOUCH_MODE_IDLE; updateSelectorState(); setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } if (mTopEdge != null) { mTopEdge.onRelease(); mBottomEdge.onRelease(); } mTouchMode = TOUCH_MODE_IDLE; break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); final int prevTouchMode = mTouchMode; if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; invalidate(); } else { mTouchMode = TOUCH_MODE_IDLE; } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { // TODO : handle mTouchMode = TOUCH_MODE_TAP; } else { mTouchMode = TOUCH_MODE_REST; } switch (prevTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight(); if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handlerTouch = getHandler(); if (handlerTouch != null) { handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } mLayoutMode = LAYOUT_NORMAL; if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(mDataChanged); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; } mBeginClick = false; updateSelectorState(); } break; } return true; }
From source file:com.android.mms.ui.MessageUtils.java
public static void resizeImage(final Context context, final Uri imageUri, final Handler handler, final ResizeImageResultCallback cb, final boolean append, boolean showToast) { /** M: Show a progress toast if the resize hasn't finished * within one second.//from ww w . ja v a 2s . c om * Stash the runnable for showing it away so we can cancel * it later if the resize completes ahead of the deadline. */ final Runnable showProgress = new Runnable() { public void run() { Toast.makeText(context, R.string.compressing, Toast.LENGTH_SHORT).show(); } }; if (showToast) { handler.post(showProgress); // handler.postDelayed(showProgress, 1000); } final PduPart part; try { UriImage image = new UriImage(context, imageUri); part = image.getResizedImageAsPart(MmsConfig.getMaxImageWidth(), MmsConfig.getMaxImageHeight(), MmsConfig.getUserSetMmsSizeLimit(true) - MESSAGE_OVERHEAD); cb.onResizeResult(part, append); } catch (IllegalArgumentException e) { MmsLog.e(TAG, "Unexpected IllegalArgumentException.", e); } finally { /// M: Cancel pending show of the progress toast if necessary. handler.removeCallbacks(showProgress); } }
From source file:com.android.mms.ui.MessageUtils.java
public static void resizeImageAsync(final Context context, final Uri imageUri, final Handler handler, final ResizeImageResultCallback cb, final boolean append) { // Show a progress toast if the resize hasn't finished // within one second. // Stash the runnable for showing it away so we can cancel // it later if the resize completes ahead of the deadline. final Runnable showProgress = new Runnable() { @Override//from w w w. java 2 s . c o m public void run() { Toast.makeText(context, R.string.compressing, Toast.LENGTH_SHORT).show(); } }; // Schedule it for one second from now. handler.postDelayed(showProgress, 1000); new Thread(new Runnable() { @Override public void run() { final PduPart part; try { UriImage image = new UriImage(context, imageUri); int widthLimit = MmsConfig.getMaxImageWidth(); int heightLimit = MmsConfig.getMaxImageHeight(); // In mms_config.xml, the max width always been declared larger than the max // height. Swap the width and height limits if necessary so scale the picture // as little as possible. if (image.getHeight() > image.getWidth()) { int temp = widthLimit; widthLimit = heightLimit; heightLimit = temp; } // / M: Code analyze 027, new feature, to improve the // performance of Mms. @{ /*part = image.getResizedImageAsPart( widthLimit, heightLimit, MmsConfig.getMaxMessageSize() - MESSAGE_OVERHEAD); */ part = image.getResizedImageAsPart(widthLimit, heightLimit, MmsConfig.getUserSetMmsSizeLimit(true) - MESSAGE_OVERHEAD); handler.post(new Runnable() { @Override public void run() { cb.onResizeResult(part, append); } }); } catch (IllegalArgumentException e) { MmsLog.e(TAG, "Unexpected IllegalArgumentException.", e); } finally { /// M: Cancel pending show of the progress toast if necessary. handler.removeCallbacks(showProgress); } /// @} } }, "MessageUtils.resizeImageAsync").start(); }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void processPickResult(final Intent data) { // The EXTRA_PHONE_URIS stores the phone's urls that were selected by user in the // multiple phone picker. final Parcelable[] uris = data.getParcelableArrayExtra(Intents.EXTRA_PHONE_URIS); final int recipientCount = uris != null ? uris.length : 0; final int recipientLimit = MmsConfig.getRecipientLimit(); if (recipientLimit != Integer.MAX_VALUE && recipientCount > recipientLimit) { new AlertDialog.Builder(this) .setMessage(getString(R.string.too_many_recipients, recipientCount, recipientLimit)) .setPositiveButton(android.R.string.ok, null).create().show(); return;/*from w w w. j av a 2 s.c o m*/ } final Handler handler = new Handler(); final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle(getText(R.string.pick_too_many_recipients)); progressDialog.setMessage(getText(R.string.adding_recipients)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); final Runnable showProgress = new Runnable() { @Override public void run() { progressDialog.show(); } }; // Only show the progress dialog if we can not finish off parsing the return data in 1s, // otherwise the dialog could flicker. handler.postDelayed(showProgress, 1000); new Thread(new Runnable() { @Override public void run() { final ContactList list; try { list = ContactList.blockingGetByUris(uris); } finally { handler.removeCallbacks(showProgress); progressDialog.dismiss(); } // TODO: there is already code to update the contact header widget and recipients // editor if the contacts change. we can re-use that code. final Runnable populateWorker = new Runnable() { @Override public void run() { mRecipientsEditor.populate(list); updateTitle(list); } }; handler.post(populateWorker); } }, "ComoseMessageActivity.processPickResult").start(); }
From source file:com.example.libwidgettv.bak.AbsListView.java
private boolean startScrollIfNeeded(int y) { // Check if we have moved far enough that it looks more like a // scroll than a tap final int deltaY = y - mMotionY; final int distance = Math.abs(deltaY); final boolean overscroll = getScrollY() != 0; if (overscroll || distance > mTouchSlop) { createScrollingCache();/*from w w w.j a v a 2 s . c o m*/ if (overscroll) { mTouchMode = TOUCH_MODE_OVERSCROLL; mMotionCorrection = 0; } else { mTouchMode = TOUCH_MODE_SCROLL; mMotionCorrection = deltaY > 0 ? mTouchSlop : -mTouchSlop; } final Handler handler = getHandler(); // Handler should not be null unless the AbsListView is not attached // to a // window, which would make it very hard to scroll it... but the // monkeys // say it's possible. if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } setPressed(false); View motionView = getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); // Time to start stealing events! Once we've stolen them, don't let // anyone // steal from us final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } scrollIfNeeded(y); return true; } return false; }
From source file:com.example.libwidgettv.bak.AbsListView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!isEnabled()) { // A disabled view that is clickable still consumes the touch // events, it just doesn't respond to them. return isClickable() || isLongClickable(); }/*from w w w .j av a 2 s . c om*/ if (mFastScroller != null) { boolean intercepted = mFastScroller.onTouchEvent(ev); if (intercepted) { return true; } } final int action = ev.getAction(); View v; initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { switch (mTouchMode) { case TOUCH_MODE_OVERFLING: { mFlingRunnable.endFling(); if (mPositionScroller != null) { mPositionScroller.stop(); } mTouchMode = TOUCH_MODE_OVERSCROLL; mMotionX = (int) ev.getX(); mMotionY = mLastY = (int) ev.getY(); mMotionCorrection = 0; mActivePointerId = ev.getPointerId(0); mDirection = 0; break; } default: { mActivePointerId = ev.getPointerId(0); final int x = (int) ev.getX(); final int y = (int) ev.getY(); int motionPosition = pointToPosition(x, y); if (!mDataChanged) { if ((mTouchMode != TOUCH_MODE_FLING) && (motionPosition >= 0) && (getAdapter().isEnabled(motionPosition))) { // User clicked on an actual view (and was not stopping // a fling). // It might be a click or a scroll. Assume it is a click // until // proven otherwise mTouchMode = TOUCH_MODE_DOWN; // FIXME Debounce if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } else { if (mTouchMode == TOUCH_MODE_FLING) { // Stopped a fling. It is a scroll. createScrollingCache(); mTouchMode = TOUCH_MODE_SCROLL; mMotionCorrection = 0; motionPosition = findMotionRow(y); mFlingRunnable.flywheelTouch(); } } } if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = v.getTop(); } mMotionX = x; mMotionY = y; mMotionPosition = motionPosition; mLastY = Integer.MIN_VALUE; break; } } // if (performButtonActionOnTouchDown(ev)) { // if (mTouchMode == TOUCH_MODE_DOWN) { // removeCallbacks(mPendingCheckForTap); // } // } break; } case MotionEvent.ACTION_MOVE: { int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) { pointerIndex = 0; mActivePointerId = ev.getPointerId(pointerIndex); } final int y = (int) ev.getY(pointerIndex); switch (mTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: // Check if we have moved far enough that it looks more like a // scroll than a tap startScrollIfNeeded(y); break; case TOUCH_MODE_SCROLL: case TOUCH_MODE_OVERSCROLL: scrollIfNeeded(y); break; } break; } case MotionEvent.ACTION_UP: { switch (mTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final int motionPosition = mMotionPosition; final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right; if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { mPerformClick = new PerformClick(); } final AbsListView.PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); mResurrectToPosition = motionPosition; if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } mLayoutMode = LAYOUT_NORMAL; if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; setSelectedPositionInt(mMotionPosition); layoutChildren(); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; updateSelectorState(); } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; updateSelectorState(); break; case TOUCH_MODE_SCROLL: final int childCount = getChildCount(); if (childCount > 0) { final int firstChildTop = getChildAt(0).getTop(); final int lastChildBottom = getChildAt(childCount - 1).getBottom(); final int contentTop = mListPadding.top; final int contentBottom = getHeight() - mListPadding.bottom; if (mFirstPosition == 0 && firstChildTop >= contentTop && mFirstPosition + childCount < mItemCount && lastChildBottom <= getHeight() - contentBottom) { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } else { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocity = (int) (velocityTracker.getYVelocity(mActivePointerId) * mVelocityScale); // Fling if we have enough velocity and we aren't at a // boundary. // Since we can potentially overfling more than we can // overscroll, don't // allow the weird behavior where you can scroll to a // boundary then // fling further. if (Math.abs(initialVelocity) > mMinimumVelocity && !((mFirstPosition == 0 && firstChildTop == contentTop - mOverscrollDistance) || (mFirstPosition + childCount == mItemCount && lastChildBottom == contentBottom + mOverscrollDistance))) { if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); mFlingRunnable.start(-initialVelocity); } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); if (mFlingRunnable != null) { mFlingRunnable.endFling(); } if (mPositionScroller != null) { mPositionScroller.stop(); } } } } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } break; case TOUCH_MODE_OVERSCROLL: if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); if (Math.abs(initialVelocity) > mMinimumVelocity) { mFlingRunnable.startOverfling(-initialVelocity); } else { mFlingRunnable.startSpringback(); } break; } setPressed(false); // Need to redraw since we probably aren't drawing the selector // anymore invalidate(); final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } recycleVelocityTracker(); mActivePointerId = INVALID_POINTER; if (PROFILE_SCROLLING) { if (mScrollProfilingStarted) { Debug.stopMethodTracing(); mScrollProfilingStarted = false; } } break; } case MotionEvent.ACTION_CANCEL: { switch (mTouchMode) { case TOUCH_MODE_OVERSCROLL: if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } mFlingRunnable.startSpringback(); break; case TOUCH_MODE_OVERFLING: // Do nothing - let it play out. break; default: mTouchMode = TOUCH_MODE_REST; setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } clearScrollingCache(); final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } recycleVelocityTracker(); } mActivePointerId = INVALID_POINTER; break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); final int x = mMotionX; final int y = mMotionY; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = v.getTop(); mMotionPosition = motionPosition; } mLastY = y; break; } case MotionEvent.ACTION_POINTER_DOWN: { // New pointers take over dragging duties final int index = ev.getActionIndex(); final int id = ev.getPointerId(index); final int x = (int) ev.getX(index); final int y = (int) ev.getY(index); mMotionCorrection = 0; mActivePointerId = id; mMotionX = x; mMotionY = y; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = v.getTop(); mMotionPosition = motionPosition; } mLastY = y; break; } } return true; }