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

Commit 319259ca authored by Steve Elliott's avatar Steve Elliott
Browse files

Introduce NICViewModel#iconColors

This CL replaces the older tint calculation logic used for AOD and
status bar notification icons with a new Recommended Architecture stack.

Flag: NOTIFICATION_ICON_CONTAINER_REFACTOR
Bug: 290787599
Bug: 278765923
Test: atest SystemUITests
Change-Id: Ie8cf64c103e5e4fa99dc499a3eaa8bd18ab6f609
parent 473f47c0
Loading
Loading
Loading
Loading
+34 −14
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.plugins;
import android.graphics.Color;
import android.graphics.Rect;
import android.view.View;
import android.widget.ImageView;

import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.plugins.annotations.DependsOn;
@@ -50,21 +49,11 @@ public interface DarkIconDispatcher {
     */
    void addDarkReceiver(DarkReceiver receiver);

    /**
     * Adds a receiver to receive callbacks onDarkChanged
     */
    void addDarkReceiver(ImageView imageView);

    /**
     * Must have been previously been added through one of the addDarkReceive methods above.
     */
    void removeDarkReceiver(DarkReceiver object);

    /**
     * Must have been previously been added through one of the addDarkReceive methods above.
     */
    void removeDarkReceiver(ImageView object);

    /**
     * Used to reapply darkness on an object, must have previously been added through
     * addDarkReceiver.
@@ -104,8 +93,8 @@ public interface DarkIconDispatcher {
    }

    /**
     * @return true if more than half of the view area are in any of the given
     *         areas, false otherwise
     * @return true if more than half of the view's area is in any of the given area Rects, false
     *         otherwise
     */
    static boolean isInAreas(Collection<Rect> areas, View view) {
        if (areas.isEmpty()) {
@@ -120,9 +109,40 @@ public interface DarkIconDispatcher {
    }

    /**
     * @return true if more than half of the view area are in area, false
     * @return true if more than half of the viewBounds are in any of the given area Rects, false
     *         otherwise
     */
    static boolean isInAreas(Collection<Rect> areas, Rect viewBounds) {
        if (areas.isEmpty()) {
            return true;
        }
        for (Rect area : areas) {
            if (isInArea(area, viewBounds)) {
                return true;
            }
        }
        return false;
    }

    /** @return true if more than half of the viewBounds are in the area Rect, false otherwise */
    static boolean isInArea(Rect area, Rect viewBounds) {
        if (area.isEmpty()) {
            return true;
        }
        sTmpRect.set(area);
        int left = viewBounds.left;
        int width = viewBounds.width();

        int intersectStart = Math.max(left, area.left);
        int intersectEnd = Math.min(left + width, area.right);
        int intersectAmount = Math.max(0, intersectEnd - intersectStart);

        boolean coversFullStatusBar = area.top <= 0;
        boolean majorityOfWidth = 2 * intersectAmount > width;
        return majorityOfWidth && coversFullStatusBar;
    }

    /** @return true if more than half of the view's area is in the area Rect, false otherwise */
    static boolean isInArea(Rect area, View view) {
        if (area.isEmpty()) {
            return true;
+60 −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.common.ui

import android.content.Context
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.DimenRes
import com.android.settingslib.Utils
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.statusbar.policy.onDensityOrFontScaleChanged
import com.android.systemui.statusbar.policy.onThemeChanged
import com.android.systemui.util.kotlin.emitOnStart
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

/** Configuration-aware-state-tracking utilities. */
class ConfigurationState
@Inject
constructor(
    private val configurationController: ConfigurationController,
    @Application private val context: Context,
) {
    /**
     * Returns a [Flow] that emits a dimension pixel size that is kept in sync with the device
     * configuration.
     *
     * @see android.content.res.Resources.getDimensionPixelSize
     */
    fun getDimensionPixelSize(@DimenRes id: Int): Flow<Int> {
        return configurationController.onDensityOrFontScaleChanged.emitOnStart().map {
            context.resources.getDimensionPixelSize(id)
        }
    }

    /**
     * Returns a [Flow] that emits a color that is kept in sync with the device theme.
     *
     * @see Utils.getColorAttrDefaultColor
     */
    fun getColorAttr(@AttrRes id: Int, @ColorInt defaultValue: Int): Flow<Int> {
        return configurationController.onThemeChanged.emitOnStart().map {
            Utils.getColorAttrDefaultColor(context, id, defaultValue)
        }
    }
}
+21 −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.common.ui.data

import com.android.systemui.common.ui.data.repository.ConfigurationRepositoryModule
import dagger.Module

@Module(includes = [ConfigurationRepositoryModule::class]) object CommonUiDataLayerModule
+10 −2
Original line number Diff line number Diff line
@@ -13,18 +13,22 @@
 * See the License for the specific language governing permissions and
 * limitations under the License
 */
@file:OptIn(ExperimentalCoroutinesApi::class)

package com.android.systemui.common.ui.data.repository

import android.content.Context
import android.content.res.Configuration
import android.view.DisplayInfo
import androidx.annotation.DimenRes
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ConflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.wrapper.DisplayUtilsWrapper
import dagger.Binds
import dagger.Module
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -48,7 +52,6 @@ interface ConfigurationRepository {
    fun getDimensionPixelSize(id: Int): Int
}

@ExperimentalCoroutinesApi
@SysUISingleton
class ConfigurationRepositoryImpl
@Inject
@@ -119,7 +122,12 @@ constructor(
        return 1f
    }

    override fun getDimensionPixelSize(id: Int): Int {
    override fun getDimensionPixelSize(@DimenRes id: Int): Int {
        return context.resources.getDimensionPixelSize(id)
    }
}

@Module
interface ConfigurationRepositoryModule {
    @Binds fun bindImpl(impl: ConfigurationRepositoryImpl): ConfigurationRepository
}
+2 −2
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import com.android.systemui.biometrics.domain.BiometricsDomainLayerModule;
import com.android.systemui.bouncer.ui.BouncerViewModule;
import com.android.systemui.classifier.FalsingModule;
import com.android.systemui.clipboardoverlay.dagger.ClipboardOverlayModule;
import com.android.systemui.common.ui.data.repository.CommonRepositoryModule;
import com.android.systemui.common.ui.data.CommonUiDataLayerModule;
import com.android.systemui.communal.dagger.CommunalModule;
import com.android.systemui.complication.dagger.ComplicationComponent;
import com.android.systemui.controls.dagger.ControlsModule;
@@ -170,7 +170,7 @@ import javax.inject.Named;
        BouncerViewModule.class,
        ClipboardOverlayModule.class,
        ClockRegistryModule.class,
        CommonRepositoryModule.class,
        CommonUiDataLayerModule.class,
        CommunalModule.class,
        ConnectivityModule.class,
        ControlsModule.class,
Loading