Rest Timer Pt. 2

-Written by: Quincy Williams

This week I worked on cleaning up some issues that I was having with the rest timer. The functionality was present that the timer was able to run if the user entered a time but the values were only allowed in minutes. After doing some research, trying to get two separate values from an edit text field in Android Studio is not the easiest, and I was able to discuss some options with my team and we came up with the idea of having the user be able to choose to use minutes or seconds via a spinner object.

This allowed for the same edit text field to be used and also also allow the user to be able to set the time of their choosing. This also allowed for the view to remain simple and clean for the activity.

Example of the Rest Timer activity screen

From the example above, the user can select the value to be used from the spinner, and based on the spinners option, a boolean value (minutes, seconds) is set that will tell the application how to process conversion of the value for time and how to display it. One of the values will be set to true while the other is set as false. It also changes the edit text field to prompt the user what measure of time is being used.

Timer spinner logic for handling minutes and seconds


Once that boolean value is set, the application then goes further into the code formatting of the timer value based on that particular setting to ensure that minutes and seconds act separately. This was achieved by splitting up a function into two separate functions to be able to make sure one is not connected to the other. This keeps the formatting of the timers text value from becoming an issue when setting the time.

One of the final issues that needed to be worked out was getting the timer to be able to continue running when leaving the activity or the application and saving that value upon return. This also applies to if the timer was started and then stopped and not running. That value was to be saved as well. This was also handled by boolean options that was used to track if the timer is running or not. This would apply when the timer was started, to set that that timer is running, or if the timer was paused or stopped, to set the boolean to tell the application the timer was not running.



The final portion was to used shared preferences to ensure that that value of time was stored and returned to the user upon coming back into the application or the activity by calling and overriding the onStop() and onDestroy() functions when leaving and calling onStart() when returning.

Comments