-
Notifications
You must be signed in to change notification settings - Fork 0
RouteSettingsFragment
The RouteSettings is a fragment that is a part of IntroActivity. The RouteSettings contains the functionality to get and store user preferences, these preferences will be used to generate routes. The preferences are saved and will stay the same after restarting the app.
The setButtons()
method provides functionality to the add and substract buttons for the distance or time value.
The buttons are set with a RepeatUpdateHandler
that either increments or decrements the value every 50 miliseconds the button is pressed. The type of value that is incremented or decremented depends on the checked button "Distance" (km) or "Time" (HH:MM).
The POI listview is created with the adapter SettingsAdapter
(found under CustomSettings folder).
There are local variables for SharedPreferences
and SharedPreferences.Editor
. The editor is use to store preferences.
The method changepreference(Radiogroup radiogroup)
is used to store the preference of manually added radiogroups in the fragment_routesettings layout file. Because the stored preference needs a string reference We have set tags for the radiobuttons under the radiogroup, using the text value of the radiobutton is not a good idea as it changes due to localisation.
Here is an example of storing a preference:
`editor.putBoolean(radioButton.getTag().toString(), true);
The first parameter is the string reference, the second is the value of the radiobutton (checked = true);
Using editor.apply();
stores the preference definitve.
You have access to these preferences in all activietes and fragments. To get a preference simply create a SharedPreferences
variable.
Here is an example:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
preferences.getBoolean("Time",false);
The first parameter is the string reference and the second parameter is the standard value if there is no preference with that string reference yet.
The same method is used in the SettingsAdapter
.