Add facility to switch to new fragments from preferences.
Change-Id: I009315b59cf81b4962e9c5a4490f0f82743ed64a
diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java
index 381f794..117e507 100644
--- a/core/java/android/preference/Preference.java
+++ b/core/java/android/preference/Preference.java
@@ -56,6 +56,7 @@
* @attr ref android.R.styleable#Preference_title
* @attr ref android.R.styleable#Preference_summary
* @attr ref android.R.styleable#Preference_order
+ * @attr ref android.R.styleable#Preference_fragment
* @attr ref android.R.styleable#Preference_layout
* @attr ref android.R.styleable#Preference_widgetLayout
* @attr ref android.R.styleable#Preference_enabled
@@ -88,6 +89,7 @@
private CharSequence mSummary;
private String mKey;
private Intent mIntent;
+ private String mFragment;
private boolean mEnabled = true;
private boolean mSelectable = true;
private boolean mRequiresKey;
@@ -210,6 +212,10 @@
mOrder = a.getInt(attr, mOrder);
break;
+ case com.android.internal.R.styleable.Preference_fragment:
+ mFragment = a.getString(attr);
+ break;
+
case com.android.internal.R.styleable.Preference_layout:
mLayoutResId = a.getResourceId(attr, mLayoutResId);
break;
@@ -315,6 +321,24 @@
}
/**
+ * Sets the class name of a fragment to be shown when this Preference is clicked.
+ *
+ * @param fragment The class name of the fragment associated with this Preference.
+ */
+ public void setFragment(String fragment) {
+ mFragment = fragment;
+ }
+
+ /**
+ * Return the fragment class name associated with this Preference.
+ *
+ * @return The fragment class name last set via {@link #setFragment} or XML.
+ */
+ public String getFragment() {
+ return mFragment;
+ }
+
+ /**
* Sets the layout resource that is inflated as the {@link View} to be shown
* for this Preference. In most cases, the default layout is sufficient for
* custom Preference objects and only the widget layout needs to be changed.