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

Commit 3f1d5b58 authored by András Kurucz's avatar András Kurucz Committed by Android (Google) Code Review
Browse files

Merge "Add NotificationIconManager interface" into main

parents 3315016c 01efcb19
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -37,13 +37,16 @@ import com.android.internal.R;
 * Icon.loadDrawable().
 */
@RemoteViews.RemoteView
public class BigPictureNotificationImageView extends ImageView {
public class BigPictureNotificationImageView extends ImageView implements
        NotificationDrawableConsumer {

    private static final String TAG = BigPictureNotificationImageView.class.getSimpleName();

    private final int mMaximumDrawableWidth;
    private final int mMaximumDrawableHeight;

    private NotificationIconManager mIconManager;

    public BigPictureNotificationImageView(@NonNull Context context) {
        this(context, null, 0, 0);
    }
@@ -69,6 +72,19 @@ public class BigPictureNotificationImageView extends ImageView {
                        : R.dimen.notification_big_picture_max_height);
    }


    /**
     * Sets an {@link NotificationIconManager} on this ImageView, which handles the loading of
     * icons, instead of using the {@link LocalImageResolver} directly.
     * If set, it overrides the behaviour of {@link #setImageIconAsync} and {@link #setImageIcon},
     * and it expects that the content of this imageView is only updated calling these two methods.
     *
     * @param iconManager to be called, when the icon is updated
     */
    public void setIconManager(NotificationIconManager iconManager) {
        mIconManager = iconManager;
    }

    @Override
    @android.view.RemotableViewMethod(asyncImpl = "setImageURIAsync")
    public void setImageURI(@Nullable Uri uri) {
@@ -84,11 +100,20 @@ public class BigPictureNotificationImageView extends ImageView {
    @Override
    @android.view.RemotableViewMethod(asyncImpl = "setImageIconAsync")
    public void setImageIcon(@Nullable Icon icon) {
        if (mIconManager != null) {
            mIconManager.updateIcon(this, icon).run();
            return;
        }
        // old code path
        setImageDrawable(loadImage(icon));
    }

    /** @hide **/
    public Runnable setImageIconAsync(@Nullable Icon icon) {
        if (mIconManager != null) {
            return mIconManager.updateIcon(this, icon);
        }
        // old code path
        final Drawable drawable = loadImage(icon);
        return () -> setImageDrawable(drawable);
    }
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 androidx.annotation.Nullable;

/**
 * An interface for the class, who will use {@link NotificationIconManager} to load icons.
 */
public interface NotificationDrawableConsumer {

    /**
     * Sets a drawable as the content of this consumer.
     *
     * @param drawable the {@link Drawable} to set, or {@code null} to clear the content
     */
    void setImageDrawable(@Nullable Drawable drawable);
}
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.Icon;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * An interface used for Notification views to delegate handling the loading of icons.
 */
public interface NotificationIconManager {

    /**
     * Called when a new icon is provided to display.
     *
     * @param drawableConsumer a consumer, which can display the loaded drawable.
     * @param icon             the updated icon to be displayed.
     *
     * @return a {@link Runnable} that sets the drawable on the consumer
     */
    @NonNull
    Runnable updateIcon(
            @NonNull NotificationDrawableConsumer drawableConsumer,
            @Nullable Icon icon
    );
}