0
Preferences & Menus Software Development for Portable Devices  BITS Pilani Goa Campus Sem I 2011-12
CS C314 Software Development For Portable Devices Foundation of :
Saving Simple Application Data <ul><li>Shared Preferences </li></ul><ul><li>Saved Application State </li></ul><ul><li>File...
Shared Preferences <ul><li>Used to store UI state, user preferences, or application settings </li></ul><ul><li>Shared Pref...
Creating And Saving Preferences <ul><li>getSharedPreferences(Pref_File_Name,Mode) </li></ul><ul><li>Creating new Shared Pr...
Preferences Activity Framework <ul><li>Android offers an XML-driven framework  </li></ul><ul><li>Native preference screens...
Preference Screen Layout <ul><li>Stored in the res/xml resources folder.  </li></ul><ul><ul><li>See folder structure </li>...
The Specific Attributes <ul><li>android:key </li></ul><ul><li>android:title </li></ul><ul><li>android:summary </li></ul><ul...
Native Preference Controls <ul><li>ListPreference :  The preference equivalent of a spinner. </li></ul><ul><li>EditTextPre...
Import System Preference Screens <ul><li>Invoke any Activity within your Preference Screen using an Intent.  </li></ul><ul...
Preference Activity <ul><li>extend the PreferenceActivity class </li></ul><ul><li>Call addPreferencesFromResource to inflat...
Menus
<ul><li>Types </li></ul><ul><ul><li>Options Menu </li></ul></ul><ul><ul><li>Context Menu </li></ul></ul><ul><ul><li>Submen...
Creating a Menu Resource <ul><li>Define a menu and all its items in an XML. </li></ul><ul><li>Inflate the menu </li></ul><...
Inflating a Menu Resource CS C314 Software Development For Portable Devices
Options Menu <ul><li>The Menu that’s pops up when you press the menu button </li></ul><ul><li>If there are more than six i...
Responding to user action CS C314 Software Development For Portable Devices
Context Menu <ul><li>On Android, a context menu is displayed when the user performs a &quot;long press&quot; (press and ho...
Context Menu <ul><li>In order for a View to provide a context menu, you must &quot;register&quot; the view for a context m...
<ul><li>Same as before </li></ul>Responding to user action CS C314 Software Development For Portable Devices
Attention! <ul><li>Join  </li></ul><ul><li>Course Name CS – IS C314 </li></ul><ul><li>Official Medium for all the question...
References <ul><li>Menu Tutorial -  http:// developer.android.com/guide/topics/ui/menus.html </li></ul><ul><li>Shared Pref...
Thank You CS C314 Software Development For Portable Devices
Upcoming SlideShare
Loading in...5
×

Lecture Slides for Preferences and Menus [Android ]

1,200

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,200
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
52
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Lecture Slides for Preferences and Menus [Android ]"

  1. 1. Preferences & Menus Software Development for Portable Devices BITS Pilani Goa Campus Sem I 2011-12
  2. 2. CS C314 Software Development For Portable Devices Foundation of :
  3. 3. Saving Simple Application Data <ul><li>Shared Preferences </li></ul><ul><li>Saved Application State </li></ul><ul><li>Files </li></ul>CS C314 Software Development For Portable Devices
  4. 4. Shared Preferences <ul><li>Used to store UI state, user preferences, or application settings </li></ul><ul><li>Shared Preferences let you save groups of key/value pairs of primitive data as named preferences. </li></ul><ul><li>They are most commonly used to persist data across user sessions and to share settings among application components. </li></ul>CS C314 Software Development For Portable Devices
  5. 5. Creating And Saving Preferences <ul><li>getSharedPreferences(Pref_File_Name,Mode) </li></ul><ul><li>Creating new Shared Preferences->Code </li></ul><ul><li>Retreiving saved Shared Preferences->Code </li></ul><ul><li>Its that Simple </li></ul><ul><li>getDefaultSharedPreferences( this)-> Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context. </li></ul>CS C314 Software Development For Portable Devices
  6. 6. Preferences Activity Framework <ul><li>Android offers an XML-driven framework </li></ul><ul><li>Native preference screens. </li></ul><ul><li>Having a native feel to your app is important </li></ul><ul><li>The Preference Activity framework consists of three parts: </li></ul><ul><ul><li>Preference Screen Layout </li></ul></ul><ul><ul><li>Preference Activity </li></ul></ul><ul><ul><li>Shared Preference Change Listener </li></ul></ul>CS C314 Software Development For Portable Devices
  7. 7. Preference Screen Layout <ul><li>Stored in the res/xml resources folder. </li></ul><ul><ul><li>See folder structure </li></ul></ul><ul><li>Each preference layout is defined as a hierarchy, beginning with a single PreferenceScreen element. </li></ul><ul><li>The PreferenceCategory is a category with preferences. </li></ul>CS C314 Software Development For Portable Devices
  8. 8. The Specific Attributes <ul><li>android:key </li></ul><ul><li>android:title </li></ul><ul><li>android:summary </li></ul><ul><li>android:defaultValue </li></ul>CS C314 Software Development For Portable Devices
  9. 9. Native Preference Controls <ul><li>ListPreference : The preference equivalent of a spinner. </li></ul><ul><li>EditTextPreference : Allows users to enter a string value as a preference. </li></ul><ul><li>CheckBoxPreference : A standard preference checkbox control. Used to set preferences to true or false. </li></ul><ul><li>RingtonePreference : A specialized List Preference that presents the list of available ringtones for user selection. </li></ul>CS C314 Software Development For Portable Devices
  10. 10. Import System Preference Screens <ul><li>Invoke any Activity within your Preference Screen using an Intent. </li></ul><ul><li>See Code </li></ul><ul><li>The android.provider.Settings class includes a number of android.settings.* constants that can be used to invoke the system settings screens. </li></ul>CS C314 Software Development For Portable Devices
  11. 11. Preference Activity <ul><li>extend the PreferenceActivity class </li></ul><ul><li>Call addPreferencesFromResource to inflate the preferences </li></ul>CS C314 Software Development For Portable Devices
  12. 12. Menus
  13. 13. <ul><li>Types </li></ul><ul><ul><li>Options Menu </li></ul></ul><ul><ul><li>Context Menu </li></ul></ul><ul><ul><li>Submenu </li></ul></ul>CS C314 Software Development For Portable Devices
  14. 14. Creating a Menu Resource <ul><li>Define a menu and all its items in an XML. </li></ul><ul><li>Inflate the menu </li></ul><ul><li>Location of your menu resource res/menu/ </li></ul>CS C314 Software Development For Portable Devices
  15. 15. Inflating a Menu Resource CS C314 Software Development For Portable Devices
  16. 16. Options Menu <ul><li>The Menu that’s pops up when you press the menu button </li></ul><ul><li>If there are more than six items in the Options Menu, Android Places the “More” Icon. </li></ul>CS C314 Software Development For Portable Devices
  17. 17. Responding to user action CS C314 Software Development For Portable Devices
  18. 18. Context Menu <ul><li>On Android, a context menu is displayed when the user performs a &quot;long press&quot; (press and hold) on an item. </li></ul>CS C314 Software Development For Portable Devices
  19. 19. Context Menu <ul><li>In order for a View to provide a context menu, you must &quot;register&quot; the view for a context menu. Call registerForContextMenu(View view) </li></ul><ul><li>View that the user selected </li></ul><ul><li>ContextMenu.ContextMenuInfo object that provides additional information about the item selected. </li></ul>CS C314 Software Development For Portable Devices
  20. 20. <ul><li>Same as before </li></ul>Responding to user action CS C314 Software Development For Portable Devices
  21. 21. Attention! <ul><li>Join </li></ul><ul><li>Course Name CS – IS C314 </li></ul><ul><li>Official Medium for all the question and answers </li></ul><ul><li>Very Useful while collaborating for projects and preparing for labs </li></ul>CS C314 Software Development For Portable Devices
  22. 22. References <ul><li>Menu Tutorial - http:// developer.android.com/guide/topics/ui/menus.html </li></ul><ul><li>Shared Preferences </li></ul><ul><li>http://developer.android.com/reference/android/content/SharedPreferences.html </li></ul>CS C314 Software Development For Portable Devices
  23. 23. Thank You CS C314 Software Development For Portable Devices
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×