/
Main.java
207 lines (177 loc) · 5.12 KB
/
Main.java
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package com.kore.instructor;
import android.app.Activity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import com.kore.instructor.Visitor.*;
public class Main extends Activity implements OnInitListener
{
protected TextToSpeech talker;
protected Countdown countdown;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.countdown = (Countdown) getLastNonConfigurationInstance();
this.talker = new TextToSpeech(this, this);
TextView countdown = (TextView) findViewById(R.id.countdown);
Typeface font = Typeface.createFromAsset(getAssets(), "lcdmn.ttf");
countdown.setTypeface(font);
if (this.countdown != null)
{
this.countdown.setAll(
countdown,
(TextView) findViewById(R.id.status),
this.talker
);
}
this.updateViewState(countdown != null);
}
protected void run(Training training)
{
VisitorI visitor = new Basic(getResources());
this.countdown = new Countdown();
this.countdown.setAll(
(TextView) findViewById(R.id.countdown),
(TextView) findViewById(R.id.status),
this.talker
);
training.accept(visitor);
countdown.start(visitor.getInstructions());
this.updateViewState(true);
}
protected void updateViewState(boolean running)
{
if (running)
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
else
{
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
findViewById(R.id.button_steps).setVisibility(running ? View.GONE : View.VISIBLE);
findViewById(R.id.button_interval).setVisibility(running ? View.GONE : View.VISIBLE);
findViewById(R.id.button_superset).setVisibility(running ? View.GONE : View.VISIBLE);
findViewById(R.id.button_circuit).setVisibility(running ? View.GONE : View.VISIBLE);
findViewById(R.id.button_intense).setVisibility(running ? View.GONE : View.VISIBLE);
findViewById(R.id.button_cancel).setVisibility(running ? View.VISIBLE : View.GONE);
}
@Override
public Object onRetainNonConfigurationInstance()
{
return countdown;
}
public void onInit(int status)
{
// Do nothing
}
public void onDestroy()
{
if (this.talker != null)
{
this.talker.stop();
this.talker.shutdown();
}
super.onDestroy();
}
public void cancelTraining(View view)
{
if (this.talker != null)
{
this.talker.stop();
}
if (this.countdown != null)
{
this.countdown.stop();
this.countdown = null;
}
this.updateViewState(false);
}
public void startSteps(View view)
{
run(
new Training(
new PracticeIteration(
new Practice(
new UnitIteration(
new Unit( 7.5 * 60, 30 ),
1
)
),
4
)
)
);
}
public void startInterval(View view)
{
run(
new Training(
new PracticeIteration(
new Practice(
new UnitIteration(
new Unit( 3 * 60 ),
3
)
),
4
)
)
);
}
public void startSuperset(View view)
{
run(
new Training(
new PracticeIteration(
new Practice(
new UnitIteration(
new Unit( 4 * 60 ),
1
)
),
6
)
)
);
}
public void startCircuit(View view)
{
run(
new Training(
new PracticeIteration(
new Practice(
new UnitIteration(
new Unit( 20 * 60 ),
1
)
),
1
)
)
);
}
public void startIntense(View view)
{
run(
new Training(
new PracticeIteration(
new Practice(
new UnitIteration(
new Unit( 20, 10 ),
8
)
),
3
)
)
);
}
}