Home -> Teaching -> CSAS Android -> iBookmark
This is a continuation of the iBookmark activity started as part of our Android workshop. Please check that page for a project description and for the first two parts of the project.
Homework: Implement the "edit" feature to edit an existing bookmark and update it in the list. As a hint, here is what I did (but you are welcome to find your own solution):
To try out the new features, you can "side-load" my compiled app, but you can't see the final code that includes the "edit" feature: After all, it is a homework question! Side-loading is easy: on your device (which must be running Android 4 or higher to be compatible with iBookmark), turn on the "Unknown sources" settings. You will find that in "Settings" (on your device), then "Security". After that, use a web browser on your device to click on this "apk" file iBookmark2.apk here. It will be downloaded to your device. You can go to the notification bar and tap on the downloaded file. Everything should be a "go" now and the new app will get installed. Make sure to test the app thoroughly to see if you find anything that does not work properly.
Part 4: In our last portion we want to define some settings for our app. For a detailed explanation, check the Android Guide on Settings. In short:
create an XML file named (usually) preferences.xml in the /res/xml folder
define various preferences using tags like "CheckBoxPreference", "EditTextPreference", "ListPreference", or simple "Preference" etc. (you can group them via "PreferenceCategory"). Each entry must have a unique "key" and a "title" as well as additional options specific to the type of preference you are defining.
create either a "PreferenceActivity" (if programming prior to Android 3.) or a "SettingsFragment" (if programming for Android 3.0 or later) embedded in a "SettingsActivity" (don't forget to add that activity to your manifest file) and inflate the preferences via "addPreferencesFromResource(R.xml.preferences)"
you could attach an "OnPreferenceClickListener" to a preference so that it could act like a 'button' when clicked to perform some action (such as resetting all variables to their default values)
you should call "PreferenceManager.setDefaultValues(this, R.xml.preferences, false)" to initialize the preferences from their default values (if the last parameter is set to "true", the preferences are supposed to be reset even if the user has already changed them)
finally, to access the preferences from anywhere in your
project, use "SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this)" to get
access to the prefs object, and then for example
prefs.getBoolean("key", true));
To download the complete source code for our Bookmark app
including editing and preferences,
get this ZIP file iBookmark2_plus.zip and
integrate it into Eclipse (or cut-and-paste).
Homework: What the above project file
iBookmark2_plus does not yet contain, is to implement the
preferences for changing the font size of the bookmark title and
address - guess what, that will be your homework and will conclude
our iBookmark project. The completed project will be posted after
the next class.
Here is the final version,of iBookmark, such as it is,- check it out if necessary to see how to work with different types of Preferences.