Finish fixing the large numbers bug by making 99:59:59 the maximum value allowed. Enhance the logging around resetting the StartStop key after a crash.
This commit is contained in:
@@ -93,9 +93,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (DEBUG) Log.d(tag, "Shutting off improper START value");
|
||||
|
||||
// Ensure START is always off if we are creating (not resuming).
|
||||
sharedPreferences.edit().putBoolean(keyStartStop, false).apply();
|
||||
int count = 0;
|
||||
while (!sharedPreferences.edit().putBoolean(keyStartStop, false).commit() && count < 50) {
|
||||
if (DEBUG) Log.d(tag, "Commit failed, trying again. count=" + count);
|
||||
count++;
|
||||
}
|
||||
|
||||
Log.d(tag, "key=" + key + " value=" + sharedPreferencesAll.get(key));
|
||||
boolean checkStartStop = sharedPreferences.getBoolean(keyStartStop, false);;
|
||||
Log.d(tag, "key=" + key + " value=" + checkStartStop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,38 +208,29 @@ public class MainActivity extends AppCompatActivity {
|
||||
try {
|
||||
hours = Integer.parseInt("0" + etHours.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
etHours.setText("");
|
||||
|
||||
hours = 99;
|
||||
}
|
||||
try {
|
||||
minutes = Integer.parseInt("0" + etMinutes.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
etMinutes.setText("");
|
||||
minutes = 59;
|
||||
}
|
||||
try {
|
||||
seconds = Integer.parseInt("0" + etSeconds.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
etSeconds.setText("");
|
||||
seconds = 59;
|
||||
}
|
||||
|
||||
// TODO: Properly handle hours being set to 999, which casues a negative.
|
||||
// TODO: Properly handle time being greater than current time, such as
|
||||
longLoopInterval = (long) (((hours*60*60) + (minutes*60) + seconds) * 1000);
|
||||
if (longLoopInterval > System.currentTimeMillis() || longLoopInterval < 0) {
|
||||
if (DEBUG) Log.d(tag, "Got a number larger than current time");
|
||||
if (DEBUG) Log.d(tag, "Setting to current time value");
|
||||
longLoopInterval = System.currentTimeMillis();
|
||||
|
||||
/* Not quite doing what we want yet.
|
||||
String sHours = "" + longLoopInterval/1000;
|
||||
String sMinutes = "" + longLoopInterval/1000/60 % 60;
|
||||
String sSeconds = "" + longLoopInterval/1000/60/60 % 60;
|
||||
|
||||
etHours.setText(sHours);
|
||||
etMinutes.setText(sMinutes);
|
||||
etSeconds.setText(sSeconds);
|
||||
*/
|
||||
if ((hours + (minutes/60) + (seconds/60/60)) > 99) {
|
||||
hours = 99;
|
||||
minutes = 59;
|
||||
seconds = 59;
|
||||
}
|
||||
|
||||
if (hours > 0) etHours.setText("" + hours);
|
||||
if (minutes > 0) etMinutes.setText("" + minutes);
|
||||
if (seconds > 0) etSeconds.setText("" + seconds);
|
||||
|
||||
if (DEBUG) Log.d(tag, "longLoopInterval=" + longLoopInterval);
|
||||
|
||||
setChronometer(longLoopInterval);
|
||||
|
Reference in New Issue
Block a user