KEMBAR78
Lecture Slides for Preferences and Menus [Android ] | PPT
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 Shared Preferences Saved Application State Files CS C314 Software Development For Portable Devices
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
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
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
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
The Specific Attributes android:key android:title android:summary android:defaultValue CS C314 Software Development For Portable Devices
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
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
Preference Activity extend the PreferenceActivity class Call addPreferencesFromResource to inflate the preferences CS C314 Software Development For Portable Devices
Menus
Types Options Menu Context Menu Submenu CS C314 Software Development For Portable Devices
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
Inflating a Menu Resource CS C314 Software Development For Portable Devices
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
Responding to user action CS C314 Software Development For Portable Devices
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
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
Same as before Responding to user action CS C314 Software Development For Portable Devices
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
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
Thank You CS C314 Software Development For Portable Devices

Lecture Slides for Preferences and Menus [Android ]

  • 1.
    Preferences & MenusSoftware Development for Portable Devices BITS Pilani Goa Campus Sem I 2011-12
  • 2.
    CS C314 SoftwareDevelopment For Portable Devices Foundation of :
  • 3.
    Saving Simple ApplicationData Shared Preferences Saved Application State Files CS C314 Software Development For Portable Devices
  • 4.
    Shared Preferences Usedto 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 SavingPreferences 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 FrameworkAndroid 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 LayoutStored 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 Attributesandroid:key android:title android:summary android:defaultValue CS C314 Software Development For Portable Devices
  • 9.
    Native Preference ControlsListPreference : 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 PreferenceScreens 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 extendthe PreferenceActivity class Call addPreferencesFromResource to inflate the preferences CS C314 Software Development For Portable Devices
  • 12.
  • 13.
    Types Options MenuContext Menu Submenu CS C314 Software Development For Portable Devices
  • 14.
    Creating a MenuResource 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 MenuResource CS C314 Software Development For Portable Devices
  • 16.
    Options Menu TheMenu 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 useraction CS C314 Software Development For Portable Devices
  • 18.
    Context Menu OnAndroid, 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 Inorder 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 beforeResponding 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 CSC314 Software Development For Portable Devices