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
This commit is contained in:
@@ -22814,10 +22814,12 @@ package android.view {
|
|||||||
public abstract class ActionProvider {
|
public abstract class ActionProvider {
|
||||||
ctor public ActionProvider(android.content.Context);
|
ctor public ActionProvider(android.content.Context);
|
||||||
method public boolean hasSubMenu();
|
method public boolean hasSubMenu();
|
||||||
|
method public boolean isVisible();
|
||||||
method public abstract deprecated android.view.View onCreateActionView();
|
method public abstract deprecated android.view.View onCreateActionView();
|
||||||
method public android.view.View onCreateActionView(android.view.MenuItem);
|
method public android.view.View onCreateActionView(android.view.MenuItem);
|
||||||
method public boolean onPerformDefaultAction();
|
method public boolean onPerformDefaultAction();
|
||||||
method public void onPrepareSubMenu(android.view.SubMenu);
|
method public void onPrepareSubMenu(android.view.SubMenu);
|
||||||
|
method public boolean overridesItemVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class Choreographer {
|
public final class Choreographer {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import com.android.internal.app.MediaRouteChooserDialogFragment;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.media.MediaRouter;
|
import android.media.MediaRouter;
|
||||||
import android.media.MediaRouter.RouteInfo;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ActionProvider;
|
import android.view.ActionProvider;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -35,7 +34,6 @@ public class MediaRouteActionProvider extends ActionProvider {
|
|||||||
private MenuItem mMenuItem;
|
private MenuItem mMenuItem;
|
||||||
private MediaRouteButton mView;
|
private MediaRouteButton mView;
|
||||||
private int mRouteTypes;
|
private int mRouteTypes;
|
||||||
private final RouterCallback mRouterCallback = new RouterCallback();
|
|
||||||
private View.OnClickListener mExtendedSettingsListener;
|
private View.OnClickListener mExtendedSettingsListener;
|
||||||
|
|
||||||
public MediaRouteActionProvider(Context context) {
|
public MediaRouteActionProvider(Context context) {
|
||||||
@@ -50,18 +48,10 @@ public class MediaRouteActionProvider extends ActionProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRouteTypes(int types) {
|
public void setRouteTypes(int types) {
|
||||||
if (types == mRouteTypes) {
|
|
||||||
// Already registered; nothing to do.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mRouteTypes != 0) {
|
|
||||||
mRouter.removeCallback(mRouterCallback);
|
|
||||||
}
|
|
||||||
mRouteTypes = types;
|
mRouteTypes = types;
|
||||||
if (mView != null) {
|
if (mView != null) {
|
||||||
mView.setRouteTypes(mRouteTypes);
|
mView.setRouteTypes(mRouteTypes);
|
||||||
}
|
}
|
||||||
mRouter.addCallback(types, mRouterCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,15 +114,13 @@ public class MediaRouteActionProvider extends ActionProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RouterCallback extends MediaRouter.SimpleCallback {
|
@Override
|
||||||
@Override
|
public boolean overridesItemVisibility() {
|
||||||
public void onRouteAdded(MediaRouter router, RouteInfo info) {
|
return true;
|
||||||
mMenuItem.setVisible(mRouter.getRouteCount() > 1);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRouteRemoved(MediaRouter router, RouteInfo info) {
|
public boolean isVisible() {
|
||||||
mMenuItem.setVisible(mRouter.getRouteCount() > 1);
|
return mRouter.getRouteCount() > 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,6 +95,32 @@ public abstract class ActionProvider {
|
|||||||
return onCreateActionView();
|
return onCreateActionView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Performs an optional default action.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -456,6 +456,9 @@ public final class MenuItemImpl implements MenuItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
|
if (mActionProvider != null && mActionProvider.overridesItemVisibility()) {
|
||||||
|
return (mFlags & HIDDEN) == 0 && mActionProvider.isVisible();
|
||||||
|
}
|
||||||
return (mFlags & HIDDEN) == 0;
|
return (mFlags & HIDDEN) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -662,6 +662,7 @@ public class MediaRouter {
|
|||||||
*/
|
*/
|
||||||
public void setTag(Object tag) {
|
public void setTag(Object tag) {
|
||||||
mTag = tag;
|
mTag = tag;
|
||||||
|
routeUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -675,7 +676,6 @@ public class MediaRouter {
|
|||||||
void setStatusInt(CharSequence status) {
|
void setStatusInt(CharSequence status) {
|
||||||
if (!status.equals(mStatus)) {
|
if (!status.equals(mStatus)) {
|
||||||
mStatus = status;
|
mStatus = status;
|
||||||
routeUpdated();
|
|
||||||
if (mGroup != null) {
|
if (mGroup != null) {
|
||||||
mGroup.memberStatusChanged(this, status);
|
mGroup.memberStatusChanged(this, status);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user