Java Code Examples for android.os.Handler#removeCallbacks()
The following examples show how to use
android.os.Handler#removeCallbacks() .
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: SplashActivity.java From WiFi-and-Sensors-Indoor-Positioning with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); { handler = new Handler(); runnable = new Runnable() { @Override public void run() { try { handler.removeCallbacks(runnable); } finally { finish(); goToMainActivity(); handler.removeCallbacks(runnable); } } }; handler.postDelayed(runnable, 2000); } }
Example 2
Source File: Request.java From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Sets the handler that will be used to invoke callbacks. By default, the handler set in * {@link BleManager} will be used. * * @param handler The handler to invoke callbacks for this request. * @return The request. */ @NonNull public Request setHandler(@NonNull final Handler handler) { this.handler = new CallbackHandler() { @Override public void post(@NonNull final Runnable r) { handler.post(r); } @Override public void postDelayed(@NonNull final Runnable r, final long delayMillis) { handler.postDelayed(r, delayMillis); } @Override public void removeCallbacks(@NonNull final Runnable r) { handler.removeCallbacks(r); } }; return this; }
Example 3
Source File: ListenerModule.java From leanback-showcase with Apache License 2.0 | 6 votes |
@PerFragment @Provides @IntoMap @ListenerModuleKey(LiveDataFragment.class) public OnItemViewSelectedListener provideOnItemViewSelectedListener(final Activity activity, final DisplayMetrics metrics, final BackgroundManager backgroundManager, final RequestOptions defaultPlaceHolder, final Drawable finalDrawable, final Handler mainHandler) { return new OnItemViewSelectedListener() { @Override public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { VideoEntity selectedVideo = (VideoEntity) item; RunnableClass backgroundRunnable = new RunnableClass(selectedVideo, activity, metrics, backgroundManager, defaultPlaceHolder, finalDrawable); if (lastTime != null) { mainHandler.removeCallbacks(lastTime); } mainHandler.postDelayed(backgroundRunnable, BACKGROUND_UPDATE_DELAY); lastTime = backgroundRunnable; } }; }
Example 4
Source File: GestureImageViewWithFullScreenMode.java From edslite with GNU General Public License v2.0 | 6 votes |
@SuppressLint("InlinedApi") private void setNavVisibility(boolean visible) { int newVis = SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; if (!visible) newVis |= SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_IMMERSIVE | SYSTEM_UI_FLAG_HIDE_NAVIGATION; final boolean changed = newVis == getSystemUiVisibility(); // Unschedule any pending event to hide navigation if we are // changing the visibility, or making the UI visible. if (changed || visible) { Handler h = getHandler(); if (h != null) h.removeCallbacks(_navHider); } // Set the new desired visibility. setSystemUiVisibility(newVis); }
Example 5
Source File: ExtendableListView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private boolean onTouchUp(final MotionEvent event) { switch (mTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: return onTouchUpTap(event); case TOUCH_MODE_SCROLLING: return onTouchUpScrolling(event); } setPressed(false); invalidate(); // redraw selector final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } recycleVelocityTracker(); mActivePointerId = INVALID_POINTER; return true; }
Example 6
Source File: TimeoutBase.java From MediaSDK with Apache License 2.0 | 6 votes |
public TimeoutBase(final Handler handler, long delay) { this.delay = delay; this.handlerish = new Handlerish() { @Override public void post(Runnable r) { handler.post(r); } @Override public Object postDelayed(Runnable r, long delay) { handler.postDelayed(r, delay); return r; } @Override public void removeAllCallbacks(Object cancellable) { if (cancellable == null) return; handler.removeCallbacks((Runnable)cancellable); } }; }
Example 7
Source File: ExtendableListView.java From UltimateAndroid with Apache License 2.0 | 5 votes |
/** * Starts a scroll that moves the difference between y and our last motions y * if it's a movement that represents a big enough scroll. */ private boolean startScrollIfNeeded(final int y) { final int deltaY = y - mMotionY; final int distance = Math.abs(deltaY); // TODO : Overscroll? // final boolean overscroll = mScrollY != 0; final boolean overscroll = false; if (overscroll || distance > mTouchSlop) { if (overscroll) { mMotionCorrection = 0; } else { mTouchMode = TOUCH_MODE_SCROLLING; mMotionCorrection = deltaY > 0 ? mTouchSlop : -mTouchSlop; } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } setPressed(false); View motionView = getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } scrollIfNeeded(y); return true; } return false; }
Example 8
Source File: Discoverer.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Discoverer(Context ctx) { mCtx = ctx; mListeners = new ArrayList<>(); mHandler = new Handler(mCtx.getMainLooper()); mTimeoutRunnable = new Runnable() { @Override public void run() { notifyDiscoveryTimedOut(); mHandler.removeCallbacks(mTimeoutRunnable); } }; initBroadcastReceiver(); }
Example 9
Source File: TinyBus.java From tinybus with Apache License 2.0 | 5 votes |
public void cancelDelayed(Class<?> eventClass, Handler handler) { Task task = null; synchronized (this) { if (mDelayedTasks != null) { task = mDelayedTasks.remove(eventClass); } } if (task != null) { handler.removeCallbacks(task); task.recycle(); } }
Example 10
Source File: TwoWayAbsListView.java From recent-images with MIT License | 5 votes |
public boolean startScrollIfNeeded(int delta) { // Check if we have moved far enough that it looks more like a // scroll than a tap final int distance = Math.abs(delta); if (distance > mTouchSlop) { createScrollingCache(); mTouchMode = TOUCH_MODE_SCROLL; mMotionCorrection = delta; final Handler handler = getHandler(); // Handler should not be null unless the TwoWayAbsListView 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 requestDisallowInterceptTouchEvent(true); return true; } return false; }
Example 11
Source File: RecordButton.java From justaline-android with Apache License 2.0 | 5 votes |
private void init() { inflate(getContext(), R.layout.view_record_button, this); mAnalytics = Fa.get(); mStopButton = findViewById(R.id.red_square); mRecordingBackground = findViewById(R.id.recording_background); mProgressBar = findViewById(R.id.progress); // // set up timer // mHandler = new Handler(); mRecordingRunnable = new Runnable() { @Override public void run() { long counterDuration = getCurrentCounterDuration(); mProgressBar.setCurrentDuration(counterDuration, MAX_DURATION); if (counterDuration >= MAX_DURATION) { setRecording(false); mHandler.removeCallbacks(mRecordingRunnable); } else if (mCounterRunning) { mHandler.postDelayed(mRecordingRunnable, mTick); } } }; }
Example 12
Source File: AbsHListView.java From Klyph with MIT License | 5 votes |
private boolean startScrollIfNeeded( int x ) { // Check if we have moved far enough that it looks more like a // scroll than a tap final int deltaX = x - mMotionX; final int distance = Math.abs( deltaX ); final boolean overscroll = getScrollX() != 0; if ( overscroll || distance > mTouchSlop ) { createScrollingCache(); if ( overscroll ) { mTouchMode = TOUCH_MODE_OVERSCROLL; mMotionCorrection = 0; } else { mTouchMode = TOUCH_MODE_SCROLL; mMotionCorrection = deltaX > 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( x ); return true; } return false; }
Example 13
Source File: TransportControllerActivity.java From V.FlyoutTest with MIT License | 5 votes |
void scheduleProgressUpdater() { Handler h = getHandler(); if (h != null) { if (mNavVisible && !mPaused) { h.removeCallbacks(mProgressUpdater); h.post(mProgressUpdater); } else { h.removeCallbacks(mProgressUpdater); } } }
Example 14
Source File: JoH.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public static void removeUiThreadRunnable(Runnable theRunnable) { final Handler mainHandler = new Handler(xdrip.getAppContext().getMainLooper()); mainHandler.removeCallbacks(theRunnable); }
Example 15
Source File: SuperUserHelper.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
public static void requestRoot(final Context context) { // Don't request root when read logs permission is already granted if (haveReadLogsPermission(context)) { failedToObtainRoot = true; return; } Handler handler = new Handler(Looper.getMainLooper()); Runnable toastRunnable = new Runnable() { @Override public void run() { Toast.makeText(context, R.string.toast_request_root, Toast.LENGTH_LONG).show(); } }; handler.postDelayed(toastRunnable, 200); Process process = null; try { // Preform su to get root privileges process = Runtime.getRuntime().exec("su"); // confirm that we have root DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); outputStream.writeBytes("echo hello\n"); // Close the terminal outputStream.writeBytes("exit\n"); outputStream.flush(); process.waitFor(); if (process.exitValue() != 0) { showWarningDialog(context); failedToObtainRoot = true; } else { // success PreferenceHelper.setJellybeanRootRan(context); } } catch (IOException | InterruptedException e) { log.w(e, "Cannot obtain root"); showWarningDialog(context); failedToObtainRoot = true; } handler.removeCallbacks(toastRunnable); }
Example 16
Source File: ModStatusBar.java From GravityBox with Apache License 2.0 | 4 votes |
private static void brightnessControl(MotionEvent event) { try { final int action = event.getAction(); final int x = (int) event.getRawX(); final int y = (int) event.getRawY(); Handler handler = (Handler) XposedHelpers.getObjectField(mPhoneStatusBar, "mHandler"); int statusBarHeaderHeight = (int) XposedHelpers.callMethod(mHeader, "getCollapsedHeight"); if (action == MotionEvent.ACTION_DOWN) { if (y < statusBarHeaderHeight) { mLinger = 0; mInitialTouchX = x; mInitialTouchY = y; mJustPeeked = true; mScreenWidth = (float) mContext.getResources().getDisplayMetrics().widthPixels; handler.removeCallbacks(mLongPressBrightnessChange); handler.postDelayed(mLongPressBrightnessChange, BRIGHTNESS_CONTROL_LONG_PRESS_TIMEOUT); } } else if (action == MotionEvent.ACTION_MOVE) { if (y < statusBarHeaderHeight && mJustPeeked) { if (mLinger > BRIGHTNESS_CONTROL_LINGER_THRESHOLD) { adjustBrightness(x); } else { final int xDiff = Math.abs(x - mInitialTouchX); final int yDiff = Math.abs(y - mInitialTouchY); final int touchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop(); if (xDiff > yDiff) { mLinger++; } if (xDiff > touchSlop || yDiff > touchSlop) { handler.removeCallbacks(mLongPressBrightnessChange); } } } else { if (y > mPeekHeight) { mJustPeeked = false; } handler.removeCallbacks(mLongPressBrightnessChange); } } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { handler.removeCallbacks(mLongPressBrightnessChange); } } catch (Throwable t) { XposedBridge.log(t); } }
Example 17
Source File: FastScroller.java From JotaTextEditor with Apache License 2.0 | 4 votes |
boolean onTouchEvent(MotionEvent me) { if (mState == STATE_NONE) { return false; } final int action = me.getAction(); if (action == MotionEvent.ACTION_DOWN) { if (isPointInside(me.getX(), me.getY())) { setState(STATE_DRAGGING); if (mSections == null ) {// Jota Text Editor getSectionsFromIndexer(); } if (mList != null) { // Jota Text Editor // mList.requestDisallowInterceptTouchEvent(true); // mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); } cancelFling(); return true; } } else if (action == MotionEvent.ACTION_UP) { // don't add ACTION_CANCEL here if (mState == STATE_DRAGGING) { if (mList != null) { // ViewGroup does the right thing already, but there might // be other classes that don't properly reset on touch-up, // so do this explicitly just in case. // Jota Text Editor // mList.requestDisallowInterceptTouchEvent(false); // mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } setState(STATE_VISIBLE); final Handler handler = mHandler; handler.removeCallbacks(mScrollFade); handler.postDelayed(mScrollFade, 1000); return true; } } else if (action == MotionEvent.ACTION_MOVE) { if (mState == STATE_DRAGGING) { long now = System.currentTimeMillis(); long diff = (now-mLastEventTime); if ( diff > 30 ){ mLastEventTime = now; final int viewHeight = mList.getHeight(); // Jitter int newThumbY = (int) me.getY() - mThumbH / 2;// Jota Text Editor if (newThumbY < 0) { newThumbY = 0; } else if (newThumbY + mThumbH > viewHeight) { newThumbY = viewHeight - mThumbH; } if (Math.abs(mThumbY - newThumbY) < 2) { return true; } mThumbY = newThumbY; // Jota Text Editor // // If the previous scrollTo is still pending // if (mScrollCompleted) { scrollTo((float) mThumbY / (viewHeight - mThumbH)); // } } return true; } } return false; }
Example 18
Source File: JoH.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static void removeUiThreadRunnable(Runnable theRunnable) { final Handler mainHandler = new Handler(xdrip.getAppContext().getMainLooper()); mainHandler.removeCallbacks(theRunnable); }
Example 19
Source File: SuperUserHelper.java From javaide with GNU General Public License v3.0 | 4 votes |
public static void requestRoot(final Context context) { // Don't request root when read logs permission is already granted if (haveReadLogsPermission(context)) { failedToObtainRoot = true; return; } Handler handler = new Handler(Looper.getMainLooper()); Runnable toastRunnable = new Runnable() { @Override public void run() { Toast.makeText(context, R.string.toast_request_root, Toast.LENGTH_LONG).show(); } }; handler.postDelayed(toastRunnable, 200); Process process = null; try { // Preform su to get root privileges process = Runtime.getRuntime().exec("su"); // confirm that we have root DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); outputStream.writeBytes("echo hello\n"); // Close the terminal outputStream.writeBytes("exit\n"); outputStream.flush(); process.waitFor(); if (process.exitValue() != 0) { showWarningDialog(context); failedToObtainRoot = true; } else { // success PreferenceHelper.setJellybeanRootRan(context); } } catch (IOException | InterruptedException e) { log.w(e, "Cannot obtain root"); showWarningDialog(context); failedToObtainRoot = true; } handler.removeCallbacks(toastRunnable); }
Example 20
Source File: MasaccioImageView.java From Masaccio with Apache License 2.0 | 3 votes |
private void cropImage(final int originalImageWidth, final int originalImageHeight) { final Handler messageHandler = mMessageHandler; if (messageHandler == null) { // We can't do anything right now. return; } if (mCropRunnable != null) { messageHandler.removeCallbacks(mCropRunnable); } if ((!mAutoFaceDetection && (mEndX == 0) && (mEndY == 0) && (mEndScale == 1)) || ( originalImageWidth <= 0) || (originalImageHeight <= 0)) { final ScaleType scaleType = super.getScaleType(); final ScaleType originalScaleType = mOriginalScaleType; if (scaleType != originalScaleType) { super.setScaleType(originalScaleType); } return; } mCropRunnable = new CropRunnable(originalImageWidth, originalImageHeight); if (Looper.getMainLooper() == Looper.myLooper()) { mCropRunnable.run(); } else { messageHandler.post(mCropRunnable); } }