Saturday, 23 February 2019

TravelTimeCalculator: Understanding the Settings Activity

In the last blog post, I added some default preferences to my app. Now, I'll try to change the code in order to understand how it works.

The first step is to add logs to see what values are parsed when a selection is made:

The log output above shows what happens when navigating the preferences. When selecting preferences, the corresponding strings that are defined in the preference files are found and printed to the console.

The strings are defined in the res/valuses/strings.xml file.
The settings themselves are defined in the settings xml files. Listeners are defined in the SettingsActivity.java file.
The pref_headers file encapsulates the sub screens for the different settings.
Here, the settings and some of their properties are set.
 Finally the source code with listeners are defined as listeners in the SettingsActivity.java file.

The second step is to modify the existing settings to two settings screens: One for general settings and one for settings related to the travel modes. I'll add suitable controls depending on what kind of input I need from the user.

  • General Settings:
    • Mode: Distance, Duration, Cost
    • Currency: A short text string, for example SEK or USD
    • Cost per Emission: SEK per kg CO2e
    • Time to cost ratio: SEK per hour
  • Travel Mode Settings:
    • Bicycling Start/Stop Time: seconds
    • Driving Start/Stop Time: seconds
    • Driving Cost per kilometer: SEK per km
    • Driving Emissions per kilometer: kg CO2e per km
    • Transit Ticket Cost: SEK
    • Transit Emissions per km; kg CO2e per km

I'll implement those settings in the next blog post.

No comments:

Post a Comment