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 |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 26 | import com.android.systemui.R |
Selim Cinek | 2de5ebb | 2020-05-20 15:39:03 -0700 | [diff] [blame] | 27 | import com.android.systemui.util.animation.TransitionLayout |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * ViewHolder for a media player. |
| 31 | */ |
| 32 | class PlayerViewHolder private constructor(itemView: View) { |
| 33 | |
Selim Cinek | 2de5ebb | 2020-05-20 15:39:03 -0700 | [diff] [blame] | 34 | val player = itemView as TransitionLayout |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 35 | |
| 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 Dupin | 5feeaca | 2020-05-28 11:01:54 -0700 | [diff] [blame] | 44 | val seamless = itemView.requireViewById<ViewGroup>(R.id.media_seamless) |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 45 | 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 Dupin | d621692 | 2020-05-17 20:51:46 -0700 | [diff] [blame] | 60 | init { |
Selim Cinek | 2de5ebb | 2020-05-20 15:39:03 -0700 | [diff] [blame] | 61 | (player.background as IlluminationDrawable).let { |
Lucas Dupin | 5feeaca | 2020-05-28 11:01:54 -0700 | [diff] [blame] | 62 | it.registerLightSource(seamless) |
| 63 | it.registerLightSource(action0) |
| 64 | it.registerLightSource(action1) |
| 65 | it.registerLightSource(action2) |
| 66 | it.registerLightSource(action3) |
| 67 | it.registerLightSource(action4) |
Lucas Dupin | d621692 | 2020-05-17 20:51:46 -0700 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 71 | 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 Cinek | 2de5ebb | 2020-05-20 15:39:03 -0700 | [diff] [blame] | 95 | val v = inflater.inflate(R.layout.media_view, parent, false) |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 96 | return PlayerViewHolder(v) |
| 97 | } |
| 98 | } |
| 99 | } |