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

Commit 8f20f0a1 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge "Adds PlatformColor to model Color" into main

parents e6eb0869 3f7c4cbe
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.Color
import com.android.compose.theme.colorAttr

/** Resolves [com.android.systemui.common.shared.model.Color] into [Color] */
@Composable
@ReadOnlyComposable
fun com.android.systemui.common.shared.model.Color.toColor(): Color {
    return when (this) {
        is com.android.systemui.common.shared.model.Color.Attribute -> colorAttr(attribute)
        is com.android.systemui.common.shared.model.Color.Loaded -> Color(color)
    }
}
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.shared.model

import android.annotation.AttrRes
import android.annotation.ColorInt

/**
 * Models a color that can be either a specific [Color.Loaded] value or a resolvable theme
 * [Color.Attribute]
 */
sealed interface Color {

    data class Loaded(@ColorInt val color: Int) : Color

    data class Attribute(@AttrRes val attribute: Int) : Color
}