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

Commit 270a3428 authored by Alan Viverette's avatar Alan Viverette
Browse files

Pass Resources when loading ImageView source from stream

Only targets >M since developers may have already had workarounds in
place or been relying on the incorrect behavior.

Bug: 23383805
Change-Id: Ifa69b204b10b8084cf6486e41d5393969e197826
parent 6aa92d1c
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ public class ImageView extends View {
    // AdjustViewBounds behavior will be in compatibility mode for older apps.
    private boolean mAdjustViewBoundsCompat = false;

    /** Whether to pass Resources when creating the source from a stream. */
    private boolean mUseCorrectStreamDensity;

    private static final ScaleType[] sScaleTypeArray = {
        ScaleType.MATRIX,
        ScaleType.FIT_XY,
@@ -202,8 +205,10 @@ public class ImageView extends View {
    private void initImageView() {
        mMatrix = new Matrix();
        mScaleType = ScaleType.FIT_CENTER;
        mAdjustViewBoundsCompat = mContext.getApplicationInfo().targetSdkVersion
                <= Build.VERSION_CODES.JELLY_BEAN_MR1;

        final int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
        mAdjustViewBoundsCompat = targetSdkVersion <= Build.VERSION_CODES.JELLY_BEAN_MR1;
        mUseCorrectStreamDensity = targetSdkVersion > Build.VERSION_CODES.M;
    }

    @Override
@@ -810,7 +815,8 @@ public class ImageView extends View {
                InputStream stream = null;
                try {
                    stream = mContext.getContentResolver().openInputStream(mUri);
                    d = Drawable.createFromStream(stream, null);
                    d = Drawable.createFromResourceStream(
                            mUseCorrectStreamDensity ? res : null, null, stream, null);
                } catch (Exception e) {
                    Log.w(LOG_TAG, "Unable to open content: " + mUri, e);
                } finally {