Revert "Removes framework Preference demos"
This reverts commit 946280d6ce.
Reason for revert: Breaking builds due to doc generation using these samples
Change-Id: I7caf9792e84e0e1eedea4a7294a321c684be2d5c
This commit is contained in:
@@ -1156,6 +1156,84 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<!-- ************************************* -->
|
||||||
|
<!-- PREFERENCE PACKAGE SAMPLES -->
|
||||||
|
<!-- ************************************* -->
|
||||||
|
|
||||||
|
<activity android:name=".preference.FragmentPreferences"
|
||||||
|
android:label="@string/fragment_preferences"
|
||||||
|
android:enabled="@bool/atLeastHoneycomb">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".preference.PreferenceWithHeaders"
|
||||||
|
android:label="@string/preference_with_headers"
|
||||||
|
android:enabled="@bool/atLeastHoneycomb">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".preference.PreferencesFromXml"
|
||||||
|
android:label="@string/preferences_from_xml">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".preference.PreferencesFromCode"
|
||||||
|
android:label="@string/preferences_from_code">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".preference.AdvancedPreferences"
|
||||||
|
android:label="@string/advanced_preferences">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".preference.LaunchingPreferences"
|
||||||
|
android:label="@string/launching_preferences">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".preference.PreferenceDependencies"
|
||||||
|
android:label="@string/preference_dependencies">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".preference.DefaultValues" android:label="@string/default_values">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".preference.SwitchPreference"
|
||||||
|
android:label="@string/switch_preference"
|
||||||
|
android:enabled="@bool/atLeastIceCreamSandwich">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<!-- ************************************* -->
|
<!-- ************************************* -->
|
||||||
<!-- CONTENT PACKAGE SAMPLES -->
|
<!-- CONTENT PACKAGE SAMPLES -->
|
||||||
<!-- ************************************* -->
|
<!-- ************************************* -->
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ that illustrate the use of various Android APIs. It includes samples of:
|
|||||||
- Menus
|
- Menus
|
||||||
- Search
|
- Search
|
||||||
- Persistent application state
|
- Persistent application state
|
||||||
|
- Preferences
|
||||||
- Background Services
|
- Background Services
|
||||||
- App Widgets
|
- App Widgets
|
||||||
- Voice Recognition
|
- Voice Recognition
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ that illustrate the use of various Android APIs. It includes samples of:
|
|||||||
<li>Menus</li>
|
<li>Menus</li>
|
||||||
<li>Search</li>
|
<li>Search</li>
|
||||||
<li>Persistent application state</li>
|
<li>Persistent application state</li>
|
||||||
|
<li>Preferences</li>
|
||||||
<li>Background Services</li>
|
<li>Background Services</li>
|
||||||
<li>App Widgets</li>
|
<li>App Widgets</li>
|
||||||
<li>Voice Recognition</li>
|
<li>Voice Recognition</li>
|
||||||
@@ -19,6 +20,8 @@ that illustrate the use of various Android APIs. It includes samples of:
|
|||||||
<p><strong>Update:</strong> The following are some of the new demos for Android 4.0:</p>
|
<p><strong>Update:</strong> The following are some of the new demos for Android 4.0:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a
|
<li><a
|
||||||
|
href="src/com/example/android/apis/preference/PreferencesFromCode.html">Switch Preference</a></li>
|
||||||
|
<li><a
|
||||||
href="src/com/example/android/apis/app/ActionBarSettingsActionProviderActivity.html">Settings Action Provider
|
href="src/com/example/android/apis/app/ActionBarSettingsActionProviderActivity.html">Settings Action Provider
|
||||||
</a></li>
|
</a></li>
|
||||||
<li><a
|
<li><a
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2006 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Custom preference type using a text view. -->
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/mypreference_widget"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginRight="6sp"
|
||||||
|
android:focusable="false"
|
||||||
|
android:clickable="false" />
|
||||||
@@ -83,6 +83,20 @@
|
|||||||
<item>Every Sunday</item>
|
<item>Every Sunday</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- Used in app/menu examples -->
|
||||||
|
<string-array name="entries_list_preference">
|
||||||
|
<item>Alpha Option 01</item>
|
||||||
|
<item>Beta Option 02</item>
|
||||||
|
<item>Charlie Option 03</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<!-- Used in app/menu examples -->
|
||||||
|
<string-array name="entryvalues_list_preference">
|
||||||
|
<item>alpha</item>
|
||||||
|
<item>beta</item>
|
||||||
|
<item>charlie</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<!-- Used in app/Sample Device Admin -->
|
<!-- Used in app/Sample Device Admin -->
|
||||||
<string-array name="password_qualities">
|
<string-array name="password_qualities">
|
||||||
<item>Unspecified</item>
|
<item>Unspecified</item>
|
||||||
|
|||||||
@@ -15,6 +15,12 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
<!-- These are the attributes that we want to retrieve from the theme
|
||||||
|
in app/PreferencesFromCode.java -->
|
||||||
|
<declare-styleable name="TogglePrefAttrs">
|
||||||
|
<attr name="android:preferenceLayoutChild" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="LabelView">
|
<declare-styleable name="LabelView">
|
||||||
<attr name="text" format="string" />
|
<attr name="text" format="string" />
|
||||||
<attr name="textColor" format="color" />
|
<attr name="textColor" format="color" />
|
||||||
|
|||||||
@@ -660,6 +660,78 @@
|
|||||||
<string name="jump">Jump</string>
|
<string name="jump">Jump</string>
|
||||||
<string name="dive">Dive</string>
|
<string name="dive">Dive</string>
|
||||||
|
|
||||||
|
<!-- ============================== -->
|
||||||
|
<!-- app/menu examples strings -->
|
||||||
|
<!-- ============================== -->
|
||||||
|
|
||||||
|
<string name="preferences_from_xml">Preference/1. Preferences from XML</string>
|
||||||
|
<string name="launching_preferences">Preference/2. Launching preferences</string>
|
||||||
|
<string name="preference_dependencies">Preference/3. Preference dependencies</string>
|
||||||
|
<string name="default_values">Preference/4. Default values</string>
|
||||||
|
<string name="preferences_from_code">Preference/5. Preferences from code</string>
|
||||||
|
<string name="advanced_preferences">Preference/6. Advanced preferences</string>
|
||||||
|
<string name="fragment_preferences">Preference/7. Fragment</string>
|
||||||
|
<string name="preference_with_headers">Preference/8. Headers</string>
|
||||||
|
<string name="switch_preference">Preference/9. Switch</string>
|
||||||
|
|
||||||
|
<string name="launch_preference_activity">Launch PreferenceActivity</string>
|
||||||
|
<string name="counter_value_is">The counter value is</string>
|
||||||
|
|
||||||
|
<string name="inline_preferences">In-line preferences</string>
|
||||||
|
<string name="dialog_based_preferences">Dialog-based preferences</string>
|
||||||
|
<string name="launch_preferences">Launch preferences</string>
|
||||||
|
<string name="preference_attributes">Preference attributes</string>
|
||||||
|
|
||||||
|
<string name="title_checkbox_preference">Checkbox preference</string>
|
||||||
|
<string name="summary_checkbox_preference">This is a checkbox</string>
|
||||||
|
|
||||||
|
<string name="title_switch_preference">Switch preference</string>
|
||||||
|
<string name="summary_switch_preference">This is a switch</string>
|
||||||
|
<string name="summary_switch_preference_yes_no">This is a switch with custom text</string>
|
||||||
|
|
||||||
|
<string name="title_yesno_preference">Yes or no preference</string>
|
||||||
|
<string name="summary_yesno_preference">An example that uses a yes/no dialog</string>
|
||||||
|
<string name="dialog_title_yesno_preference">Do you like bananas?</string>
|
||||||
|
|
||||||
|
<string name="title_edittext_preference">Edit text preference</string>
|
||||||
|
<string name="summary_edittext_preference">An example that uses an edit text dialog</string>
|
||||||
|
<string name="dialog_title_edittext_preference">Enter your favorite animal</string>
|
||||||
|
|
||||||
|
<string name="title_list_preference">List preference</string>
|
||||||
|
<string name="summary_list_preference">An example that uses a list dialog</string>
|
||||||
|
<string name="dialog_title_list_preference">Choose one</string>
|
||||||
|
|
||||||
|
<string name="title_screen_preference">Screen preference</string>
|
||||||
|
<string name="summary_screen_preference">Shows another screen of preferences</string>
|
||||||
|
|
||||||
|
<string name="title_fragment_preference">Fragment preference</string>
|
||||||
|
<string name="summary_fragment_preference">Shows another fragment of preferences</string>
|
||||||
|
|
||||||
|
<string name="title_next_screen_toggle_preference">Toggle preference</string>
|
||||||
|
<string name="summary_next_screen_toggle_preference">Preference that is on the next screen but same hierarchy</string>
|
||||||
|
|
||||||
|
<string name="title_intent_preference">Intent preference</string>
|
||||||
|
<string name="summary_intent_preference">Launches an Activity from an Intent</string>
|
||||||
|
|
||||||
|
<string name="title_my_preference">My preference</string>
|
||||||
|
<string name="summary_my_preference">This is a custom counter preference</string>
|
||||||
|
|
||||||
|
<string name="title_advanced_toggle_preference">Haunted preference</string>
|
||||||
|
<string name="summary_on_advanced_toggle_preference">I\'m on! :)</string>
|
||||||
|
<string name="summary_off_advanced_toggle_preference">I\'m off! :(</string>
|
||||||
|
|
||||||
|
<string name="title_parent_preference">Parent checkbox preference</string>
|
||||||
|
<string name="summary_parent_preference">This is visually a parent</string>
|
||||||
|
<string name="title_child_preference">Child checkbox preference</string>
|
||||||
|
<string name="summary_child_preference">This is visually a child</string>
|
||||||
|
|
||||||
|
<string name="example_preference_dependency">Example preference dependency</string>
|
||||||
|
<string name="title_wifi">WiFi</string>
|
||||||
|
<string name="title_wifi_settings">WiFi settings</string>
|
||||||
|
|
||||||
|
<string name="default_value_list_preference">beta</string>
|
||||||
|
<string name="default_value_edittext_preference">Default value</string>
|
||||||
|
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
<!-- app/search examples strings -->
|
<!-- app/search examples strings -->
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
|
|||||||
38
samples/ApiDemos/res/xml/advanced_preferences.xml
Normal file
38
samples/ApiDemos/res/xml/advanced_preferences.xml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This is an advanced example showing the custom preference types and manually handling
|
||||||
|
preference clicks. -->
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<!-- My custom preference type. This just replaces the actual widget
|
||||||
|
portion of the preference, if the whole preference wanted to be
|
||||||
|
replaced we would use the layout attribute instead of the widgetLayout
|
||||||
|
attribute. -->
|
||||||
|
<com.example.android.apis.preference.MyPreference
|
||||||
|
android:key="my_preference"
|
||||||
|
android:title="@string/title_my_preference"
|
||||||
|
android:summary="@string/summary_my_preference"
|
||||||
|
android:defaultValue="100" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="advanced_checkbox_preference"
|
||||||
|
android:title="@string/title_advanced_toggle_preference"
|
||||||
|
android:summaryOn="@string/summary_on_advanced_toggle_preference"
|
||||||
|
android:summaryOff="@string/summary_off_advanced_toggle_preference" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
44
samples/ApiDemos/res/xml/default_values.xml
Normal file
44
samples/ApiDemos/res/xml/default_values.xml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This is a primitive example showing how to set default values for preferences.
|
||||||
|
See DefaultValues.java for more information. -->
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="default_checkbox"
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:title="@string/title_checkbox_preference"
|
||||||
|
android:summary="@string/summary_checkbox_preference" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:key="default_edittext"
|
||||||
|
android:defaultValue="@string/default_value_edittext_preference"
|
||||||
|
android:title="@string/title_edittext_preference"
|
||||||
|
android:summary="@string/summary_edittext_preference"
|
||||||
|
android:dialogTitle="@string/dialog_title_edittext_preference" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="default_list"
|
||||||
|
android:defaultValue="@string/default_value_list_preference"
|
||||||
|
android:title="@string/title_list_preference"
|
||||||
|
android:summary="@string/summary_list_preference"
|
||||||
|
android:entries="@array/entries_list_preference"
|
||||||
|
android:entryValues="@array/entryvalues_list_preference"
|
||||||
|
android:dialogTitle="@string/dialog_title_list_preference" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
97
samples/ApiDemos/res/xml/fragmented_preferences.xml
Normal file
97
samples/ApiDemos/res/xml/fragmented_preferences.xml
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This is a primitive example showing the different types of preferences available. -->
|
||||||
|
<!-- BEGIN_INCLUDE(preferences) -->
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/inline_preferences">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="checkbox_preference"
|
||||||
|
android:title="@string/title_checkbox_preference"
|
||||||
|
android:summary="@string/summary_checkbox_preference" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/dialog_based_preferences">
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:key="edittext_preference"
|
||||||
|
android:title="@string/title_edittext_preference"
|
||||||
|
android:summary="@string/summary_edittext_preference"
|
||||||
|
android:dialogTitle="@string/dialog_title_edittext_preference" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="list_preference"
|
||||||
|
android:title="@string/title_list_preference"
|
||||||
|
android:summary="@string/summary_list_preference"
|
||||||
|
android:entries="@array/entries_list_preference"
|
||||||
|
android:entryValues="@array/entryvalues_list_preference"
|
||||||
|
android:dialogTitle="@string/dialog_title_list_preference" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/launch_preferences">
|
||||||
|
|
||||||
|
<!-- This PreferenceScreen tag sends the user to a new fragment of
|
||||||
|
preferences. If running in a large screen, they can be embedded
|
||||||
|
inside of the overall preferences UI. -->
|
||||||
|
<PreferenceScreen
|
||||||
|
android:fragment="com.example.android.apis.preference.PreferenceWithHeaders$Prefs1FragmentInner"
|
||||||
|
android:title="@string/title_fragment_preference"
|
||||||
|
android:summary="@string/summary_fragment_preference">
|
||||||
|
<!-- Arbitrary key/value pairs can be included for fragment arguments -->
|
||||||
|
<extra android:name="someKey" android:value="somePrefValue" />
|
||||||
|
</PreferenceScreen>
|
||||||
|
|
||||||
|
<!-- This PreferenceScreen tag sends the user to a completely different
|
||||||
|
activity, switching out of the current preferences UI. -->
|
||||||
|
<PreferenceScreen
|
||||||
|
android:title="@string/title_intent_preference"
|
||||||
|
android:summary="@string/summary_intent_preference">
|
||||||
|
|
||||||
|
<intent android:action="android.intent.action.VIEW"
|
||||||
|
android:data="http://www.android.com" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/preference_attributes">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="parent_checkbox_preference"
|
||||||
|
android:title="@string/title_parent_preference"
|
||||||
|
android:summary="@string/summary_parent_preference" />
|
||||||
|
|
||||||
|
<!-- The visual style of a child is defined by this styled theme attribute. -->
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="child_checkbox_preference"
|
||||||
|
android:dependency="parent_checkbox_preference"
|
||||||
|
android:layout="?android:attr/preferenceLayoutChild"
|
||||||
|
android:title="@string/title_child_preference"
|
||||||
|
android:summary="@string/summary_child_preference" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
|
<!-- END_INCLUDE(preferences) -->
|
||||||
26
samples/ApiDemos/res/xml/fragmented_preferences_inner.xml
Normal file
26
samples/ApiDemos/res/xml/fragmented_preferences_inner.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This is a primitive example showing the different types of preferences available. -->
|
||||||
|
<!-- BEGIN_INCLUDE(preferences) -->
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="next_screen_checkbox_preference"
|
||||||
|
android:title="@string/title_next_screen_toggle_preference"
|
||||||
|
android:summary="@string/summary_next_screen_toggle_preference" />
|
||||||
|
</PreferenceScreen>
|
||||||
|
<!-- END_INCLUDE(preferences) -->
|
||||||
35
samples/ApiDemos/res/xml/preference_dependencies.xml
Normal file
35
samples/ApiDemos/res/xml/preference_dependencies.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This is a primitive example showing how some preferences can depend on other preferences. -->
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/example_preference_dependency">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="wifi"
|
||||||
|
android:title="@string/title_wifi" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:layout="?android:attr/preferenceLayoutChild"
|
||||||
|
android:title="@string/title_wifi_settings"
|
||||||
|
android:dependency="wifi" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
44
samples/ApiDemos/res/xml/preference_headers.xml
Normal file
44
samples/ApiDemos/res/xml/preference_headers.xml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This is a primitive example showing the different types of preferences available. -->
|
||||||
|
<!-- BEGIN_INCLUDE(headers) -->
|
||||||
|
<preference-headers
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<header android:fragment="com.example.android.apis.preference.PreferenceWithHeaders$Prefs1Fragment"
|
||||||
|
android:icon="@drawable/ic_settings_applications"
|
||||||
|
android:title="Prefs 1"
|
||||||
|
android:summary="An example of some preferences." />
|
||||||
|
|
||||||
|
<header android:fragment="com.example.android.apis.preference.PreferenceWithHeaders$Prefs2Fragment"
|
||||||
|
android:icon="@drawable/ic_settings_display"
|
||||||
|
android:title="Prefs 2"
|
||||||
|
android:summary="Some other preferences you can see.">
|
||||||
|
<!-- Arbitrary key/value pairs can be included with a header as
|
||||||
|
arguments to its fragment. -->
|
||||||
|
<extra android:name="someKey" android:value="someHeaderValue" />
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<header android:icon="@drawable/ic_settings_display"
|
||||||
|
android:title="Intent"
|
||||||
|
android:summary="Launches an Intent.">
|
||||||
|
<intent android:action="android.intent.action.VIEW"
|
||||||
|
android:data="http://www.android.com" />
|
||||||
|
</header>
|
||||||
|
|
||||||
|
</preference-headers>
|
||||||
|
<!-- END_INCLUDE(headers) -->
|
||||||
46
samples/ApiDemos/res/xml/preference_switch
Normal file
46
samples/ApiDemos/res/xml/preference_switch
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2011 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This is a primitive example showing the different types of preferences available. -->
|
||||||
|
<!-- BEGIN_INCLUDE(preferences) -->
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/inline_preferences">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="checkbox_preference"
|
||||||
|
android:title="@string/title_checkbox_preference"
|
||||||
|
android:summary="@string/summary_checkbox_preference" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="checkbox_preference"
|
||||||
|
android:title="@string/title_switch_preference"
|
||||||
|
android:summary="@string/summary_switch_preference" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="checkbox_preference"
|
||||||
|
android:title="@string/title_switch_preference"
|
||||||
|
android:summary="@string/summary_switch_preference_yes_no"
|
||||||
|
android:switchTextOn = "YES"
|
||||||
|
android:switchTextOff = "NO"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
|
<!-- END_INCLUDE(preferences) -->
|
||||||
101
samples/ApiDemos/res/xml/preferences.xml
Normal file
101
samples/ApiDemos/res/xml/preferences.xml
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This is a primitive example showing the different types of preferences available. -->
|
||||||
|
<!-- BEGIN_INCLUDE(preferences) -->
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/inline_preferences">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="checkbox_preference"
|
||||||
|
android:title="@string/title_checkbox_preference"
|
||||||
|
android:summary="@string/summary_checkbox_preference" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/dialog_based_preferences">
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:key="edittext_preference"
|
||||||
|
android:title="@string/title_edittext_preference"
|
||||||
|
android:summary="@string/summary_edittext_preference"
|
||||||
|
android:dialogTitle="@string/dialog_title_edittext_preference" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="list_preference"
|
||||||
|
android:title="@string/title_list_preference"
|
||||||
|
android:summary="@string/summary_list_preference"
|
||||||
|
android:entries="@array/entries_list_preference"
|
||||||
|
android:entryValues="@array/entryvalues_list_preference"
|
||||||
|
android:dialogTitle="@string/dialog_title_list_preference" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/launch_preferences">
|
||||||
|
|
||||||
|
<!-- This PreferenceScreen tag serves as a screen break (similar to page break
|
||||||
|
in word processing). Like for other preference types, we assign a key
|
||||||
|
here so it is able to save and restore its instance state. -->
|
||||||
|
<PreferenceScreen
|
||||||
|
android:key="screen_preference"
|
||||||
|
android:title="@string/title_screen_preference"
|
||||||
|
android:summary="@string/summary_screen_preference">
|
||||||
|
|
||||||
|
<!-- You can place more preferences here that will be shown on the next screen. -->
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="next_screen_checkbox_preference"
|
||||||
|
android:title="@string/title_next_screen_toggle_preference"
|
||||||
|
android:summary="@string/summary_next_screen_toggle_preference" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
|
|
||||||
|
<PreferenceScreen
|
||||||
|
android:title="@string/title_intent_preference"
|
||||||
|
android:summary="@string/summary_intent_preference">
|
||||||
|
|
||||||
|
<intent android:action="android.intent.action.VIEW"
|
||||||
|
android:data="http://www.android.com" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/preference_attributes">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="parent_checkbox_preference"
|
||||||
|
android:title="@string/title_parent_preference"
|
||||||
|
android:summary="@string/summary_parent_preference" />
|
||||||
|
|
||||||
|
<!-- The visual style of a child is defined by this styled theme attribute. -->
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="child_checkbox_preference"
|
||||||
|
android:dependency="parent_checkbox_preference"
|
||||||
|
android:layout="?android:attr/preferenceLayoutChild"
|
||||||
|
android:title="@string/title_child_preference"
|
||||||
|
android:summary="@string/summary_child_preference" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
|
<!-- END_INCLUDE(preferences) -->
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example that shows finding a preference from the hierarchy and a custom preference type.
|
||||||
|
*/
|
||||||
|
public class AdvancedPreferences extends PreferenceActivity implements OnSharedPreferenceChangeListener {
|
||||||
|
public static final String KEY_MY_PREFERENCE = "my_preference";
|
||||||
|
public static final String KEY_ADVANCED_CHECKBOX_PREFERENCE = "advanced_checkbox_preference";
|
||||||
|
|
||||||
|
private CheckBoxPreference mCheckBoxPreference;
|
||||||
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a simple example of controlling a preference from code.
|
||||||
|
*/
|
||||||
|
private Runnable mForceCheckBoxRunnable = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (mCheckBoxPreference != null) {
|
||||||
|
mCheckBoxPreference.setChecked(!mCheckBoxPreference.isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force toggle again in a second
|
||||||
|
mHandler.postDelayed(this, 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Load the XML preferences file
|
||||||
|
addPreferencesFromResource(R.xml.advanced_preferences);
|
||||||
|
|
||||||
|
// Get a reference to the checkbox preference
|
||||||
|
mCheckBoxPreference = (CheckBoxPreference)getPreferenceScreen().findPreference(
|
||||||
|
KEY_ADVANCED_CHECKBOX_PREFERENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
// Start the force toggle
|
||||||
|
mForceCheckBoxRunnable.run();
|
||||||
|
|
||||||
|
// Set up a listener whenever a key changes
|
||||||
|
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
|
||||||
|
// Unregister the listener whenever a key changes
|
||||||
|
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
mHandler.removeCallbacks(mForceCheckBoxRunnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
// Let's do something when my counter preference value changes
|
||||||
|
if (key.equals(KEY_MY_PREFERENCE)) {
|
||||||
|
Toast.makeText(this, "Thanks! You increased my count to "
|
||||||
|
+ sharedPreferences.getInt(key, 0), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This activity is an example of a simple settings screen that has default
|
||||||
|
* values.
|
||||||
|
* <p>
|
||||||
|
* In order for the default values to be populated into the
|
||||||
|
* {@link SharedPreferences} (from the preferences XML file), the client must
|
||||||
|
* call
|
||||||
|
* {@link PreferenceManager#setDefaultValues(android.content.Context, int, boolean)}.
|
||||||
|
* <p>
|
||||||
|
* This should be called early, typically when the application is first created.
|
||||||
|
* An easy way to do this is to have a common function for retrieving the
|
||||||
|
* SharedPreferences that takes care of calling it.
|
||||||
|
*/
|
||||||
|
public class DefaultValues extends PreferenceActivity {
|
||||||
|
// This is the global (to the .apk) name under which we store these
|
||||||
|
// preferences. We want this to be unique from other preferences so that
|
||||||
|
// we do not have unexpected name conflicts, and the framework can correctly
|
||||||
|
// determine whether these preferences' defaults have already been written.
|
||||||
|
static final String PREFS_NAME = "defaults";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getPrefs(this);
|
||||||
|
getPreferenceManager().setSharedPreferencesName(PREFS_NAME);
|
||||||
|
addPreferencesFromResource(R.xml.default_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SharedPreferences getPrefs(Context context) {
|
||||||
|
PreferenceManager.setDefaultValues(context, PREFS_NAME, MODE_PRIVATE,
|
||||||
|
R.xml.default_values, false);
|
||||||
|
return context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstration of PreferenceFragment, showing a single fragment in an
|
||||||
|
* activity.
|
||||||
|
*/
|
||||||
|
public class FragmentPreferences extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Display the fragment as the main content.
|
||||||
|
getFragmentManager().beginTransaction().replace(android.R.id.content,
|
||||||
|
new PrefsFragment()).commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
//BEGIN_INCLUDE(fragment)
|
||||||
|
public static class PrefsFragment extends PreferenceFragment {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//END_INCLUDE(fragment)
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstrates launching a PreferenceActivity and grabbing a value it saved.
|
||||||
|
*/
|
||||||
|
public class LaunchingPreferences extends Activity implements OnClickListener {
|
||||||
|
|
||||||
|
private static final int REQUEST_CODE_PREFERENCES = 1;
|
||||||
|
|
||||||
|
private TextView mCounterText;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These preferences have defaults, so before using them go apply those
|
||||||
|
* defaults. This will only execute once -- when the defaults are applied
|
||||||
|
* a boolean preference is set so they will not be applied again.
|
||||||
|
*/
|
||||||
|
PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, false);
|
||||||
|
|
||||||
|
// Simple layout
|
||||||
|
LinearLayout layout = new LinearLayout(this);
|
||||||
|
layout.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
setContentView(layout);
|
||||||
|
|
||||||
|
// Create a simple button that will launch the preferences
|
||||||
|
Button launchPreferences = new Button(this);
|
||||||
|
launchPreferences.setText(getString(R.string.launch_preference_activity));
|
||||||
|
launchPreferences.setOnClickListener(this);
|
||||||
|
layout.addView(launchPreferences, new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||||
|
LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
|
mCounterText = new TextView(this);
|
||||||
|
layout.addView(mCounterText, new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||||
|
LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
|
updateCounterText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
// When the button is clicked, launch an activity through this intent
|
||||||
|
Intent launchPreferencesIntent = new Intent().setClass(this, AdvancedPreferences.class);
|
||||||
|
|
||||||
|
// Make it a subactivity so we know when it returns
|
||||||
|
startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
// The preferences returned if the request code is what we had given
|
||||||
|
// earlier in startSubActivity
|
||||||
|
if (requestCode == REQUEST_CODE_PREFERENCES) {
|
||||||
|
// Read a sample value they have set
|
||||||
|
updateCounterText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCounterText() {
|
||||||
|
// Since we're in the same package, we can use this context to get
|
||||||
|
// the default shared preferences
|
||||||
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
final int counter = sharedPref.getInt(AdvancedPreferences.KEY_MY_PREFERENCE, 0);
|
||||||
|
mCounterText.setText(getString(R.string.counter_value_is) + " " + counter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an example of a custom preference type. The preference counts the
|
||||||
|
* number of clicks it has received and stores/retrieves it from the storage.
|
||||||
|
*/
|
||||||
|
public class MyPreference extends Preference {
|
||||||
|
private int mClickCounter;
|
||||||
|
|
||||||
|
// This is the constructor called by the inflater
|
||||||
|
public MyPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
|
||||||
|
setWidgetLayoutResource(R.layout.preference_widget_mypreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onBindView(View view) {
|
||||||
|
super.onBindView(view);
|
||||||
|
|
||||||
|
// Set our custom views inside the layout
|
||||||
|
final TextView myTextView = (TextView) view.findViewById(R.id.mypreference_widget);
|
||||||
|
if (myTextView != null) {
|
||||||
|
myTextView.setText(String.valueOf(mClickCounter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
int newValue = mClickCounter + 1;
|
||||||
|
// Give the client a chance to ignore this change if they deem it
|
||||||
|
// invalid
|
||||||
|
if (!callChangeListener(newValue)) {
|
||||||
|
// They don't want the value to be set
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment counter
|
||||||
|
mClickCounter = newValue;
|
||||||
|
|
||||||
|
// Save to persistent storage (this method will make sure this
|
||||||
|
// preference should be persistent, along with other useful checks)
|
||||||
|
persistInt(mClickCounter);
|
||||||
|
|
||||||
|
// Data has changed, notify so UI can be refreshed!
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||||
|
// This preference type's value type is Integer, so we read the default
|
||||||
|
// value from the attributes as an Integer.
|
||||||
|
return a.getInteger(index, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
|
||||||
|
if (restoreValue) {
|
||||||
|
// Restore state
|
||||||
|
mClickCounter = getPersistedInt(mClickCounter);
|
||||||
|
} else {
|
||||||
|
// Set state
|
||||||
|
int value = (Integer) defaultValue;
|
||||||
|
mClickCounter = value;
|
||||||
|
persistInt(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Parcelable onSaveInstanceState() {
|
||||||
|
/*
|
||||||
|
* Suppose a client uses this preference type without persisting. We
|
||||||
|
* must save the instance state so it is able to, for example, survive
|
||||||
|
* orientation changes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
final Parcelable superState = super.onSaveInstanceState();
|
||||||
|
if (isPersistent()) {
|
||||||
|
// No need to save instance state since it's persistent
|
||||||
|
return superState;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the instance state
|
||||||
|
final SavedState myState = new SavedState(superState);
|
||||||
|
myState.clickCounter = mClickCounter;
|
||||||
|
return myState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRestoreInstanceState(Parcelable state) {
|
||||||
|
if (!state.getClass().equals(SavedState.class)) {
|
||||||
|
// Didn't save state for us in onSaveInstanceState
|
||||||
|
super.onRestoreInstanceState(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore the instance state
|
||||||
|
SavedState myState = (SavedState) state;
|
||||||
|
super.onRestoreInstanceState(myState.getSuperState());
|
||||||
|
mClickCounter = myState.clickCounter;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SavedState, a subclass of {@link BaseSavedState}, will store the state
|
||||||
|
* of MyPreference, a subclass of Preference.
|
||||||
|
* <p>
|
||||||
|
* It is important to always call through to super methods.
|
||||||
|
*/
|
||||||
|
private static class SavedState extends BaseSavedState {
|
||||||
|
int clickCounter;
|
||||||
|
|
||||||
|
public SavedState(Parcel source) {
|
||||||
|
super(source);
|
||||||
|
|
||||||
|
// Restore the click counter
|
||||||
|
clickCounter = source.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
super.writeToParcel(dest, flags);
|
||||||
|
|
||||||
|
// Save the click counter
|
||||||
|
dest.writeInt(clickCounter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SavedState(Parcelable superState) {
|
||||||
|
super(superState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<SavedState> CREATOR =
|
||||||
|
new Parcelable.Creator<SavedState>() {
|
||||||
|
public SavedState createFromParcel(Parcel in) {
|
||||||
|
return new SavedState(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SavedState[] newArray(int size) {
|
||||||
|
return new SavedState[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
|
||||||
|
public class PreferenceDependencies extends PreferenceActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.preference_dependencies);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstration of PreferenceActivity to make a top-level preference
|
||||||
|
* panel with headers.
|
||||||
|
*/
|
||||||
|
//BEGIN_INCLUDE(activity)
|
||||||
|
public class PreferenceWithHeaders extends PreferenceActivity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Add a button to the header list.
|
||||||
|
if (hasHeaders()) {
|
||||||
|
Button button = new Button(this);
|
||||||
|
button.setText("Some action");
|
||||||
|
setListFooter(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populate the activity with the top-level headers.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onBuildHeaders(List<Header> target) {
|
||||||
|
loadHeadersFromResource(R.xml.preference_headers, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This fragment shows the preferences for the first header.
|
||||||
|
*/
|
||||||
|
public static class Prefs1Fragment extends PreferenceFragment {
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Make sure default values are applied. In a real app, you would
|
||||||
|
// want this in a shared function that is used to retrieve the
|
||||||
|
// SharedPreferences wherever they are needed.
|
||||||
|
PreferenceManager.setDefaultValues(getActivity(),
|
||||||
|
R.xml.advanced_preferences, false);
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.fragmented_preferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This fragment contains a second-level set of preference that you
|
||||||
|
* can get to by tapping an item in the first preferences fragment.
|
||||||
|
*/
|
||||||
|
public static class Prefs1FragmentInner extends PreferenceFragment {
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Can retrieve arguments from preference XML.
|
||||||
|
Log.i("args", "Arguments: " + getArguments());
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.fragmented_preferences_inner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This fragment shows the preferences for the second header.
|
||||||
|
*/
|
||||||
|
public static class Prefs2Fragment extends PreferenceFragment {
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Can retrieve arguments from headers XML.
|
||||||
|
Log.i("args", "Arguments: " + getArguments());
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.preference_dependencies);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//END_INCLUDE(activity)
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.preference.EditTextPreference;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceCategory;
|
||||||
|
import android.preference.PreferenceScreen;
|
||||||
|
import android.preference.SwitchPreference;
|
||||||
|
|
||||||
|
public class PreferencesFromCode extends PreferenceActivity {
|
||||||
|
|
||||||
|
private static final String PARENT_CHECKBOX_PREFERENCE = "parent_checkbox_preference";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
|
||||||
|
setPreferenceScreen(root);
|
||||||
|
populatePreferenceHierarchy(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populatePreferenceHierarchy(PreferenceScreen root) {
|
||||||
|
// Inline preferences
|
||||||
|
PreferenceCategory inlinePrefCat = new PreferenceCategory(this);
|
||||||
|
inlinePrefCat.setTitle(R.string.inline_preferences);
|
||||||
|
root.addPreference(inlinePrefCat);
|
||||||
|
|
||||||
|
// Checkbox preference
|
||||||
|
CheckBoxPreference checkboxPref = new CheckBoxPreference(this);
|
||||||
|
checkboxPref.setKey("checkbox_preference");
|
||||||
|
checkboxPref.setTitle(R.string.title_checkbox_preference);
|
||||||
|
checkboxPref.setSummary(R.string.summary_checkbox_preference);
|
||||||
|
inlinePrefCat.addPreference(checkboxPref);
|
||||||
|
|
||||||
|
// Switch preference
|
||||||
|
SwitchPreference switchPref = new SwitchPreference(this);
|
||||||
|
switchPref.setKey("switch_preference");
|
||||||
|
switchPref.setTitle(R.string.title_switch_preference);
|
||||||
|
switchPref.setSummary(R.string.summary_switch_preference);
|
||||||
|
inlinePrefCat.addPreference(switchPref);
|
||||||
|
|
||||||
|
// Dialog based preferences
|
||||||
|
PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
|
||||||
|
dialogBasedPrefCat.setTitle(R.string.dialog_based_preferences);
|
||||||
|
root.addPreference(dialogBasedPrefCat);
|
||||||
|
|
||||||
|
// Edit text preference
|
||||||
|
EditTextPreference editTextPref = new EditTextPreference(this);
|
||||||
|
editTextPref.setDialogTitle(R.string.dialog_title_edittext_preference);
|
||||||
|
editTextPref.setKey("edittext_preference");
|
||||||
|
editTextPref.setTitle(R.string.title_edittext_preference);
|
||||||
|
editTextPref.setSummary(R.string.summary_edittext_preference);
|
||||||
|
dialogBasedPrefCat.addPreference(editTextPref);
|
||||||
|
|
||||||
|
// List preference
|
||||||
|
ListPreference listPref = new ListPreference(this);
|
||||||
|
listPref.setEntries(R.array.entries_list_preference);
|
||||||
|
listPref.setEntryValues(R.array.entryvalues_list_preference);
|
||||||
|
listPref.setDialogTitle(R.string.dialog_title_list_preference);
|
||||||
|
listPref.setKey("list_preference");
|
||||||
|
listPref.setTitle(R.string.title_list_preference);
|
||||||
|
listPref.setSummary(R.string.summary_list_preference);
|
||||||
|
dialogBasedPrefCat.addPreference(listPref);
|
||||||
|
|
||||||
|
// Launch preferences
|
||||||
|
PreferenceCategory launchPrefCat = new PreferenceCategory(this);
|
||||||
|
launchPrefCat.setTitle(R.string.launch_preferences);
|
||||||
|
root.addPreference(launchPrefCat);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The Preferences screenPref serves as a screen break (similar to page
|
||||||
|
* break in word processing). Like for other preference types, we assign
|
||||||
|
* a key here so that it is able to save and restore its instance state.
|
||||||
|
*/
|
||||||
|
// Screen preference
|
||||||
|
PreferenceScreen screenPref = getPreferenceManager().createPreferenceScreen(this);
|
||||||
|
screenPref.setKey("screen_preference");
|
||||||
|
screenPref.setTitle(R.string.title_screen_preference);
|
||||||
|
screenPref.setSummary(R.string.summary_screen_preference);
|
||||||
|
launchPrefCat.addPreference(screenPref);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* You can add more preferences to screenPref that will be shown on the
|
||||||
|
* next screen.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Example of next screen toggle preference
|
||||||
|
CheckBoxPreference nextScreenCheckBoxPref = new CheckBoxPreference(this);
|
||||||
|
nextScreenCheckBoxPref.setKey("next_screen_toggle_preference");
|
||||||
|
nextScreenCheckBoxPref.setTitle(R.string.title_next_screen_toggle_preference);
|
||||||
|
nextScreenCheckBoxPref.setSummary(R.string.summary_next_screen_toggle_preference);
|
||||||
|
screenPref.addPreference(nextScreenCheckBoxPref);
|
||||||
|
|
||||||
|
// Intent preference
|
||||||
|
PreferenceScreen intentPref = getPreferenceManager().createPreferenceScreen(this);
|
||||||
|
intentPref.setIntent(new Intent().setAction(Intent.ACTION_VIEW)
|
||||||
|
.setData(Uri.parse("http://www.android.com")));
|
||||||
|
intentPref.setTitle(R.string.title_intent_preference);
|
||||||
|
intentPref.setSummary(R.string.summary_intent_preference);
|
||||||
|
launchPrefCat.addPreference(intentPref);
|
||||||
|
|
||||||
|
// Preference attributes
|
||||||
|
PreferenceCategory prefAttrsCat = new PreferenceCategory(this);
|
||||||
|
prefAttrsCat.setTitle(R.string.preference_attributes);
|
||||||
|
root.addPreference(prefAttrsCat);
|
||||||
|
|
||||||
|
// Visual parent toggle preference
|
||||||
|
CheckBoxPreference parentCheckBoxPref = new CheckBoxPreference(this);
|
||||||
|
parentCheckBoxPref.setTitle(R.string.title_parent_preference);
|
||||||
|
parentCheckBoxPref.setSummary(R.string.summary_parent_preference);
|
||||||
|
prefAttrsCat.addPreference(parentCheckBoxPref);
|
||||||
|
parentCheckBoxPref.setKey(PARENT_CHECKBOX_PREFERENCE);
|
||||||
|
|
||||||
|
// Visual child toggle preference
|
||||||
|
// See res/values/attrs.xml for the <declare-styleable> that defines
|
||||||
|
// TogglePrefAttrs.
|
||||||
|
TypedArray a = obtainStyledAttributes(R.styleable.TogglePrefAttrs);
|
||||||
|
CheckBoxPreference childCheckBoxPref = new CheckBoxPreference(this);
|
||||||
|
childCheckBoxPref.setTitle(R.string.title_child_preference);
|
||||||
|
childCheckBoxPref.setSummary(R.string.summary_child_preference);
|
||||||
|
childCheckBoxPref.setLayoutResource(
|
||||||
|
a.getResourceId(R.styleable.TogglePrefAttrs_android_preferenceLayoutChild,
|
||||||
|
0));
|
||||||
|
prefAttrsCat.addPreference(childCheckBoxPref);
|
||||||
|
childCheckBoxPref.setDependency(PARENT_CHECKBOX_PREFERENCE);
|
||||||
|
a.recycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
|
||||||
|
public class PreferencesFromXml extends PreferenceActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
public class SwitchPreference extends PreferenceActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
PreferenceManager.setDefaultValues(this, "switch", MODE_PRIVATE,
|
||||||
|
R.xml.default_values, false);
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
getPreferenceManager().setSharedPreferencesName("switch");
|
||||||
|
addPreferencesFromResource(R.xml.preference_switch);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user