android.os.Handler#postAtTime ( )源码实例Demo

下面列出了android.os.Handler#postAtTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BigApp_Discuz_Android   文件: ClockView.java
@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();
}
 
@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();
}
 
源代码3 项目: AndroidOperationQueue   文件: AndroidOperation.java
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);
    }
}
 
源代码4 项目: arcusandroid   文件: WaterHeaterFragment.java
private void eventDebounce() {
    Runnable runnable = new Runnable() {

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

    Handler handler = new Handler();

    handler.postAtTime(runnable, 1000);
}
 
源代码5 项目: android_9.0.0_r45   文件: DigitalClock.java
@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();
}
 
源代码6 项目: LaunchEnr   文件: LauncherAppWidgetHostView.java
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);
    }
}
 
源代码7 项目: AndroidTvDemo   文件: DateView.java
@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();
}
 
源代码8 项目: AndroidTvDemo   文件: TimeAPMView.java
@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();
}
 
源代码9 项目: AndroidTvDemo   文件: TimeView.java
@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();
}
 
源代码10 项目: GravityBox   文件: StatusbarClock.java
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();
    }
}
 
源代码11 项目: codeexamples-android   文件: GameView.java
void animateFrame() {
    long currentStepTime = SystemClock.uptimeMillis();
    step(currentStepTime);

    Handler handler = getHandler();
    if (handler != null) {
        handler.postAtTime(mAnimationRunnable, currentStepTime + ANIMATION_TIME_STEP);
        invalidate();
    }
}
 
@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();
	}