Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/media/remote/FullscreenMediaRouteButton.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/FullscreenMediaRouteButton.java b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/FullscreenMediaRouteButton.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..99194f6966038701ab1546a199cd5543fd76742d |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/FullscreenMediaRouteButton.java |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2012 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.remote; |
| + |
| +import android.content.Context; |
| +import android.support.v7.app.MediaRouteButton; |
| +import android.util.AttributeSet; |
| +import android.view.View; |
| + |
| +/** |
| + * Cast button that wraps around a MediaRouteButton. We show the button only if there are available |
| + * cast devices. |
| + */ |
| +public class FullscreenMediaRouteButton extends MediaRouteButton { |
| + |
| + // Are we in the time window when the button should become visible if there're routes? |
| + private boolean mVisibilityRequested; |
| + |
| + /** |
| + * The constructor invoked when inflating the button. |
| + */ |
| + public FullscreenMediaRouteButton(Context context, AttributeSet attributeSet) { |
| + super(context, attributeSet); |
| + mVisibilityRequested = false; |
| + } |
| + |
| + /** |
| + * Set the necessary state for the button to work. |
| + */ |
| + public void initialize(MediaRouteController controller) { |
| + setRouteSelector(controller.buildMediaRouteSelector()); |
| + setDialogFactory(new ChromeMediaRouteDialogFactory()); |
| + } |
| + |
| + @Override |
| + public void setEnabled(boolean enabled) { |
| + if (!RemoteMediaPlayerController.isRemotePlaybackEnabled()) return; |
| + |
| + // We need to check if the button was in the same state before to avoid doing anything, |
| + // but we also need to update the current state for {@link #setButtonVisibility} to work. |
| + boolean wasEnabled = isEnabled(); |
| + super.setEnabled(enabled); |
| + |
| + if (wasEnabled == enabled) return; |
|
qinmin
2015/03/20 19:35:46
can this line be moved on top of the super.setEnab
aberent
2015/03/23 17:35:31
No idea. There seems to have been a history of sub
whywhat
2015/03/23 17:46:35
Actually, setButtonVisibility() below depends on i
|
| + |
| + if (enabled && mVisibilityRequested) { |
| + setButtonVisibility(View.VISIBLE); |
| + } else { |
| + setVisibility(View.GONE); |
| + } |
| + } |
| + |
| + private void setButtonVisibility(int visibility) { |
| + // If the button is being set to visible, first make sure that it can even cast |
| + // to anything before making it actually visible. |
| + if (visibility == View.VISIBLE) { |
| + if (isEnabled()) { |
| + setVisibility(View.VISIBLE); |
| + } else { |
| + setVisibility(View.GONE); |
| + } |
| + } else { |
| + setVisibility(visibility); |
| + } |
| + } |
| + |
| +} |
| + |