Advertisement
Shiyan12

Untitled

Apr 18th, 2021
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. package ru.valeriyshiyan.quest;
  2.  
  3. import androidx.appcompat.app.AlertDialog;
  4. import androidx.appcompat.app.AppCompatActivity;
  5.  
  6. import android.content.DialogInterface;
  7. import android.content.Intent;
  8. import android.os.Bundle;
  9. import android.os.CountDownTimer;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.CheckBox;
  13. import android.widget.TextView;
  14.  
  15. import java.text.SimpleDateFormat;
  16. import java.util.Calendar;
  17. import java.util.Timer;
  18. import java.util.TimerTask;
  19.  
  20. public class MainActivity extends AppCompatActivity {
  21.     CheckBox mCheck;
  22.     Button mStart, mStop;
  23.     TextView mCount;
  24.  
  25.     Timer timer;
  26.     TimerTask mTimerTask;
  27.  
  28.     @Override
  29.     protected void onCreate(Bundle savedInstanceState) {
  30.         super.onCreate(savedInstanceState);
  31.         setContentView(R.layout.activity_main);
  32.  
  33.         // Связываемся с элементами пользовательского интерфейса
  34.         mCheck = findViewById(R.id.single_shot);
  35.         mStart = findViewById(R.id.start);
  36.         mStop = findViewById(R.id.stop);
  37.         mCount = findViewById(R.id.count);
  38.  
  39.         new CountDownTimer(20000, 1000) {
  40.             public void onTick(long millisUntilFinished) {
  41.                 mCount.setText("Осталось: " + millisUntilFinished / 1000);
  42.             }
  43.  
  44.             public void onFinish() {
  45.                 mCount.setText("Бабах!");
  46.                 AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  47.                 builder.setTitle("Ошибка!")
  48.                         .setMessage("Процессор перегружен!")
  49.                         .setCancelable(false)
  50.                         .setPositiveButton("Выключить устройство", new DialogInterface.OnClickListener() {
  51.                             @Override
  52.                             public void onClick(DialogInterface dialog, int which) {
  53.                                 dialog.cancel();
  54.                             }
  55.                         });
  56.                 AlertDialog Error = builder.create();
  57.                 Error.show();
  58.             }
  59.         }.start();
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement