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

Commit 5df1df82 authored by Steve Elliott's avatar Steve Elliott
Browse files

Replace NIC+SBIV#setDozing w/ SBIV#setTintAlpha

Flag: ACONFIG com.android.systemui.notifications_icon_container_refactor DEVELOPMENT
Bug: 278765923
Test: atest SystemUITests

Change-Id: Ie7a48d0430d57cbf3e5903cfd532918fec055c27
parent a0974ea8
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -605,7 +605,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
                            mAodIconsViewModel,
                            mConfigurationState,
                            mConfigurationController,
                            mDozeParameters,
                            mAodIconViewStore);
                    final DisposableHandle visHandle = KeyguardRootViewBinder.bindAodIconVisibility(
                            nic,
+0 −1
Original line number Diff line number Diff line
@@ -94,7 +94,6 @@ constructor(
                    nicAodViewModel,
                    configurationState,
                    configurationController,
                    dozeParameters,
                    nicAodIconViewStore,
                )
        } else {
+20 −9
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import com.android.internal.util.ContrastColorUtil;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.notification.NotificationDozeHelper;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.notification.shared.NotificationIconContainerRefactor;
import com.android.systemui.util.drawable.DrawableSize;

import java.lang.annotation.Retention;
@@ -164,7 +165,6 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
    private int mDrawableColor;
    private int mIconColor;
    private int mDecorColor;
    private float mDozeAmount;
    private ValueAnimator mColorAnimator;
    private int mCurrentSetColor = NO_COLOR;
    private int mAnimationStartColor = NO_COLOR;
@@ -174,7 +174,6 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
                animation.getAnimatedFraction());
        setColorInternal(newColor);
    };
    private final NotificationDozeHelper mDozer;
    private int mContrastedDrawableColor;
    private int mCachedContrastBackgroundColor = NO_COLOR;
    private float[] mMatrix;
@@ -184,6 +183,8 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
    private Runnable mOnDismissListener;
    private boolean mIncreasedSize;
    private boolean mShowsConversation;
    private float mDozeAmount;
    private final NotificationDozeHelper mDozer;

    public StatusBarIconView(Context context, String slot, StatusBarNotification sbn) {
        this(context, slot, sbn, false);
@@ -958,18 +959,28 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
        return mDotAppearAmount;
    }

    public void setDozing(boolean dozing, boolean fade, long delay) {
        setDozing(dozing, fade, delay, /* onChildCompleted= */ null);
    public void setDozing(boolean dozing, boolean animate, long delay) {
        setDozing(dozing, animate, delay, /* onChildCompleted= */ null);
    }

    public void setDozing(boolean dozing, boolean fade, long delay,
            @Nullable Runnable endRunnable) {
        mDozer.setDozing(f -> {
            mDozeAmount = f;
    public void setTintAlpha(float tintAlpha) {
        if (NotificationIconContainerRefactor.isUnexpectedlyInLegacyMode()) return;
        setDozeAmount(tintAlpha);
    }

    private void setDozeAmount(float dozeAmount) {
        mDozeAmount = dozeAmount;
        updateDecorColor();
        updateIconColor();
    }

    public void setDozing(boolean dozing, boolean animate, long delay,
            @Nullable Runnable endRunnable) {
        NotificationIconContainerRefactor.assertInLegacyMode();
        mDozer.setDozing(f -> {
            setDozeAmount(f);
            updateAllowAnimation();
        }, dozing, fade, delay, this, endRunnable);
        }, dozing, animate, delay, this, endRunnable);
    }

    private void updateAllowAnimation() {
+26 −49
Original line number Diff line number Diff line
@@ -28,15 +28,12 @@ import com.android.systemui.common.ui.ConfigurationState
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.res.R
import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.notification.NotificationUtils
import com.android.systemui.statusbar.notification.collection.NotifCollection
import com.android.systemui.statusbar.notification.icon.ui.viewbinder.NotificationIconContainerViewBinder.IconViewStore
import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconColors
import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconContainerAlwaysOnDisplayViewModel
import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconContainerShelfViewModel
import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconContainerStatusBarViewModel
import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconsViewData
import com.android.systemui.statusbar.phone.DozeParameters
import com.android.systemui.statusbar.phone.NotificationIconContainer
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.statusbar.policy.onConfigChanged
@@ -44,7 +41,6 @@ import com.android.systemui.util.children
import com.android.systemui.util.kotlin.mapValuesNotNullTo
import com.android.systemui.util.kotlin.sample
import com.android.systemui.util.kotlin.stateFlow
import com.android.systemui.util.ui.AnimatedValue
import com.android.systemui.util.ui.isAnimating
import com.android.systemui.util.ui.stopAnimating
import com.android.systemui.util.ui.value
@@ -95,7 +91,11 @@ object NotificationIconContainerViewBinder {
                        configurationController,
                        viewStore,
                    ) { _, sbiv ->
                        iconColors.collect { sbiv.updateTintForIcon(it, contrastColorUtil) }
                        StatusBarIconViewBinder.bindIconColors(
                            sbiv,
                            iconColors,
                            contrastColorUtil,
                        )
                    }
                }
                launch { viewModel.bindIsolatedIcon(view, viewStore) }
@@ -110,7 +110,6 @@ object NotificationIconContainerViewBinder {
        viewModel: NotificationIconContainerAlwaysOnDisplayViewModel,
        configuration: ConfigurationState,
        configurationController: ConfigurationController,
        dozeParameters: DozeParameters,
        viewStore: IconViewStore,
    ): DisposableHandle {
        return view.repeatWhenAttached {
@@ -122,48 +121,37 @@ object NotificationIconContainerViewBinder {
                        configurationController,
                        viewStore,
                    ) { _, sbiv ->
                        configuration
                            .getColorAttr(R.attr.wallpaperTextColor, DEFAULT_AOD_ICON_COLOR)
                            .collect { tint ->
                                sbiv.staticDrawableColor = tint
                                sbiv.setDecorColor(tint)
                            }
                    }
                        viewModel.bindAodStatusBarIconView(sbiv, configuration)
                    }
                launch { viewModel.animationsEnabled.bindAnimationsEnabled(view) }
                launch { viewModel.isDozing.bindIsDozing(view, dozeParameters) }
                }
                launch { viewModel.areContainerChangesAnimated.bindAnimationsEnabled(view) }
            }
        }

    /** Binds to [NotificationIconContainer.setAnimationsEnabled] */
    private suspend fun Flow<Boolean>.bindAnimationsEnabled(view: NotificationIconContainer) {
        collect(view::setAnimationsEnabled)
    }

    private suspend fun Flow<AnimatedValue<Boolean>>.bindIsDozing(
        view: NotificationIconContainer,
        dozeParameters: DozeParameters,
    private suspend fun NotificationIconContainerAlwaysOnDisplayViewModel.bindAodStatusBarIconView(
        sbiv: StatusBarIconView,
        configuration: ConfigurationState,
    ) {
        collect { isDozing ->
            if (isDozing.isAnimating) {
                val animate = !dozeParameters.displayNeedsBlanking
                view.setDozing(
                    /* dozing = */ isDozing.value,
                    /* fade = */ animate,
                    /* delay = */ 0,
                    /* endRunnable = */ isDozing::stopAnimating,
                )
            } else {
                view.setDozing(
                    /* dozing = */ isDozing.value,
                    /* fade= */ false,
                    /* delay= */ 0,
        coroutineScope {
            launch {
                val color: Flow<Int> =
                    configuration.getColorAttr(
                        R.attr.wallpaperTextColor,
                        DEFAULT_AOD_ICON_COLOR,
                    )
                StatusBarIconViewBinder.bindColor(sbiv, color)
            }
            launch { StatusBarIconViewBinder.bindTintAlpha(sbiv, tintAlpha) }
            launch { StatusBarIconViewBinder.bindAnimationsEnabled(sbiv, areIconAnimationsEnabled) }
        }
    }

    /** Binds to [NotificationIconContainer.setAnimationsEnabled] */
    private suspend fun Flow<Boolean>.bindAnimationsEnabled(view: NotificationIconContainer) {
        collect(view::setAnimationsEnabled)
    }

    private suspend fun NotificationIconContainerStatusBarViewModel.bindIsolatedIcon(
        view: NotificationIconContainer,
        viewStore: IconViewStore,
@@ -261,6 +249,7 @@ object NotificationIconContainerViewBinder {
                // and added again
                view.removeTransientView(sbiv)
                view.addView(sbiv, i, layoutParams)
                iconBindings.remove(key)?.cancel()
                iconBindings[key] = launch { bindIcon(key, sbiv) }
            }

@@ -282,18 +271,6 @@ object NotificationIconContainerViewBinder {
        }
    }

    // TODO(b/305739416): Once StatusBarIconView has its own Recommended Architecture stack, this
    //  can be moved there and cleaned up.
    private fun StatusBarIconView.updateTintForIcon(
        iconColors: NotificationIconColors,
        contrastColorUtil: ContrastColorUtil,
    ) {
        val isPreL = java.lang.Boolean.TRUE == getTag(R.id.icon_is_pre_L)
        val isColorized = !isPreL || NotificationUtils.isGrayscale(this, contrastColorUtil)
        staticDrawableColor = iconColors.staticDrawableColor(viewBounds, isColorized)
        setDecorColor(iconColors.tint)
    }

    /** External storage for [StatusBarIconView] instances. */
    fun interface IconViewStore {
        fun iconView(key: String): StatusBarIconView
+73 −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.systemui.statusbar.notification.icon.ui.viewbinder

import android.graphics.Rect
import android.view.View
import com.android.internal.util.ContrastColorUtil
import com.android.systemui.res.R
import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.notification.NotificationUtils
import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconColors
import kotlinx.coroutines.flow.Flow

object StatusBarIconViewBinder {

    // TODO(b/305739416): Once StatusBarIconView has its own Recommended Architecture stack, these
    //  methods can become private and we can have a single bind() method for SBIV and its
    //  view-model (which, at the time of this writing, does not yet exist).

    suspend fun bindColor(view: StatusBarIconView, color: Flow<Int>) {
        color.collect { color ->
            view.staticDrawableColor = color
            view.setDecorColor(color)
        }
    }

    suspend fun bindTintAlpha(view: StatusBarIconView, tintAlpha: Flow<Float>) {
        tintAlpha.collect { amt -> view.setTintAlpha(amt) }
    }

    suspend fun bindAnimationsEnabled(view: StatusBarIconView, allowAnimation: Flow<Boolean>) {
        allowAnimation.collect(view::setAllowAnimation)
    }

    suspend fun bindIconColors(
        view: StatusBarIconView,
        iconColors: Flow<NotificationIconColors>,
        contrastColorUtil: ContrastColorUtil,
    ) {
        iconColors.collect { colors ->
            val isPreL = java.lang.Boolean.TRUE == view.getTag(R.id.icon_is_pre_L)
            val isColorized = !isPreL || NotificationUtils.isGrayscale(view, contrastColorUtil)
            view.staticDrawableColor = colors.staticDrawableColor(view.viewBounds, isColorized)
            view.setDecorColor(colors.tint)
        }
    }
}

private val View.viewBounds: Rect
    get() {
        val tmpArray = intArrayOf(0, 0)
        getLocationOnScreen(tmpArray)
        return Rect(
            /* left = */ tmpArray[0],
            /* top = */ tmpArray[1],
            /* right = */ left + width,
            /* bottom = */ top + height,
        )
    }
Loading