private void showMediaRouteDialog(MediaStateListener player, MediaRouteController controller, Activity activity) { FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager(); if (fm == null) { throw new IllegalStateException("The activity must be a subclass of FragmentActivity"); } MediaRouteDialogFactory factory = new MediaRouteChooserDialogFactory(player, controller, activity); if (fm.findFragmentByTag( "android.support.v7.mediarouter:MediaRouteChooserDialogFragment") != null) { Log.w(TAG, "showDialog(): Route chooser dialog already showing!"); return; } MediaRouteChooserDialogFragment f = factory.onCreateChooserDialogFragment(); f.setRouteSelector(controller.buildMediaRouteSelector()); f.show(fm, "android.support.v7.mediarouter:MediaRouteChooserDialogFragment"); }
private void showMediaRouteControlDialog(MediaStateListener player, Activity activity) { FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager(); if (fm == null) { throw new IllegalStateException("The activity must be a subclass of FragmentActivity"); } MediaRouteDialogFactory factory = new MediaRouteControllerDialogFactory(player); if (fm.findFragmentByTag( "android.support.v7.mediarouter:MediaRouteControllerDialogFragment") != null) { Log.w(TAG, "showDialog(): Route controller dialog already showing!"); return; } MediaRouteControllerDialogFragment f = factory.onCreateControllerDialogFragment(); f.show(fm, "android.support.v7.mediarouter:MediaRouteControllerDialogFragment"); }
/** * called after the user finishes the screen capture permissions activity * @param requestCode arbitrary int representing why the activity was started * @param resultCode int indicating success or failure * @param data an Intent representing screen capture permission */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode != SCREEN_CAPTURE_REQUEST) { // this request wasn't meant for us } else if (resultCode != AppCompatActivity.RESULT_OK) { Toast.makeText(this, "Screen casting won't work without capture permission", Toast.LENGTH_LONG).show(); } else { mPermissionsResultCode = resultCode; mPermissionsData = data; if (mProvider != null && mProvider.getMediaRouteButton() != null) { MediaRouteDialogFactory factory = mProvider.getMediaRouteButton().getDialogFactory(); MediaRouteChooserDialogFragment chooser = factory.onCreateChooserDialogFragment(); chooser.setRouteSelector(mSelector); FragmentManager fm = getSupportFragmentManager(); chooser.show(fm, CastScreenMediaRouteButton.CHOOSER_TAG); } else { Log.e(TAG, "Null action provider or route button - " + PLEASE_REPORT_BUG); } } }
private void showMediaRouteDialog(MediaRouteController controller, Activity activity) { FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager(); if (fm == null) { throw new IllegalStateException("The activity must be a subclass of FragmentActivity"); } MediaRouteDialogFactory factory = new ChromeMediaRouteDialogFactory(); if (fm.findFragmentByTag( "android.support.v7.mediarouter:MediaRouteChooserDialogFragment") != null) { Log.w(TAG, "showDialog(): Route chooser dialog already showing!"); return; } MediaRouteChooserDialogFragment f = factory.onCreateChooserDialogFragment(); f.setRouteSelector(controller.buildMediaRouteSelector()); f.show(fm, "android.support.v7.mediarouter:MediaRouteChooserDialogFragment"); }
private void showMediaRouteControlDialog(MediaRouteController controller, Activity activity) { FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager(); if (fm == null) { throw new IllegalStateException("The activity must be a subclass of FragmentActivity"); } MediaRouteDialogFactory factory = new ChromeMediaRouteDialogFactory(); if (fm.findFragmentByTag( "android.support.v7.mediarouter:MediaRouteControllerDialogFragment") != null) { Log.w(TAG, "showDialog(): Route controller dialog already showing!"); return; } MediaRouteControllerDialogFragment f = factory.onCreateControllerDialogFragment(); f.show(fm, "android.support.v7.mediarouter:MediaRouteControllerDialogFragment"); }
/** * Shows the {@link MediaRouteChooserDialogFragment} dialog if it's not shown yet. * @param sourceUrn the URN identifying the media source to filter the devices with. */ @CalledByNative public void createDialog(String sourceUrn) { if (isShowingDialog()) return; MediaSource mediaSource = MediaSource.from(sourceUrn); if (mediaSource == null) return; FragmentActivity currentActivity = (FragmentActivity) ApplicationStatus.getLastTrackedFocusedActivity(); if (currentActivity == null) return; FragmentManager fm = currentActivity.getSupportFragmentManager(); if (fm == null) return; if (fm.findFragmentByTag(MEDIA_ROUTE_CHOOSER_DIALOG_FRAGMENT) != null) return; MediaRouteSelector selector = mediaSource.buildRouteSelector(); mAndroidMediaRouter.addCallback(selector, this); MediaRouteDialogFactory factory = new ChromeMediaRouteDialogFactory(); mChooserDialogFragment = factory.onCreateChooserDialogFragment(); mChooserDialogFragment.setRouteSelector(selector); mChooserDialogFragment.show(fm, MEDIA_ROUTE_CHOOSER_DIALOG_FRAGMENT); fm.executePendingTransactions(); Dialog dialog = mChooserDialogFragment.getDialog(); if (dialog == null) { closeDialog(); return; } dialog.setOnDismissListener(this); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Be sure to call the super class. super.onCreateOptionsMenu(menu); // Inflate the menu and configure the media router action provider. getMenuInflater().inflate(R.menu.sample_media_router_menu, menu); MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item); MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider)MenuItemCompat.getActionProvider(mediaRouteMenuItem); mediaRouteActionProvider.setRouteSelector(mSelector); mediaRouteActionProvider.setDialogFactory(new MediaRouteDialogFactory() { @Override public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() { return new MediaRouteControllerDialogFragment() { @Override public MediaRouteControllerDialog onCreateControllerDialog( Context context, Bundle savedInstanceState) { mControllerDialog = new SampleMediaRouteControllerDialog( context, mSessionManager, mPlayer); return mControllerDialog; } }; } }); // Return true to show the menu. return true; }
private void openCastDialog() { final FragmentManager fm = getSupportFragmentManager(); MediaRouteChooserDialogFragment f = MediaRouteDialogFactory.getDefault().onCreateChooserDialogFragment(); f.setRouteSelector(CastContext.getSharedInstance(this).getMergedSelector()); f.show(fm, "android.support.v7.mediarouter:MediaRouteChooserDialogFragment"); }
public MediaRouteDialogFactory getMediaRouteDialogFactory() { return mMediaRouteDialogFactory; }
/** * (Optional) Sets the {@link MediaRouteDialogFactory}. This is optional and if not called, * the default dialog will be used. */ public Builder setMediaRouteDialogFactory(MediaRouteDialogFactory factory) { mMediaRouteDialogFactory = factory; return this; }
@Override protected MediaRouteDialogFactory getMediaRouteDialogFactory() { return null; }
@Override protected MediaRouteDialogFactory getMediaRouteDialogFactory() { return new VideoMediaRouteDialogFactory(); }
@Override MediaRouteDialogFactory getMediaRouteDialogFactory() { return new VideoMediaRouteDialogFactory(); }
/** * Returns the {@link MediaRouteDialogFactory} that defines the chooser and controller dialogs * for selecting a route and controlling the route when connected. The default factory will be * used unless a different one is configured in {@link CastConfiguration}. */ private MediaRouteDialogFactory getMediaRouteDialogFactory() { return mCastConfiguration.getMediaRouteDialogFactory(); }
/** * Subclasses can decide how the Cast Controller Dialog should be built. If this returns * <code>null</code>, the default dialog will be shown. */ abstract protected MediaRouteDialogFactory getMediaRouteDialogFactory();
/** * Subclasses can decide how the Cast Controller Dialog should be built. If this returns * <code>null</code>, the default dialog will be shown. */ abstract MediaRouteDialogFactory getMediaRouteDialogFactory();
/** * Subclasses can decide how the Cast Controller Dialog should be built. If this returns * <code>null</code>, the default dialog will be shown. * * @return */ abstract MediaRouteDialogFactory getMediaRouteDialogFactory();