Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (flag == false) {
- counter = new MyCount(720000, 1000);//360000
- counter.start();
- } else {
- counter.cancel();
- counter = new MyCount(millisUntilFinishedVariable, 1000);
- counter.start();
- }
- public class MyCount extends CountDownTimer {
- public MyCount(long millisInFuture, long countDownInterval) {
- super(millisInFuture, countDownInterval);
- }
- @Override
- public void onFinish() {
- titleTextView.setText("Time out");
- tv_mins.setText("");
- final Dialog dialog = new Dialog(getMyActivityContext());
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- Window window = dialog.getWindow();
- dialog.setContentView(R.layout.custom_dialog);
- window.setGravity(Gravity.CENTER);
- window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
- dialog.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation;
- dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
- dialog.setCancelable(true);
- TextView textView = (TextView) dialog.findViewById(R.id.text);
- TextView btnDismis = (TextView) dialog.findViewById(R.id.txt_ok);
- // textView.setGravity(Gravity.CENTER);
- textView.setText("Your session timed out. Please try again");
- dialog.setCanceledOnTouchOutside(false);
- dialog.show();
- btnDismis.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- dialog.dismiss();
- }
- });//TextView object should be defined in onCreate*/
- flag = false;
- }
- @Override
- public void onTick(long millisUntilFinished) {
- millisUntilFinishedVariable = millisUntilFinished;
- flag = true;
- String minsec = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished), TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)));
- titleTextView.setText(minsec);// This will be called every Second.
- tv_mins.setText("MINS LEFT");
- }
- }
Add Comment
Please, Sign In to add comment