Android 使用Andengine的倒计时日期/天数
我正在寻找一个倒计时教程使用安引擎。这是我需要做的应用ie我需要计数到特定日期,当它到达该日期时,它必须显示一些消息,当该日期过去时,它必须再次显示倒计时到明年的日期。如何实现这一点。我搜索了各种教程,但无法找到找到答案。希望有人能帮我 更新: clocktext=新文本CAMERA_WIDTH/4.4f,CAMERA_HEIGHT/3.6f,this.mFont,Hello and Engine!,this.getVertexBufferObjectManagerAndroid 使用Andengine的倒计时日期/天数,android,date,andengine,countdown,Android,Date,Andengine,Countdown,我正在寻找一个倒计时教程使用安引擎。这是我需要做的应用ie我需要计数到特定日期,当它到达该日期时,它必须显示一些消息,当该日期过去时,它必须再次显示倒计时到明年的日期。如何实现这一点。我搜索了各种教程,但无法找到找到答案。希望有人能帮我 更新: clocktext=新文本CAMERA_WIDTH/4.4f,CAMERA_HEIGHT/3.6f,this.mFont,Hello and Engine!,this.getVertexBufferObjectManager Calendar
Calendar thatDay = Calendar.getInstance();
thatDay.set(Calendar.DAY_OF_MONTH,30);
thatDay.set(Calendar.MONTH,9); // 0-11 so 1 less
thatDay.set(Calendar.YEAR, 2014);
Calendar today = Calendar.getInstance();
//long diff = today.getTimeInMillis() - thatDay.getTimeInMillis(); //result in millis
long diff = thatDay.getTimeInMillis()-today.getTimeInMillis(); //result in millis
long days = diff / (24 * 60 * 60 * 1000);
this.remain = days;
if(remain<0){
clocktext = new Text(CAMERA_WIDTH/9.8f, CAMERA_HEIGHT/1.4f,this.mFont, remain + "", this.getVertexBufferObjectManager());
}if(remain==0){
clocktext = new Text(CAMERA_WIDTH/9.8f, CAMERA_HEIGHT/1.4f,this.mFont, "HAPPY HALLOWEEN", this.getVertexBufferObjectManager());
}if(remain>0){
clocktext = new Text(CAMERA_WIDTH/9.8f, CAMERA_HEIGHT/1.4f,this.mFont, remain + "", this.getVertexBufferObjectManager());
}
下面是代码剪贴:
package de.goddchen.android.andthrow.library;
import org.anddev.andengine.engine.handler.IUpdateHandler;
public class CountDownTimer implements IUpdateHandler {
private float timerSeconds;
private float timerInterval;
private float lastCall;
private boolean isRunning;
private float timeElapsed;
private iCountDownListener listener;
public interface iCountDownListener {
public void onIntervalElapsed(float timeRemaining, CountDownTimer timer);
public void onCountDownEnded(CountDownTimer timer);
}
public CountDownTimer(float timerSeconds, float timerInterval,
iCountDownListener listener) {
this.timerInterval = timerInterval;
this.timerSeconds = timerSeconds;
this.listener = listener;
this.isRunning = true;
}
@Override
public void onUpdate(float pSecondsElapsed) {
timeElapsed += pSecondsElapsed;
// Log.d(getClass().getSimpleName(), "elapsed: " + timeElapsed);
if (isRunning) {
if (timeElapsed - lastCall > timerInterval) {
listener.onIntervalElapsed(timerSeconds - timeElapsed, this);
lastCall = timeElapsed;
}
if (timeElapsed > timerSeconds) {
listener.onCountDownEnded(this);
cancel();
}
}
}
@Override
public void reset() {
}
public void cancel() {
isRunning = false;
}
}
另一种选择是:在andengine中,你也可以实现简单的java或android倒计时,或者更确切地说,你也可以使用色度计。@mtetno谢谢你的回答。如何设置准确的日期,比如从日历开始的30/10/年和从当前日期开始的30/10/年,我希望得到差异,即天数。到达该日期时,我希望显示一条消息,当日期过去时,我希望计数器开始显示到明年的剩余天数。@mtetno更新的代码我试过了。你只想要日期差异而不是时间差异,对吗?@mtetno是的。日期差异