Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.media;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 import java.util.ArrayList;
     23 
     24 /**
     25  * Information available from MediaRouterService about the state perceived by
     26  * a particular client and the routes that are available to it.
     27  *
     28  * Clients must not modify the contents of this object.
     29  * @hide
     30  */
     31 public final class MediaRouterClientState implements Parcelable {
     32     /**
     33      * A list of all known routes.
     34      */
     35     public final ArrayList<RouteInfo> routes;
     36 
     37     public MediaRouterClientState() {
     38         routes = new ArrayList<RouteInfo>();
     39     }
     40 
     41     MediaRouterClientState(Parcel src) {
     42         routes = src.createTypedArrayList(RouteInfo.CREATOR);
     43     }
     44 
     45     public RouteInfo getRoute(String id) {
     46         final int count = routes.size();
     47         for (int i = 0; i < count; i++) {
     48             final RouteInfo route = routes.get(i);
     49             if (route.id.equals(id)) {
     50                 return route;
     51             }
     52         }
     53         return null;
     54     }
     55 
     56     @Override
     57     public int describeContents() {
     58         return 0;
     59     }
     60 
     61     @Override
     62     public void writeToParcel(Parcel dest, int flags) {
     63         dest.writeTypedList(routes);
     64     }
     65 
     66     @Override
     67     public String toString() {
     68         return "MediaRouterClientState{ routes=" + routes.toString() + " }";
     69     }
     70 
     71     public static final Parcelable.Creator<MediaRouterClientState> CREATOR =
     72             new Parcelable.Creator<MediaRouterClientState>() {
     73         @Override
     74         public MediaRouterClientState createFromParcel(Parcel in) {
     75             return new MediaRouterClientState(in);
     76         }
     77 
     78         @Override
     79         public MediaRouterClientState[] newArray(int size) {
     80             return new MediaRouterClientState[size];
     81         }
     82     };
     83 
     84     public static final class RouteInfo implements Parcelable {
     85         public String id;
     86         public String name;
     87         public String description;
     88         public int supportedTypes;
     89         public boolean enabled;
     90         public int statusCode;
     91         public int playbackType;
     92         public int playbackStream;
     93         public int volume;
     94         public int volumeMax;
     95         public int volumeHandling;
     96         public int presentationDisplayId;
     97         public @MediaRouter.RouteInfo.DeviceType int deviceType;
     98 
     99         public RouteInfo(String id) {
    100             this.id = id;
    101             enabled = true;
    102             statusCode = MediaRouter.RouteInfo.STATUS_NONE;
    103             playbackType = MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE;
    104             playbackStream = -1;
    105             volumeHandling = MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED;
    106             presentationDisplayId = -1;
    107             deviceType = MediaRouter.RouteInfo.DEVICE_TYPE_UNKNOWN;
    108         }
    109 
    110         public RouteInfo(RouteInfo other) {
    111             id = other.id;
    112             name = other.name;
    113             description = other.description;
    114             supportedTypes = other.supportedTypes;
    115             enabled = other.enabled;
    116             statusCode = other.statusCode;
    117             playbackType = other.playbackType;
    118             playbackStream = other.playbackStream;
    119             volume = other.volume;
    120             volumeMax = other.volumeMax;
    121             volumeHandling = other.volumeHandling;
    122             presentationDisplayId = other.presentationDisplayId;
    123             deviceType = other.deviceType;
    124         }
    125 
    126         RouteInfo(Parcel in) {
    127             id = in.readString();
    128             name = in.readString();
    129             description = in.readString();
    130             supportedTypes = in.readInt();
    131             enabled = in.readInt() != 0;
    132             statusCode = in.readInt();
    133             playbackType = in.readInt();
    134             playbackStream = in.readInt();
    135             volume = in.readInt();
    136             volumeMax = in.readInt();
    137             volumeHandling = in.readInt();
    138             presentationDisplayId = in.readInt();
    139             deviceType = in.readInt();
    140         }
    141 
    142         @Override
    143         public int describeContents() {
    144             return 0;
    145         }
    146 
    147         @Override
    148         public void writeToParcel(Parcel dest, int flags) {
    149             dest.writeString(id);
    150             dest.writeString(name);
    151             dest.writeString(description);
    152             dest.writeInt(supportedTypes);
    153             dest.writeInt(enabled ? 1 : 0);
    154             dest.writeInt(statusCode);
    155             dest.writeInt(playbackType);
    156             dest.writeInt(playbackStream);
    157             dest.writeInt(volume);
    158             dest.writeInt(volumeMax);
    159             dest.writeInt(volumeHandling);
    160             dest.writeInt(presentationDisplayId);
    161             dest.writeInt(deviceType);
    162         }
    163 
    164         @Override
    165         public String toString() {
    166             return "RouteInfo{ id=" + id
    167                     + ", name=" + name
    168                     + ", description=" + description
    169                     + ", supportedTypes=0x" + Integer.toHexString(supportedTypes)
    170                     + ", enabled=" + enabled
    171                     + ", statusCode=" + statusCode
    172                     + ", playbackType=" + playbackType
    173                     + ", playbackStream=" + playbackStream
    174                     + ", volume=" + volume
    175                     + ", volumeMax=" + volumeMax
    176                     + ", volumeHandling=" + volumeHandling
    177                     + ", presentationDisplayId=" + presentationDisplayId
    178                     + ", deviceType=" + deviceType
    179                     + " }";
    180         }
    181 
    182         @SuppressWarnings("hiding")
    183         public static final Parcelable.Creator<RouteInfo> CREATOR =
    184                 new Parcelable.Creator<RouteInfo>() {
    185             @Override
    186             public RouteInfo createFromParcel(Parcel in) {
    187                 return new RouteInfo(in);
    188             }
    189 
    190             @Override
    191             public RouteInfo[] newArray(int size) {
    192                 return new RouteInfo[size];
    193             }
    194         };
    195     }
    196 }
    197