Update preference samples.
Change-Id: Ia78d9c0f4f7e58f500aef55413b911904d0c40cd
diff --git a/samples/ApiDemos/res/layout-land/fragment_preferences.xml b/samples/ApiDemos/res/layout-land/fragment_preferences.xml
deleted file mode 100644
index 815ca02..0000000
--- a/samples/ApiDemos/res/layout-land/fragment_preferences.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?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.
--->
-
-<!-- Top-level content view for the layout fragment sample when displayed
- in landscape. -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <fragment class="com.example.android.apis.preference.FragmentPreferences$CategoriesFragment"
- android:id="@+id/categories"
- android:layout_width="0px"
- android:layout_height="match_parent"
- android:layout_weight=".3" />
- <FrameLayout android:id="@+id/prefs"
- android:layout_width="0px"
- android:layout_height="match_parent"
- android:layout_weight=".7" />
-</LinearLayout>
diff --git a/samples/ApiDemos/res/layout/fragment_preferences.xml b/samples/ApiDemos/res/layout/fragment_preferences.xml
deleted file mode 100644
index f3ba6c9..0000000
--- a/samples/ApiDemos/res/layout/fragment_preferences.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?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.
--->
-
-<!-- Top-level content view for the preference fragment sample. -->
-
-<!-- BEGIN_INCLUDE(layout) -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <fragment class="com.example.android.apis.preference.FragmentPreferences$CategoriesFragment"
- android:id="@+id/categories"
- android:layout_width="match_parent"
- android:layout_height="0px"
- android:layout_weight=".3" />
- <FrameLayout android:id="@+id/prefs"
- android:layout_width="match_parent"
- android:layout_height="0px"
- android:layout_weight=".7" />
-</LinearLayout>
-<!-- END_INCLUDE(layout) -->
diff --git a/samples/ApiDemos/res/xml/preference_headers.xml b/samples/ApiDemos/res/xml/preference_headers.xml
index 737aa22..7dcc531 100644
--- a/samples/ApiDemos/res/xml/preference_headers.xml
+++ b/samples/ApiDemos/res/xml/preference_headers.xml
@@ -32,6 +32,13 @@
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) -->
diff --git a/samples/ApiDemos/src/com/example/android/apis/preference/FragmentPreferences.java b/samples/ApiDemos/src/com/example/android/apis/preference/FragmentPreferences.java
index 02c53ab..b3cc6a3 100644
--- a/samples/ApiDemos/src/com/example/android/apis/preference/FragmentPreferences.java
+++ b/samples/ApiDemos/src/com/example/android/apis/preference/FragmentPreferences.java
@@ -19,61 +19,26 @@
import com.example.android.apis.R;
import android.app.Activity;
-import android.app.Fragment;
-import android.app.ListFragment;
import android.os.Bundle;
import android.preference.PreferenceFragment;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
/**
- * Demonstration of PreferenceFragment, splitting the activity into a
- * list categories and preferences.
+ * Demonstration of PreferenceFragment, showing a single fragment in an
+ * activity.
*/
-//BEGIN_INCLUDE(activity)
public class FragmentPreferences extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // The content for this activity places CategoriesFragment to one
- // side, and leaves the rest to dynamically add the prefs fragment.
- setContentView(R.layout.fragment_preferences);
- }
-
- /**
- * This fragment shows a list of categories the user can pick. When they
- * pick one, the corresponding preferences fragment is created and shown.
- */
- public static class CategoriesFragment extends ListFragment {
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- setListAdapter(new ArrayAdapter<String>(getActivity(),
- android.R.layout.simple_list_item_1,
- new String[] { "Prefs 1", "Prefs 2" }));
- switchPreferences(0);
- }
-
- @Override
- public void onListItemClick(ListView l, View v, int position, long id) {
- switchPreferences(position);
- }
-
- /**
- * Show the given preferences, replacing whatever was last shown.
- */
- void switchPreferences(int which) {
- Fragment f = which == 0 ? new Prefs1Fragment() : new Prefs2Fragment();
- getActivity().openFragmentTransaction().replace(R.id.prefs, f).commit();
- }
+ // Display the fragment as the main content.
+ getFragmentManager().openTransaction().replace(android.R.id.content,
+ new PrefsFragment()).commit();
}
//BEGIN_INCLUDE(fragment)
- public static class Prefs1Fragment extends PreferenceFragment {
+ public static class PrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -84,16 +49,4 @@
}
}
//END_INCLUDE(fragment)
-
- public static class Prefs2Fragment extends PreferenceFragment {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.preference_dependencies);
- }
- }
}
-//END_INCLUDE(activity)
diff --git a/samples/ApiDemos/src/com/example/android/apis/preference/PreferenceWithHeaders.java b/samples/ApiDemos/src/com/example/android/apis/preference/PreferenceWithHeaders.java
index 2f320d7..6437e1e 100644
--- a/samples/ApiDemos/src/com/example/android/apis/preference/PreferenceWithHeaders.java
+++ b/samples/ApiDemos/src/com/example/android/apis/preference/PreferenceWithHeaders.java
@@ -22,6 +22,7 @@
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.util.Log;
+import android.widget.Button;
import java.util.List;
@@ -31,6 +32,18 @@
*/
//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.
*/