Showing posts with label countdown timer. Show all posts
Showing posts with label countdown timer. Show all posts

Android Count Down Timer Examples?

Here another nice topic am cover Countdown Timer , Here Is the Android Official Documentation is http://developer.android.com/reference/android/os/CountDownTimer.html ,

In this topic am fount two types of  count down timers.

FIRST ONE:


  1.   String oldFormat = "yyyy-MM-dd HH:mm:ss";

       SimpleDateFormat sdf1 = new SimpleDateFormat(oldFormat);
       TimeZone obj = TimeZone.getTimeZone("CST");
           sdf1.setTimeZone(obj);
         
           Date date = sdf1.parse(" your match time ");
           millis = date.getTime();


          long currentTimeInMili = new Date().getTime(); // Current time
          final CountDownTimer Counter1 = new CountDownTimer(millis - currentTimeInMili, 1 * 1000) {
             public void onTick(long millisUntilFinished) {
                  matchUpcomingText.setText("" + formatTime(millisUntilFinished) + "till match start");
        }

        public void onFinish() {
       matchUpcomingText.setText("Finished!");
           }
         }.start();

SECOND ONE:


  1. String oldFormat = "yyyy-MM-dd HH:mm:ss";

       SimpleDateFormat sdf1 = new SimpleDateFormat(oldFormat);
       TimeZone obj = TimeZone.getTimeZone("CST");
           sdf1.setTimeZone(obj);
         
           Date date = sdf1.parse(" your match time ");
           millis = date.getTime();

    long currentTimeInMili = new Date().getTime();
    MyCount counter = new MyCount(millis - currentTimeInMili, 1 * 1000);
    counter.start();

        public static class MyCount extends CountDownTimer {
    public MyCount(long millisInFuture, long countDownInterval) {
    super(millisInFuture, countDownInterval);
    }// MyCount
    public void onPause() {
    onPause();
    }// finish
    public void onTick(long millisUntilFinished) {
    matchUpcomingText.setText(""+ formatTime(millisUntilFinished)+ " till match start");
    Log.i(" formatTime ==> ", "" + formatTime(millisUntilFinished));
    Log.i(" millisUntilFinished ==> ", "" + millisUntilFinished);
    }// on tick
    @Override
    public void onFinish() {
    //onStop();
    }// finish
    }

    public static String formatTime(long millis) {
    String output = "00:00";
    try {
    long seconds = millis / 1000;
    long minutes = seconds / 60;
    long hours = seconds / 3600;
    long days = seconds / (3600 * 24);

    seconds = seconds % 60;
    minutes = minutes % 60;
    hours = hours % 24;
    days = days % 30;

    String sec = String.valueOf(seconds);
    String min = String.valueOf(minutes);
    String hur = String.valueOf(hours);
    String day = String.valueOf(days);

    if (seconds < 10)
    sec = "0" + seconds;
    if (minutes < 10)
    min = "0" + minutes;
    if (hours < 10)
    hur = "0" + hours;
    if (days < 10)
    day = "0" + days;

    output = day + "D " + hur + "H " + min + "M " + sec + "S";
    } catch (Exception e) {
    e.printStackTrace();
    }
    return output;
    } 
   

Select DateRange UsingRangePicker.

  /* * This Method is for select range from picker. * */ private fun selectDateRangeUsingRangePicker () { pageNumber = 1 val displ...