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 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.TextView 24 import androidx.annotation.IntegerRes 25 import com.android.systemui.R 26 import com.android.systemui.util.animation.TransitionLayout 27 28 /** ViewHolder for a Smartspace media recommendation. */ 29 class RecommendationViewHolder private constructor(itemView: View) { 30 31 val recommendations = itemView as TransitionLayout 32 33 // Recommendation screen 34 val cardIcon = itemView.requireViewById<ImageView>(R.id.recommendation_card_icon) 35 val cardText = itemView.requireViewById<TextView>(R.id.recommendation_card_text) 36 val mediaCoverItems = listOf<ImageView>( 37 itemView.requireViewById(R.id.media_cover1), 38 itemView.requireViewById(R.id.media_cover2), 39 itemView.requireViewById(R.id.media_cover3), 40 itemView.requireViewById(R.id.media_cover4), 41 itemView.requireViewById(R.id.media_cover5), 42 itemView.requireViewById(R.id.media_cover6)) 43 val mediaCoverContainers = listOf<ViewGroup>( 44 itemView.requireViewById(R.id.media_cover1_container), 45 itemView.requireViewById(R.id.media_cover2_container), 46 itemView.requireViewById(R.id.media_cover3_container), 47 itemView.requireViewById(R.id.media_cover4_container), 48 itemView.requireViewById(R.id.media_cover5_container), 49 itemView.requireViewById(R.id.media_cover6_container)) 50 val mediaCoverItemsResIds = listOf<@IntegerRes Int>( 51 R.id.media_cover1, 52 R.id.media_cover2, 53 R.id.media_cover3, 54 R.id.media_cover4, 55 R.id.media_cover5, 56 R.id.media_cover6) 57 val mediaCoverContainersResIds = listOf<@IntegerRes Int>( 58 R.id.media_cover1_container, 59 R.id.media_cover2_container, 60 R.id.media_cover3_container, 61 R.id.media_cover4_container, 62 R.id.media_cover5_container, 63 R.id.media_cover6_container) 64 65 // Settings/Guts screen 66 val longPressText = itemView.requireViewById<TextView>(R.id.remove_text) 67 val cancel = itemView.requireViewById<View>(R.id.cancel) 68 val dismiss = itemView.requireViewById<ViewGroup>(R.id.dismiss) 69 val dismissLabel = dismiss.getChildAt(0) 70 val settings = itemView.requireViewById<View>(R.id.settings) 71 val settingsText = itemView.requireViewById<TextView>(R.id.settings_text) 72 73 init { 74 (recommendations.background as IlluminationDrawable).let { background -> 75 mediaCoverContainers.forEach { background.registerLightSource(it) } 76 background.registerLightSource(cancel) 77 background.registerLightSource(dismiss) 78 background.registerLightSource(dismissLabel) 79 background.registerLightSource(settings) 80 } 81 } 82 83 fun marquee(start: Boolean, delay: Long) { 84 longPressText.getHandler().postDelayed({ longPressText.setSelected(start) }, delay) 85 } 86 87 companion object { 88 /** 89 * Creates a RecommendationViewHolder. 90 * 91 * @param inflater LayoutInflater to use to inflate the layout. 92 * @param parent Parent of inflated view. 93 */ 94 @JvmStatic fun create(inflater: LayoutInflater, parent: ViewGroup): 95 RecommendationViewHolder { 96 val itemView = 97 inflater.inflate( 98 R.layout.media_smartspace_recommendations, 99 parent, 100 false /* attachToRoot */) 101 // Because this media view (a TransitionLayout) is used to measure and layout the views 102 // in various states before being attached to its parent, we can't depend on the default 103 // LAYOUT_DIRECTION_INHERIT to correctly resolve the ltr direction. 104 itemView.layoutDirection = View.LAYOUT_DIRECTION_LOCALE 105 return RecommendationViewHolder(itemView) 106 } 107 108 // Res Ids for the control components on the recommendation view. 109 val controlsIds = setOf( 110 R.id.recommendation_card_icon, 111 R.id.recommendation_card_text, 112 R.id.media_cover1, 113 R.id.media_cover2, 114 R.id.media_cover3, 115 R.id.media_cover4, 116 R.id.media_cover5, 117 R.id.media_cover6, 118 R.id.media_cover1_container, 119 R.id.media_cover2_container, 120 R.id.media_cover3_container, 121 R.id.media_cover4_container, 122 R.id.media_cover5_container, 123 R.id.media_cover6_container 124 ) 125 126 // Res Ids for the components on the guts panel. 127 val gutsIds = setOf( 128 R.id.remove_text, 129 R.id.cancel, 130 R.id.dismiss, 131 R.id.settings 132 ) 133 } 134 }