Custom Cast Button and Behavior Implementation
android, google-cast
Solution
In my application I am using ActionBarSherlock with a split ActionBar, so I cannot use the built in MediaRouteActionProvider (at least not to my knowledge) that is in the Google Cast SDK.
`MediaRouteActionProvider` is in the `appcompat_v7` library project, not the Cast SDK.
I forked `MediaRouteActionProvider` and created a version that works using the native API Level 11 action bar. You could do the same thing to create one that works with ActionBarSherlock, at least in principle. I know of no reason why this would not work -- if it works with the native action bar and the `appcompat_v7` backport, it should work for ActionBarSherlock.
Problem
Does anyone know if it is possible to Create a Custom `ImageButton` using the Cast Icons, and add an `ActionProvider` to this `ImageButton` to replicate the MediaRouteActionProvider behavior? In my application I am using ActionBarSherlock with a split `ActionBar`, so I cannot use the built in MediaRouteActionProvider (at least not to my knowledge) that is in the MediaRouter v7 support library as this would push too many of my Items into the Overflow menu. In other words how can I hook into the functionality of the MediaRouteActionProvider without using a `MenuItem` and instead using an `ImageButton`? Any Help or thoughts would be appreciated! Update This can be easily done by adding the MediaRouteButton in XML and then attaching the Selector to the button. So my implementation is such: Create a MediaRouteButton via xml: ``` <android.support.v7.app.MediaRouteButton android:id="@+id/media_route_button" android:layout_height="wrap_content" android:layout_width="wrap_content"/> ``` Then when you want to use it create a MediaRouteSelector NOTE:CHROME_CAST is the Id generated by the Developer Console when you register your application at https://cast.google.com/publish/ and attach the selector to your Button using the setRouteSelector() method ``` MediaRouteSelector m_mediaRouteSelector = new MediaRouteSelector.Builder() .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) .addControlCategory( CastMediaControlIntent.categoryForCast(CHROME_CAST)) .build(); MediaRouteButton m_mediaRouteButton = (MediaRouteButton) findViewById(R.id.media_route_button); ``` then just do: ``` m_mediaRouteButton.setRouteSelector(m_mediaRouteSelector); ``` Important for those with ActionBarSherlock* Note though that to get this to work with ActionBarSherlock you will want to create your own class that `extends MediaRouteButton` and specifically do the following ``` @Override public boolean showDialog(){ /** Do all the logic to find routes and show an AlertDialog where you call * setView(View v) on in order to show the list of available routes * since to use the built in buttons you have to use a base class that * extends from FragmentActivity */ return true; } ```