diff options
author | Domingos Lopes <domingos86lopes+github@gmail.com> | 2016-03-28 03:34:07 -0400 |
---|---|---|
committer | Domingos Lopes <domingos86lopes+github@gmail.com> | 2016-04-23 21:39:57 -0400 |
commit | e70f4d5389fc21fc00e3ecdda0e86f07873883ba (patch) | |
tree | 8f662b7a87da349ba13b0d445217b1d2bdeb0abc /core | |
parent | c915366c7b813e1d51f8bd992d334f6e7e675212 (diff) | |
download | AntennaPod-e70f4d5389fc21fc00e3ecdda0e86f07873883ba.zip |
fix media router button still showing when disabled
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/cast/CastManager.java | 21 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/cast/SwitchableMediaRouteActionProvider.java | 36 |
2 files changed, 57 insertions, 0 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/cast/CastManager.java b/core/src/main/java/de/danoeh/antennapod/core/cast/CastManager.java index 59a10c89f..b68e98e89 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/cast/CastManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/cast/CastManager.java @@ -21,9 +21,11 @@ package de.danoeh.antennapod.core.cast; import android.content.Context; import android.os.Build; +import android.support.v4.view.MenuItemCompat; import android.support.v7.media.MediaRouter; import android.util.Log; import android.view.KeyEvent; +import android.view.MenuItem; import com.google.android.gms.cast.ApplicationMetadata; import com.google.android.gms.cast.Cast; @@ -1713,4 +1715,23 @@ public class CastManager extends BaseCastManager implements OnFailedListener { return defaultVal; } } + + /** + * Adds and wires up the Switchable Media Router cast button. It returns a reference to the + * {@link SwitchableMediaRouteActionProvider} associated with the button if the caller needs + * such reference. It is assumed that the enclosing + * {@link android.app.Activity} inherits (directly or indirectly) from + * {@link android.support.v7.app.AppCompatActivity}. + * + * @param menuItem MenuItem of the Media Router cast button. + */ + public final SwitchableMediaRouteActionProvider addMediaRouterButton(MenuItem menuItem) { + SwitchableMediaRouteActionProvider mediaRouteActionProvider = (SwitchableMediaRouteActionProvider) + MenuItemCompat.getActionProvider(menuItem); + mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector); + if (mCastConfiguration.getMediaRouteDialogFactory() != null) { + mediaRouteActionProvider.setDialogFactory(mCastConfiguration.getMediaRouteDialogFactory()); + } + return mediaRouteActionProvider; + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/cast/SwitchableMediaRouteActionProvider.java b/core/src/main/java/de/danoeh/antennapod/core/cast/SwitchableMediaRouteActionProvider.java new file mode 100644 index 000000000..3d40c90fd --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/cast/SwitchableMediaRouteActionProvider.java @@ -0,0 +1,36 @@ +package de.danoeh.antennapod.core.cast; + +import android.content.Context; +import android.support.v7.app.MediaRouteActionProvider; + +/** + * <p>Action Provider that extends {@link MediaRouteActionProvider} and allows the client to + * disable completely the button by calling {@link #setEnabled(boolean)}.</p> + * + * <p>It is disabled by default, so if a client wants to initially have it enabled it must call + * <code>setEnabled(true)</code>.</p> + */ +public class SwitchableMediaRouteActionProvider extends MediaRouteActionProvider { + + private boolean enabled; + + public SwitchableMediaRouteActionProvider(Context context) { + super(context); + enabled = false; + } + + /** + * <p>Sets whether the Media Router button should be allowed to become visible or not.</p> + * + * <p>It's invisible by default.</p> + */ + public void setEnabled(boolean newVal) { + enabled = newVal; + refreshVisibility(); + } + + @Override + public boolean isVisible() { + return enabled && super.isVisible(); + } +} |