blob: 600fdc27ef89bd71947eeb4e727041cf55a26675 [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)
Robert Snoeberger07340432020-06-19 17:33:48 -040047 val seamlessFallback = itemView.requireViewById<ImageView>(R.id.media_seamless_fallback)
Robert Snoebergereb49e942020-05-12 16:31:09 -040048
49 // Seek bar
50 val seekBar = itemView.requireViewById<SeekBar>(R.id.media_progress_bar)
Jeff DeCewafec78f2020-06-12 13:57:23 -040051 val progressTimes = itemView.requireViewById<ViewGroup>(R.id.notification_media_progress_time)
Robert Snoebergereb49e942020-05-12 16:31:09 -040052 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
Lucas Dupind6216922020-05-17 20:51:46 -070062 init {
Selim Cinek2de5ebb2020-05-20 15:39:03 -070063 (player.background as IlluminationDrawable).let {
Lucas Dupin5feeaca2020-05-28 11:01:54 -070064 it.registerLightSource(seamless)
65 it.registerLightSource(action0)
66 it.registerLightSource(action1)
67 it.registerLightSource(action2)
68 it.registerLightSource(action3)
69 it.registerLightSource(action4)
Lucas Dupind6216922020-05-17 20:51:46 -070070 }
71 }
72
Robert Snoebergereb49e942020-05-12 16:31:09 -040073 fun getAction(id: Int): ImageButton {
74 return when (id) {
75 R.id.action0 -> action0
76 R.id.action1 -> action1
77 R.id.action2 -> action2
78 R.id.action3 -> action3
79 R.id.action4 -> action4
80 else -> {
81 throw IllegalArgumentException()
82 }
83 }
84 }
85
86 // Settings screen
87 val options = itemView.requireViewById<View>(R.id.qs_media_controls_options)
88
89 companion object {
90 /**
91 * Creates a PlayerViewHolder.
92 *
93 * @param inflater LayoutInflater to use to inflate the layout.
94 * @param parent Parent of inflated view.
95 */
96 @JvmStatic fun create(inflater: LayoutInflater, parent: ViewGroup): PlayerViewHolder {
Jeff DeCewafec78f2020-06-12 13:57:23 -040097 val mediaView = inflater.inflate(R.layout.media_view, parent, false)
98 // Because this media view (a TransitionLayout) is used to measure and layout the views
99 // in various states before being attached to its parent, we can't depend on the default
100 // LAYOUT_DIRECTION_INHERIT to correctly resolve the ltr direction.
101 mediaView.layoutDirection = View.LAYOUT_DIRECTION_LOCALE
102 return PlayerViewHolder(mediaView).apply {
103 // Media playback is in the direction of tape, not time, so it stays LTR
104 seekBar.layoutDirection = View.LAYOUT_DIRECTION_LTR
105 progressTimes.layoutDirection = View.LAYOUT_DIRECTION_LTR
106 }
Robert Snoebergereb49e942020-05-12 16:31:09 -0400107 }
108 }
109}