Java Code Examples for android.os.Handler#postAtTime()

The following examples show how to use android.os.Handler#postAtTime() . 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: ClockView.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
	super.onAttachedToWindow();
	mHandler = new Handler();

	/**
	 * requests a tick on the next hard-second boundary
	 */
	mTicker = new Runnable() {
		public void run() {

			String timeStr = DateUtils.getCurrDateFormat(format);

			// System.out.println("timeStr: " + timeStr);
			setText(timeStr);

			invalidate();
			long now = SystemClock.uptimeMillis();

			long next = now + (1000 - now % 1000);

			mHandler.postAtTime(mTicker, next);
		}
	};
	mTicker.run();
}
 
Example 2
Source File: HommizationDateView.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
	super.onAttachedToWindow();
	mHandler = new Handler();

	/**
	 * requests a tick on the next hard-second boundary
	 */
	mTicker = new Runnable() {
		public void run() {

			String timeStr = DateUtils.getHommizationDate(time, format);

			// System.out.println("timeStr: " + timeStr);
			setText(timeStr);

			invalidate();
			long now = SystemClock.uptimeMillis();

			long next = now + (1000 - now % 1000);

			mHandler.postAtTime(mTicker, next);
		}
	};
	mTicker.run();
}
 
Example 3
Source File: AndroidOperation.java    From AndroidOperationQueue with MIT License 6 votes vote down vote up
protected void queueing(Handler handler) {
    switch (type) {
        case NORMAL:
            handler.post(this);
            break;
        case ATFIRST:
            handler.postAtFrontOfQueue(this);
            break;
        case ATTIME:
            handler.postAtTime(this, time);
            break;
        case ATTIME_WITH_TOKEN:
            handler.postAtTime(this, token, time);
            break;
        case DELAY:
            handler.postDelayed(this, time);
    }
}
 
Example 4
Source File: WaterHeaterFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private void eventDebounce() {
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            mUserInteraction = false;
        }
    };

    Handler handler = new Handler();

    handler.postAtTime(runnable, 1000);
}
 
Example 5
Source File: DigitalClock.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    mTickerStopped = false;
    super.onAttachedToWindow();

    mFormatChangeObserver = new FormatChangeObserver();
    getContext().getContentResolver().registerContentObserver(
            Settings.System.CONTENT_URI, true, mFormatChangeObserver);
    setFormat();

    mHandler = new Handler();

    /**
     * requests a tick on the next hard-second boundary
     */
    mTicker = new Runnable() {
        public void run() {
            if (mTickerStopped) return;
            mCalendar.setTimeInMillis(System.currentTimeMillis());
            setText(DateFormat.format(mFormat, mCalendar));
            invalidate();
            long now = SystemClock.uptimeMillis();
            long next = now + (1000 - now % 1000);
            mHandler.postAtTime(mTicker, next);
        }
    };
    mTicker.run();
}
 
Example 6
Source File: LauncherAppWidgetHostView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
private void scheduleNextAdvance() {
    if (!mIsAutoAdvanceRegistered) {
        return;
    }
    long now = SystemClock.uptimeMillis();
    long advanceTime = now + (ADVANCE_INTERVAL - (now % ADVANCE_INTERVAL)) +
            ADVANCE_STAGGER * sAutoAdvanceWidgetIds.indexOfKey(getAppWidgetId());
    Handler handler = getHandler();
    if (handler != null) {
        handler.postAtTime(mAutoAdvanceRunnable, advanceTime);
    }
}
 
Example 7
Source File: DateView.java    From AndroidTvDemo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow()
{
    mTickerStopped = false;
    super.onAttachedToWindow();
    mHandler = new Handler();
    
    /**
     * requests a tick on the next hard-second boundary
     */
    mTicker = new Runnable()
    {
        @Override
        public void run()
        {
            if (mTickerStopped)
                return;
            mCalendar.setTimeInMillis(System.currentTimeMillis());
            setText(DateFormat.format(mFormat, mCalendar));
            invalidate();
            long now = SystemClock.uptimeMillis();
            long next = now + (1000 - now % 1000);
            mHandler.postAtTime(mTicker, next);
        }
    };
    mTicker.run();
}
 
Example 8
Source File: TimeAPMView.java    From AndroidTvDemo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow()
{
    mTickerStopped = false;
    super.onAttachedToWindow();
    mHandler = new Handler();
    
    /**
     * requests a tick on the next hard-second boundary
     */
    mTicker = new Runnable()
    {
        @Override
        public void run()
        {
            if (mTickerStopped)
                return;
            mCalendar.setTimeInMillis(System.currentTimeMillis());
            setText(DateFormat.format(mFormat, mCalendar));
            invalidate();
            long now = SystemClock.uptimeMillis();
            long next = now + (1000 - now % 1000);
            mHandler.postAtTime(mTicker, next);
        }
    };
    mTicker.run();
}
 
Example 9
Source File: TimeView.java    From AndroidTvDemo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow()
{
    mTickerStopped = false;
    super.onAttachedToWindow();
    mHandler = new Handler();
    
    /**
     * requests a tick on the next hard-second boundary
     */
    mTicker = new Runnable()
    {
        @Override
        public void run()
        {
            if (mTickerStopped)
                return;
            mCalendar.setTimeInMillis(System.currentTimeMillis());
            setText(DateFormat.format(mFormat, mCalendar));
            invalidate();
            long now = SystemClock.uptimeMillis();
            long next = now + (1000 - now % 1000);
            mHandler.postAtTime(mTicker, next);
        }
    };
    mTicker.run();
}
 
Example 10
Source File: StatusbarClock.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void updateSecondsHandler() {
    if (mClock == null) return;

    if (mShowSeconds && mClock.getDisplay() != null) {
        mSecondsHandler = new Handler();
        if (mClock.getDisplay().getState() == Display.STATE_ON && !mClockHidden) {
            mSecondsHandler.postAtTime(mSecondTick,
                    SystemClock.uptimeMillis() / 1000 * 1000 + 1000);
        }
    } else if (mSecondsHandler != null) {
        mSecondsHandler.removeCallbacks(mSecondTick);
        mSecondsHandler = null;
        updateClock();
    }
}
 
Example 11
Source File: GameView.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
void animateFrame() {
    long currentStepTime = SystemClock.uptimeMillis();
    step(currentStepTime);

    Handler handler = getHandler();
    if (handler != null) {
        handler.postAtTime(mAnimationRunnable, currentStepTime + ANIMATION_TIME_STEP);
        invalidate();
    }
}
 
Example 12
Source File: CountDownDigitalClock.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
@Override
	protected void onAttachedToWindow() {
		mTickerStopped = false;
		super.onAttachedToWindow();
		mHandler = new Handler();

		/**
		 * requests a tick on the next hard-second boundary
		 */
		mTicker = new Runnable() {
			public void run() {
				if (mTickerStopped)
					return;
				// mCalendar.setTimeInMillis(System.currentTimeMillis());
				long mCurrentTime = System.currentTimeMillis();
				// add begin by fly

//				java.util.Date dt = new Date(mCurrentTime);
//				SimpleDateFormat sdf2 = new SimpleDateFormat(
//						"yyyy/MM/dd HH:mm:ss");
//				String d = sdf2.format(dt);
//				String d2 = sdf2.format(dt);
//
//				System.out.println(mDeadtime + " = mDeadtime mCurrentTime= "
//						+ mCurrentTime + " " + d);

				if (mCurrentTime >= mDeadtime) {
					mDeadtimeLister.onTimeEnd();
					return;
				}
				long mTimeDistance = mDeadtime - mCurrentTime;
				if (mTimeDistance <= 0) {
					return;
				}

				String deadTimeStr = format(mTimeDistance);
				// String deadTimeStr = "距离活动结束还有" + deadDays + "天" + deadHour
				// + "小时" + deadMinute + "分" + deadMills + "秒";
				//System.out.println(deadTimeStr);
				// add end by fly
				setText(deadTimeStr);
				// setText(DateFormat.format(mFormat, mCalendar));
				invalidate();
				long now = SystemClock.uptimeMillis();
				long next = now + (1000 - now % 1000);
				mHandler.postAtTime(mTicker, next);
			}
		};
		mTicker.run();
	}