From b35c445f34e1a18e17aef3e3dfbc1c39b4d1815c Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Tue, 12 Jun 2012 11:25:54 -0700 Subject: MediaRouter work Fix a bug where MediaRouter would crash on creation Add click listener for app-supplied extended settings on the route selection dialog. Change-Id: I2991db1720b5c574148e250526984592f4dc3c44 --- api/current.txt | 2 ++ .../java/android/app/MediaRouteActionProvider.java | 11 ++++++++- core/java/android/app/MediaRouteButton.java | 7 ++++++ media/java/android/media/MediaRouter.java | 26 +++++++++++++--------- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/api/current.txt b/api/current.txt index dcf4bf2..55c9e28 100644 --- a/api/current.txt +++ b/api/current.txt @@ -3679,6 +3679,7 @@ package android.app { public class MediaRouteActionProvider extends android.view.ActionProvider { ctor public MediaRouteActionProvider(android.content.Context); method public android.view.View onCreateActionView(); + method public void setExtendedSettingsClickListener(android.view.View.OnClickListener); method public void setRouteTypes(int); } @@ -3687,6 +3688,7 @@ package android.app { ctor public MediaRouteButton(android.content.Context, android.util.AttributeSet); ctor public MediaRouteButton(android.content.Context, android.util.AttributeSet, int); method public int getRouteTypes(); + method public void setExtendedSettingsClickListener(android.view.View.OnClickListener); method public void setRouteTypes(int); } diff --git a/core/java/android/app/MediaRouteActionProvider.java b/core/java/android/app/MediaRouteActionProvider.java index 7764ac6..5fe08ec 100644 --- a/core/java/android/app/MediaRouteActionProvider.java +++ b/core/java/android/app/MediaRouteActionProvider.java @@ -33,11 +33,12 @@ public class MediaRouteActionProvider extends ActionProvider { private MediaRouteButton mView; private int mRouteTypes; private final RouterCallback mRouterCallback = new RouterCallback(); + private View.OnClickListener mExtendedSettingsListener; public MediaRouteActionProvider(Context context) { super(context); mContext = context; - mRouter = (MediaRouter)context.getSystemService(Context.MEDIA_ROUTER_SERVICE); + mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE); // Start with live audio by default. // TODO Update this when new route types are added; segment by API level @@ -76,6 +77,7 @@ public class MediaRouteActionProvider extends ActionProvider { mView = new MediaRouteButton(mContext); mMenuItem.setVisible(mRouter.getRouteCount() > 1); mView.setRouteTypes(mRouteTypes); + mView.setExtendedSettingsClickListener(mExtendedSettingsListener); return mView; } @@ -85,6 +87,13 @@ public class MediaRouteActionProvider extends ActionProvider { return true; } + public void setExtendedSettingsClickListener(View.OnClickListener listener) { + mExtendedSettingsListener = listener; + if (mView != null) { + mView.setExtendedSettingsClickListener(listener); + } + } + private class RouterCallback extends MediaRouter.SimpleCallback { @Override public void onRouteAdded(MediaRouter router, RouteInfo info) { diff --git a/core/java/android/app/MediaRouteButton.java b/core/java/android/app/MediaRouteButton.java index 8f9379a..385241c 100644 --- a/core/java/android/app/MediaRouteButton.java +++ b/core/java/android/app/MediaRouteButton.java @@ -43,6 +43,8 @@ public class MediaRouteButton extends View { private int mMinWidth; private int mMinHeight; + private OnClickListener mExtendedSettingsClickListener; + private static final int[] ACTIVATED_STATE_SET = { R.attr.state_activated }; @@ -260,6 +262,11 @@ public class MediaRouteButton extends View { mRemoteIndicator.draw(canvas); } + public void setExtendedSettingsClickListener(OnClickListener listener) { + // TODO: if dialog is already open, propagate so that it updates live. + mExtendedSettingsClickListener = listener; + } + private class MediaRouteCallback extends MediaRouter.SimpleCallback { @Override public void onRouteSelected(MediaRouter router, int type, RouteInfo info) { diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index 7c74f0a..38fe363 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -45,21 +45,21 @@ public class MediaRouter { private static final String TAG = "MediaRouter"; static class Static { - private final Resources mResources; - private final AudioManager mAudioManager; - private final Handler mHandler; - private final ArrayList mCallbacks = new ArrayList(); + final Resources mResources; + final AudioManager mAudioManager; + final Handler mHandler; + final ArrayList mCallbacks = new ArrayList(); - private final ArrayList mRoutes = new ArrayList(); - private final ArrayList mCategories = new ArrayList(); + final ArrayList mRoutes = new ArrayList(); + final ArrayList mCategories = new ArrayList(); - private final RouteCategory mSystemCategory; - private final HeadphoneChangedBroadcastReceiver mHeadphoneChangedReceiver; + final RouteCategory mSystemCategory; + final HeadphoneChangedBroadcastReceiver mHeadphoneChangedReceiver; - private RouteInfo mDefaultAudio; - private RouteInfo mBluetoothA2dpRoute; + RouteInfo mDefaultAudio; + RouteInfo mBluetoothA2dpRoute; - private RouteInfo mSelectedRoute; + RouteInfo mSelectedRoute; Static(Context appContext) { mResources = Resources.getSystem(); @@ -78,7 +78,10 @@ public class MediaRouter { speakerFilter.addAction(Intent.ACTION_HDMI_AUDIO_PLUG); mHeadphoneChangedReceiver = new HeadphoneChangedBroadcastReceiver(); appContext.registerReceiver(mHeadphoneChangedReceiver, speakerFilter); + } + // Called after sStatic is initialized + void initDefaultRoutes() { mDefaultAudio = new RouteInfo(mSystemCategory); mDefaultAudio.mName = mResources.getText( com.android.internal.R.string.default_audio_route_name); @@ -130,6 +133,7 @@ public class MediaRouter { synchronized (Static.class) { if (sStatic == null) { sStatic = new Static(context.getApplicationContext()); + sStatic.initDefaultRoutes(); } } } -- cgit v1.1