summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.xml39
-rw-r--r--core/java/android/preference/Preference.java59
-rw-r--r--core/res/res/layout/preference.xml20
-rw-r--r--core/res/res/layout/preference_child.xml22
-rw-r--r--core/res/res/values-land/dimens.xml4
-rwxr-xr-xcore/res/res/values/attrs.xml2
6 files changed, 135 insertions, 11 deletions
diff --git a/api/current.xml b/api/current.xml
index 839d387..319b280 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -144742,6 +144742,17 @@
visibility="public"
>
</method>
+<method name="getIcon"
+ return="android.graphics.drawable.Drawable"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
<method name="getIntent"
return="android.content.Intent"
abstract="false"
@@ -145328,6 +145339,32 @@
<parameter name="fragment" type="java.lang.String">
</parameter>
</method>
+<method name="setIcon"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="icon" type="android.graphics.drawable.Drawable">
+</parameter>
+</method>
+<method name="setIcon"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="iconResId" type="int">
+</parameter>
+</method>
<method name="setIntent"
return="void"
abstract="false"
@@ -246932,7 +246969,7 @@
deprecated="not deprecated"
visibility="public"
>
-<parameter name="arg0" type="T">
+<parameter name="t" type="T">
</parameter>
</method>
</interface>
diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java
index 12b9f0c..e869f3f 100644
--- a/core/java/android/preference/Preference.java
+++ b/core/java/android/preference/Preference.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -31,6 +32,7 @@ import android.view.AbsSavedState;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
@@ -52,6 +54,7 @@ import java.util.Set;
* {@link SharedPreferences}. It is up to the subclass to decide how to store
* the value.
*
+ * @attr ref android.R.styleable#Preference_icon
* @attr ref android.R.styleable#Preference_key
* @attr ref android.R.styleable#Preference_title
* @attr ref android.R.styleable#Preference_summary
@@ -87,6 +90,11 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
private int mOrder = DEFAULT_ORDER;
private CharSequence mTitle;
private CharSequence mSummary;
+ /**
+ * mIconResId is overridden by mIcon, if mIcon is specified.
+ */
+ private int mIconResId;
+ private Drawable mIcon;
private String mKey;
private Intent mIntent;
private String mFragment;
@@ -197,6 +205,10 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
for (int i = a.getIndexCount(); i >= 0; i--) {
int attr = a.getIndex(i);
switch (attr) {
+ case com.android.internal.R.styleable.Preference_icon:
+ mIconResId = a.getResourceId(attr, 0);
+ break;
+
case com.android.internal.R.styleable.Preference_key:
mKey = a.getString(attr);
break;
@@ -499,11 +511,20 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
}
}
+ ImageView imageView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
+ if (imageView != null && (mIconResId != 0 || mIcon != null)) {
+ if (mIcon == null) {
+ mIcon = getContext().getResources().getDrawable(mIconResId);
+ }
+ if (mIcon != null) {
+ imageView.setImageDrawable(mIcon);
+ }
+ }
if (mShouldDisableView) {
setEnabledStateOnViews(view, isEnabled());
}
}
-
+
/**
* Makes sure the view (and any children) get the enabled state changed.
*/
@@ -587,6 +608,42 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
}
/**
+ * Sets the icon for this Preference with a Drawable.
+ * This icon will be placed into the ID
+ * {@link android.R.id#icon} within the View created by
+ * {@link #onCreateView(ViewGroup)}.
+ *
+ * @param icon The optional icon for this Preference.
+ */
+ public void setIcon(Drawable icon) {
+ if ((icon == null && mIcon != null) || (icon != null && mIcon != icon)) {
+ mIcon = icon;
+ notifyChanged();
+ }
+ }
+
+ /**
+ * Sets the icon for this Preference with a resource ID.
+ *
+ * @see #setIcon(Drawable)
+ * @param iconResId The icon as a resource ID.
+ */
+ public void setIcon(int iconResId) {
+ mIconResId = iconResId;
+ setIcon(mContext.getResources().getDrawable(iconResId));
+ }
+
+ /**
+ * Returns the icon of this Preference.
+ *
+ * @return The icon.
+ * @see #setIcon(Drawable)
+ */
+ public Drawable getIcon() {
+ return mIcon;
+ }
+
+ /**
* Returns the summary of this Preference.
*
* @return The summary.
diff --git a/core/res/res/layout/preference.xml b/core/res/res/layout/preference.xml
index 46c3e9c..6bd5efa 100644
--- a/core/res/res/layout/preference.xml
+++ b/core/res/res/layout/preference.xml
@@ -24,13 +24,19 @@
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize">
- <!-- Preference should place its actual preference widget here. -->
- <LinearLayout android:id="@+android:id/widget_frame"
+ <LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="@dimen/preference_widget_width"
android:gravity="center"
- android:orientation="vertical" />
+ android:orientation="horizontal">
+ <ImageView
+ android:id="@+android:id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ />
+ </LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
@@ -59,4 +65,12 @@
</RelativeLayout>
+ <!-- Preference should place its actual preference widget here. -->
+ <LinearLayout android:id="@+android:id/widget_frame"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:minWidth="@dimen/preference_widget_width"
+ android:gravity="center"
+ android:orientation="vertical" />
+
</LinearLayout>
diff --git a/core/res/res/layout/preference_child.xml b/core/res/res/layout/preference_child.xml
index 713aa17..e9b50e0 100644
--- a/core/res/res/layout/preference_child.xml
+++ b/core/res/res/layout/preference_child.xml
@@ -20,20 +20,26 @@
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
+ android:paddingLeft="16dip"
android:paddingRight="?android:attr/scrollbarSize">
- <!-- Preference should place its actual preference widget here. -->
- <LinearLayout android:id="@+android:id/widget_frame"
+ <LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="@dimen/preference_widget_width"
android:gravity="center"
- android:orientation="vertical" />
+ android:orientation="horizontal">
+ <ImageView
+ android:id="@+android:id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ />
+ </LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginLeft="16dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
@@ -58,4 +64,12 @@
</RelativeLayout>
+ <!-- Preference should place its actual preference widget here. -->
+ <LinearLayout android:id="@+android:id/widget_frame"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:minWidth="@dimen/preference_widget_width"
+ android:gravity="center"
+ android:orientation="vertical" />
+
</LinearLayout>
diff --git a/core/res/res/values-land/dimens.xml b/core/res/res/values-land/dimens.xml
index d562d96..b1f12b5 100644
--- a/core/res/res/values-land/dimens.xml
+++ b/core/res/res/values-land/dimens.xml
@@ -21,6 +21,6 @@
<resources>
<dimen name="password_keyboard_key_height">47dip</dimen>
<dimen name="password_keyboard_spacebar_vertical_correction">2dip</dimen>
- <dimen name="preference_screen_side_margin">32dp</dimen>
- <dimen name="preference_widget_width">64dp</dimen>
+ <dimen name="preference_screen_side_margin">96dp</dimen>
+ <dimen name="preference_widget_width">72dp</dimen>
</resources> \ No newline at end of file
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 55b3258..555de5e 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3854,6 +3854,8 @@
<!-- Base attributes available to Preference. -->
<declare-styleable name="Preference">
+ <!-- The optional icon for the preference -->
+ <attr name="icon" />
<!-- The key to store the Preference value. -->
<attr name="key" format="string" />
<!-- The title for the Preference in a PreferenceActivity screen. -->