diff options
author | Adam Powell <adamp@google.com> | 2012-06-15 19:21:34 -0700 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2012-06-15 20:19:29 -0700 |
commit | 130b4572d1f3df702e5b296a655d15a41f6d4c66 (patch) | |
tree | dcbeec24c1138901ac4925446d20b810887267e2 /core/java/android | |
parent | d8bbf96a84cba7c31fa1535fe2467520f2aa0198 (diff) | |
download | frameworks_base-130b4572d1f3df702e5b296a655d15a41f6d4c66.zip frameworks_base-130b4572d1f3df702e5b296a655d15a41f6d4c66.tar.gz frameworks_base-130b4572d1f3df702e5b296a655d15a41f6d4c66.tar.bz2 |
ActionProvider API update
* Add ActionProvider#overridesItemVisibility and isVisible.
These methods allow an ActionProvider to override the
visibility of a MenuItem that it is bound to. If a MenuItem
has been explicitly hidden by the application, it will not
be visible.
* Change MediaRouteActionProvider to not require a MediaRouter
callback, to avoid extra lifecycle management headaches.
Change-Id: I606fa98b3a6a3e60a953dd024274f9bf9c67acdd
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/app/MediaRouteActionProvider.java | 26 | ||||
-rw-r--r-- | core/java/android/view/ActionProvider.java | 26 |
2 files changed, 33 insertions, 19 deletions
diff --git a/core/java/android/app/MediaRouteActionProvider.java b/core/java/android/app/MediaRouteActionProvider.java index 4860182..b1fc90a 100644 --- a/core/java/android/app/MediaRouteActionProvider.java +++ b/core/java/android/app/MediaRouteActionProvider.java @@ -21,7 +21,6 @@ import com.android.internal.app.MediaRouteChooserDialogFragment; import android.content.Context; import android.content.ContextWrapper; import android.media.MediaRouter; -import android.media.MediaRouter.RouteInfo; import android.util.Log; import android.view.ActionProvider; import android.view.MenuItem; @@ -35,7 +34,6 @@ public class MediaRouteActionProvider extends ActionProvider { private MenuItem mMenuItem; private MediaRouteButton mView; private int mRouteTypes; - private final RouterCallback mRouterCallback = new RouterCallback(); private View.OnClickListener mExtendedSettingsListener; public MediaRouteActionProvider(Context context) { @@ -50,18 +48,10 @@ public class MediaRouteActionProvider extends ActionProvider { } public void setRouteTypes(int types) { - if (types == mRouteTypes) { - // Already registered; nothing to do. - return; - } - if (mRouteTypes != 0) { - mRouter.removeCallback(mRouterCallback); - } mRouteTypes = types; if (mView != null) { mView.setRouteTypes(mRouteTypes); } - mRouter.addCallback(types, mRouterCallback); } @Override @@ -124,15 +114,13 @@ public class MediaRouteActionProvider extends ActionProvider { } } - private class RouterCallback extends MediaRouter.SimpleCallback { - @Override - public void onRouteAdded(MediaRouter router, RouteInfo info) { - mMenuItem.setVisible(mRouter.getRouteCount() > 1); - } + @Override + public boolean overridesItemVisibility() { + return true; + } - @Override - public void onRouteRemoved(MediaRouter router, RouteInfo info) { - mMenuItem.setVisible(mRouter.getRouteCount() > 1); - } + @Override + public boolean isVisible() { + return mRouter.getRouteCount() > 1; } } diff --git a/core/java/android/view/ActionProvider.java b/core/java/android/view/ActionProvider.java index fa79d36..af9bf9e 100644 --- a/core/java/android/view/ActionProvider.java +++ b/core/java/android/view/ActionProvider.java @@ -96,6 +96,32 @@ public abstract class ActionProvider { } /** + * The result of this method determines whether or not {@link #isVisible()} will be used + * by the {@link MenuItem} this ActionProvider is bound to help determine its visibility. + * + * @return true if this ActionProvider overrides the visibility of the MenuItem + * it is bound to, false otherwise. The default implementation returns false. + * @see #isVisible() + */ + public boolean overridesItemVisibility() { + return false; + } + + /** + * If {@link #overridesItemVisibility()} returns true, the return value of this method + * will help determine the visibility of the {@link MenuItem} this ActionProvider is bound to. + * + * <p>If the MenuItem's visibility is explicitly set to false by the application, + * the MenuItem will not be shown, even if this method returns true.</p> + * + * @return true if the MenuItem this ActionProvider is bound to is visible, false if + * it is invisible. The default implementation returns true. + */ + public boolean isVisible() { + return true; + } + + /** * Performs an optional default action. * <p> * For the case of an action provider placed in a menu item not shown as an action this |