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

Commit 2abe8b3b authored by Wu Ahan's avatar Wu Ahan Committed by Android (Google) Code Review
Browse files

Merge "Apply cache and preload mechanism to inline image notifications."

parents de337233 de396fa8
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -3423,6 +3423,12 @@ public class RemoteViews implements Parcelable, Filter {
     * @hide
     */
    public interface OnViewAppliedListener {
        /**
         * Callback when the RemoteView has finished inflating,
         * but no actions have been applied yet.
         */
        default void onViewInflated(View v) {};

        void onViewApplied(View v);

        void onError(Exception e);
@@ -3519,6 +3525,10 @@ public class RemoteViews implements Parcelable, Filter {
        @Override
        protected void onPostExecute(ViewTree viewTree) {
            if (mError == null) {
                if (mListener != null) {
                    mListener.onViewInflated(viewTree.mRoot);
                }

                try {
                    if (mActions != null) {
                        OnClickHandler handler = mHandler == null
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

package com.android.internal.widget;

/**
 * An interface for the class who will use the {@link ImageResolver} to resolve images.
 */
public interface ImageMessageConsumer {
    /**
     * Set the custom {@link ImageResolver} other than {@link LocalImageResolver}.
     * @param resolver An image resolver that has custom implementation.
     */
    void setImageResolver(ImageResolver resolver);
}
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

package com.android.internal.widget;

import android.graphics.drawable.Drawable;
import android.net.Uri;

/**
 * An interface for image resolvers that have custom implementations like cache mechanisms.
 */
public interface ImageResolver {
    /**
     * Load an image from specified uri.
     * @param uri Uri of the target image.
     * @return Target image in Drawable.
     */
    Drawable loadImage(Uri uri);
}
+0 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.internal.widget;

import android.annotation.Nullable;
import android.app.Notification;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+14 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pools;
@@ -57,6 +58,7 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
    private int mActualWidth;
    private int mActualHeight;
    private boolean mIsIsolated;
    private ImageResolver mImageResolver;

    public MessagingImageMessage(@NonNull Context context) {
        this(context, null);
@@ -96,11 +98,16 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
        MessagingMessage.super.setMessage(message);
        Drawable drawable;
        try {
            drawable = LocalImageResolver.resolveImage(message.getDataUri(), getContext());
            Uri uri = message.getDataUri();
            drawable = mImageResolver != null ? mImageResolver.loadImage(uri) :
                    LocalImageResolver.resolveImage(uri, getContext());
        } catch (IOException | SecurityException e) {
            e.printStackTrace();
            return false;
        }
        if (drawable == null) {
            return false;
        }
        int intrinsicHeight = drawable.getIntrinsicHeight();
        if (intrinsicHeight == 0) {
            Log.w(TAG, "Drawable with 0 intrinsic height was returned");
@@ -114,7 +121,7 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
    }

    static MessagingMessage createMessage(MessagingLayout layout,
            Notification.MessagingStyle.Message m) {
            Notification.MessagingStyle.Message m, ImageResolver resolver) {
        MessagingLinearLayout messagingLinearLayout = layout.getMessagingLinearLayout();
        MessagingImageMessage createdMessage = sInstancePool.acquire();
        if (createdMessage == null) {
@@ -125,6 +132,7 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
                            false);
            createdMessage.addOnLayoutChangeListener(MessagingLayout.MESSAGING_PROPERTY_ANIMATOR);
        }
        createdMessage.setImageResolver(resolver);
        boolean created = createdMessage.setMessage(m);
        if (!created) {
            createdMessage.recycle();
@@ -133,6 +141,10 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
        return createdMessage;
    }

    private void setImageResolver(ImageResolver resolver) {
        mImageResolver = resolver;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.save();
Loading