Skip to content

Commit f5e6eab

Browse files
committed
foo
1 parent 7883f85 commit f5e6eab

File tree

8 files changed

+125
-257
lines changed

8 files changed

+125
-257
lines changed

app/src/main/java/omegacentauri/mobi/tiltstopwatch/MyChrono.java

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.text.Spanned;
1818
import android.text.method.ScrollingMovementMethod;
1919
import android.text.style.TabStopSpan;
20+
import android.util.Log;
2021
import android.util.TypedValue;
2122
import android.view.View;
2223
import android.view.WindowManager;
@@ -34,7 +35,6 @@ public class MyChrono implements BigTextView.GetCenter, MyTimeKeeper {
3435
TextView angleView;
3536
public long baseTime;
3637
public long pauseTime;
37-
int vibrateAfterCountDown = 100;
3838
public boolean paused = false;
3939
public boolean active = false;
4040
boolean quiet = false;
@@ -46,8 +46,7 @@ public class MyChrono implements BigTextView.GetCenter, MyTimeKeeper {
4646
public int precision = 100;
4747
private TextToSpeech tts = null;
4848
private boolean ttsMode;
49-
int STREAM = AudioManager.STREAM_ALARM;;
50-
private boolean boostAudio = false;
49+
static final int STREAM = AudioManager.STREAM_ALARM;;
5150
private static final int GAIN = 2000;
5251
HashMap<String,String> ttsParams = new HashMap<String,String>();
5352
private LoudnessEnhancer loudnessEnhancer = null;
@@ -57,6 +56,7 @@ public class MyChrono implements BigTextView.GetCenter, MyTimeKeeper {
5756
private double lastAngle = 0;
5857
private AudioTrack shortTone;
5958
private AudioTrack longTone;
59+
private long lastAnnouncement = 0;
6060

6161
@SuppressLint("NewApi")
6262
public MyChrono(Activity context, SharedPreferences options, BigTextView mainView, TextView fractionView, View mainContainer) {
@@ -82,51 +82,26 @@ public long getTime() {
8282
}
8383

8484
private void announce(long t) {
85-
// long vibrate = Options.getVibration(options);
86-
if (/*(quiet && vibrate == 0) || */ !active || paused)
85+
if (!active || paused || quiet || t < (lastAnnouncement+10)/10*10)
8786
return;
88-
if (t < -3000 || t >= 1000) {
89-
lastAnnounced = floorDiv(t, 1000)*1000;
90-
}
91-
else if (t < 0) {
92-
if (tts != null && ttsMode) {
93-
String msg;
94-
if (-1000 <= t) {
95-
msg = "1";
96-
}
97-
else if (-2000 <= t) {
98-
msg = "2";
99-
}
100-
else {
101-
msg = "3";
102-
}
103-
StopWatch.debug("say: "+msg);
104-
tts.speak(msg,TextToSpeech.QUEUE_FLUSH, ttsParams);
105-
}
106-
else if (!quiet) {
107-
shortTone.stop();
108-
shortTone.reloadStaticData();
109-
shortTone.play();
110-
}
111-
lastAnnounced = floorDiv(t, 1000)*1000;
87+
88+
89+
if (tts != null && ttsMode) {
90+
String msg = "" + t;
91+
StopWatch.debug("say: "+msg);
92+
tts.speak(msg,TextToSpeech.QUEUE_FLUSH, ttsParams);
11293
}
113-
else if (t >= 0) {
114-
if (!quiet) {
115-
longTone.stop();
116-
longTone.reloadStaticData();
117-
longTone.play();
118-
}
119-
ShowTime.vibrate(context, vibrateAfterCountDown);
120-
lastAnnounced = 0;
94+
else if (!quiet) {
95+
shortTone.stop();
96+
shortTone.reloadStaticData();
97+
shortTone.play();
12198
}
99+
lastAnnouncement = t;
122100
}
123101

124102
public void updateViews() {
125103
long t = getTime();
126-
if (lastAnnounced < 0 && lastAnnounced + 1000 <= t) {
127-
announce(t+10);
128-
}
129-
104+
announce(t/1000);
130105
mainView.setText(formatTime(t,mainView.getHeight() > mainView.getWidth()));
131106
}
132107

@@ -195,6 +170,7 @@ else if (precision == 1)
195170

196171
public void reset() {
197172
active = false;
173+
lastAnnouncement = 0;
198174
stopUpdating();
199175
}
200176

@@ -240,11 +216,6 @@ else if (!active) {
240216
}
241217

242218
public void setAudio(String soundMode) {
243-
boostAudio = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && options.getBoolean(Options.PREF_BOOST, false);
244-
STREAM = Options.getStream(options);
245-
246-
vibrateAfterCountDown = options.getBoolean(Options.PREF_VIBRATE_AFTER_COUNTDOWN, true) ? (int)LONG_TONE_LENGTH/2 : 0;
247-
248219
if (soundMode.equals("none")) {
249220
quiet = true;
250221
ttsMode = false;
@@ -273,23 +244,6 @@ public void setAudio(String soundMode) {
273244
if (options.getBoolean(Options.PREF_BOOST, false))
274245
am.setStreamVolume(STREAM, am.getStreamMaxVolume(STREAM), 0);
275246

276-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && boostAudio) {
277-
try {
278-
StopWatch.debug("trying to boost");
279-
loudnessEnhancer = new LoudnessEnhancer(sessionId);
280-
loudnessEnhancer.setTargetGain(GAIN);
281-
loudnessEnhancer.setEnabled(true);
282-
if (!loudnessEnhancer.getEnabled()) {
283-
loudnessEnhancer = null;
284-
}
285-
else {
286-
StopWatch.debug("loudness success");
287-
}
288-
}
289-
catch(Exception e) {
290-
}
291-
}
292-
293247
if (soundMode.equals("voice")) {
294248
ttsMode = true;
295249
ttsParams.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(STREAM));
@@ -317,7 +271,7 @@ public void restore() {
317271
pauseTime = options.getLong(Options.PREF_PAUSED_TIME, 0);
318272
active = options.getBoolean(Options.PREF_ACTIVE, false);
319273
paused = options.getBoolean(Options.PREF_PAUSED, false);
320-
lastAnnounced = options.getLong(Options.PREF_LAST_ANNOUNCED, 0);
274+
lastAnnouncement = options.getLong(Options.PREF_LAST_ANNOUNCED, 0);
321275
setAudio(options.getString(Options.PREF_SOUND, "voice"));
322276

323277
precision = Integer.parseInt(options.getString(Options.PREF_PRECISION, "100"));
@@ -364,7 +318,7 @@ public void save() {
364318
ed.putLong(Options.PREF_PAUSED_TIME, pauseTime);
365319
ed.putBoolean(Options.PREF_ACTIVE, active);
366320
ed.putBoolean(Options.PREF_PAUSED, paused);
367-
ed.putLong(Options.PREF_LAST_ANNOUNCED, lastAnnounced);
321+
ed.putLong(Options.PREF_LAST_ANNOUNCED, lastAnnouncement);
368322
ed.putLong(Options.PREF_BOOT_TIME, getBootTime());
369323

370324
apply(ed);
@@ -391,7 +345,7 @@ public void run() {
391345
}
392346
}, 0, precision<=10 ? precision : 50); // avoid off-by-1 errors at lower precisions, at cost of some battery life
393347
}
394-
if (options.getBoolean(Options.PREF_SCREEN_ON, false))
348+
if (options.getBoolean(Options.PREF_SCREEN_ON, true))
395349
((Activity)context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
396350
else
397351
((Activity)context).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
@@ -469,6 +423,8 @@ public float getCenter() {
469423

470424
public void setAngle(double angle) {
471425
this.lastAngle = angle;
472-
setAngleView(String.format("%.1f\u00B0",lastAngle));
426+
String f = String.format("%.1f\u00B0",lastAngle);
427+
if (!f.equals(angleView.getText()))
428+
setAngleView(f);
473429
}
474430
}

app/src/main/java/omegacentauri/mobi/tiltstopwatch/Options.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class Options extends PreferenceActivity {
3131
public static final String PREF_ACTIVE = "active";
3232
public static final String PREF_PAUSED = "paused";
3333
public static final String PREF_BOOT_TIME = "boot";
34+
public static final String PREF_START_ANGLE = "startAngle";
35+
public static final String PREF_STOP_ANGLE = "stopAngle";
3436
public static final String PREF_SCREEN_ON = "screenOn";
3537
public static final String PREF_PRECISION = "precision";
3638
public static final String PREF_STOPWATCH_COLOR = "color";
@@ -83,6 +85,18 @@ static float getMaxAspect(SharedPreferences options) {
8385
return Float.parseFloat(options.getString(Options.PREF_DISTORTION, "10"))*.01f + 1f;
8486
}
8587

88+
static float getStartAngle(SharedPreferences options) {
89+
return getAngle(options.getString(Options.PREF_START_ANGLE, "6*"));
90+
}
91+
92+
private static float getAngle(String string) {
93+
return Float.parseFloat(string.substring(0, string.length()-1));
94+
}
95+
96+
static float getStopAngle(SharedPreferences options) {
97+
return getAngle(options.getString(Options.PREF_STOP_ANGLE, "12*"));
98+
}
99+
86100
static MiniFont getFont(SharedPreferences options) {
87101
String f = options.getString(PREF_FONT, "medium");
88102
MiniFont mf;

app/src/main/java/omegacentauri/mobi/tiltstopwatch/ShowTime.java

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ public float dp2px(float dp){
6868
}
6969

7070
public int getControlBarForeColor() {
71-
int base = Options.getForeColor(this, options);
72-
if (!options.getBoolean(Options.PREF_FULLSCREEN, false))
73-
return base;
74-
int controlBarBrightness = 255 * Integer.parseInt(options.getString(Options.PREF_FS_BRIGHT, "0")) / 100;
75-
if (controlBarBrightness == 0)
76-
return base;
77-
return (base & 0xFFFFFF) | (controlBarBrightness << 24);
71+
return Options.getForeColor(this, options);
7872
}
7973

8074
@Override
@@ -194,54 +188,6 @@ else if (o.equals("portrait"))
194188

195189
}
196190

197-
protected void setFullScreen()
198-
{
199-
boolean fs = options.getBoolean(Options.PREF_CONTROL_FULLSCREEN, true) && options.getBoolean(Options.PREF_FULLSCREEN, false);
200-
Window w = getWindow();
201-
WindowManager.LayoutParams attrs = w.getAttributes();
202-
203-
if (options.getBoolean(Options.PREF_FULLSCREEN, false)) {
204-
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
205-
}
206-
else {
207-
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
208-
}
209-
210-
w.setAttributes(attrs);
211-
212-
View dv = w.getDecorView();
213-
214-
if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
215-
dv.setSystemUiVisibility(fs ? View.GONE : View.VISIBLE);
216-
} else if(Build.VERSION.SDK_INT >= 19) {
217-
int flags = dv.getSystemUiVisibility();
218-
if (fs)
219-
flags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
220-
else
221-
flags &= ~(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
222-
dv.setSystemUiVisibility(flags);
223-
}
224-
int controlBarBrightness = 0;
225-
if (fs) {
226-
controlBarBrightness = 255 * Integer.parseInt(options.getString(Options.PREF_FS_BRIGHT, "0")) / 100;
227-
}
228-
229-
controlBar.setVisibility((fs && controlBarBrightness == 0) ? View.GONE : View.VISIBLE);
230-
if (controlBarBrightness > 0 && fs)
231-
controlBar.setBackgroundColor(Options.getBackColor(this, options) & (controlBarBrightness<<24));
232-
else
233-
controlBar.setBackgroundColor(Options.getBackColor(this, options) | 0xFF000000);
234-
235-
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
236-
if (! fs) {
237-
lp.addRule(RelativeLayout.ABOVE, R.id.controlBar);
238-
}
239-
else {
240-
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
241-
}
242-
mainContainer.setLayoutParams(lp);
243-
}
244-
245191
@Override
246192
protected void onResume() {
247193
super.onResume();
@@ -261,7 +207,6 @@ public void run() {
261207
setOrientation();
262208

263209
setTheme();
264-
setFullScreen();
265210
debug("theme");
266211
int orientation = getResources().getConfiguration().orientation;
267212

@@ -304,7 +249,6 @@ public static void debug(String s) {
304249
@Override
305250
public void onOptionsMenuClosed(Menu menu) {
306251
super.onOptionsMenuClosed(menu);
307-
setFullScreen();
308252
}
309253

310254
public void lockOrientation() {
@@ -370,13 +314,6 @@ public static void clip(Context c, String s) {
370314
clip.setText(s);
371315
}
372316

373-
public static void vibrate(Activity context, long time) {
374-
if (time == 0)
375-
return;
376-
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
377-
vibrator.vibrate(time);
378-
}
379-
380317
public boolean isTV() {
381318
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
382319
return getPackageManager().hasSystemFeature("android.hardware.type.television");
@@ -405,35 +342,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
405342
return super.onOptionsItemSelected(item);
406343
}
407344

408-
public void switchActivity(Class a, int direction) {
409-
SharedPreferences.Editor ed = options.edit();
410-
ed.putString(Options.PREF_LAST_ACTIVITY, a.getName());
411-
MyChrono.apply(ed);
412-
startActivity(new Intent(this, a));
413-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
414-
if (direction == RIGHT) {
415-
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right);
416-
finish();
417-
}
418-
else if (direction == LEFT) {
419-
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
420-
finish();
421-
}
422-
else if (direction == DOWN) {
423-
overridePendingTransition(R.anim.slide_in_down, R.anim.slide_out_down);
424-
finish();
425-
}
426-
else if (direction == UP) {
427-
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
428-
finish();
429-
}
430-
else if (direction == NONE) {
431-
overridePendingTransition(0,0);
432-
finish();
433-
}
434-
}
435-
}
436-
437345
}
438346

439347
class MyStateDrawable extends StateListDrawable {

0 commit comments

Comments
 (0)