Guest User

Untitled

a guest
Apr 28th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. try {
  2.  
  3. titleTextView = (TextView) toolbar.findViewById(R.id.toolbar);
  4. if (!getToolBarTitle().equals("FOOD")) {
  5. titleTextView.setText(getToolBarTitle());
  6. counter.cancel();
  7. App_Constants.timeflag=false;
  8.  
  9. Log.w("timer time",""+millisUntilFinishedVariable);
  10. } else {
  11.  
  12. //timerDialog();
  13. if ( App_Constants.timeflag== false) {
  14. counter = new MyCount(360000, 1000);//360000
  15. counter.start();
  16. } else {
  17. counter.cancel();
  18. counter = new MyCount(millisUntilFinishedVariable, 1000);
  19. counter.start();
  20. }
  21. }
  22. } catch (Exception e) {
  23. e.printStackTrace();
  24. }
  25.  
  26.  
  27.  
  28. public class MyCount extends CountDownTimer {
  29.  
  30. public MyCount(long millisInFuture, long countDownInterval) {
  31. super(millisInFuture, countDownInterval);
  32. }
  33.  
  34. @Override
  35. public void onFinish() {
  36. Log.w("timer flag", "" + App_Constants.timeflag);
  37. if(App_Constants.tmf) {
  38. titleTextView.setText("Time out");
  39.  
  40. final Dialog dialog = new Dialog(getMyActivityContext());
  41. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  42. Window window = dialog.getWindow();
  43. dialog.setContentView(R.layout.popupdialog);
  44. window.setGravity(Gravity.CENTER);
  45. window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
  46. dialog.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation;
  47. dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  48. dialog.setCancelable(true);
  49.  
  50. TextView textView = (TextView) dialog.findViewById(R.id.popup_text);
  51. textView.setTextColor(ContextCompat.getColor(getMyActivityContext(), R.color.colorAccent));
  52. TextView btnDismis = (TextView) dialog.findViewById(R.id.close);
  53. // textView.setGravity(Gravity.CENTER);
  54. textView.setText("Your session time out");
  55. dialog.setCanceledOnTouchOutside(false);
  56. dialog.show();
  57. btnDismis.setOnClickListener(new View.OnClickListener() {
  58. @Override
  59. public void onClick(View v) {
  60. finish();
  61. dialog.dismiss();
  62. }
  63. });//TextView object should be defined in onCreate*/
  64. App_Constants.timeflag = false;
  65. }else {
  66. counter.cancel();
  67. }
  68. }
  69.  
  70. @Override
  71. public void onTick(long millisUntilFinished) {
  72. millisUntilFinishedVariable = millisUntilFinished;
  73. App_Constants.timeflag=true;
  74. String minsec = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished), TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)));
  75.  
  76. titleTextView.setText(minsec + " MINS LEFT");// This will be called every Second.
  77. }
  78. }
Add Comment
Please, Sign In to add comment