Update media router API.
Bug: 8175766
Change-Id: Ie780c6c6309d111019ddf7ba37612c09242b923e
diff --git a/samples/Support7Demos/AndroidManifest.xml b/samples/Support7Demos/AndroidManifest.xml
index 1a8bf80..1edf3e6 100644
--- a/samples/Support7Demos/AndroidManifest.xml
+++ b/samples/Support7Demos/AndroidManifest.xml
@@ -46,7 +46,26 @@
<!-- MediaRouter Support Samples -->
<activity android:name=".media.SampleMediaRouterActivity"
- android:label="@string/sample_media_router_activity">
+ android:label="@string/sample_media_router_activity_dark"
+ android:theme="@style/Theme.AppCompat">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.example.android.supportv7.SAMPLE_CODE" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".media.SampleMediaRouterActivity$Light"
+ android:label="@string/sample_media_router_activity_light"
+ android:theme="@style/Theme.AppCompat.Light">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.example.android.supportv7.SAMPLE_CODE" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".media.SampleMediaRouterActivity$LightWithDarkActionBar"
+ android:label="@string/sample_media_router_activity_light_with_dark_action_bar"
+ android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
@@ -55,7 +74,7 @@
<service android:name=".media.SampleMediaRouteProviderService"
android:label="@string/sample_media_route_provider_service"
- android:process=":mediarouteprovider">
+ android:process=":mrp">
<intent-filter>
<action android:name="android.media.MediaRouteProviderService" />
</intent-filter>
diff --git a/samples/Support7Demos/res/menu/sample_media_router_menu.xml b/samples/Support7Demos/res/menu/sample_media_router_menu.xml
index aac1e96..8057fa8 100644
--- a/samples/Support7Demos/res/menu/sample_media_router_menu.xml
+++ b/samples/Support7Demos/res/menu/sample_media_router_menu.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2012 Google Inc.
+<!-- Copyright (C) 2013 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
-<!-- TODO: Use MediaRouter support library -->
- <item android:id="@+id/menu_media_route"
- android:title="@string/sample_media_router_play_on"
- android:showAsAction="always"
- android:orderInCategory="1"
- android:actionProviderClass="android.app.MediaRouteActionProvider"/>
+ <item android:id="@+id/media_route_menu_item"
+ android:title="@string/media_route_menu_title"
+ app:showAsAction="always"
+ app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"/>
</menu>
diff --git a/samples/Support7Demos/res/values/strings.xml b/samples/Support7Demos/res/values/strings.xml
index 4dd65b0..1c9f6ff 100644
--- a/samples/Support7Demos/res/values/strings.xml
+++ b/samples/Support7Demos/res/values/strings.xml
@@ -19,10 +19,12 @@
<!-- MediaRouter -->
- <string name="sample_media_router_activity">MediaRouter</string>
+ <string name="sample_media_router_activity_dark">MediaRouter/Dark Theme</string>
+ <string name="sample_media_router_activity_light">MediaRouter/Light Theme</string>
+ <string name="sample_media_router_activity_light_with_dark_action_bar">MediaRouter/Light Theme, Dark Action Bar</string>
<string name="sample_media_router_text">This activity demonstrates how to
use MediaRouter from the support library. Select a route from the action bar.</string>
- <string name="sample_media_router_play_on">Play on...</string>
+ <string name="media_route_menu_title">Play on...</string>
<string name="play_button_text">Play</string>
<string name="statistics_button_text">Show Statistics</string>
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteProvider.java b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteProvider.java
index 2e3bb50..8a80bac 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteProvider.java
+++ b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteProvider.java
@@ -29,9 +29,12 @@
import android.support.v7.media.MediaControlIntent;
import android.support.v7.media.MediaRouteProvider;
import android.support.v7.media.MediaRouter.ControlRequestCallback;
+import android.support.v7.media.MediaRouteProviderDescriptor;
+import android.support.v7.media.MediaRouteDescriptor;
import android.util.Log;
import android.widget.Toast;
+import java.util.ArrayList;
import java.util.UUID;
/**
@@ -51,7 +54,7 @@
* supported by this provider's routes.
*/
public static final String CATEGORY_SAMPLE_ROUTE =
- "com.example.android.supportv4.media.CATEGORY_SAMPLE_ROUTE";
+ "com.example.android.supportv7.media.CATEGORY_SAMPLE_ROUTE";
/**
* A custom media control intent action for special requests that are
@@ -64,29 +67,31 @@
* @see #DATA_PLAYBACK_COUNT
*/
public static final String ACTION_GET_STATISTICS =
- "com.example.android.supportv4.media.ACTION_GET_STATISTICS";
+ "com.example.android.supportv7.media.ACTION_GET_STATISTICS";
/**
* {@link #ACTION_GET_STATISTICS} result data: Number of times the
* playback action was invoked.
*/
public static final String DATA_PLAYBACK_COUNT =
- "com.example.android.supportv4.media.EXTRA_PLAYBACK_COUNT";
+ "com.example.android.supportv7.media.EXTRA_PLAYBACK_COUNT";
- private static final IntentFilter[] CONTROL_FILTERS;
+ private static final ArrayList<IntentFilter> CONTROL_FILTERS;
static {
- CONTROL_FILTERS = new IntentFilter[2];
+ IntentFilter f1 = new IntentFilter();
+ f1.addCategory(CATEGORY_SAMPLE_ROUTE);
+ f1.addAction(ACTION_GET_STATISTICS);
- CONTROL_FILTERS[0] = new IntentFilter();
- CONTROL_FILTERS[0].addCategory(CATEGORY_SAMPLE_ROUTE);
- CONTROL_FILTERS[0].addAction(ACTION_GET_STATISTICS);
+ IntentFilter f2 = new IntentFilter();
+ f2.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
+ f2.addAction(MediaControlIntent.ACTION_PLAY);
+ f2.addDataScheme("http");
+ f2.addDataScheme("https");
+ addDataTypeUnchecked(f2, "video/*");
- CONTROL_FILTERS[1] = new IntentFilter();
- CONTROL_FILTERS[1].addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
- CONTROL_FILTERS[1].addAction(MediaControlIntent.ACTION_PLAY);
- CONTROL_FILTERS[1].addDataScheme("http");
- CONTROL_FILTERS[1].addDataScheme("https");
- addDataTypeUnchecked(CONTROL_FILTERS[1], "video/*");
+ CONTROL_FILTERS = new ArrayList<IntentFilter>();
+ CONTROL_FILTERS.add(f1);
+ CONTROL_FILTERS.add(f2);
}
private static void addDataTypeUnchecked(IntentFilter filter, String type) {
@@ -114,29 +119,33 @@
private void publishRoutes() {
Resources r = getContext().getResources();
- RouteDescriptor routeDescriptor1 = new RouteDescriptor(
+ MediaRouteDescriptor routeDescriptor1 = new MediaRouteDescriptor.Builder(
FIXED_VOLUME_ROUTE_ID,
- r.getString(R.string.fixed_volume_route_name));
- routeDescriptor1.setControlFilters(CONTROL_FILTERS);
- routeDescriptor1.setIconResource(R.drawable.media_route_icon);
- routeDescriptor1.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE);
- routeDescriptor1.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED);
- routeDescriptor1.setVolume(VOLUME_MAX);
+ r.getString(R.string.fixed_volume_route_name))
+ .addControlFilters(CONTROL_FILTERS)
+ .setIconResource(R.drawable.media_route_icon)
+ .setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
+ .setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED)
+ .setVolume(VOLUME_MAX)
+ .build();
- RouteDescriptor routeDescriptor2 = new RouteDescriptor(
+ MediaRouteDescriptor routeDescriptor2 = new MediaRouteDescriptor.Builder(
VARIABLE_VOLUME_ROUTE_ID,
- r.getString(R.string.variable_volume_route_name));
- routeDescriptor2.setControlFilters(CONTROL_FILTERS);
- routeDescriptor2.setIconResource(R.drawable.media_route_icon);
- routeDescriptor2.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE);
- routeDescriptor2.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE);
- routeDescriptor2.setVolumeMax(VOLUME_MAX);
- routeDescriptor2.setVolume(mVolume);
+ r.getString(R.string.variable_volume_route_name))
+ .addControlFilters(CONTROL_FILTERS)
+ .setIconResource(R.drawable.media_route_icon)
+ .setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
+ .setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE)
+ .setVolumeMax(VOLUME_MAX)
+ .setVolume(mVolume)
+ .build();
- ProviderDescriptor providerDescriptor = new ProviderDescriptor();
- providerDescriptor.setRoutes(new RouteDescriptor[] {
- routeDescriptor1, routeDescriptor2
- });
+ MediaRouteProviderDescriptor providerDescriptor =
+ new MediaRouteProviderDescriptor.Builder()
+ .addRoute(routeDescriptor1)
+ .addRoute(routeDescriptor2)
+ .addDiscoverableControlFilters(CONTROL_FILTERS)
+ .build();
setDescriptor(providerDescriptor);
}
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java
index 37b22c9..a27e46d 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java
+++ b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java
@@ -18,15 +18,17 @@
import com.example.android.supportv7.R;
-import android.app.Activity;
-import android.app.MediaRouteActionProvider;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.app.MediaRouteActionProvider;
import android.support.v7.media.MediaControlIntent;
import android.support.v7.media.MediaRouter;
import android.support.v7.media.MediaRouter.RouteInfo;
import android.support.v7.media.MediaRouter.ProviderInfo;
+import android.support.v7.media.MediaRouteSelector;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -49,10 +51,11 @@
* targets.
* </p>
*/
-public class SampleMediaRouterActivity extends Activity {
+public class SampleMediaRouterActivity extends ActionBarActivity {
private final String TAG = "MediaRouterSupport";
private MediaRouter mMediaRouter;
+ private MediaRouteSelector mSelector;
private ArrayAdapter<MediaItem> mMediaItems;
private TextView mInfoTextView;
private ListView mMediaListView;
@@ -67,6 +70,14 @@
// Get the media router service.
mMediaRouter = MediaRouter.getInstance(this);
+ // Create a route selector for the type of routes that we care about.
+ mSelector = new MediaRouteSelector.Builder()
+ .addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
+ .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
+ .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
+ .addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE)
+ .build();
+
// Populate an array adapter with fake media items.
String[] mediaNames = getResources().getStringArray(R.array.media_names);
String[] mediaUris = getResources().getStringArray(R.array.media_uris);
@@ -114,7 +125,8 @@
super.onResume();
// Listen for changes to media routes.
- mMediaRouter.addCallback(mMediaRouterCallback);
+ mMediaRouter.addCallback(mSelector, mCallback,
+ MediaRouter.CALLBACK_FLAG_UNFILTERED_EVENTS);
updateRouteStatus();
}
@@ -124,10 +136,9 @@
super.onPause();
// Stop listening for changes to media routes.
- mMediaRouter.removeCallback(mMediaRouterCallback);
+ mMediaRouter.removeCallback(mCallback);
}
- // TODO: Use ActionBar support library.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Be sure to call the super class.
@@ -136,14 +147,10 @@
// Inflate the menu and configure the media router action provider.
getMenuInflater().inflate(R.menu.sample_media_router_menu, menu);
- // TODO: Use support library media route action provider.
- MenuItem mediaRouteMenuItem = menu.findItem(R.id.menu_media_route);
+ MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
MediaRouteActionProvider mediaRouteActionProvider =
- (MediaRouteActionProvider)mediaRouteMenuItem.getActionProvider();
- mediaRouteActionProvider.setRouteTypes(
- android.media.MediaRouter.ROUTE_TYPE_LIVE_AUDIO
- | android.media.MediaRouter.ROUTE_TYPE_LIVE_VIDEO
- | android.media.MediaRouter.ROUTE_TYPE_USER);
+ (MediaRouteActionProvider)MenuItemCompat.getActionProvider(mediaRouteMenuItem);
+ mediaRouteActionProvider.setRouteSelector(mSelector);
// Return true to show the menu.
return true;
@@ -277,7 +284,7 @@
return null;
}
- private final MediaRouter.Callback mMediaRouterCallback = new MediaRouter.Callback() {
+ private final MediaRouter.Callback mCallback = new MediaRouter.Callback() {
@Override
public void onRouteAdded(MediaRouter router, RouteInfo route) {
Log.d(TAG, "onRouteAdded: route=" + route);
@@ -325,6 +332,11 @@
public void onProviderRemoved(MediaRouter router, ProviderInfo provider) {
Log.d(TAG, "onRouteProviderRemoved: provider=" + provider);
}
+
+ @Override
+ public void onProviderChanged(MediaRouter router, ProviderInfo provider) {
+ Log.d(TAG, "onRouteProviderChanged: provider=" + provider);
+ }
};
private static final class MediaItem {
@@ -341,4 +353,18 @@
return mName;
}
}
+
+ /**
+ * Trivial subclass of this activity used to provide another copy of the
+ * same activity using a light theme instead of the dark theme.
+ */
+ public static class Light extends SampleMediaRouterActivity {
+ }
+
+ /**
+ * Trivial subclass of this activity used to provide another copy of the
+ * same activity using a light theme with dark action bar instead of the dark theme.
+ */
+ public static class LightWithDarkActionBar extends SampleMediaRouterActivity {
+ }
}