-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bateria.cs
45 lines (43 loc) · 1.37 KB
/
Bateria.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace Lanterna
{
class Bateria : INotifyPropertyChanged
{
private int nivelBateria;
private Timer timer;
public event PropertyChangedEventHandler PropertyChanged;
public Bateria()
{
this.nivelBateria = 100;
this.timer = new Timer();
this.timer.Tick += new EventHandler(atualizarNivelBateria);
this.timer.Interval = 1000;
this.timer.Start();
this.timer.Enabled = false;
}
public string getNivelBateria()
{
return nivelBateria.ToString() + "%";
}
private void atualizarNivelBateria(object sender, EventArgs a)
{
nivelBateria -= 1;
BatteryPropertyChanged();
if (nivelBateria == 0) timer.Enabled = false;
}
public void usandoBateria(bool isOn)
{
if (isOn && nivelBateria > 0)
timer.Enabled = true;
else
timer.Enabled = false;
}
private void BatteryPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}