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) |
Robert Snoeberger | 0734043 | 2020-06-19 17:33:48 -0400 | [diff] [blame] | 47 | val seamlessFallback = itemView.requireViewById<ImageView>(R.id.media_seamless_fallback) |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 48 | |
| 49 | // Seek bar |
| 50 | val seekBar = itemView.requireViewById<SeekBar>(R.id.media_progress_bar) |
Jeff DeCew | afec78f | 2020-06-12 13:57:23 -0400 | [diff] [blame] | 51 | val progressTimes = itemView.requireViewById<ViewGroup>(R.id.notification_media_progress_time) |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 52 | 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 Dupin | d621692 | 2020-05-17 20:51:46 -0700 | [diff] [blame] | 62 | init { |
Selim Cinek | 2de5ebb | 2020-05-20 15:39:03 -0700 | [diff] [blame] | 63 | (player.background as IlluminationDrawable).let { |
Lucas Dupin | 5feeaca | 2020-05-28 11:01:54 -0700 | [diff] [blame] | 64 | it.registerLightSource(seamless) |
| 65 | it.registerLightSource(action0) |
| 66 | it.registerLightSource(action1) |
| 67 | it.registerLightSource(action2) |
| 68 | it.registerLightSource(action3) |
| 69 | it.registerLightSource(action4) |
Lucas Dupin | d621692 | 2020-05-17 20:51:46 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Robert Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 73 | 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 DeCew | afec78f | 2020-06-12 13:57:23 -0400 | [diff] [blame] | 97 | 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 Snoeberger | eb49e94 | 2020-05-12 16:31:09 -0400 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | } |