Committer: Rajdeep Dua <rajdeep@google.com>
Test cases for android.preference
Change-Id: Ia0979222f1b5c81cb8149a339080e42958537b97
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 97e1065..b10ac0f 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -73,6 +73,7 @@
CtsPermissionTestCases \
CtsPermission2TestCases \
CtsPreferenceTestCases \
+ CtsPreference2TestCases \
CtsProviderTestCases \
CtsRenderscriptTestCases \
CtsSaxTestCases \
diff --git a/tests/tests/preference2/Android.mk b/tests/tests/preference2/Android.mk
new file mode 100644
index 0000000..8fda601
--- /dev/null
+++ b/tests/tests/preference2/Android.mk
@@ -0,0 +1,31 @@
+# Copyright (C) 2012 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := CtsPreference2TestCases
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/preference2/AndroidManifest.xml b/tests/tests/preference2/AndroidManifest.xml
new file mode 100644
index 0000000..5043e1f
--- /dev/null
+++ b/tests/tests/preference2/AndroidManifest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.cts.preference2">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ <activity
+ android:name="android.preference2.cts.PreferenceFragmentActivity" >
+ </activity>
+ <activity
+ android:name="android.preference2.cts.PreferenceStubActivity" >
+ </activity>
+ <activity
+ android:name="android.preference2.cts.PreferenceFromCodeActivity" >
+ </activity>
+ <activity android:name="android.preference2.cts.PreferencesFromXml" />
+ <activity android:name="android.preference2.cts.PreferenceWithHeaders" />
+ </application>
+
+ <!-- This is a self-instrumenting test package. -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.cts.preference2"
+ android:label="CTS Test Cases for android.preference"/>
+
+</manifest>
+
diff --git a/tests/tests/preference2/res/drawable-hdpi/ic_launcher.png b/tests/tests/preference2/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..8074c4c
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/tests/tests/preference2/res/drawable-ldpi/ic_launcher.png b/tests/tests/preference2/res/drawable-ldpi/ic_launcher.png
new file mode 100755
index 0000000..1095584
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-ldpi/ic_launcher.png
Binary files differ
diff --git a/tests/tests/preference2/res/drawable-mdpi/ic_launcher.png b/tests/tests/preference2/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..a07c69f
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/tests/tests/preference2/res/drawable-mdpi/ic_settings_applications.png b/tests/tests/preference2/res/drawable-mdpi/ic_settings_applications.png
new file mode 100755
index 0000000..745ff2a
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-mdpi/ic_settings_applications.png
Binary files differ
diff --git a/tests/tests/preference2/res/drawable-mdpi/ic_settings_display.png b/tests/tests/preference2/res/drawable-mdpi/ic_settings_display.png
new file mode 100755
index 0000000..85af393
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-mdpi/ic_settings_display.png
Binary files differ
diff --git a/tests/tests/preference2/res/layout/main.xml b/tests/tests/preference2/res/layout/main.xml
new file mode 100755
index 0000000..a6b7f10
--- /dev/null
+++ b/tests/tests/preference2/res/layout/main.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ />
+
+</LinearLayout>
diff --git a/tests/tests/preference2/res/values/arrays.xml b/tests/tests/preference2/res/values/arrays.xml
new file mode 100755
index 0000000..198d989
--- /dev/null
+++ b/tests/tests/preference2/res/values/arrays.xml
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<resources>
+ <!-- Used in View/Spinner1.java -->
+ <string-array name="colors">
+ <item>red</item>
+ <item>orange</item>
+ <item>yellow</item>
+ <item>green</item>
+ <item>blue</item>
+ <item>violet</item>
+ </string-array>
+
+ <!-- Used in View/Spinner1.java -->
+ <string-array name="planets">
+ <item>Mercury</item>
+ <item>Venus</item>
+ <item>Earth</item>
+ <item>Mars</item>
+ <item>Jupiter</item>
+ <item>Saturn</item>
+ <item>Uranus</item>
+ <item>Neptune</item>
+ <item>Pluto</item>
+ </string-array>
+
+ <!-- Used in content/ClipboardSample.java -->
+ <string-array name="clip_data_types">
+ <item>No data in clipboard</item>
+ <item>Text clip</item>
+ <item>Intent clip</item>
+ <item>Uri clip</item>
+ </string-array>
+
+ <!-- Used in App/SearchInvoke.java -->
+ <string-array name="search_menuModes">
+ <item>Search Key</item>
+ <item>Menu Item</item>
+ <item>Type-To-Search</item>
+ <item>Disabled</item>
+ </string-array>
+
+ <!-- Used in app/dialog examples -->
+ <string-array name="select_dialog_items">
+ <item>Command one</item>
+ <item>Command two</item>
+ <item>Command three</item>
+ <item>Command four</item>
+ </string-array>
+
+ <string-array name="select_dialog_items2">
+ <item>Map</item>
+ <item>Satellite</item>
+ <item>Traffic</item>
+ <item>Street view</item>
+ </string-array>
+
+ <string-array name="select_dialog_items3">
+ <item>Every Monday</item>
+ <item>Every Tuesday</item>
+ <item>Every Wednesday</item>
+ <item>Every Thursday</item>
+ <item>Every Friday</item>
+ <item>Every Saturday</item>
+ <item>Every Sunday</item>
+ </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 -->
+ <string-array name="password_qualities">
+ <item>Unspecified</item>
+ <item>Something</item>
+ <item>Numeric</item>
+ <item>Alphabetic</item>
+ <item>Alphanumeric</item>
+ <item>Complex</item>
+ </string-array>
+
+ <!-- Used in app/Screen Orientation -->
+ <string-array name="screen_orientations">
+ <item>UNSPECIFIED</item>
+ <item>LANDSCAPE</item>
+ <item>PORTRAIT</item>
+ <item>USER</item>
+ <item>BEHIND</item>
+ <item>SENSOR</item>
+ <item>NOSENSOR</item>
+ <item>SENSOR_LANDSCAPE</item>
+ <item>SENSOR_PORTRAIT</item>
+ <item>REVERSE_LANDSCAPE</item>
+ <item>REVERSE_PORTRAIT</item>
+ <item>FULL_SENSOR</item>
+ </string-array>
+
+ <!-- Used in view/Secure View examples -->
+ <string-array name="secure_view_clicked">
+ <item>*bzzt*\nTransferred $1,000,000 to J. Phisher. Thank you!</item>
+ <item>*bzzt*\nSending all life savings to the International Cabal of Evil Penguins.</item>
+ <item>*bzzt*\nOpening portal to R\'lyeh. Long live Cthulhu!</item>
+ <item>*bzzt*\nYou\'re not very good at this, are you?</item>
+ <item>*bzzt*\nGo away...</item>
+ </string-array>
+
+ <!-- Used in view/Split Touch View example -->
+ <string-array name="cheese_responses">
+ <item>I\'m afraid we\'re fresh out.</item>
+ <item>I\'m afraid we never have that at the end of the week, sir. We get it fresh on Monday.
+ </item>
+ <item>Ah. It\'s been on order, sir, for two weeks. I was expecting it this morning.</item>
+ <item>Normally, sir, yes. Today the van broke down.</item>
+ <item>No.</item>
+ <item>No.</item>
+ <item>No.</item>
+ <item>Yes, sir. It\'s, ah ..... it\'s a bit runny.</item>
+ <item>Well, it\'s very runny, actually, sir.</item>
+ <item>I think it\'s a bit runnier than you\'ll like it, sir.</item>
+ <item>Oh... The cat\'s eaten it.</item>
+ <item>No.</item>
+ <item>No.</item>
+ <item>No.</item>
+ <item>Mmm... cheese.</item>
+ </string-array>
+</resources>
diff --git a/tests/tests/preference2/res/values/attrs.xml b/tests/tests/preference2/res/values/attrs.xml
new file mode 100755
index 0000000..e80e204
--- /dev/null
+++ b/tests/tests/preference2/res/values/attrs.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<resources>
+ <declare-styleable name="CustPref">
+ <attr name="icon" format="integer"/>
+ <attr name="title" format="string"/>
+ </declare-styleable>
+</resources>
diff --git a/tests/tests/preference2/res/values/colors.xml b/tests/tests/preference2/res/values/colors.xml
new file mode 100755
index 0000000..bfcd0b4
--- /dev/null
+++ b/tests/tests/preference2/res/values/colors.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<resources>
+ <color name="white">#FFFFFF</color>
+ <color name="android_orange">#FF9E18</color>
+ <color name="android_yellow">#F2E406</color>
+ <color name="black">#000000</color>
+ <color name="red">#FF0000</color>
+</resources>
diff --git a/tests/tests/preference2/res/values/strings.xml b/tests/tests/preference2/res/values/strings.xml
new file mode 100755
index 0000000..d43d3eb
--- /dev/null
+++ b/tests/tests/preference2/res/values/strings.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<resources>
+ <string name="app_name">CtsPreferenceTestCases</string>
+ <string name="test_prefs">Test Preferences</string>
+
+ <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="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="summary_on_checkbox_preference">Checkbox preference On</string>
+ <string name="summary_off_checkbox_preference">Checkbox preference Off</string>
+
+ <string name="title_switch_preference">Switch preference</string>
+ <string name="summary_switch_preference">This is a switch</string>
+ <string name="summary_on_switch_preference">Switch Summary On</string>
+ <string name="summary_off_switch_preference">Switch Summary Off</string>
+ <string name="switchtext_on">Switch Text On</string>
+ <string name="switchtext_off">Switch Text Off</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>
+ <string name="text_edittext_preference">Edit Text</string>
+ <string name="preset_title">Preset Title</string>
+ <string name="dialog_message">"Dialog Message"</string>
+
+ <string name="title_dialog_preference">Dialog preference</string>
+ <string name="dialogtitle_dialog_preference">Dialog Title</string>
+ <string name="summary_dialog_preference">An example that uses a dialog</string>
+ <string name="positive_button_text">"Accept"</string>
+ <string name="negative_button_text">"Decline"</string>
+
+ <string name="cust_title_dialog_preference">Custom Dialog preference</string>
+ <string name="cust_dialogtitle_dialog_preference">Custom Dialog Title</string>
+</resources>
diff --git a/tests/tests/preference2/res/xml/fragmented_preferences.xml b/tests/tests/preference2/res/xml/fragmented_preferences.xml
new file mode 100755
index 0000000..24537b4
--- /dev/null
+++ b/tests/tests/preference2/res/xml/fragmented_preferences.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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. -->
+<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" />
+
+ </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>
+
diff --git a/tests/tests/preference2/res/xml/fragmented_preferences_inner.xml b/tests/tests/preference2/res/xml/fragmented_preferences_inner.xml
new file mode 100755
index 0000000..fe235db
--- /dev/null
+++ b/tests/tests/preference2/res/xml/fragmented_preferences_inner.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<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>
+
diff --git a/tests/tests/preference2/res/xml/pref_cb.xml b/tests/tests/preference2/res/xml/pref_cb.xml
new file mode 100755
index 0000000..b5f77b9
--- /dev/null
+++ b/tests/tests/preference2/res/xml/pref_cb.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2012 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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:in="http://schemas.android.com/apk/res/com.android.cts.preference2" >
+
+ <PreferenceCategory android:title="@string/inline_preferences" >
+ <android.preference2.cts.CustomCheckBoxPreference
+ android:id="@+id/custom_check"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="25dp"
+ android:key="custom_checkbox_pref_1"
+ in:icon="@drawable/ic_launcher"
+ in:title="@string/preset_title" />
+ <android.preference2.cts.CustomSwitchPreference
+ android:id="@+id/custom_switch"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="25dp"
+ android:key="custom_switch_pref_1"
+ in:icon="@drawable/ic_launcher"
+ in:title="@string/preset_title" />
+
+ <android.preference2.cts.CustomDialogPreference
+ android:id="@+id/custom_switch"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="25dp"
+ android:key="custom_dialog_pref_1"
+ in:icon="@drawable/ic_launcher"
+ in:title="@string/preset_title" />
+
+ <android.preference2.cts.CustomEditTextPreference
+ android:id="@+id/custom_switch"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="25dp"
+ android:key="custom_edittext_pref_1"
+ in:icon="@drawable/ic_launcher"
+ in:title="@string/preset_title" />
+ </PreferenceCategory>
+</PreferenceScreen>
diff --git a/tests/tests/preference2/res/xml/preference_dependencies.xml b/tests/tests/preference2/res/xml/preference_dependencies.xml
new file mode 100755
index 0000000..405cad6
--- /dev/null
+++ b/tests/tests/preference2/res/xml/preference_dependencies.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<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>
diff --git a/tests/tests/preference2/res/xml/preference_headers.xml b/tests/tests/preference2/res/xml/preference_headers.xml
new file mode 100755
index 0000000..45ee629
--- /dev/null
+++ b/tests/tests/preference2/res/xml/preference_headers.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<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>
diff --git a/tests/tests/preference2/res/xml/preferences.xml b/tests/tests/preference2/res/xml/preferences.xml
new file mode 100755
index 0000000..fa35107
--- /dev/null
+++ b/tests/tests/preference2/res/xml/preferences.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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. -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <PreferenceCategory
+ android:title="@string/inline_preferences">
+
+ <CheckBoxPreference android:id="@+id/checkbox1"
+ 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" />
+ </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>
+
diff --git a/tests/tests/preference2/src/android/preference2/cts/CheckBoxPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CheckBoxPreferenceTest.java
new file mode 100755
index 0000000..de129e0
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CheckBoxPreferenceTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.preference.CheckBoxPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.cts.preference2.R;
+
+public class CheckBoxPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+ private PreferenceFromCodeActivity mActivity;
+
+ public CheckBoxPreferenceTest() {
+ super(PreferenceFromCodeActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ }
+
+ public void testNotNull() {
+ CheckBoxPreference checkBoxPref = (CheckBoxPreference) mActivity.findPreference(
+ "checkbox_preference");
+ assertNotNull(checkBoxPref);
+ }
+
+ public void testGetSummary() {
+ CheckBoxPreference checkBoxPref = (CheckBoxPreference) mActivity.findPreference(
+ "checkbox_preference");
+ String summary = (String) checkBoxPref.getSummary();
+ String summaryExp = mActivity.getResources().getString(
+ R.string.summary_checkbox_preference);
+ assertEquals(summaryExp, summary);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreference.java
new file mode 100755
index 0000000..d51eddd
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreference.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.CheckBoxPreference;
+import android.util.AttributeSet;
+
+public class CustomCheckBoxPreference extends CheckBoxPreference {
+ private Drawable mIcon;
+ private String mTitle;
+ public CustomCheckBoxPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(attrs);
+ setIcon(mIcon);
+ this.setTitle(mTitle);
+ }
+
+ public CustomCheckBoxPreference(Context context) {
+ super(context);
+ }
+
+ public CustomCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(attrs);
+ setIcon(mIcon);
+ this.setTitle(mTitle);
+ }
+
+ private void init(AttributeSet attrs) {
+ TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+ mTitle = a.getString(R.styleable.CustPref_title);
+ mIcon = a.getDrawable(R.styleable.CustPref_icon);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreferenceTest.java
new file mode 100755
index 0000000..25ba3f3
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreferenceTest.java
@@ -0,0 +1,44 @@
+ /*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.preference.CheckBoxPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class CustomCheckBoxPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferencesFromXml> {
+
+ private PreferencesFromXml mActivity;
+ private CheckBoxPreference mCheckBoxPref;
+
+ public CustomCheckBoxPreferenceTest() {
+ super(PreferencesFromXml.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mCheckBoxPref = (CheckBoxPreference) mActivity.findPreference(
+ "custom_checkbox_pref_1");
+ }
+
+ public void testNotNull() {
+ assertNotNull(mCheckBoxPref);
+ }
+
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreference.java
new file mode 100755
index 0000000..db584ac
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreference.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+
+public class CustomDialogPreference extends DialogPreference {
+ private Drawable mIcon;
+ private String mTitle;
+ public CustomDialogPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(attrs);
+ setIcon(mIcon);
+ this.setTitle(mTitle);
+ }
+
+ public CustomDialogPreference(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(attrs);
+ setIcon(mIcon);
+ this.setTitle(mTitle);
+ }
+
+ private void init(AttributeSet attrs) {
+ TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+ mTitle = a.getString(R.styleable.CustPref_title);
+ mIcon = a.getDrawable(R.styleable.CustPref_icon);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreferenceTest.java
new file mode 100755
index 0000000..5384420
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreferenceTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class CustomDialogPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferencesFromXml> {
+
+ private PreferencesFromXml mActivity;
+ private CustomDialogPreference mDialogPref;
+
+ public CustomDialogPreferenceTest() {
+ super(PreferencesFromXml.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mDialogPref = (CustomDialogPreference) mActivity.findPreference(
+ "custom_dialog_pref_1");
+ }
+
+ public void testNotNull() {
+ assertNotNull(mDialogPref);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreference.java
new file mode 100755
index 0000000..51fdf13
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreference.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.EditTextPreference;
+import android.util.AttributeSet;
+
+public class CustomEditTextPreference extends EditTextPreference {
+ private Drawable mIcon;
+ private String mTitle;
+ public CustomEditTextPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(attrs);
+ setIcon(mIcon);
+ this.setTitle(mTitle);
+ }
+
+ public CustomEditTextPreference(Context context) {
+ super(context);
+ }
+
+ public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(attrs);
+ setIcon(mIcon);
+ this.setTitle(mTitle);
+ }
+
+ private void init(AttributeSet attrs) {
+ TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+ mTitle =a.getString(R.styleable.CustPref_title);
+ mIcon = a.getDrawable(R.styleable.CustPref_icon);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreferenceTest.java
new file mode 100755
index 0000000..c131539
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreferenceTest.java
@@ -0,0 +1,42 @@
+ /*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class CustomEditTextPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferencesFromXml> {
+
+ private PreferencesFromXml mActivity;
+ private CustomEditTextPreference mEditTextPref;
+
+ public CustomEditTextPreferenceTest() {
+ super(PreferencesFromXml.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = (PreferencesFromXml)getActivity();
+ mEditTextPref = (CustomEditTextPreference) mActivity.findPreference(
+ "custom_edittext_pref_1");
+ }
+
+ public void testNotNull() {
+ assertNotNull(mEditTextPref);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreference.java
new file mode 100755
index 0000000..54e7861
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreference.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.SwitchPreference;
+import android.util.AttributeSet;
+
+public class CustomSwitchPreference extends SwitchPreference {
+ private Drawable mIcon;
+ private String mTitle;
+ public CustomSwitchPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(attrs);
+ setIcon(mIcon);
+ this.setTitle(mTitle);
+ }
+
+ public CustomSwitchPreference(Context context) {
+ super(context);
+ }
+
+ public CustomSwitchPreference(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(attrs);
+ setIcon(mIcon);
+ this.setTitle(mTitle);
+ }
+
+ private void init(AttributeSet attrs) {
+ TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+ mTitle =a.getString(R.styleable.CustPref_title);
+ mIcon = a.getDrawable(R.styleable.CustPref_icon);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreferenceTest.java
new file mode 100755
index 0000000..937e48f
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreferenceTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class CustomSwitchPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferencesFromXml> {
+
+ private PreferencesFromXml mActivity;
+ private CustomSwitchPreference mSwitchPref;
+
+ public CustomSwitchPreferenceTest() {
+ super(PreferencesFromXml.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mSwitchPref = (CustomSwitchPreference) mActivity.findPreference(
+ "custom_switch_pref_1");
+ }
+
+ public void testNotNull() {
+ assertNotNull(mSwitchPref);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/DialogPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/DialogPreferenceTest.java
new file mode 100755
index 0000000..1136cee
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/DialogPreferenceTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.graphics.drawable.Drawable;
+import android.preference.DialogPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.cts.preference2.R;
+
+public class DialogPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+ private PreferenceFromCodeActivity mActivity;
+ private DialogPreference mDialogPreference;
+
+ public DialogPreferenceTest() {
+ super(PreferenceFromCodeActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mDialogPreference = (DialogPreference)mActivity.findPreference(
+ "dialog_preference");
+ }
+
+ public void testGetTitle() {
+ String title = (String) mDialogPreference.getTitle();
+ String titleExp = mActivity.getResources().getString(R.string.title_dialog_preference);
+ assertEquals(titleExp, title);
+ }
+
+ public void testGetDialogTitle() {
+ String title = (String) mDialogPreference.getDialogTitle();
+ String titleExp = mActivity.getResources().getString(
+ R.string.dialogtitle_dialog_preference);
+ assertEquals(titleExp, title);
+ }
+
+ public void testGetDialogIcon() {
+ Drawable drawable = mDialogPreference.getDialogIcon();
+ Drawable drawableExp = mActivity.getResources().getDrawable(R.drawable.ic_launcher);
+ assertEquals(drawableExp.getBounds(), drawable.getBounds());
+ }
+
+ public void testGetDialogMessage() {
+ CharSequence dialogMessage = mDialogPreference.getDialogMessage();
+ CharSequence dialogMessageExp = mActivity.getResources().getString(
+ R.string.dialog_message);
+ assertEquals(dialogMessageExp, dialogMessage);
+ }
+
+ public void testGetPositiveButtonText() {
+ CharSequence positiveButtonText = mDialogPreference.getPositiveButtonText();
+ CharSequence postiveButtonTextExp = mActivity.getResources().getString(
+ R.string.positive_button_text);
+ assertEquals(positiveButtonText, postiveButtonTextExp);
+ }
+
+ public void testGetNegativeButtonText() {
+ CharSequence negativeButtonText = mDialogPreference.getNegativeButtonText();
+ CharSequence negativeButtonTextExp = mActivity.getResources().getString(
+ R.string.negative_button_text);
+ assertEquals(negativeButtonText, negativeButtonTextExp);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/EditTextPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/EditTextPreferenceTest.java
new file mode 100755
index 0000000..e0d5c8c
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/EditTextPreferenceTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.preference.EditTextPreference;
+import android.test.ActivityInstrumentationTestCase2;
+import android.widget.EditText;
+
+public class EditTextPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+ private PreferenceFromCodeActivity mActivity;
+ private EditTextPreference mEditTextPref;
+
+ public EditTextPreferenceTest() {
+ super(PreferenceFromCodeActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mEditTextPref = (EditTextPreference) mActivity.findPreference(
+ "edittext_preference");
+ }
+
+ public void testGetEditText() {
+ EditText editText = mEditTextPref.getEditText();
+ assertNotNull(editText);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/ListPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/ListPreferenceTest.java
new file mode 100755
index 0000000..32596ff
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/ListPreferenceTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.preference.ListPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.cts.preference2.R;
+
+public class ListPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+ private PreferenceFromCodeActivity mActivity;
+ private ListPreference mListPref;
+
+ public ListPreferenceTest() {
+ super(PreferenceFromCodeActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mListPref = (ListPreference) mActivity.findPreference("list_preference");
+ }
+
+ public void testGetEntries() {
+ String[] entries = convertToStringArray((CharSequence[]) mListPref.getEntries());
+ String[] entriesExp = mActivity.getResources().getStringArray(
+ R.array.entries_list_preference);
+ compareArrays(entriesExp, entries);
+ }
+
+ public void testGetEntryValues() {
+ String[] entryValues = convertToStringArray((CharSequence[]) mListPref.getEntryValues());
+ String[] entryValuesExp = mActivity.getResources().getStringArray(
+ R.array.entryvalues_list_preference);
+ compareArrays(entryValuesExp,entryValues);
+ }
+
+ public void testIsEnabled() {
+ boolean isEnabled = mListPref.isEnabled();
+ assertTrue(isEnabled);
+ }
+
+ private synchronized String[] convertToStringArray(CharSequence[] array){
+ String[] strArray = new String[array.length];
+ for(int i = 0; i < array.length; i++){
+ strArray[i] = (String) array[i];
+ }
+ return strArray;
+ }
+
+ private void compareArrays(String[] firstArray,String[] secArray){
+ assertEquals(firstArray.length, secArray.length);
+ for(int i = 0; i < firstArray.length; i++) {
+ assertEquals(firstArray[i], secArray[i]);
+ }
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceCategoryTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceCategoryTest.java
new file mode 100755
index 0000000..33adceb
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceCategoryTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.preference.Preference;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class PreferenceCategoryTest
+ extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+ private PreferenceFromCodeActivity mActivity;
+
+ public PreferenceCategoryTest() {
+ super(PreferenceFromCodeActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ }
+
+ public void testPreferenceCategory() {
+ Preference prefCat = mActivity.findPreference("pref-1");
+ assertNotNull(prefCat);
+ assertTrue(!prefCat.isEnabled());
+
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentActivity.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentActivity.java
new file mode 100755
index 0000000..4f12d17
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentActivity.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.app.Activity;
+import android.app.FragmentTransaction;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+/**
+ * Demonstration of PreferenceFragment, showing a single fragment in an
+ * activity.
+ */
+public class PreferenceFragmentActivity extends Activity {
+
+ public PrefFragment prefFragment;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ prefFragment = new PrefFragment();
+
+ FragmentTransaction transaction = getFragmentManager().beginTransaction()
+ .replace(android.R.id.content, prefFragment, PrefFragment.TAG);
+ transaction.commit();
+ }
+
+ public class PrefFragment extends PreferenceFragment {
+ public static final String TAG = "Pref-1";
+
+ public PrefFragment() {
+
+ }
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentTest.java
new file mode 100755
index 0000000..4c883c2
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.preference2.cts.PreferenceFragmentActivity.PrefFragment;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class PreferenceFragmentTest
+ extends ActivityInstrumentationTestCase2<PreferenceFragmentActivity> {
+
+ private PreferenceFragmentActivity mActivity;
+
+ public PreferenceFragmentTest() {
+ super(PreferenceFragmentActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ }
+
+ public void testGetPreferenceManager() {
+ PrefFragment prefFragment = (PrefFragment) mActivity.getFragmentManager().
+ findFragmentByTag(PrefFragment.TAG);
+ PreferenceManager prefManager = prefFragment.getPreferenceManager();
+ assertNotNull(prefManager);
+ }
+
+ public void testGetPreferenceScreen() {
+ PrefFragment prefsFragment = (PrefFragment) mActivity.getFragmentManager().
+ findFragmentByTag(PrefFragment.TAG);
+ PreferenceScreen prefScreen = prefsFragment.getPreferenceScreen();
+ assertNull(prefScreen);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java
new file mode 100755
index 0000000..ee0dde1
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
+
+public class PreferenceFromCodeActivity extends PreferenceActivity {
+ private Preference mPref;
+ protected PreferenceScreen mPrefScreen;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mPrefScreen = getPreferenceManager().createPreferenceScreen(this);
+ addPreferenceCategory();
+ setPreferenceScreen(mPrefScreen);
+ }
+
+ private void addPreferenceCategory() {
+ PreferenceCategory prefCat = new PreferenceCategory(this);
+ prefCat.setTitle(R.string.inline_preferences);
+ prefCat.setKey("pref-1");
+ mPrefScreen.addPreference(prefCat);
+
+ //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);
+ checkboxPref.setSummaryOn(R.string.summary_on_checkbox_preference);
+ checkboxPref.setSummaryOff(R.string.summary_off_checkbox_preference);
+ checkboxPref.setChecked(true);
+ checkboxPref.shouldDisableDependents();
+ prefCat.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);
+ switchPref.setSummaryOn(R.string.summary_on_switch_preference);
+ switchPref.setSummaryOff(R.string.summary_off_switch_preference);
+ switchPref.setSwitchTextOff(R.string.switchtext_off);
+ switchPref.setSwitchTextOn(R.string.switchtext_on);
+ prefCat.addPreference(switchPref);
+
+ SwitchPreference switchPref2 = new SwitchPreference(this);
+ switchPref2.setKey("switch_preference_2");
+ switchPref2.setTitle(R.string.title_switch_preference);
+ switchPref2.setSummary(R.string.summary_switch_preference);
+ switchPref2.setSummaryOn(R.string.summary_on_switch_preference);
+ switchPref2.setSummaryOff(R.string.summary_off_switch_preference);
+ prefCat.addPreference(switchPref2);
+
+ // Dialog based preferences
+ PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
+ dialogBasedPrefCat.setTitle(R.string.dialog_based_preferences);
+ mPrefScreen.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);
+ editTextPref.setText(getResources().getString(R.string.text_edittext_preference));
+ dialogBasedPrefCat.addPreference(editTextPref);
+
+ EditTextPreference dialogPref = new EditTextPreference(this);
+ dialogPref.setDialogTitle(R.string.dialogtitle_dialog_preference);
+ dialogPref.setKey("dialog_preference");
+ dialogPref.setTitle(R.string.title_dialog_preference);
+ dialogPref.setSummary(R.string.summary_dialog_preference);
+ dialogPref.setDialogIcon(R.drawable.ic_launcher);
+ dialogPref.setDialogMessage(R.string.dialog_message);
+ dialogPref.setNegativeButtonText(R.string.negative_button_text);
+ dialogPref.setPositiveButtonText(R.string.positive_button_text);
+
+ dialogBasedPrefCat.addPreference(dialogPref);
+
+ 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);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java
new file mode 100755
index 0000000..7a23daf
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.widget.Button;
+import com.android.cts.preference2.R;
+import java.util.List;
+
+/**
+ * Demonstration of PreferenceActivity to make a top-level preference
+ * panel with headers.
+ */
+
+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);
+ }
+}
+
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java
new file mode 100755
index 0000000..5b78369
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class PreferenceWithHeadersTest
+ extends ActivityInstrumentationTestCase2<PreferenceWithHeaders> {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ }
+
+ private PreferenceWithHeaders mActivity;
+
+ public PreferenceWithHeadersTest() {
+ super(PreferenceWithHeaders.class);
+ }
+
+ public void testHasHeaders() {
+ assertTrue(mActivity.hasHeaders());
+ }
+
+ public void testOnIsHidingHeaders() {
+ assertFalse(mActivity.onIsHidingHeaders());
+ }
+
+ public class PrefsOneFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.preferences);
+ }
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferencesFromXml.java b/tests/tests/preference2/src/android/preference2/cts/PreferencesFromXml.java
new file mode 100755
index 0000000..0a61461
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferencesFromXml.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import com.android.cts.preference2.R;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class PreferencesFromXml extends PreferenceActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.pref_cb);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/SwitchPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/SwitchPreferenceTest.java
new file mode 100755
index 0000000..3bd42d2
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/SwitchPreferenceTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2012 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 android.preference2.cts;
+
+import android.content.res.Resources;
+import android.preference.SwitchPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.cts.preference2.R;
+
+public class SwitchPreferenceTest
+ extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+ private PreferenceFromCodeActivity mActivity;
+ private SwitchPreference mSwitchPref;
+ private Resources mResources;
+
+ public SwitchPreferenceTest() {
+ super(PreferenceFromCodeActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mSwitchPref = (SwitchPreference) mActivity.findPreference(
+ "switch_preference");
+ mResources = mActivity.getResources();
+ }
+
+ public void testGetTitle() {
+ String title = (String) mSwitchPref.getTitle();
+ String titleExp = mResources.getString(R.string.title_switch_preference);
+ assertEquals(titleExp, title);
+ }
+
+ public void testGetSummary() {
+ String summary = (String) mSwitchPref.getSummary();
+ String summaryExp = mResources.getString(R.string.summary_switch_preference);
+ assertEquals(summaryExp, summary);
+ }
+
+ public void testGetSummaryOn() {
+ String summaryOn = (String) mSwitchPref.getSummaryOn();
+ String summaryOnExp = mResources.getString(
+ R.string.summary_on_switch_preference);
+ assertEquals(summaryOnExp, summaryOn);
+ }
+
+ public void testSummaryOff() {
+ String summaryOff = (String) mSwitchPref.getSummaryOff();
+ String summaryOffExp = mResources.getString(
+ R.string.summary_off_switch_preference);
+ assertEquals(summaryOffExp, summaryOff);
+ }
+
+ public void testSetSwitchTextOff_One() throws Throwable {
+ final CharSequence switchOff = "SwitchedOff";
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mSwitchPref.setSwitchTextOff(switchOff);
+ }
+ });
+ CharSequence switchOffExp = mSwitchPref.getSwitchTextOff();
+ assertEquals(switchOffExp, switchOff);
+ }
+
+ public void testSetSwitchTextOff_Two() throws Throwable {
+ final CharSequence switchOffExp = mResources.getString(
+ R.string.switchtext_off);
+ CharSequence switchOff = mSwitchPref.getSwitchTextOff();
+ assertEquals(switchOffExp, switchOff);
+ }
+
+ public void testSetSwitchTextOn_One() throws Throwable {
+ final CharSequence switchOn = "SwitchedOff";
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mSwitchPref.setSwitchTextOn(switchOn);
+ }
+ });
+ CharSequence switchOnExp = mSwitchPref.getSwitchTextOn();
+ assertEquals(switchOnExp, switchOn);
+ }
+
+ public void testSetSwitchTextOn_Two() throws Throwable {
+ final CharSequence switchOnExp = mResources.getString(
+ R.string.switchtext_on);
+
+ CharSequence switchOn = mSwitchPref.getSwitchTextOn();
+ assertEquals(switchOnExp, switchOn);
+ }
+}