Add new sample for multi-pane PreferenceActivity.
Also re-arrange all preference API demos to go in their own package, since the preferfence APIs themselves are in their own package. Change-Id: I305f77dc09748bb60d1de8a23d063db64c11bb1e
This commit is contained in:
@@ -48,7 +48,7 @@
|
|||||||
to be installed if it doesn't exist. -->
|
to be installed if it doesn't exist. -->
|
||||||
<uses-library android:name="com.example.will.never.exist" android:required="false" />
|
<uses-library android:name="com.example.will.never.exist" android:required="false" />
|
||||||
|
|
||||||
<activity android:name="ApiDemos">
|
<activity android:name="ApiDemos" android:screenOrientation="landscape">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
@@ -277,14 +277,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".app.FragmentPreferences"
|
|
||||||
android:label="@string/fragment_preferences">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.SAMPLE_CODE" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name=".app.FragmentRetainInstance"
|
<activity android:name=".app.FragmentRetainInstance"
|
||||||
android:label="@string/fragment_retain_instance">
|
android:label="@string/fragment_retain_instance">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -617,50 +609,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!-- Preferences Samples -->
|
|
||||||
|
|
||||||
<activity android:name=".app.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=".app.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=".app.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=".app.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=".app.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=".app.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>
|
|
||||||
|
|
||||||
<!-- Device Admin Samples -->
|
<!-- Device Admin Samples -->
|
||||||
|
|
||||||
<activity android:name=".app.DeviceAdminSample$Controller"
|
<activity android:name=".app.DeviceAdminSample$Controller"
|
||||||
@@ -702,6 +650,73 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<!-- ************************************* -->
|
||||||
|
<!-- PREFERENCE PACKAGE SAMPLES -->
|
||||||
|
<!-- ************************************* -->
|
||||||
|
|
||||||
|
<activity android:name=".preference.FragmentPreferences"
|
||||||
|
android:label="@string/fragment_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.PreferenceWithHeaders"
|
||||||
|
android:label="@string/preference_with_headers">
|
||||||
|
<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>
|
||||||
|
|
||||||
<!-- ************************************* -->
|
<!-- ************************************* -->
|
||||||
<!-- CONTENT PACKAGE SAMPLES -->
|
<!-- CONTENT PACKAGE SAMPLES -->
|
||||||
<!-- ************************************* -->
|
<!-- ************************************* -->
|
||||||
|
|||||||
BIN
samples/ApiDemos/res/drawable-mdpi/ic_settings_applications.png
Executable file
BIN
samples/ApiDemos/res/drawable-mdpi/ic_settings_applications.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
BIN
samples/ApiDemos/res/drawable-mdpi/ic_settings_display.png
Normal file
BIN
samples/ApiDemos/res/drawable-mdpi/ic_settings_display.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -21,7 +21,7 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
<fragment android:name="com.example.android.apis.app.FragmentPreferences$CategoriesFragment"
|
<fragment android:name="com.example.android.apis.preference.FragmentPreferences$CategoriesFragment"
|
||||||
android:id="@+id/categories"
|
android:id="@+id/categories"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0px"
|
android:layout_height="0px"
|
||||||
|
|||||||
@@ -107,8 +107,6 @@
|
|||||||
<string name="fragment1menu">Show fragment 1 menu</string>
|
<string name="fragment1menu">Show fragment 1 menu</string>
|
||||||
<string name="fragment2menu">Show fragment 2 menu</string>
|
<string name="fragment2menu">Show fragment 2 menu</string>
|
||||||
|
|
||||||
<string name="fragment_preferences">App/Fragment/Preferences</string>
|
|
||||||
|
|
||||||
<string name="fragment_retain_instance">App/Fragment/Retain Instance</string>
|
<string name="fragment_retain_instance">App/Fragment/Retain Instance</string>
|
||||||
<string name="fragment_retain_instance_msg">Current progress of retained fragment;
|
<string name="fragment_retain_instance_msg">Current progress of retained fragment;
|
||||||
restarts if fragment is re-created.</string>
|
restarts if fragment is re-created.</string>
|
||||||
@@ -384,12 +382,14 @@
|
|||||||
<!-- app/menu examples strings -->
|
<!-- app/menu examples strings -->
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
|
|
||||||
<string name="preferences_from_xml">App/Preferences/1. Preferences from XML</string>
|
<string name="preferences_from_xml">Preference/1. Preferences from XML</string>
|
||||||
<string name="launching_preferences">App/Preferences/2. Launching preferences</string>
|
<string name="launching_preferences">Preference/2. Launching preferences</string>
|
||||||
<string name="preference_dependencies">App/Preferences/3. Preference dependencies</string>
|
<string name="preference_dependencies">Preference/3. Preference dependencies</string>
|
||||||
<string name="default_values">App/Preferences/4. Default values</string>
|
<string name="default_values">Preference/4. Default values</string>
|
||||||
<string name="preferences_from_code">App/Preferences/5. Preferences from code</string>
|
<string name="preferences_from_code">Preference/5. Preferences from code</string>
|
||||||
<string name="advanced_preferences">App/Preferences/6. Advanced preferences</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="launch_preference_activity">Launch PreferenceActivity</string>
|
||||||
<string name="counter_value_is">The counter value is</string>
|
<string name="counter_value_is">The counter value is</string>
|
||||||
|
|||||||
31
samples/ApiDemos/res/xml/preference_headers.xml
Normal file
31
samples/ApiDemos/res/xml/preference_headers.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?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) -->
|
||||||
|
<PreferenceHeaders
|
||||||
|
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." />
|
||||||
|
</PreferenceHeaders>
|
||||||
|
<!-- END_INCLUDE(headers) -->
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- This is a primitive example showing the different types of preferences available. -->
|
<!-- This is a primitive example showing the different types of preferences available. -->
|
||||||
|
<!-- BEGIN_INCLUDE(preferences) -->
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
@@ -97,3 +98,4 @@
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
<!-- END_INCLUDE(preferences) -->
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class FragmentDialog extends Activity {
|
|||||||
mStackLevel++;
|
mStackLevel++;
|
||||||
DialogFragment newFragment = new MyDialogFragment(mStackLevel);
|
DialogFragment newFragment = new MyDialogFragment(mStackLevel);
|
||||||
FragmentTransaction ft = openFragmentTransaction();
|
FragmentTransaction ft = openFragmentTransaction();
|
||||||
Fragment prev = this.findFragmentByTag("dialog");
|
Fragment prev = findFragmentByTag("dialog");
|
||||||
if (prev != null) {
|
if (prev != null) {
|
||||||
ft.remove(prev);
|
ft.remove(prev);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.example.android.apis.app;
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class AdvancedPreferences extends PreferenceActivity implements OnSharedP
|
|||||||
|
|
||||||
private CheckBoxPreference mCheckBoxPreference;
|
private CheckBoxPreference mCheckBoxPreference;
|
||||||
private Handler mHandler = new Handler();
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a simple example of controlling a preference from code.
|
* This is a simple example of controlling a preference from code.
|
||||||
*/
|
*/
|
||||||
@@ -44,19 +44,19 @@ public class AdvancedPreferences extends PreferenceActivity implements OnSharedP
|
|||||||
if (mCheckBoxPreference != null) {
|
if (mCheckBoxPreference != null) {
|
||||||
mCheckBoxPreference.setChecked(!mCheckBoxPreference.isChecked());
|
mCheckBoxPreference.setChecked(!mCheckBoxPreference.isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force toggle again in a second
|
// Force toggle again in a second
|
||||||
mHandler.postDelayed(this, 1000);
|
mHandler.postDelayed(this, 1000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Load the XML preferences file
|
// Load the XML preferences file
|
||||||
addPreferencesFromResource(R.xml.advanced_preferences);
|
addPreferencesFromResource(R.xml.advanced_preferences);
|
||||||
|
|
||||||
// Get a reference to the checkbox preference
|
// Get a reference to the checkbox preference
|
||||||
mCheckBoxPreference = (CheckBoxPreference)getPreferenceScreen().findPreference(
|
mCheckBoxPreference = (CheckBoxPreference)getPreferenceScreen().findPreference(
|
||||||
KEY_ADVANCED_CHECKBOX_PREFERENCE);
|
KEY_ADVANCED_CHECKBOX_PREFERENCE);
|
||||||
@@ -68,7 +68,7 @@ public class AdvancedPreferences extends PreferenceActivity implements OnSharedP
|
|||||||
|
|
||||||
// Start the force toggle
|
// Start the force toggle
|
||||||
mForceCheckBoxRunnable.run();
|
mForceCheckBoxRunnable.run();
|
||||||
|
|
||||||
// Set up a listener whenever a key changes
|
// Set up a listener whenever a key changes
|
||||||
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ public class AdvancedPreferences extends PreferenceActivity implements OnSharedP
|
|||||||
|
|
||||||
// Unregister the listener whenever a key changes
|
// Unregister the listener whenever a key changes
|
||||||
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
mHandler.removeCallbacks(mForceCheckBoxRunnable);
|
mHandler.removeCallbacks(mForceCheckBoxRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,5 +90,5 @@ public class AdvancedPreferences extends PreferenceActivity implements OnSharedP
|
|||||||
+ sharedPreferences.getInt(key, 0), Toast.LENGTH_SHORT).show();
|
+ sharedPreferences.getInt(key, 0), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.example.android.apis.app;
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
import com.example.android.apis.ApiDemosApplication;
|
import com.example.android.apis.ApiDemosApplication;
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
@@ -46,7 +46,7 @@ public class DefaultValues extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.default_values);
|
addPreferencesFromResource(R.xml.default_values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,26 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.example.android.apis.app;
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
import com.example.android.apis.Shakespeare;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.ListFragment;
|
import android.app.ListFragment;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
|
||||||
import android.preference.EditTextPreference;
|
|
||||||
import android.preference.ListPreference;
|
|
||||||
import android.preference.PreferenceCategory;
|
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceScreen;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
@@ -81,6 +70,7 @@ public class FragmentPreferences extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//BEGIN_INCLUDE(fragment)
|
||||||
public static class Prefs1Fragment extends PreferenceFragment {
|
public static class Prefs1Fragment extends PreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -90,6 +80,7 @@ public class FragmentPreferences extends Activity {
|
|||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//END_INCLUDE(fragment)
|
||||||
|
|
||||||
public static class Prefs2Fragment extends PreferenceFragment {
|
public static class Prefs2Fragment extends PreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.example.android.apis.app;
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
@@ -36,9 +36,9 @@ import android.widget.LinearLayout.LayoutParams;
|
|||||||
public class LaunchingPreferences extends Activity implements OnClickListener {
|
public class LaunchingPreferences extends Activity implements OnClickListener {
|
||||||
|
|
||||||
private static final int REQUEST_CODE_PREFERENCES = 1;
|
private static final int REQUEST_CODE_PREFERENCES = 1;
|
||||||
|
|
||||||
private TextView mCounterText;
|
private TextView mCounterText;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -50,33 +50,33 @@ public class LaunchingPreferences extends Activity implements OnClickListener {
|
|||||||
* subclass of Application, so your default values would be loaded
|
* subclass of Application, so your default values would be loaded
|
||||||
* regardless of entry into your application (for example, a service or
|
* regardless of entry into your application (for example, a service or
|
||||||
* activity).
|
* activity).
|
||||||
*/
|
*/
|
||||||
PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, false);
|
PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, false);
|
||||||
|
|
||||||
// Simple layout
|
// Simple layout
|
||||||
LinearLayout layout = new LinearLayout(this);
|
LinearLayout layout = new LinearLayout(this);
|
||||||
layout.setOrientation(LinearLayout.VERTICAL);
|
layout.setOrientation(LinearLayout.VERTICAL);
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Create a simple button that will launch the preferences
|
// Create a simple button that will launch the preferences
|
||||||
Button launchPreferences = new Button(this);
|
Button launchPreferences = new Button(this);
|
||||||
launchPreferences.setText(getString(R.string.launch_preference_activity));
|
launchPreferences.setText(getString(R.string.launch_preference_activity));
|
||||||
launchPreferences.setOnClickListener(this);
|
launchPreferences.setOnClickListener(this);
|
||||||
layout.addView(launchPreferences, new LayoutParams(LayoutParams.MATCH_PARENT,
|
layout.addView(launchPreferences, new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||||
LayoutParams.WRAP_CONTENT));
|
LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
mCounterText = new TextView(this);
|
mCounterText = new TextView(this);
|
||||||
layout.addView(mCounterText, new LayoutParams(LayoutParams.MATCH_PARENT,
|
layout.addView(mCounterText, new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||||
LayoutParams.WRAP_CONTENT));
|
LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
updateCounterText();
|
updateCounterText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
// When the button is clicked, launch an activity through this intent
|
// When the button is clicked, launch an activity through this intent
|
||||||
Intent launchPreferencesIntent = new Intent().setClass(this, AdvancedPreferences.class);
|
Intent launchPreferencesIntent = new Intent().setClass(this, AdvancedPreferences.class);
|
||||||
|
|
||||||
// Make it a subactivity so we know when it returns
|
// Make it a subactivity so we know when it returns
|
||||||
startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
|
startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ public class LaunchingPreferences extends Activity implements OnClickListener {
|
|||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
// The preferences returned if the request code is what we had given
|
// The preferences returned if the request code is what we had given
|
||||||
// earlier in startSubActivity
|
// earlier in startSubActivity
|
||||||
if (requestCode == REQUEST_CODE_PREFERENCES) {
|
if (requestCode == REQUEST_CODE_PREFERENCES) {
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.example.android.apis.app;
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ public class PreferenceDependencies extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.preference_dependencies);
|
addPreferencesFromResource(R.xml.preference_dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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 java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstration of PreferenceActivity to make a top-level preference
|
||||||
|
* panel with headers.
|
||||||
|
*/
|
||||||
|
//BEGIN_INCLUDE(activity)
|
||||||
|
public class PreferenceWithHeaders extends PreferenceActivity {
|
||||||
|
@Override
|
||||||
|
public void onBuildHeaders(List<Header> target) {
|
||||||
|
loadHeadersFromResource(R.xml.preference_headers, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Prefs1Fragment extends PreferenceFragment {
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.example.android.apis.app;
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
@@ -34,26 +34,26 @@ public class PreferencesFromCode extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setPreferenceScreen(createPreferenceHierarchy());
|
setPreferenceScreen(createPreferenceHierarchy());
|
||||||
}
|
}
|
||||||
|
|
||||||
private PreferenceScreen createPreferenceHierarchy() {
|
private PreferenceScreen createPreferenceHierarchy() {
|
||||||
// Root
|
// Root
|
||||||
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
|
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
|
||||||
|
|
||||||
// Inline preferences
|
// Inline preferences
|
||||||
PreferenceCategory inlinePrefCat = new PreferenceCategory(this);
|
PreferenceCategory inlinePrefCat = new PreferenceCategory(this);
|
||||||
inlinePrefCat.setTitle(R.string.inline_preferences);
|
inlinePrefCat.setTitle(R.string.inline_preferences);
|
||||||
root.addPreference(inlinePrefCat);
|
root.addPreference(inlinePrefCat);
|
||||||
|
|
||||||
// Toggle preference
|
// Toggle preference
|
||||||
CheckBoxPreference togglePref = new CheckBoxPreference(this);
|
CheckBoxPreference togglePref = new CheckBoxPreference(this);
|
||||||
togglePref.setKey("toggle_preference");
|
togglePref.setKey("toggle_preference");
|
||||||
togglePref.setTitle(R.string.title_toggle_preference);
|
togglePref.setTitle(R.string.title_toggle_preference);
|
||||||
togglePref.setSummary(R.string.summary_toggle_preference);
|
togglePref.setSummary(R.string.summary_toggle_preference);
|
||||||
inlinePrefCat.addPreference(togglePref);
|
inlinePrefCat.addPreference(togglePref);
|
||||||
|
|
||||||
// Dialog based preferences
|
// Dialog based preferences
|
||||||
PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
|
PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
|
||||||
dialogBasedPrefCat.setTitle(R.string.dialog_based_preferences);
|
dialogBasedPrefCat.setTitle(R.string.dialog_based_preferences);
|
||||||
@@ -66,7 +66,7 @@ public class PreferencesFromCode extends PreferenceActivity {
|
|||||||
editTextPref.setTitle(R.string.title_edittext_preference);
|
editTextPref.setTitle(R.string.title_edittext_preference);
|
||||||
editTextPref.setSummary(R.string.summary_edittext_preference);
|
editTextPref.setSummary(R.string.summary_edittext_preference);
|
||||||
dialogBasedPrefCat.addPreference(editTextPref);
|
dialogBasedPrefCat.addPreference(editTextPref);
|
||||||
|
|
||||||
// List preference
|
// List preference
|
||||||
ListPreference listPref = new ListPreference(this);
|
ListPreference listPref = new ListPreference(this);
|
||||||
listPref.setEntries(R.array.entries_list_preference);
|
listPref.setEntries(R.array.entries_list_preference);
|
||||||
@@ -76,7 +76,7 @@ public class PreferencesFromCode extends PreferenceActivity {
|
|||||||
listPref.setTitle(R.string.title_list_preference);
|
listPref.setTitle(R.string.title_list_preference);
|
||||||
listPref.setSummary(R.string.summary_list_preference);
|
listPref.setSummary(R.string.summary_list_preference);
|
||||||
dialogBasedPrefCat.addPreference(listPref);
|
dialogBasedPrefCat.addPreference(listPref);
|
||||||
|
|
||||||
// Launch preferences
|
// Launch preferences
|
||||||
PreferenceCategory launchPrefCat = new PreferenceCategory(this);
|
PreferenceCategory launchPrefCat = new PreferenceCategory(this);
|
||||||
launchPrefCat.setTitle(R.string.launch_preferences);
|
launchPrefCat.setTitle(R.string.launch_preferences);
|
||||||
@@ -93,19 +93,19 @@ public class PreferencesFromCode extends PreferenceActivity {
|
|||||||
screenPref.setTitle(R.string.title_screen_preference);
|
screenPref.setTitle(R.string.title_screen_preference);
|
||||||
screenPref.setSummary(R.string.summary_screen_preference);
|
screenPref.setSummary(R.string.summary_screen_preference);
|
||||||
launchPrefCat.addPreference(screenPref);
|
launchPrefCat.addPreference(screenPref);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* You can add more preferences to screenPref that will be shown on the
|
* You can add more preferences to screenPref that will be shown on the
|
||||||
* next screen.
|
* next screen.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Example of next screen toggle preference
|
// Example of next screen toggle preference
|
||||||
CheckBoxPreference nextScreenCheckBoxPref = new CheckBoxPreference(this);
|
CheckBoxPreference nextScreenCheckBoxPref = new CheckBoxPreference(this);
|
||||||
nextScreenCheckBoxPref.setKey("next_screen_toggle_preference");
|
nextScreenCheckBoxPref.setKey("next_screen_toggle_preference");
|
||||||
nextScreenCheckBoxPref.setTitle(R.string.title_next_screen_toggle_preference);
|
nextScreenCheckBoxPref.setTitle(R.string.title_next_screen_toggle_preference);
|
||||||
nextScreenCheckBoxPref.setSummary(R.string.summary_next_screen_toggle_preference);
|
nextScreenCheckBoxPref.setSummary(R.string.summary_next_screen_toggle_preference);
|
||||||
screenPref.addPreference(nextScreenCheckBoxPref);
|
screenPref.addPreference(nextScreenCheckBoxPref);
|
||||||
|
|
||||||
// Intent preference
|
// Intent preference
|
||||||
PreferenceScreen intentPref = getPreferenceManager().createPreferenceScreen(this);
|
PreferenceScreen intentPref = getPreferenceManager().createPreferenceScreen(this);
|
||||||
intentPref.setIntent(new Intent().setAction(Intent.ACTION_VIEW)
|
intentPref.setIntent(new Intent().setAction(Intent.ACTION_VIEW)
|
||||||
@@ -113,18 +113,18 @@ public class PreferencesFromCode extends PreferenceActivity {
|
|||||||
intentPref.setTitle(R.string.title_intent_preference);
|
intentPref.setTitle(R.string.title_intent_preference);
|
||||||
intentPref.setSummary(R.string.summary_intent_preference);
|
intentPref.setSummary(R.string.summary_intent_preference);
|
||||||
launchPrefCat.addPreference(intentPref);
|
launchPrefCat.addPreference(intentPref);
|
||||||
|
|
||||||
// Preference attributes
|
// Preference attributes
|
||||||
PreferenceCategory prefAttrsCat = new PreferenceCategory(this);
|
PreferenceCategory prefAttrsCat = new PreferenceCategory(this);
|
||||||
prefAttrsCat.setTitle(R.string.preference_attributes);
|
prefAttrsCat.setTitle(R.string.preference_attributes);
|
||||||
root.addPreference(prefAttrsCat);
|
root.addPreference(prefAttrsCat);
|
||||||
|
|
||||||
// Visual parent toggle preference
|
// Visual parent toggle preference
|
||||||
CheckBoxPreference parentCheckBoxPref = new CheckBoxPreference(this);
|
CheckBoxPreference parentCheckBoxPref = new CheckBoxPreference(this);
|
||||||
parentCheckBoxPref.setTitle(R.string.title_parent_preference);
|
parentCheckBoxPref.setTitle(R.string.title_parent_preference);
|
||||||
parentCheckBoxPref.setSummary(R.string.summary_parent_preference);
|
parentCheckBoxPref.setSummary(R.string.summary_parent_preference);
|
||||||
prefAttrsCat.addPreference(parentCheckBoxPref);
|
prefAttrsCat.addPreference(parentCheckBoxPref);
|
||||||
|
|
||||||
// Visual child toggle preference
|
// Visual child toggle preference
|
||||||
// See res/values/attrs.xml for the <declare-styleable> that defines
|
// See res/values/attrs.xml for the <declare-styleable> that defines
|
||||||
// TogglePrefAttrs.
|
// TogglePrefAttrs.
|
||||||
@@ -137,7 +137,7 @@ public class PreferencesFromCode extends PreferenceActivity {
|
|||||||
0));
|
0));
|
||||||
prefAttrsCat.addPreference(childCheckBoxPref);
|
prefAttrsCat.addPreference(childCheckBoxPref);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.example.android.apis.app;
|
package com.example.android.apis.preference;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ public class PreferencesFromXml extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Load the preferences from an XML resource
|
// Load the preferences from an XML resource
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user