use of android.media.MediaRouter.RouteInfo in project Android-Developers-Samples by johnjohndoe.
the class MainActivity method updatePresentation.
/**
* Updates the displayed presentation to enable a secondary screen if it has
* been selected in the {@link android.media.MediaRouter} for the
* {@link android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO} type. If no screen has been
* selected by the {@link android.media.MediaRouter}, the current screen is disabled.
* Otherwise a new {@link SamplePresentation} is initialized and shown on
* the secondary screen.
*/
private void updatePresentation() {
// BEGIN_INCLUDE(updatePresentationInit)
// Get the selected route for live video
RouteInfo selectedRoute = mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
// Get its Display if a valid route has been selected
Display selectedDisplay = null;
if (selectedRoute != null) {
selectedDisplay = selectedRoute.getPresentationDisplay();
}
/*
* Dismiss the current presentation if the display has changed or no new
* route has been selected
*/
if (mPresentation != null && mPresentation.getDisplay() != selectedDisplay) {
mPresentation.dismiss();
mPresentation = null;
mButton.setEnabled(false);
mTextStatus.setText(R.string.secondary_notconnected);
}
/*
* Show a new presentation if the previous one has been dismissed and a
* route has been selected.
*/
if (mPresentation == null && selectedDisplay != null) {
// Initialise a new Presentation for the Display
mPresentation = new SamplePresentation(this, selectedDisplay);
mPresentation.setOnDismissListener(mOnDismissListener);
// gone away in the mean time
try {
mPresentation.show();
mTextStatus.setText(getResources().getString(R.string.secondary_connected, selectedRoute.getName(MainActivity.this)));
mButton.setEnabled(true);
showNextColor();
} catch (WindowManager.InvalidDisplayException ex) {
// Couldn't show presentation - display was already removed
mPresentation = null;
}
}
// END_INCLUDE(updatePresentationNew)
}
use of android.media.MediaRouter.RouteInfo in project robolectric by robolectric.
the class ShadowMediaRouterTest method testRemoveBluetoothRoute_whenDefaultSelected_defaultRouteAvailableAndSelected.
@Test
public void testRemoveBluetoothRoute_whenDefaultSelected_defaultRouteAvailableAndSelected() {
shadowOf(mediaRouter).addBluetoothRoute();
RouteInfo bluetoothRoute = mediaRouter.getRouteAt(1);
mediaRouter.selectRoute(ROUTE_TYPE_LIVE_AUDIO, bluetoothRoute);
shadowOf(mediaRouter).removeBluetoothRoute();
assertThat(mediaRouter.getRouteCount()).isEqualTo(1);
assertThat(mediaRouter.getSelectedRoute(ROUTE_TYPE_LIVE_AUDIO)).isEqualTo(getDefaultRoute());
}
use of android.media.MediaRouter.RouteInfo in project robolectric by robolectric.
the class ShadowMediaRouterTest method testAddBluetoothRoute_checkBluetoothRouteProperties_apiN.
@Test
@Config(minSdk = N)
public void testAddBluetoothRoute_checkBluetoothRouteProperties_apiN() {
shadowOf(mediaRouter).addBluetoothRoute();
RouteInfo bluetoothRoute = mediaRouter.getRouteAt(1);
assertThat(bluetoothRoute.getDeviceType()).isEqualTo(RouteInfo.DEVICE_TYPE_BLUETOOTH);
}
Aggregations