Lecture Slides for Preferences and Menus [Android ]
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,542
On Slideshare
1,541
From Embeds
1
Number of Embeds
1

Actions

Shares
Downloads
41
Comments
0
Likes
1

Embeds 1

http://firety.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

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