Example usage for android.os CountDownTimer CountDownTimer

List of usage examples for android.os CountDownTimer CountDownTimer

Introduction

In this page you can find the example usage for android.os CountDownTimer CountDownTimer.

Prototype

public CountDownTimer(long millisInFuture, long countDownInterval) 

Source Link

Usage

From source file:Main.java

protected static void delayFinish(final Activity activity, long delay) {
    new CountDownTimer(delay, 100) {
        @Override/*from   www.j a v  a 2s.  com*/
        public void onTick(long millisUntilFinished) {
            // do nothing
        }

        @Override
        public void onFinish() {
            activity.finish();
        }
    }.start();
}

From source file:com.antonioleiva.materialeverywhere.HomeActivity1.java

@Override
public void onNewIntent(Intent i) {
    CountDownTimer mCountDown = null;// w ww  .  j a v  a  2s .com

    mCountDown = new CountDownTimer(10000, 1000) {

        @Override
        public void onTick(long millisUntilFinished) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onFinish() {
            Notification_Vibration();
        }
    }.start();
}

From source file:com.hx.template.ui.RegisterActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);
    ButterKnife.bind(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   w w w  .j a  v a 2 s  .c om*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mProgressDialog = new ProgressDialog(this);
    countDownTimer = new CountDownTimer(60000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            if (getvcode != null) {
                getvcode.setText((millisUntilFinished / 1000) + "");
            }
        }

        @Override
        public void onFinish() {
            if (getvcode != null) {
                getvcode.setText("???");
                getvcode.setEnabled(true);
            }
        }
    };
}

From source file:com.project.richard.insightjournal.ui.timerscreen.TimerService.java

public void startTimer(long duration, long prep) {
    if (mCountDownTimer != null)
        mCountDownTimer.cancel();/*w w  w  .j  av a  2 s  . co  m*/
    if (prep != 0) {
        mCountDownTimer = new CountDownTimer(prep, 100) {
            @Override
            public void onTick(long millisUntilFinished) {
                mPrep = millisUntilFinished;
                onPrepTickEvent.currentTick = mPrep;
                EventBus.getDefault().post(onPrepTickEvent);

            }

            @Override
            public void onFinish() {
                mPrep = 0;
                startTimer(mDuration, mPrep);
            }
        }.start();
    } else {
        mCountDownTimer = new CountDownTimer(duration, 100) {
            @Override
            public void onTick(long millisUntilFinished) {
                mDuration = millisUntilFinished;
                onTickEvent.currentTick = mDuration;
                EventBus.getDefault().post(onTickEvent);
            }

            @Override
            public void onFinish() {
                mDuration = 0;
                onTickFinishedEvent.finishedTick = mDuration;
                EventBus.getDefault().post(onTickFinishedEvent);
                stopSelf();
            }
        }.start();
    }

}

From source file:com.google.android.apps.location.gps.gnsslogger.TimerService.java

void setTimer(TimerValues values) {
    // Only allow setting when not already running
    if (!mTimerStarted) {
        mCountDownTimer = new CountDownTimer(values.getTotalMilliseconds(),
                TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS) /* countDownInterval */) {
            @Override/*  w w w  .  ja v  a 2s. c om*/
            public void onTick(long millisUntilFinished) {
                Intent broadcast = new Intent(TIMER_ACTION);
                broadcast.putExtra(EXTRA_KEY_TYPE, TYPE_UPDATE);
                broadcast.putExtra(EXTRA_KEY_UPDATE_REMAINING, millisUntilFinished);
                LocalBroadcastManager.getInstance(TimerService.this).sendBroadcast(broadcast);
            }

            @Override
            public void onFinish() {
                mTimerStarted = false;
                Intent broadcast = new Intent(TIMER_ACTION);
                broadcast.putExtra(EXTRA_KEY_TYPE, TYPE_FINISH);
                LocalBroadcastManager.getInstance(TimerService.this).sendBroadcast(broadcast);
            }
        };
    }
}

From source file:com.google.android.panoramio.ImageGrid.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;

    mImageManager = ImageManager.getInstance(mContext);
    try {/*from   ww  w. j a v  a2  s.co  m*/
        handleIntent(getIntent());
    } catch (final IOException e) {
        e.printStackTrace();
    } catch (final URISyntaxException e) {
        e.printStackTrace();
    } catch (final JSONException e) {
        e.printStackTrace();
    }

    if (!isSplashShown) {
        setContentView(R.layout.splash_screen);
        isSplashShown = true;
        CountDownTimer timer = new CountDownTimer(3000, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                initGridView();
            }
        }.start();
    } else {
        initGridView();
    }
}

From source file:com.shilpasweth.android_bus_tracker.MapsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d("MainActivity", "Entered onCreate()");
    first_time = 0;//from   w  w  w .j a  v  a 2 s  .  co m

    fetchBuses();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    gen_txt = (TextView) findViewById(R.id.general_text);
    boy_txt = (TextView) findViewById(R.id.boy_text);
    girl_txt = (TextView) findViewById(R.id.girl_text);

    mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(MapsActivity.this);

    //Timer to update bus positions
    final CountDownTimer mapRefresh = new CountDownTimer(1000, 1000) {

        public void onTick(long millisUntilFinished) {
            //mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
        }

        public void onFinish() {
            //mTextField.setText("done!");
            Log.d("MainActivity", "Entered CountDownTimer-onFinish()");
            if (wait == 0) {
                wait = 1;
                fetchBuses();
                onMapRefresh();
                wait = 0;
                this.start();
            }
            Log.d("MainActivity", "Exited CountDownTimer-onFinish()");
        }
    };

    mapRefresh.start();
    Log.d("MainActivity", "Exited onCreate()");

}

From source file:com.somethoughts.chinmay.game.Dice.DiceFragment.java

void spin() {
    if (inProgress) {
        Toast.makeText(getActivity(), "Please Wait", Toast.LENGTH_SHORT).show();
        return;/*from  w w  w  . j av a2  s  .c  o m*/
    }
    Typeface custom_font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/myfnt.ttf");
    final TextView textView = (TextView) view.findViewById(R.id.dice_result_textview);
    final TextView textViewrun = (TextView) view.findViewById(R.id.result_textView_run);
    final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.dice_progressBar);
    progressBar.setIndeterminate(false);
    progressBar.setMax(3000);
    textView.setTypeface(custom_font);
    textViewrun.setTypeface(custom_font);
    progressBar.setVisibility(View.VISIBLE);

    countDownTimer = new CountDownTimer(3000, 250) {
        @Override
        public void onTick(long l) {
            inProgress = true;
            Random random = new Random();

            progressBar.setProgress(3000 - (int) l);

            Log.v("Progress", Integer.toString(progressBar.getProgress()));
            textViewrun.setVisibility(View.VISIBLE);
            textViewrun.setText("Waiting");
            textView.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
            textView.setText(Integer.toString(random.nextInt(6) + 1));
        }

        @Override
        public void onFinish() {
            inProgress = false;
            view.setBackgroundColor(getResources().getColor(R.color.colorWin));
            textViewrun.setText("Here you go");
            progressBar.setProgress(3000);
            return;
        }
    }.start();
}

From source file:com.licenta.android.licenseapp.alarm.AlarmFragment.java

@Nullable
@Override//from  w w  w .  j  av a  2 s.  c om
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_alarm, container, false);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

    mAlarmFab = (FloatingActionButton) rootView.findViewById(R.id.alarm_fab);
    mAlarmFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            handleAlarm();

        }
    });
    setUpAlarmFab();

    FloatingActionButton safeFab = (FloatingActionButton) rootView.findViewById(R.id.safe_fab);
    safeFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCountDownTimer.onFinish();
            FacebookUtils.printKeyHash(getActivity());
        }
    });

    mTimerText = (TextView) rootView.findViewById(R.id.timer);
    final long futureTime = Long.parseLong(mPrefs.getString("repeat_interval", "0"));
    mCountDownTimer = new CountDownTimer(futureTime * DateUtils.MINUTE_IN_MILLIS, DateUtils.SECOND_IN_MILLIS) {

        public void onTick(long millisUntilFinished) {
            mTimerText.setText(new SimpleDateFormat("mm:ss").format(new Date(millisUntilFinished)));
        }

        public void onFinish() {
            mTimerText.setText(R.string.timer_default);
        }
    };

    return rootView;
}

From source file:uk.org.freeflight.wifefinder.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Get previously used aircraft id
    id = getPreferences(MODE_PRIVATE).getLong(AIRCRAFT_ID_PREF, -1);

    // Setup App Bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
    setSupportActionBar(toolbar);/*  w w  w.j av  a 2 s.c  o  m*/
    toolbar.setTitle(R.string.app_title);

    db = new WifeFinderDb(this);
    aircraftCursorAdapter = null;

    // Own location
    locationService = new WifeFinderLocationService(this);

    locationService.setLatitude(getPreferences(MODE_PRIVATE).getFloat(LAT_PREF, 0));
    locationService.setLongitude(getPreferences(MODE_PRIVATE).getFloat(LON_PREF, 0));

    // Aircraft position
    aircraftPosition = new AircraftPosition();

    // Own location locationTimer
    locationTimer = new CountDownTimer(LOCATION_TIMEOUT, 1000) {
        public void onTick(long msRemaining) {
            if (locationService.hasAccuracy() && (locationService.getAccuracy() < LOCATION_ACCURACY)) {
                stopLocationUpdate();
            }
        }

        public void onFinish() {
            stopLocationUpdate();

            if (!locationService.hasAccuracy()) {
                new AlertDialog.Builder(MainActivity.this).setTitle(R.string.no_location_title)
                        .setMessage(R.string.no_location_msg).setIcon(android.R.drawable.ic_dialog_info)
                        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        }).show();
            }
        }
    };
}