blob: 571e18d0ff20f07eb8788531e424acec617be823 [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
26
27import androidx.constraintlayout.motion.widget.MotionLayout
28
29import com.android.systemui.R
30
31/**
32 * ViewHolder for a media player.
33 */
34class PlayerViewHolder private constructor(itemView: View) {
35
36 val player = itemView as MotionLayout
37 val background = itemView.requireViewById<View>(R.id.media_background)
38
39 // Player information
40 val appIcon = itemView.requireViewById<ImageView>(R.id.icon)
41 val appName = itemView.requireViewById<TextView>(R.id.app_name)
42 val albumView = itemView.requireViewById<ImageView>(R.id.album_art)
43 val titleText = itemView.requireViewById<TextView>(R.id.header_title)
44 val artistText = itemView.requireViewById<TextView>(R.id.header_artist)
45
46 // Output switcher
47 val seamless = itemView.findViewById<ViewGroup>(R.id.media_seamless)
48 val seamlessIcon = itemView.requireViewById<ImageView>(R.id.media_seamless_image)
49 val seamlessText = itemView.requireViewById<TextView>(R.id.media_seamless_text)
50
51 // Seek bar
52 val seekBar = itemView.requireViewById<SeekBar>(R.id.media_progress_bar)
53 val elapsedTimeView = itemView.requireViewById<TextView>(R.id.media_elapsed_time)
54 val totalTimeView = itemView.requireViewById<TextView>(R.id.media_total_time)
55
56 // Action Buttons
57 val action0 = itemView.requireViewById<ImageButton>(R.id.action0)
58 val action1 = itemView.requireViewById<ImageButton>(R.id.action1)
59 val action2 = itemView.requireViewById<ImageButton>(R.id.action2)
60 val action3 = itemView.requireViewById<ImageButton>(R.id.action3)
61 val action4 = itemView.requireViewById<ImageButton>(R.id.action4)
62
63 fun getAction(id: Int): ImageButton {
64 return when (id) {
65 R.id.action0 -> action0
66 R.id.action1 -> action1
67 R.id.action2 -> action2
68 R.id.action3 -> action3
69 R.id.action4 -> action4
70 else -> {
71 throw IllegalArgumentException()
72 }
73 }
74 }
75
76 // Settings screen
77 val options = itemView.requireViewById<View>(R.id.qs_media_controls_options)
78
79 companion object {
80 /**
81 * Creates a PlayerViewHolder.
82 *
83 * @param inflater LayoutInflater to use to inflate the layout.
84 * @param parent Parent of inflated view.
85 */
86 @JvmStatic fun create(inflater: LayoutInflater, parent: ViewGroup): PlayerViewHolder {
87 val v = inflater.inflate(R.layout.qs_media_panel, parent, false)
88 return PlayerViewHolder(v)
89 }
90 }
91}