Java Code Examples for android.support.v7.app.MediaRouteButton#setRouteSelector()

The following examples show how to use android.support.v7.app.MediaRouteButton#setRouteSelector() . 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: 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 2
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;
    }