Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d8d9c22 authored by Bjorn Bringert's avatar Bjorn Bringert
Browse files

Get correct density info when using resource URIs in ImageView

Before, when an android.resource URI was passed to
ImageView.setImageURI(), it was loaded through an InputStream.
This didn't get the density information correctly.

Instead, we use Resources to load the Drawable, which fixes
the denisty problem.

Change-Id: Ie8427ea04da43f414b49014d012671fc0aa27a30
parent e0a8efd8
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -491,8 +491,16 @@ public class ImageView extends View {
            }
        } else if (mUri != null) {
            String scheme = mUri.getScheme();
            if (ContentResolver.SCHEME_CONTENT.equals(scheme)
                    || ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)
            if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) {
                try {
                    // Load drawable through Resources, to get the source density information
                    ContentResolver.OpenResourceIdResult r =
                            mContext.getContentResolver().getResourceId(mUri);
                    d = r.r.getDrawable(r.id);
                } catch (Exception e) {
                    Log.w("ImageView", "Unable to open content: " + mUri, e);
                }
            } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)
                    || ContentResolver.SCHEME_FILE.equals(scheme)) {
                try {
                    d = Drawable.createFromStream(