Advertisement
Sketchware

Mostra a bateria e avisa quando chega 70%

Jan 12th, 2023
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.85 KB | None | 0 0
  1. final BatteryProgressView bat = new BatteryProgressView(this);
  2. bat.setLayoutParams(new LinearLayout.LayoutParams(250, 250));
  3. linear1.addView(bat);
  4. bat.setProgress(66);
  5. final android.os.Handler handler = new android.os.Handler();
  6. handler.postDelayed(new Runnable() {
  7.     @Override
  8.     public void run() {
  9.         bat.setProgress(63);
  10.         if (bat.getProgress() <= 70) {
  11.             Toast.makeText(getApplicationContext(), "Battery level is low", Toast.LENGTH_SHORT).show();
  12.         }
  13.         handler.postDelayed(new Runnable() {
  14.             @Override
  15.             public void run() {
  16.                 bat.setProgress(77);
  17.                 if (bat.getProgress() <= 70) {
  18.                     Toast.makeText(getApplicationContext(), "Battery level is low", Toast.LENGTH_SHORT).show();
  19.                 }
  20.             }
  21.         },1000);
  22.     }
  23. },2000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement