Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.media.ui; | |
| 6 | |
| 7 import java.util.Set; | |
| 8 import java.util.concurrent.CopyOnWriteArraySet; | |
| 9 | |
| 10 /** | |
| 11 * MediaPlaybackControls is an abstract base class for various UI views that are intended to control | |
| 12 * media playback. MediaPlaybackControls contains a number of setters that will update the | |
| 13 * MediaPlaybackControls's UI. | |
| 14 * Call {@code MediaPlaybackControls#addListener} with an implementation of | |
| 15 * {@code MediaPlaybackControls.Listener} to receive messages when the user inte racts with the | |
| 16 * controls. | |
| 17 */ | |
| 18 public abstract class MediaPlaybackControls implements MediaPlaybackListener { | |
|
mlamouri (slow - plz ping)
2015/06/23 14:58:56
I think having that class here is great but are th
whywhat
2015/06/23 19:39:11
You're right.
| |
| 19 | |
| 20 /** | |
| 21 * Base interface for classes that need to listen to transport control event s. | |
| 22 */ | |
| 23 public static interface Listener { | |
| 24 void onPlay(); | |
| 25 void onPause(); | |
| 26 } | |
| 27 | |
| 28 // Initialized lazily to simplify testing. Should only ever be accessed thro ugh getListeners to | |
| 29 // ensure correct initialization. | |
| 30 private Set<Listener> mListeners; | |
| 31 protected MediaInfo mMediaInfo; | |
| 32 | |
| 33 /** | |
| 34 * @return the media information previously assigned with | |
| 35 * {@link #setMediaInfo(MediaInfo)}, or {@code null} if the {@link MediaInfo } | |
| 36 * has not yet been assigned. | |
| 37 */ | |
| 38 public final MediaInfo getMediaInfo() { | |
| 39 return mMediaInfo; | |
| 40 } | |
| 41 | |
| 42 /** | |
| 43 * Sets the media information to display on the MediaPlaybackControls. | |
| 44 * @param mediaInfo the media information to use. | |
| 45 */ | |
| 46 public final void setMediaInfo(MediaInfo mediaInfo) { | |
| 47 if (equal(mMediaInfo, mediaInfo)) return; | |
|
mlamouri (slow - plz ping)
2015/06/23 14:58:56
nit: mMediaInfo.equals(mediaInfo)
whywhat
2015/06/23 19:39:11
This would cause NPE if mMediaInfo is null.
| |
| 48 | |
| 49 mMediaInfo = mediaInfo; | |
| 50 onMediaInfoChanged(); | |
| 51 } | |
| 52 | |
| 53 /** | |
| 54 * Registers a {@link Listener} with the MediaPlaybackControls. | |
| 55 * @param listener the Listener to be registered. | |
| 56 */ | |
| 57 public void addListener(Listener listener) { | |
| 58 getListeners().add(listener); | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * Unregisters a {@link Listener} previously registered with {@link #addList ener(Listener)}. | |
| 63 * @param listener the Listener to be removed. | |
| 64 */ | |
| 65 public void removeListener(Listener listener) { | |
| 66 getListeners().remove(listener); | |
| 67 } | |
| 68 | |
| 69 /** | |
| 70 * Displays the MediaPlaybackControls to the user. | |
| 71 * @param mediaInfo the information about the media. | |
| 72 */ | |
| 73 public abstract void show(MediaInfo mediaInfo); | |
| 74 | |
| 75 /** | |
| 76 * Hides the MediaPlaybackControls. | |
| 77 * @param tabId tab that requests to hide the controls | |
| 78 */ | |
| 79 public abstract void hide(int tabId); | |
| 80 | |
| 81 /** | |
| 82 * @return the current list of listeners. | |
| 83 */ | |
| 84 protected final Set<Listener> getListeners() { | |
| 85 if (mListeners == null) mListeners = new CopyOnWriteArraySet<Listener>() ; | |
| 86 return mListeners; | |
| 87 } | |
| 88 | |
| 89 protected void onMediaInfoChanged() {} | |
| 90 | |
| 91 private static boolean equal(Object a, Object b) { | |
|
mlamouri (slow - plz ping)
2015/06/23 14:58:56
Why do you need that?
whywhat
2015/06/23 19:39:11
See above :) I think we need a more generic equal
| |
| 92 return (a == null) ? (b == null) : a.equals(b); | |
| 93 } | |
| 94 } | |
| OLD | NEW |