Skip to content

Commit fb5c3db

Browse files
author
Dianne Hackborn
committed
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
1 parent d51ac09 commit fb5c3db

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

core/java/android/content/res/Resources.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,20 @@ public float getFraction(int id, int base, int pbase) {
630630
* Various types of objects will be returned depending on the underlying
631631
* resource -- for example, a solid color, PNG image, scalable image, etc.
632632
* The Drawable API hides these implementation details.
633-
*
633+
*
634+
* <p class="note"><strong>Note:</strong> Prior to
635+
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, this function
636+
* would not correctly retrieve the final configuration density when
637+
* the resource ID passed here is an alias to another Drawable resource.
638+
* This means that if the density configuration of the alias resource
639+
* is different than the actual resource, the density of the returned
640+
* Drawable would be incorrect, resulting in bad scaling. To work
641+
* around this, you can instead retrieve the Drawable through
642+
* {@link TypedArray#getDrawable TypedArray.getDrawable}. Use
643+
* {@link android.content.Context#obtainStyledAttributes(int[])
644+
* Context.obtainStyledAttributes} with
645+
* an array containing the resource ID of interest to create the TypedArray.</p>
646+
*
634647
* @param id The desired resource identifier, as generated by the aapt
635648
* tool. This integer encodes the package, type, and resource
636649
* entry. The value 0 is an invalid identifier.

core/jni/android_util_AssetManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static jint android_content_AssetManager_loadResourceValue(JNIEnv* env, jobject
703703
#endif
704704
uint32_t ref = ident;
705705
if (resolve) {
706-
block = res.resolveReference(&value, block, &ref);
706+
block = res.resolveReference(&value, block, &ref, &typeSpecFlags, &config);
707707
#if THROW_ON_BAD_ID
708708
if (block == BAD_INDEX) {
709709
jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!");

0 commit comments

Comments
 (0)