android.support.v7.app.MediaRouteButton Java Examples

The following examples show how to use android.support.v7.app.MediaRouteButton. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleCastButtonManager.java    From react-native-google-cast with MIT License 6 votes vote down vote up
@Override
public MediaRouteButton createViewInstance(ThemedReactContext context) {
  CastContext castContext = CastContext.getSharedInstance(context);

  final MediaRouteButton button = new ColorableMediaRouteButton(context);
  googleCastButtonManagerInstance = button;

  CastButtonFactory.setUpMediaRouteButton(context, button);

  updateButtonState(button, castContext.getCastState());

  castContext.addCastStateListener(new CastStateListener() {
    @Override
    public void onCastStateChanged(int newState) {
      GoogleCastButtonManager.this.updateButtonState(button, newState);
    }
  });

  return button;
}
 
Example #2
Source File: MainActivity.java    From Casty with MIT License 5 votes vote down vote up
private void setUpMediaRouteButton() {
    MediaRouteButton mediaRouteButton = (MediaRouteButton) findViewById(R.id.media_route_button);
    casty.setUpMediaRouteButton(mediaRouteButton);
}
 
Example #3
Source File: GoogleCastButtonManager.java    From react-native-google-cast with MIT License 5 votes vote down vote up
private void updateButtonState(MediaRouteButton button, int state) {
  // hide the button when no device available (default behavior is show it
  // disabled)
  if (CastState.NO_DEVICES_AVAILABLE == state) {
    button.setVisibility(View.GONE);
  } else {
    button.setVisibility(View.VISIBLE);
  }
}
 
Example #4
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
private Drawable getRemoteIndicatorDrawable(){
    Context castContext = new ContextThemeWrapper(getContext(), android.support.v7.mediarouter.R.style.Theme_MediaRouter);
    TypedArray a = castContext.obtainStyledAttributes(null,
            android.support.v7.mediarouter.R.styleable.MediaRouteButton, android.support.v7.mediarouter.R.attr.mediaRouteButtonStyle, 0);
    Drawable remoteIndicatorDrawable = a.getDrawable(
            android.support.v7.mediarouter.R.styleable.MediaRouteButton_externalRouteEnabledDrawable);
    a.recycle();
    return remoteIndicatorDrawable;
}
 
Example #5
Source File: CastyNoOp.java    From Casty with MIT License 4 votes vote down vote up
@Override
public void setUpMediaRouteButton(@NonNull MediaRouteButton mediaRouteButton) {
    //no-op
}
 
Example #6
Source File: GoogleCastButtonManager.java    From react-native-google-cast with MIT License 4 votes vote down vote up
public static MediaRouteButton getGoogleCastButtonManagerInstance() {
  return googleCastButtonManagerInstance;
}
 
Example #7
Source File: NowPlayingFragment.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
	DownloadService downloadService = getDownloadService();
	if(Util.isOffline(context)) {
		menuInflater.inflate(R.menu.nowplaying_offline, menu);
	} else {
		menuInflater.inflate(R.menu.nowplaying, menu);
	}
	if(downloadService != null && downloadService.getSleepTimer()) {
		int timeRemaining = downloadService.getSleepTimeRemaining();
		timerMenu = menu.findItem(R.id.menu_toggle_timer);
		if(timeRemaining > 1){
			timerMenu.setTitle(context.getResources().getString(R.string.download_stop_time_remaining, Util.formatDuration(timeRemaining)));
		} else {
			timerMenu.setTitle(R.string.menu_set_timer);
		}
	}
	if(downloadService != null && downloadService.getKeepScreenOn()) {
		menu.findItem(R.id.menu_screen_on_off).setChecked(true);
	}

	boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerAvailable();
	boolean isRemoteEnabled = downloadService != null && downloadService.isRemoteEnabled();
	if(equalizerAvailable && !isRemoteEnabled) {
		SharedPreferences prefs = Util.getPreferences(context);
		boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false);
		if (equalizerOn && downloadService != null) {
			if(downloadService.getEqualizerController() != null && downloadService.getEqualizerController().isEnabled()) {
				menu.findItem(R.id.menu_equalizer).setChecked(true);
			}
		}
	} else {
		menu.removeItem(R.id.menu_equalizer);
	}

	if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M || isRemoteEnabled) {
		playbackSpeedButton.setVisibility(View.GONE);
	} else {
		playbackSpeedButton.setVisibility(View.VISIBLE);
	}

	if(downloadService != null) {
		MenuItem mediaRouteItem = menu.findItem(R.id.menu_mediaroute);
		if(mediaRouteItem != null) {
			MediaRouteButton mediaRouteButton = (MediaRouteButton) MenuItemCompat.getActionView(mediaRouteItem);
			mediaRouteButton.setDialogFactory(new CustomMediaRouteDialogFactory());
			mediaRouteButton.setRouteSelector(downloadService.getRemoteSelector());
		}
	}
}
 
Example #8
Source File: BaseCastManager.java    From android with Apache License 2.0 3 votes vote down vote up
/**
     * Adds and wires up the {@link android.support.v7.app.MediaRouteButton} instance that is passed
     * as an argument. This requires that
     * <ul>
     *     <li>The enclosing {@link android.app.Activity} inherits (directly or indirectly) from
     *     {@link android.support.v4.app.FragmentActivity}</li>
     *     <li>User adds the {@link android.support.v7.app.MediaRouteButton} to the layout and
     *     pass a reference to that instance to this method</li>
     *     <li>User is in charge of controlling the visibility of this button. However, this
     *     library makes it easier to do so: use the callback
     *     <code>onCastAvailabilityChanged(boolean)</code> to change the visibility of the button in
     *     your client. For example, extend
     *     {@link com.google.sample.castcompanionlibrary.cast.callbacks.VideoCastConsumerImpl}
     *     and override that method:
     *     <pre>
{@code
public void onCastAvailabilityChanged(boolean castPresent) {
    mMediaRouteButton.setVisibility(castPresent ? View.VISIBLE : View.INVISIBLE);
}
    }
     *     </pre>
     *     </li>
     * </ul>
     * @param button
     * @return
     */
    public MediaRouteButton addMediaRouterButton(MediaRouteButton button) {
        button.setRouteSelector(mMediaRouteSelector);
        if (null != getMediaRouteDialogFactory()) {
            button.setDialogFactory(getMediaRouteDialogFactory());
        }
        return button;
    }
 
Example #9
Source File: Casty.java    From Casty with MIT License 2 votes vote down vote up
/**
 * Makes {@link MediaRouteButton} react to discovery events.
 * Must be run on UiThread.
 *
 * @param mediaRouteButton Button to be set up
 */
@UiThread
public void setUpMediaRouteButton(@NonNull MediaRouteButton mediaRouteButton) {
    CastButtonFactory.setUpMediaRouteButton(activity, mediaRouteButton);
}