43-Android GeriSayım Tarih Uygulaması
Merhabalar
Android’te belirli bir tarih için geri sayım uygulamasında kullanacağınız kod bloğu aşağıdadır. Bir tane text view ile kolayca geri sayım uygulaması yapabilirsiniz.
public void countDownStart() {
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
handler.postDelayed(this, 1000);
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd hh:mm");
futureDate = dateFormat.parse("2018-03-11 10:00");
currentDate = new Date();
if (!currentDate.after(futureDate)) {
diff = futureDate.getTime()
- currentDate.getTime();
days = diff / (24 * 60 * 60 * 1000);
diff -= days * (24 * 60 * 60 * 1000);
hours = diff / (60 * 60 * 1000);
diff -= hours * (60 * 60 * 1000);
minutes = diff / (60 * 1000);
diff -= minutes * (60 * 1000);
seconds = diff / 1000;
txtTimerDay.setText("" + String.format("%02d", days));
txtTimerHour.setText("" + String.format("%02d", hours));
txtTimerMinute.setText(""
+ String.format("%02d", minutes));
txtTimerSecond.setText(""
+ String.format("%02d", seconds));
/* NotificationCompat.Builder builder =
new NotificationCompat.Builder(c)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notifications Example")
.setContentText(Long.toString(days) + " - "+ Long.toString(hours) +" - "+ Long.toString(minutes) + " - " +
Long.toString(seconds));
Intent notificationIntent = new Intent(c, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(c, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
*/
} else {
tvEvent.setVisibility(View.VISIBLE);
tvEvent.setText("The event started!");
textViewGone();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
handler.postDelayed(runnable, 1 * 1000);
}



