/* * Copyright (C) 2022 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.media.controls.ui.view import android.content.res.ColorStateList import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.ImageButton import android.widget.TextView import com.android.systemui.media.controls.ui.animation.onPrimaryFromScheme import com.android.systemui.media.controls.ui.animation.primaryFromScheme import com.android.systemui.monet.ColorScheme import com.android.systemui.res.R /** * A view holder for the guts menu of a media player. The guts are shown when the user long-presses * on the media player. */ class GutsViewHolder(itemView: View) { val gutsText: TextView = itemView.requireViewById(R.id.remove_text) val cancel: View = itemView.requireViewById(R.id.cancel) val cancelText: TextView = itemView.requireViewById(R.id.cancel_text) val dismiss: ViewGroup = itemView.requireViewById(R.id.dismiss) val dismissText: TextView = itemView.requireViewById(R.id.dismiss_text) val settings: ImageButton = itemView.requireViewById(R.id.settings) private var isDismissible: Boolean = true private var colorScheme: ColorScheme? = null private var textColorFixed: Int? = null /** Marquees the main text of the guts menu. */ fun marquee(start: Boolean, delay: Long, tag: String) { val gutsTextHandler = gutsText.handler if (gutsTextHandler == null) { Log.d(tag, "marquee while longPressText.getHandler() is null", Exception()) return } gutsTextHandler.postDelayed({ gutsText.isSelected = start }, delay) } /** Set whether this control can be dismissed, and update appearance to match */ fun setDismissible(dismissible: Boolean) { if (isDismissible == dismissible) return isDismissible = dismissible colorScheme?.let { setColors(it) } } /** Sets the right colors on all the guts views based on the given [ColorScheme]. */ fun setColors(scheme: ColorScheme) { colorScheme = scheme textColorFixed?.let { setTextColor(it) } setPrimaryColor(primaryFromScheme(scheme)) setOnPrimaryColor(onPrimaryFromScheme(scheme)) } private fun setPrimaryColor(color: Int) { val colorList = ColorStateList.valueOf(color) dismissText.backgroundTintList = colorList cancelText.backgroundTintList = colorList } private fun setOnPrimaryColor(color: Int) { dismissText.setTextColor(color) if (!isDismissible) { cancelText.setTextColor(color) } } fun setTextColor(color: Int) { textColorFixed = color gutsText.setTextColor(color) settings.imageTintList = ColorStateList.valueOf(color) if (isDismissible) { cancelText.setTextColor(color) } } companion object { val ids = setOf(R.id.remove_text, R.id.cancel, R.id.dismiss, R.id.settings) } }