Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 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 | |
| 27 | import androidx.constraintlayout.motion.widget.MotionLayout |
| 28 | |
| 29 | import com.android.systemui.R |
| 30 | |
| 31 | /** |
| 32 | * ViewHolder for a media player. |
| 33 | */ |
| 34 | class 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 | } |