Guest User

Untitled

a guest
Nov 29th, 2016
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. if (flag == false) {
  2. counter = new MyCount(720000, 1000);//360000
  3. counter.start();
  4. } else {
  5. counter.cancel();
  6. counter = new MyCount(millisUntilFinishedVariable, 1000);
  7. counter.start();
  8. }
  9.  
  10.  
  11.  
  12.  
  13. public class MyCount extends CountDownTimer {
  14.  
  15. public MyCount(long millisInFuture, long countDownInterval) {
  16. super(millisInFuture, countDownInterval);
  17. }
  18.  
  19. @Override
  20. public void onFinish() {
  21. titleTextView.setText("Time out");
  22. tv_mins.setText("");
  23. final Dialog dialog = new Dialog(getMyActivityContext());
  24. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  25. Window window = dialog.getWindow();
  26. dialog.setContentView(R.layout.custom_dialog);
  27. window.setGravity(Gravity.CENTER);
  28. window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
  29. dialog.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation;
  30. dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  31. dialog.setCancelable(true);
  32.  
  33. TextView textView = (TextView) dialog.findViewById(R.id.text);
  34. TextView btnDismis = (TextView) dialog.findViewById(R.id.txt_ok);
  35. // textView.setGravity(Gravity.CENTER);
  36. textView.setText("Your session timed out. Please try again");
  37. dialog.setCanceledOnTouchOutside(false);
  38. dialog.show();
  39. btnDismis.setOnClickListener(new View.OnClickListener() {
  40. @Override
  41. public void onClick(View v) {
  42. finish();
  43. dialog.dismiss();
  44. }
  45. });//TextView object should be defined in onCreate*/
  46. flag = false;
  47. }
  48.  
  49. @Override
  50. public void onTick(long millisUntilFinished) {
  51. millisUntilFinishedVariable = millisUntilFinished;
  52. flag = true;
  53. String minsec = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished), TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)));
  54.  
  55. titleTextView.setText(minsec);// This will be called every Second.
  56. tv_mins.setText("MINS LEFT");
  57. }
  58. }
Add Comment
Please, Sign In to add comment