Saturday, 16 February 2019

TravelTimeCalculator: Adding a Preference Activity

My app can now query Google Directions for the best travel mode with respect to duration and present that on a map, when the user is tapping on it.

I want to let the user define what the best travel mode is, by selecting some parameters.

There will be three options for estimating the best travel mode:

  • Duration
  • Distance
  • Cost
Cost will consider the following parameters:
  • Travel duration and distance
  • Start and stop time (unlocking and locking the bike, finding a parking space for the car)
  • Travel costs per km (fuel cost and vehicle depreciation)
  • Travel costs per travel (transit ticket price)
  • Emissions (CO2e per km)
  • Time cost (SEK/s)
  • Environmental cost (SEK/CO2e
The app will calculate the cost for each travel mode:

For transit and driving, I'll use the estimates from klimatsmart semester (climate-smart vacation) to estimate the emissions per person-kilometer.

Adding a Settings Activity to the App
Users will need to change the settings above. I started by adding an activity to the project:

Specify the parent class

A couple of new files are created automatically, with the necessary code to make the new activity appear. Now, I need to understand the anatomy of the new files.

The preferences are defined in xml files in the java/res/xml folder
Currently, the code is autogenerated. The settings are divided into three submenus.
Preferences for ringtones are located in a submenu:

A listener is declared in the SettingsActivity class

The settings are designed in the XML file and accessed from the SettingsActivity class.

In the next blog post, I will explore the settings and its listeners further.

No comments:

Post a Comment