Add support for saving and using the Preference's key value

- make public and hide the PreferenceGroupAdapter class
- add setActivated(int position) to be able to set the activated item
- udpate getView(int position, View convertView, ViewGroup parent) to set/unset
the activated item

Change-Id: I8a653ad6541bb6b7a043ba7c3d95e5ecad924a0d
diff --git a/core/java/android/preference/PreferenceGroupAdapter.java b/core/java/android/preference/PreferenceGroupAdapter.java
index 23d0a19..c2e1f51 100644
--- a/core/java/android/preference/PreferenceGroupAdapter.java
+++ b/core/java/android/preference/PreferenceGroupAdapter.java
@@ -45,8 +45,11 @@
  * adapter, use {@link PreferenceCategoryAdapter} instead.
  * 
  * @see PreferenceCategoryAdapter
+ *
+ * @hide
  */
-class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeInternalListener {
+public class PreferenceGroupAdapter extends BaseAdapter
+        implements OnPreferenceChangeInternalListener {
     
     private static final String TAG = "PreferenceGroupAdapter";
 
@@ -88,6 +91,8 @@
         }
     };
 
+    private int mActivatedPosition = -1;
+
     private static class PreferenceLayout implements Comparable<PreferenceLayout> {
         private int resId;
         private int widgetResId;
@@ -207,6 +212,10 @@
         return this.getItem(position).getId();
     }
 
+    public void setActivated(int position) {
+        mActivatedPosition = position;
+    }
+
     public View getView(int position, View convertView, ViewGroup parent) {
         final Preference preference = this.getItem(position);
         // Build a PreferenceLayout to compare with known ones that are cacheable.
@@ -217,8 +226,9 @@
         if (Collections.binarySearch(mPreferenceLayouts, mTempPreferenceLayout) < 0) {
             convertView = null;
         }
-
-        return preference.getView(convertView, parent);
+        View result = preference.getView(convertView, parent);
+        result.setActivated(position == mActivatedPosition);
+        return result;
     }
 
     @Override
diff --git a/core/res/res/layout/preference_holo.xml b/core/res/res/layout/preference_holo.xml
index 1cc803b..1b3ab86 100644
--- a/core/res/res/layout/preference_holo.xml
+++ b/core/res/res/layout/preference_holo.xml
@@ -23,7 +23,8 @@
     android:minHeight="?android:attr/listPreferredItemHeight"
     android:gravity="center_vertical"
     android:paddingStart="@dimen/preference_item_padding_side"
-    android:paddingEnd="?android:attr/scrollbarSize">
+    android:paddingEnd="?android:attr/scrollbarSize"
+    android:background="?android:attr/activatedBackgroundIndicator">
 
     <LinearLayout
         android:layout_width="wrap_content"