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

Commit 71cf617e authored by Jared Duke's avatar Jared Duke
Browse files

Revert "Downscale large bitmaps in CachingIconView"

Revert submission 17083643-large-icons-tm

Reason for revert: Speculative revert for android.app.cts.NotificationManagerTest breakage.
Reverted Changes:
Ib66933a8f:Size restrict right notification icon size
If3d871e78:Downscale large bitmaps in CachingIconView
I504694cb2:Support downscaling of Drawable icons in LocalImag...

Bug: 224768026
Change-Id: Iabb2d26899979aff25afa095baacd6bae12f6fde
parent 0543804e
Loading
Loading
Loading
Loading
+7 −116
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
@@ -36,9 +35,6 @@ import android.view.RemotableViewMethod;
import android.widget.ImageView;
import android.widget.RemoteViews;

import com.android.internal.R;

import java.io.IOException;
import java.util.Objects;
import java.util.function.Consumer;

@@ -59,42 +55,9 @@ public class CachingIconView extends ImageView {
    private int mBackgroundColor;
    private boolean mWillBeForceHidden;

    private int mMaxDrawableWidth = -1;
    private int mMaxDrawableHeight = -1;

    public CachingIconView(Context context) {
        this(context, null, 0, 0);
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public CachingIconView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0, 0);
    }

    public CachingIconView(Context context, @Nullable AttributeSet attrs,
            int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public CachingIconView(Context context, @Nullable AttributeSet attrs,
            int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context, attrs, defStyleAttr, defStyleRes);
    }

    private void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        if (attrs == null) {
            return;
        }

        TypedArray ta = context.obtainStyledAttributes(attrs,
                R.styleable.CachingIconView, defStyleAttr, defStyleRes);
        mMaxDrawableWidth = ta.getDimensionPixelSize(R.styleable
                .CachingIconView_maxDrawableWidth, -1);
        mMaxDrawableHeight = ta.getDimensionPixelSize(R.styleable
                .CachingIconView_maxDrawableHeight, -1);
        ta.recycle();
        super(context, attrs);
    }

    @Override
@@ -103,31 +66,15 @@ public class CachingIconView extends ImageView {
        if (!testAndSetCache(icon)) {
            mInternalSetDrawable = true;
            // This calls back to setImageDrawable, make sure we don't clear the cache there.
            Drawable drawable = loadSizeRestrictedIcon(icon);
            if (drawable == null) {
            super.setImageIcon(icon);
            } else {
                super.setImageDrawable(drawable);
            }
            mInternalSetDrawable = false;
        }
    }

    @Nullable
    private Drawable loadSizeRestrictedIcon(@Nullable Icon icon) {
        try {
            return LocalImageResolver.resolveImage(icon, getContext(), mMaxDrawableWidth,
                    mMaxDrawableHeight);
        } catch (IOException e) {
            return null;
        }
    }

    @Override
    public Runnable setImageIconAsync(@Nullable final Icon icon) {
    public Runnable setImageIconAsync(@Nullable Icon icon) {
        resetCache();
        Drawable drawable = loadSizeRestrictedIcon(icon);
        return () -> setImageDrawable(drawable);
        return super.setImageIconAsync(icon);
    }

    @Override
@@ -136,34 +83,14 @@ public class CachingIconView extends ImageView {
        if (!testAndSetCache(resId)) {
            mInternalSetDrawable = true;
            // This calls back to setImageDrawable, make sure we don't clear the cache there.
            Drawable drawable = loadSizeRestrictedDrawable(resId);
            if (drawable == null) {
            super.setImageResource(resId);
            } else {
                super.setImageDrawable(drawable);
            }
            mInternalSetDrawable = false;
        }
    }

    @Nullable
    private Drawable loadSizeRestrictedDrawable(@DrawableRes int resId) {
        try {
            return LocalImageResolver.resolveImage(resId, getContext(), mMaxDrawableWidth,
                    mMaxDrawableHeight);
        } catch (IOException e) {
            return null;
        }
    }

    @Override
    public Runnable setImageResourceAsync(@DrawableRes int resId) {
        resetCache();
        Drawable drawable = loadSizeRestrictedDrawable(resId);
        if (drawable != null) {
            return () -> setImageDrawable(drawable);
        }

        return super.setImageResourceAsync(resId);
    }

@@ -171,35 +98,13 @@ public class CachingIconView extends ImageView {
    @RemotableViewMethod(asyncImpl="setImageURIAsync")
    public void setImageURI(@Nullable Uri uri) {
        resetCache();
        Drawable drawable = loadSizeRestrictedUri(uri);
        if (drawable == null) {
        super.setImageURI(uri);
        } else {
            mInternalSetDrawable = true;
            super.setImageDrawable(drawable);
            mInternalSetDrawable = false;
        }
    }

    @Nullable
    private Drawable loadSizeRestrictedUri(@Nullable Uri uri) {
        try {
            return LocalImageResolver.resolveImage(uri, getContext(), mMaxDrawableWidth,
                    mMaxDrawableHeight);
        } catch (IOException e) {
            return null;
        }
    }

    @Override
    public Runnable setImageURIAsync(@Nullable Uri uri) {
        resetCache();
        Drawable drawable = loadSizeRestrictedUri(uri);
        if (drawable == null) {
        return super.setImageURIAsync(uri);
        } else {
            return () -> setImageDrawable(drawable);
        }
    }

    @Override
@@ -402,18 +307,4 @@ public class CachingIconView extends ImageView {
    public void setWillBeForceHidden(boolean forceHidden) {
        mWillBeForceHidden = forceHidden;
    }

    /**
     * Returns the set maximum width of drawable in pixels. -1 if not set.
     */
    public int getMaxDrawableWidth() {
        return mMaxDrawableWidth;
    }

    /**
     * Returns the set maximum height of drawable in pixels. -1 if not set.
     */
    public int getMaxDrawableHeight() {
        return mMaxDrawableHeight;
    }
}
+0 −8
Original line number Diff line number Diff line
@@ -9807,12 +9807,4 @@
        of the supported locale. {@link android.app.LocaleConfig} -->
        <attr name="name" />
    </declare-styleable>
    <!-- @hide -->
    <declare-styleable name="CachingIconView">
        <!-- Maximum width of displayed drawable. Drawables exceeding this size will be downsampled. -->
        <attr name="maxDrawableWidth" format="dimension"/>
        <!-- Maximum width of height drawable. Drawables exceeding this size will be downsampled. -->
        <attr name="maxDrawableHeight" format="dimension"/>
    </declare-styleable>
    </resources>
+0 −4
Original line number Diff line number Diff line
@@ -148,10 +148,6 @@
    <public name="supportsInlineSuggestionsWithTouchExploration" />
    <public name="lineBreakStyle" />
    <public name="lineBreakWordStyle" />
    <!-- @hide -->
    <public name="maxDrawableWidth" />
    <!-- @hide -->
    <public name="maxDrawableHeight" />
  </staging-public-group>

  <staging-public-group type="id" first-id="0x01de0000">
+0 −24
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<com.android.internal.widget.CachingIconView
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/caching_icon_view"
          android:layout_width="120dp"
          android:layout_height="120dp"
          android:maxDrawableWidth="80dp"
          android:maxDrawableHeight="80dp" />
+0 −22
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<com.android.internal.widget.CachingIconView
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/caching_icon_view"
          android:layout_width="120dp"
          android:layout_height="120dp" />
Loading