Fecha/días de cuenta regresiva usando Andengine
Frecuentes
Visto 171 equipos
0
Estoy buscando un tutorial de cuenta regresiva usando Andengine. Esto es lo que necesito hacer con la aplicación, es decir, necesito contar hasta una fecha específica y cuando llega a esa fecha debe mostrar algún mensaje y cuando pasa esa fecha debe mostrar una vez más la cuenta regresiva hasta esa fecha para el próximo año. Cómo implementar esto. Busqué varios tutoriales pero no puedo encontrarlos. Espero que alguien me ayude.
Actualización: clocktext = new Text(CAMERA_WIDTH/4.4f, CAMERA_HEIGHT/3.6f,this.mFont, "¡Hola AndEngine!", this.getVertexBufferObjectManager());
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());
}
1 Respuestas
0
Aquí hay un fragmento de código:
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;
}
}
Respondido 07 Oct 14, 14:10
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas android date andengine countdown or haz tu propia pregunta.
solo una alternativa: en andengine también puede implementar un temporizador de cuenta regresiva simple de Java o Android, o más bien puede usar el cronómetro también ... - KOTIOS
@mtetno Gracias por la respuesta. Cómo establecer la fecha exacta, digamos 30/10/año desde el calendario y desde la fecha actual, me gustaría obtener la diferencia, es decir, Días. Y al llegar a esa fecha, me gustaría mostrar un mensaje y cuándo pasa la fecha Me gustaría que Counter comenzara a mostrar los días restantes hasta el próximo año. - Govind Narayan
@mtetno actualizó el código que probé. - Govind Narayan
solo quieres la diferencia de fecha, no la diferencia de tiempo, ¿verdad? - KOTIOS
@mtetno Sí. Diferencia de fecha - Govind Narayan