1 /* <lambda>null2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.media.controls.ui.view 18 19 import android.view.LayoutInflater 20 import android.view.View 21 import android.view.ViewGroup 22 import android.widget.ImageView 23 import android.widget.SeekBar 24 import android.widget.TextView 25 import com.android.internal.widget.CachingIconView 26 import com.android.systemui.media.controls.ui.drawable.IlluminationDrawable 27 import com.android.systemui.res.R 28 import com.android.systemui.util.animation.TransitionLayout 29 30 private const val TAG = "RecommendationViewHolder" 31 32 /** ViewHolder for a Smartspace media recommendation. */ 33 class RecommendationViewHolder private constructor(itemView: View) { 34 35 val recommendations = itemView as TransitionLayout 36 37 // Recommendation screen 38 val cardTitle: TextView = itemView.requireViewById(R.id.media_rec_title) 39 40 val mediaCoverContainers = 41 listOf<ViewGroup>( 42 itemView.requireViewById(R.id.media_cover1_container), 43 itemView.requireViewById(R.id.media_cover2_container), 44 itemView.requireViewById(R.id.media_cover3_container) 45 ) 46 val mediaAppIcons: List<CachingIconView> = 47 mediaCoverContainers.map { it.requireViewById(R.id.media_rec_app_icon) } 48 val mediaTitles: List<TextView> = 49 mediaCoverContainers.map { it.requireViewById(R.id.media_title) } 50 val mediaSubtitles: List<TextView> = 51 mediaCoverContainers.map { it.requireViewById(R.id.media_subtitle) } 52 val mediaProgressBars: List<SeekBar> = 53 mediaCoverContainers.map { 54 it.requireViewById<SeekBar?>(R.id.media_progress_bar).apply { 55 // Media playback is in the direction of tape, not time, so it stays LTR 56 layoutDirection = View.LAYOUT_DIRECTION_LTR 57 } 58 } 59 60 val mediaCoverItems: List<ImageView> = 61 mediaCoverContainers.map { it.requireViewById(R.id.media_cover) } 62 val gutsViewHolder = GutsViewHolder(itemView) 63 64 init { 65 (recommendations.background as IlluminationDrawable).let { background -> 66 mediaCoverContainers.forEach { background.registerLightSource(it) } 67 background.registerLightSource(gutsViewHolder.cancel) 68 background.registerLightSource(gutsViewHolder.dismiss) 69 background.registerLightSource(gutsViewHolder.settings) 70 } 71 } 72 73 fun marquee(start: Boolean, delay: Long) { 74 gutsViewHolder.marquee(start, delay, TAG) 75 } 76 77 companion object { 78 /** 79 * Creates a RecommendationViewHolder. 80 * 81 * @param inflater LayoutInflater to use to inflate the layout. 82 * @param parent Parent of inflated view. 83 */ 84 @JvmStatic 85 fun create(inflater: LayoutInflater, parent: ViewGroup): RecommendationViewHolder { 86 val itemView = 87 inflater.inflate(R.layout.media_recommendations, parent, false /* attachToRoot */) 88 // Because this media view (a TransitionLayout) is used to measure and layout the views 89 // in various states before being attached to its parent, we can't depend on the default 90 // LAYOUT_DIRECTION_INHERIT to correctly resolve the ltr direction. 91 itemView.layoutDirection = View.LAYOUT_DIRECTION_LOCALE 92 return RecommendationViewHolder(itemView) 93 } 94 95 // Res Ids for the control components on the recommendation view. 96 val controlsIds = 97 setOf( 98 R.id.media_rec_title, 99 R.id.media_cover, 100 R.id.media_cover1_container, 101 R.id.media_cover2_container, 102 R.id.media_cover3_container, 103 R.id.media_title, 104 R.id.media_subtitle, 105 ) 106 107 val mediaTitlesAndSubtitlesIds = 108 setOf( 109 R.id.media_title, 110 R.id.media_subtitle, 111 ) 112 113 val mediaContainersIds = 114 setOf( 115 R.id.media_cover1_container, 116 R.id.media_cover2_container, 117 R.id.media_cover3_container 118 ) 119 120 val backgroundId = R.id.sizing_view 121 } 122 } 123