From fb5c3dba4ddac023cfd4cdcabdfdbcf343197c94 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Fri, 18 May 2012 15:24:24 -0700 Subject: [PATCH] Fix issue #6440173: MenuItem.setIcon(Drawable) scaling incorrectly... ...when resource is aliased We were not correctly using the final resolved configuration when retrieving a drawable through Resources.getDrawable(). (It already does the correct behavior when going through TypedArray.getDrawable()). Change-Id: I9032b788b592412178e31e2e6b0181b92c20fe45 --- core/java/android/content/res/Resources.java | 15 ++++++++++++++- core/jni/android_util_AssetManager.cpp | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index c68285242dc44..c630bb51c96cc 100755 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -630,7 +630,20 @@ public class Resources { * Various types of objects will be returned depending on the underlying * resource -- for example, a solid color, PNG image, scalable image, etc. * The Drawable API hides these implementation details. - * + * + *

Note: Prior to + * {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, this function + * would not correctly retrieve the final configuration density when + * the resource ID passed here is an alias to another Drawable resource. + * This means that if the density configuration of the alias resource + * is different than the actual resource, the density of the returned + * Drawable would be incorrect, resulting in bad scaling. To work + * around this, you can instead retrieve the Drawable through + * {@link TypedArray#getDrawable TypedArray.getDrawable}. Use + * {@link android.content.Context#obtainStyledAttributes(int[]) + * Context.obtainStyledAttributes} with + * an array containing the resource ID of interest to create the TypedArray.

+ * * @param id The desired resource identifier, as generated by the aapt * tool. This integer encodes the package, type, and resource * entry. The value 0 is an invalid identifier. diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp index 7146667472ab3..d422951039e86 100644 --- a/core/jni/android_util_AssetManager.cpp +++ b/core/jni/android_util_AssetManager.cpp @@ -703,7 +703,7 @@ static jint android_content_AssetManager_loadResourceValue(JNIEnv* env, jobject #endif uint32_t ref = ident; if (resolve) { - block = res.resolveReference(&value, block, &ref); + block = res.resolveReference(&value, block, &ref, &typeSpecFlags, &config); #if THROW_ON_BAD_ID if (block == BAD_INDEX) { jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!");