1 /* 2 * 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.ImageButton 23 import android.widget.ImageView 24 import android.widget.SeekBar 25 import android.widget.TextView 26 import com.android.systemui.R 27 import com.android.systemui.util.animation.TransitionLayout 28 29 /** 30 * ViewHolder for a media player. 31 */ 32 class PlayerViewHolder private constructor(itemView: View) { 33 34 val player = itemView as TransitionLayout 35 36 // Player information 37 val appIcon = itemView.requireViewById<ImageView>(R.id.icon) 38 val appName = itemView.requireViewById<TextView>(R.id.app_name) 39 val albumView = itemView.requireViewById<ImageView>(R.id.album_art) 40 val titleText = itemView.requireViewById<TextView>(R.id.header_title) 41 val artistText = itemView.requireViewById<TextView>(R.id.header_artist) 42 43 // Output switcher 44 val seamless = itemView.requireViewById<ViewGroup>(R.id.media_seamless) 45 val seamlessIcon = itemView.requireViewById<ImageView>(R.id.media_seamless_image) 46 val seamlessText = itemView.requireViewById<TextView>(R.id.media_seamless_text) 47 val seamlessFallback = itemView.requireViewById<ImageView>(R.id.media_seamless_fallback) 48 49 // Seek bar 50 val seekBar = itemView.requireViewById<SeekBar>(R.id.media_progress_bar) 51 val progressTimes = itemView.requireViewById<ViewGroup>(R.id.notification_media_progress_time) 52 val elapsedTimeView = itemView.requireViewById<TextView>(R.id.media_elapsed_time) 53 val totalTimeView = itemView.requireViewById<TextView>(R.id.media_total_time) 54 55 // Action Buttons 56 val action0 = itemView.requireViewById<ImageButton>(R.id.action0) 57 val action1 = itemView.requireViewById<ImageButton>(R.id.action1) 58 val action2 = itemView.requireViewById<ImageButton>(R.id.action2) 59 val action3 = itemView.requireViewById<ImageButton>(R.id.action3) 60 val action4 = itemView.requireViewById<ImageButton>(R.id.action4) 61 62 // Settings screen 63 val settingsText = itemView.requireViewById<TextView>(R.id.remove_text) 64 val cancel = itemView.requireViewById<View>(R.id.cancel) 65 val dismiss = itemView.requireViewById<ViewGroup>(R.id.dismiss) 66 val dismissLabel = dismiss.getChildAt(0) 67 val settings = itemView.requireViewById<View>(R.id.settings) 68 69 init { <lambda>null70 (player.background as IlluminationDrawable).let { 71 it.registerLightSource(seamless) 72 it.registerLightSource(action0) 73 it.registerLightSource(action1) 74 it.registerLightSource(action2) 75 it.registerLightSource(action3) 76 it.registerLightSource(action4) 77 it.registerLightSource(cancel) 78 it.registerLightSource(dismiss) 79 it.registerLightSource(settings) 80 } 81 } 82 getActionnull83 fun getAction(id: Int): ImageButton { 84 return when (id) { 85 R.id.action0 -> action0 86 R.id.action1 -> action1 87 R.id.action2 -> action2 88 R.id.action3 -> action3 89 R.id.action4 -> action4 90 else -> { 91 throw IllegalArgumentException() 92 } 93 } 94 } 95 96 companion object { 97 /** 98 * Creates a PlayerViewHolder. 99 * 100 * @param inflater LayoutInflater to use to inflate the layout. 101 * @param parent Parent of inflated view. 102 */ createnull103 @JvmStatic fun create(inflater: LayoutInflater, parent: ViewGroup): PlayerViewHolder { 104 val mediaView = inflater.inflate(R.layout.media_view, parent, false) 105 // Because this media view (a TransitionLayout) is used to measure and layout the views 106 // in various states before being attached to its parent, we can't depend on the default 107 // LAYOUT_DIRECTION_INHERIT to correctly resolve the ltr direction. 108 mediaView.layoutDirection = View.LAYOUT_DIRECTION_LOCALE 109 return PlayerViewHolder(mediaView).apply { 110 // Media playback is in the direction of tape, not time, so it stays LTR 111 seekBar.layoutDirection = View.LAYOUT_DIRECTION_LTR 112 progressTimes.layoutDirection = View.LAYOUT_DIRECTION_LTR 113 } 114 } 115 116 val controlsIds = setOf( 117 R.id.icon, 118 R.id.app_name, 119 R.id.album_art, 120 R.id.header_title, 121 R.id.header_artist, 122 R.id.media_seamless, 123 R.id.notification_media_progress_time, 124 R.id.media_progress_bar, 125 R.id.action0, 126 R.id.action1, 127 R.id.action2, 128 R.id.action3, 129 R.id.action4, 130 R.id.icon 131 ) 132 val gutsIds = setOf( 133 R.id.media_text, 134 R.id.remove_text, 135 R.id.cancel, 136 R.id.dismiss, 137 R.id.settings 138 ) 139 } 140 } 141