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 albumView = itemView.requireViewById<ImageView>(R.id.album_art) 39 val titleText = itemView.requireViewById<TextView>(R.id.header_title) 40 val artistText = itemView.requireViewById<TextView>(R.id.header_artist) 41 42 // Output switcher 43 val seamless = itemView.requireViewById<ViewGroup>(R.id.media_seamless) 44 val seamlessIcon = itemView.requireViewById<ImageView>(R.id.media_seamless_image) 45 val seamlessText = itemView.requireViewById<TextView>(R.id.media_seamless_text) 46 val seamlessFallback = itemView.requireViewById<ImageView>(R.id.media_seamless_fallback) 47 48 // Seek bar 49 val seekBar = itemView.requireViewById<SeekBar>(R.id.media_progress_bar) 50 val progressTimes = itemView.requireViewById<ViewGroup>(R.id.notification_media_progress_time) 51 val elapsedTimeView = itemView.requireViewById<TextView>(R.id.media_elapsed_time) 52 val totalTimeView = itemView.requireViewById<TextView>(R.id.media_total_time) 53 54 // Action Buttons 55 val action0 = itemView.requireViewById<ImageButton>(R.id.action0) 56 val action1 = itemView.requireViewById<ImageButton>(R.id.action1) 57 val action2 = itemView.requireViewById<ImageButton>(R.id.action2) 58 val action3 = itemView.requireViewById<ImageButton>(R.id.action3) 59 val action4 = itemView.requireViewById<ImageButton>(R.id.action4) 60 61 // Settings screen 62 val longPressText = itemView.requireViewById<TextView>(R.id.remove_text) 63 val cancel = itemView.requireViewById<View>(R.id.cancel) 64 val dismiss = itemView.requireViewById<ViewGroup>(R.id.dismiss) 65 val dismissLabel = dismiss.getChildAt(0) 66 val settings = itemView.requireViewById<View>(R.id.settings) 67 val settingsText = itemView.requireViewById<TextView>(R.id.settings_text) 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 marqueenull96 fun marquee(start: Boolean, delay: Long) { 97 longPressText.getHandler().postDelayed({ longPressText.setSelected(start) }, delay) 98 } 99 100 companion object { 101 /** 102 * Creates a PlayerViewHolder. 103 * 104 * @param inflater LayoutInflater to use to inflate the layout. 105 * @param parent Parent of inflated view. 106 */ createnull107 @JvmStatic fun create(inflater: LayoutInflater, parent: ViewGroup): PlayerViewHolder { 108 val mediaView = inflater.inflate(R.layout.media_view, parent, false) 109 // Because this media view (a TransitionLayout) is used to measure and layout the views 110 // in various states before being attached to its parent, we can't depend on the default 111 // LAYOUT_DIRECTION_INHERIT to correctly resolve the ltr direction. 112 mediaView.layoutDirection = View.LAYOUT_DIRECTION_LOCALE 113 return PlayerViewHolder(mediaView).apply { 114 // Media playback is in the direction of tape, not time, so it stays LTR 115 seekBar.layoutDirection = View.LAYOUT_DIRECTION_LTR 116 progressTimes.layoutDirection = View.LAYOUT_DIRECTION_LTR 117 } 118 } 119 120 val controlsIds = setOf( 121 R.id.icon, 122 R.id.app_name, 123 R.id.album_art, 124 R.id.header_title, 125 R.id.header_artist, 126 R.id.media_seamless, 127 R.id.media_seamless_fallback, 128 R.id.notification_media_progress_time, 129 R.id.media_progress_bar, 130 R.id.action0, 131 R.id.action1, 132 R.id.action2, 133 R.id.action3, 134 R.id.action4, 135 R.id.icon 136 ) 137 val gutsIds = setOf( 138 R.id.remove_text, 139 R.id.cancel, 140 R.id.dismiss, 141 R.id.settings 142 ) 143 } 144 } 145