下面列出了android.os.Handler#postAtTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
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);
}
}
private void eventDebounce() {
Runnable runnable = new Runnable() {
@Override
public void run() {
mUserInteraction = false;
}
};
Handler handler = new Handler();
handler.postAtTime(runnable, 1000);
}
@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();
}
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);
}
}
@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();
}
@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();
}
@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();
}
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();
}
}
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();
}