Index: chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaPlaybackControls.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaPlaybackControls.java b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaPlaybackControls.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a46ee3c938e9565160ea31edbebc2d3470a40131 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaPlaybackControls.java |
@@ -0,0 +1,94 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.media.ui; |
+ |
+import java.util.Set; |
+import java.util.concurrent.CopyOnWriteArraySet; |
+ |
+/** |
+ * MediaPlaybackControls is an abstract base class for various UI views that are intended to control |
+ * media playback. MediaPlaybackControls contains a number of setters that will update the |
+ * MediaPlaybackControls's UI. |
+ * Call {@code MediaPlaybackControls#addListener} with an implementation of |
+ * {@code MediaPlaybackControls.Listener} to receive messages when the user interacts with the |
+ * controls. |
+ */ |
+public abstract class MediaPlaybackControls implements MediaPlaybackListener { |
+ |
+ /** |
+ * Base interface for classes that need to listen to transport control events. |
+ */ |
+ public static interface Listener { |
+ void onPlay(); |
+ void onPause(); |
+ } |
+ |
+ // Initialized lazily to simplify testing. Should only ever be accessed through getListeners to |
+ // ensure correct initialization. |
+ private Set<Listener> mListeners; |
+ protected MediaInfo mMediaInfo; |
+ |
+ /** |
+ * @return the media information previously assigned with |
+ * {@link #setMediaInfo(MediaInfo)}, or {@code null} if the {@link MediaInfo} |
+ * has not yet been assigned. |
+ */ |
+ public final MediaInfo getMediaInfo() { |
+ return mMediaInfo; |
+ } |
+ |
+ /** |
+ * Sets the media information to display on the MediaPlaybackControls. |
+ * @param mediaInfo the media information to use. |
+ */ |
+ public final void setMediaInfo(MediaInfo mediaInfo) { |
+ if (equal(mMediaInfo, mediaInfo)) return; |
+ |
+ mMediaInfo = mediaInfo; |
+ onMediaInfoChanged(); |
+ } |
+ |
+ /** |
+ * Registers a {@link Listener} with the MediaPlaybackControls. |
+ * @param listener the Listener to be registered. |
+ */ |
+ public void addListener(Listener listener) { |
+ getListeners().add(listener); |
+ } |
+ |
+ /** |
+ * Unregisters a {@link Listener} previously registered with {@link #addListener(Listener)}. |
+ * @param listener the Listener to be removed. |
+ */ |
+ public void removeListener(Listener listener) { |
+ getListeners().remove(listener); |
+ } |
+ |
+ /** |
+ * Displays the MediaPlaybackControls to the user. |
+ * @param mediaInfo the information about the media. |
+ */ |
+ public abstract void show(MediaInfo mediaInfo); |
+ |
+ /** |
+ * Hides the MediaPlaybackControls. |
+ * @param tabId tab that requests to hide the controls |
+ */ |
+ public abstract void hide(int tabId); |
+ |
+ /** |
+ * @return the current list of listeners. |
+ */ |
+ protected final Set<Listener> getListeners() { |
+ if (mListeners == null) mListeners = new CopyOnWriteArraySet<Listener>(); |
+ return mListeners; |
+ } |
+ |
+ protected void onMediaInfoChanged() {} |
+ |
+ private static boolean equal(Object a, Object b) { |
+ return (a == null) ? (b == null) : a.equals(b); |
+ } |
+} |