/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.support.v7.media; import android.content.IntentFilter; import android.content.IntentSender; import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; /** * Describes the properties of a route. *
* Each route is uniquely identified by an opaque id string. This token * may take any form as long as it is unique within the media route provider. *
* This object is immutable once created using a {@link Builder} instance. *
*/ public final class MediaRouteDescriptor { private static final String KEY_ID = "id"; private static final String KEY_GROUP_MEMBER_IDS = "groupMemberIds"; private static final String KEY_NAME = "name"; private static final String KEY_DESCRIPTION = "status"; private static final String KEY_ICON_URI = "iconUri"; private static final String KEY_ENABLED = "enabled"; private static final String KEY_CONNECTING = "connecting"; private static final String KEY_CONNECTION_STATE = "connectionState"; private static final String KEY_CONTROL_FILTERS = "controlFilters"; private static final String KEY_PLAYBACK_TYPE = "playbackType"; private static final String KEY_PLAYBACK_STREAM = "playbackStream"; private static final String KEY_DEVICE_TYPE = "deviceType"; private static final String KEY_VOLUME = "volume"; private static final String KEY_VOLUME_MAX = "volumeMax"; private static final String KEY_VOLUME_HANDLING = "volumeHandling"; private static final String KEY_PRESENTATION_DISPLAY_ID = "presentationDisplayId"; private static final String KEY_EXTRAS = "extras"; private static final String KEY_CAN_DISCONNECT = "canDisconnect"; private static final String KEY_SETTINGS_INTENT = "settingsIntent"; private final Bundle mBundle; private List* The route id associated with a route descriptor functions as a stable * identifier for the route and must be unique among all routes offered * by the provider. *
*/ public String getId() { return mBundle.getString(KEY_ID); } /** * Gets the group member ids of the route. ** A route descriptor that has one or more group member route ids * represents a route group. A member route may belong to another group. *
* @hide */ public List* The route name identifies the destination represented by the route. * It may be a user-supplied name, an alias, or device serial number. *
*/ public String getName() { return mBundle.getString(KEY_NAME); } /** * Gets the user-visible description of the route. ** The route description describes the kind of destination represented by the route. * It may be a user-supplied string, a model number or brand of device. *
*/ public String getDescription() { return mBundle.getString(KEY_DESCRIPTION); } /** * Gets the URI of the icon representing this route. ** This icon will be used in picker UIs if available. *
*/ public Uri getIconUri() { String iconUri = mBundle.getString(KEY_ICON_URI); return iconUri == null ? null : Uri.parse(iconUri); } /** * Gets whether the route is enabled. */ public boolean isEnabled() { return mBundle.getBoolean(KEY_ENABLED, true); } /** * Gets whether the route is connecting. * @deprecated Use {@link #getConnectionState} instead */ @Deprecated public boolean isConnecting() { return mBundle.getBoolean(KEY_CONNECTING, false); } /** * Gets the connection state of the route. * * @return The connection state of this route: * {@link MediaRouter.RouteInfo#CONNECTION_STATE_DISCONNECTED}, * {@link MediaRouter.RouteInfo#CONNECTION_STATE_CONNECTING}, or * {@link MediaRouter.RouteInfo#CONNECTION_STATE_CONNECTED}. */ public int getConnectionState() { return mBundle.getInt(KEY_CONNECTION_STATE, MediaRouter.RouteInfo.CONNECTION_STATE_DISCONNECTED); } /** * Gets whether the route can be disconnected without stopping playback. ** The route can normally be disconnected without stopping playback when * the destination device on the route is connected to two or more source * devices. The route provider should update the route immediately when the * number of connected devices changes. *
* To specify that the route should disconnect without stopping use * {@link MediaRouter#unselect(int)} with * {@link MediaRouter#UNSELECT_REASON_DISCONNECTED}. *
*/ public boolean canDisconnectAndKeepPlaying() { return mBundle.getBoolean(KEY_CAN_DISCONNECT, false); } /** * Gets an {@link IntentSender} for starting a settings activity for this * route. The activity may have specific route settings or general settings * for the connected device or route provider. * * @return An {@link IntentSender} to start a settings activity. */ public IntentSender getSettingsActivity() { return mBundle.getParcelable(KEY_SETTINGS_INTENT); } /** * Gets the route's {@link MediaControlIntent media control intent} filters. */ public List* The route id associated with a route descriptor functions as a stable * identifier for the route and must be unique among all routes offered * by the provider. *
*/ public Builder setId(String id) { mBundle.putString(KEY_ID, id); return this; } /** * Adds a group member id of the route. ** A route descriptor that has one or more group member route ids * represents a route group. A member route may belong to another group. *
* @hide */ public Builder addGroupMemberId(String groupMemberId) { if (TextUtils.isEmpty(groupMemberId)) { throw new IllegalArgumentException("groupMemberId must not be empty"); } if (mGroupMemberIds == null) { mGroupMemberIds = new ArrayList<>(); } if (!mGroupMemberIds.contains(groupMemberId)) { mGroupMemberIds.add(groupMemberId); } return this; } /** * Adds a list of group member ids of the route. ** A route descriptor that has one or more group member route ids * represents a route group. A member route may belong to another group. *
* @hide */ public Builder addGroupMemberIds(Collection* The route name identifies the destination represented by the route. * It may be a user-supplied name, an alias, or device serial number. *
*/ public Builder setName(String name) { mBundle.putString(KEY_NAME, name); return this; } /** * Sets the user-visible description of the route. ** The route description describes the kind of destination represented by the route. * It may be a user-supplied string, a model number or brand of device. *
*/ public Builder setDescription(String description) { mBundle.putString(KEY_DESCRIPTION, description); return this; } /** * Sets the URI of the icon representing this route. ** This icon will be used in picker UIs if available. *
* The URI must be one of the following formats: *
* Disabled routes represent routes that a route provider knows about, such as paired * Wifi Display receivers, but that are not currently available for use. *
*/ public Builder setEnabled(boolean enabled) { mBundle.putBoolean(KEY_ENABLED, enabled); return this; } /** * Sets whether the route is in the process of connecting and is not yet * ready for use. * @deprecated Use {@link #setConnectionState} instead. */ @Deprecated public Builder setConnecting(boolean connecting) { mBundle.putBoolean(KEY_CONNECTING, connecting); return this; } /** * Sets the route's connection state. * * @param connectionState The connection state of the route: * {@link MediaRouter.RouteInfo#CONNECTION_STATE_DISCONNECTED}, * {@link MediaRouter.RouteInfo#CONNECTION_STATE_CONNECTING}, or * {@link MediaRouter.RouteInfo#CONNECTION_STATE_CONNECTED}. */ public Builder setConnectionState(int connectionState) { mBundle.putInt(KEY_CONNECTION_STATE, connectionState); return this; } /** * Sets whether the route can be disconnected without stopping playback. */ public Builder setCanDisconnect(boolean canDisconnect) { mBundle.putBoolean(KEY_CAN_DISCONNECT, canDisconnect); return this; } /** * Sets an intent sender for launching the settings activity for this * route. */ public Builder setSettingsActivity(IntentSender is) { mBundle.putParcelable(KEY_SETTINGS_INTENT, is); return this; } /** * Adds a {@link MediaControlIntent media control intent} filter for the route. */ public Builder addControlFilter(IntentFilter filter) { if (filter == null) { throw new IllegalArgumentException("filter must not be null"); } if (mControlFilters == null) { mControlFilters = new ArrayList