blob: 610e00ddd7f103bd4caedc361b05767cf15f0b2a [file] [log] [blame]
Robert Snoebergereb49e942020-05-12 16:31:09 -04001/*
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
17package com.android.systemui.media
18
19import android.view.LayoutInflater
20import android.view.View
21import android.view.ViewGroup
22import android.widget.ImageButton
23import android.widget.ImageView
24import android.widget.SeekBar
25import android.widget.TextView
Robert Snoebergereb49e942020-05-12 16:31:09 -040026import com.android.systemui.R
Selim Cinek2de5ebb2020-05-20 15:39:03 -070027import com.android.systemui.util.animation.TransitionLayout
Robert Snoebergereb49e942020-05-12 16:31:09 -040028
29/**
30 * ViewHolder for a media player.
31 */
32class PlayerViewHolder private constructor(itemView: View) {
33
Selim Cinek2de5ebb2020-05-20 15:39:03 -070034 val player = itemView as TransitionLayout
Robert Snoebergereb49e942020-05-12 16:31:09 -040035
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
Lucas Dupin5feeaca2020-05-28 11:01:54 -070044 val seamless = itemView.requireViewById<ViewGroup>(R.id.media_seamless)
Robert Snoebergereb49e942020-05-12 16:31:09 -040045 val seamlessIcon = itemView.requireViewById<ImageView>(R.id.media_seamless_image)
46 val seamlessText = itemView.requireViewById<TextView>(R.id.media_seamless_text)
47
48 // Seek bar
49 val seekBar = itemView.requireViewById<SeekBar>(R.id.media_progress_bar)
50 val elapsedTimeView = itemView.requireViewById<TextView>(R.id.media_elapsed_time)
51 val totalTimeView = itemView.requireViewById<TextView>(R.id.media_total_time)
52
53 // Action Buttons
54 val action0 = itemView.requireViewById<ImageButton>(R.id.action0)
55 val action1 = itemView.requireViewById<ImageButton>(R.id.action1)
56 val action2 = itemView.requireViewById<ImageButton>(R.id.action2)
57 val action3 = itemView.requireViewById<ImageButton>(R.id.action3)
58 val action4 = itemView.requireViewById<ImageButton>(R.id.action4)
59
Lucas Dupind6216922020-05-17 20:51:46 -070060 init {
Selim Cinek2de5ebb2020-05-20 15:39:03 -070061 (player.background as IlluminationDrawable).let {
Lucas Dupin5feeaca2020-05-28 11:01:54 -070062 it.registerLightSource(seamless)
63 it.registerLightSource(action0)
64 it.registerLightSource(action1)
65 it.registerLightSource(action2)
66 it.registerLightSource(action3)
67 it.registerLightSource(action4)
Lucas Dupind6216922020-05-17 20:51:46 -070068 }
69 }
70
Robert Snoebergereb49e942020-05-12 16:31:09 -040071 fun getAction(id: Int): ImageButton {
72 return when (id) {
73 R.id.action0 -> action0
74 R.id.action1 -> action1
75 R.id.action2 -> action2
76 R.id.action3 -> action3
77 R.id.action4 -> action4
78 else -> {
79 throw IllegalArgumentException()
80 }
81 }
82 }
83
84 // Settings screen
85 val options = itemView.requireViewById<View>(R.id.qs_media_controls_options)
86
87 companion object {
88 /**
89 * Creates a PlayerViewHolder.
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): PlayerViewHolder {
Selim Cinek2de5ebb2020-05-20 15:39:03 -070095 val v = inflater.inflate(R.layout.media_view, parent, false)
Robert Snoebergereb49e942020-05-12 16:31:09 -040096 return PlayerViewHolder(v)
97 }
98 }
99}