-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScreenSaver.java
More file actions
114 lines (97 loc) · 2.56 KB
/
ScreenSaver.java
File metadata and controls
114 lines (97 loc) · 2.56 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import java.util.ArrayList;
/***
class used to update new ideas in reatime and perform searches
**/
class ScreenSaver extends Thread
{
public static int WAITING = 0;
public static int ALERT = 1;
public static int SCREENSAVER = 2;
public static long SCREENSAVER_TRIGGER = 10000;
private ObjectProvider objects;
private long lastMouseMove;
private long lastCheck;
private int mode;
ScreenSaver(ObjectProvider objects)
{
this.mode = WAITING;
this.objects = objects;
this.lastMouseMove = System.currentTimeMillis();
this.lastCheck = 0;
}
public void run()
{
while (true) {
if(mode == WAITING)
{
// WAITING MODE CHECKS EVERY 2 SECONDS IF THE MOUSE HAS BEEN STOPPED
try {
Thread.sleep(4000);
} catch (InterruptedException x) {
break;
}
//System.out.println("Screensaver thread running in waiting mode: last move => " + lastMouseMove);
if (lastMouseMove == lastCheck)
{
this.alertMode();
}
lastCheck = lastMouseMove;
}
else if(mode == ALERT)
{
//ALERT MODE RUNS EVERY SECOND TO SEE IF THE MOUSE IS STILL STOPPED
try {
Thread.sleep(1000);
} catch (InterruptedException x) {
break;
}
//System.out.println("Screensaver thread running in alert mode: last move => " + lastMouseMove);
if (lastMouseMove != lastCheck)
{
this.waitingMode();
}
else
{
if(System.currentTimeMillis() - lastMouseMove >= SCREENSAVER_TRIGGER)
{
this.screensaverMode();
}
}
}
else if(mode == SCREENSAVER)
{
//SCREENSAVER MODE RUNS EVERY SECOND TO ACTIVATE ROTATION AND PULSE
try {
Thread.sleep(1000);
} catch (InterruptedException x) {
break;
}
//System.out.println("Screensaver thread running in screensaver mode: last move => " + lastMouseMove);
if (lastMouseMove != lastCheck)
{
this.waitingMode();
}
}
}
}
public void waitingMode()
{
this.mode = WAITING;
//SET SCREENSAVER OFF
objects.setScreensaver(false);
}
public void alertMode()
{
this.mode = ALERT;
}
public void screensaverMode()
{
this.mode = SCREENSAVER;
//SET SCEREENSAVER ON
objects.setScreensaver(true);
}
public void moved()
{
this.lastMouseMove = System.currentTimeMillis();
}
}