Search in sources :

Example 31 with RouteInfo

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)
}
Also used : RouteInfo(android.media.MediaRouter.RouteInfo) Display(android.view.Display) WindowManager(android.view.WindowManager)

Example 32 with RouteInfo

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());
}
Also used : RouteInfo(android.media.MediaRouter.RouteInfo) Test(org.junit.Test)

Example 33 with RouteInfo

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);
}
Also used : RouteInfo(android.media.MediaRouter.RouteInfo) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

RouteInfo (android.media.MediaRouter.RouteInfo)33 Test (org.junit.Test)8 ArraySet (android.util.ArraySet)5 Config (org.robolectric.annotation.Config)3 RouteGroup (android.media.MediaRouter.RouteGroup)1 Display (android.view.Display)1 WindowManager (android.view.WindowManager)1