ss5

Last week GitHub user spaetz brought forward a great idea for the Hourglass Android timer app that I made a while back. He recommended that the manual time entry be adjusted so that entering any number without a colon (:) would be counted as minutes. Here you can see his issue in the tracker:

https://github.com/alaskalinuxuser/app_hourglass/issues/7

After a quick review of the code, I came up with a simple fix, which you can see in my commit here:

https://github.com/alaskalinuxuser/app_hourglass/commit/fb28250c74e59582e887ede69cf75c1f061caf3c

Essentially, I just check to see if the entered time includes a colon. If it does, then I check it as usual. If not, then I take it as minutes only. Nothing spectacular here, but this is the main portion of the change:

// We wrap this in try, so the app can’t crash if they put in some weird number….
 try {
 –
 + int sec,min,math;
 // Alright, let’s split that time based on colon.
 – String[] foundSplit = manualTime.split(“:”);
 + if (manualTime.contains(“:”)) {
 + String[] foundSplit = manualTime.split(“:”);
 + // Testing only // Log.i(“WJH”, foundSplit[0]);
 + // Testing only // Log.i(“WJH”, foundSplit[1]);

 – // And let’s get the seconds from the split.
 – String seconds = foundSplit[1];
 + // And let’s get the seconds from the split.
 + String seconds = foundSplit[1];

 – // And the minutes from the split.
 – String minutes = foundSplit[0];
 + // And the minutes from the split.
 + String minutes = foundSplit[0];

 – // Then we convert them to integers.
 – int sec = Integer.parseInt(seconds);
 – int min = Integer.parseInt(minutes);
 + // Then we convert them to integers.
 + sec = Integer.parseInt(seconds);
 + min = Integer.parseInt(minutes);
 + } else {
 + sec = 0;
 + min = Integer.parseInt(manualTime);
 + // Testing only // Log.i(“WJH”, String.valueOf(min));
 + }

 // And do some basic math to turn them into milliseconds.
 – int math = (min * 60 * 1000) + (sec * 1000);
 + math = (min * 60 * 1000) + (sec * 1000);

Note that the – symbol is a line deleted, and the + symbol is a line added.

But that’s what’s great about open source apps. Not only could someone suggest a change, someone could also make changes and offer up improvements. Either way, the Hourglass app is better for it with this addition.

Linux – keep it simple.

Leave a Reply

Your email address will not be published.