• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 package android.car.navigation;
17 
18 import android.annotation.IntDef;
19 import android.annotation.SystemApi;
20 import android.os.Bundle;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 
26 /**
27  * Holds options related to navigation for the car's instrument cluster.
28  * @hide
29  */
30 @SystemApi
31 public class CarNavigationInstrumentCluster implements Parcelable {
32 
33     /** Navigation Next Turn messages contain an image, as well as an enum. */
34     public static final int CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED = 1;
35     /** Navigation Next Turn messages contain only an enum. */
36     public static final int CLUSTER_TYPE_IMAGE_CODES_ONLY = 2;
37 
38     /** @hide */
39     @Retention(RetentionPolicy.SOURCE)
40     @IntDef({
41         CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED,
42         CLUSTER_TYPE_IMAGE_CODES_ONLY
43     })
44     public @interface ClusterType {}
45 
46     private int mMinIntervalMillis;
47 
48     @ClusterType
49     private final int mType;
50 
51     private final int mImageWidth;
52 
53     private final int mImageHeight;
54 
55     private final int mImageColorDepthBits;
56 
57     private final Bundle mExtra;
58 
59     public static final Parcelable.Creator<CarNavigationInstrumentCluster> CREATOR
60             = new Parcelable.Creator<CarNavigationInstrumentCluster>() {
61         public CarNavigationInstrumentCluster createFromParcel(Parcel in) {
62             return new CarNavigationInstrumentCluster(in);
63         }
64 
65         public CarNavigationInstrumentCluster[] newArray(int size) {
66             return new CarNavigationInstrumentCluster[size];
67         }
68     };
69 
createCluster(int minIntervalMillis)70     public static CarNavigationInstrumentCluster createCluster(int minIntervalMillis) {
71         return new CarNavigationInstrumentCluster(minIntervalMillis, CLUSTER_TYPE_IMAGE_CODES_ONLY,
72                 0, 0, 0);
73     }
74 
createCustomImageCluster(int minIntervalMs, int imageWidth, int imageHeight, int imageColorDepthBits)75     public static CarNavigationInstrumentCluster createCustomImageCluster(int minIntervalMs,
76             int imageWidth, int imageHeight, int imageColorDepthBits) {
77         return new CarNavigationInstrumentCluster(minIntervalMs,
78                 CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED,
79                 imageWidth, imageHeight, imageColorDepthBits);
80     }
81 
82     /** Minimum time between instrument cluster updates in milliseconds.*/
getMinIntervalMillis()83     public int getMinIntervalMillis() {
84         return mMinIntervalMillis;
85     }
86 
87     /**
88      * Type of instrument cluster, can be {@link #CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED} or
89      * {@link #CLUSTER_TYPE_IMAGE_CODES_ONLY}.
90      */
91     @ClusterType
getType()92     public int getType() {
93         return mType;
94     }
95 
96     /** If instrument cluster is image, width of instrument cluster in pixels. */
getImageWidth()97     public int getImageWidth() {
98         return mImageWidth;
99     }
100 
101     /** If instrument cluster is image, height of instrument cluster in pixels. */
getImageHeight()102     public int getImageHeight() {
103         return mImageHeight;
104     }
105 
106     /**
107      * Contains extra information about instrument cluster.
108      * @hide
109      */
getExtra()110     public Bundle getExtra() { return mExtra; }
111 
112     /**
113      * If instrument cluster is image, number of bits of colour depth it supports (8, 16, or 32).
114      */
getImageColorDepthBits()115     public int getImageColorDepthBits() {
116         return mImageColorDepthBits;
117     }
118 
CarNavigationInstrumentCluster(CarNavigationInstrumentCluster that)119     public CarNavigationInstrumentCluster(CarNavigationInstrumentCluster that) {
120       this(that.mMinIntervalMillis,
121           that.mType,
122           that.mImageWidth,
123           that.mImageHeight,
124           that.mImageColorDepthBits);
125     }
126 
127     /**
128      * Whether cluster support custom image or not.
129      * @return
130      */
supportsCustomImages()131     public boolean supportsCustomImages() {
132       return mType == CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED;
133     }
134 
CarNavigationInstrumentCluster( int minIntervalMillis, @ClusterType int type, int imageWidth, int imageHeight, int imageColorDepthBits)135     private CarNavigationInstrumentCluster(
136             int minIntervalMillis,
137             @ClusterType int type,
138             int imageWidth,
139             int imageHeight,
140             int imageColorDepthBits) {
141         mMinIntervalMillis = minIntervalMillis;
142         mType = type;
143         mImageWidth = imageWidth;
144         mImageHeight = imageHeight;
145         mImageColorDepthBits = imageColorDepthBits;
146         mExtra = new Bundle();
147     }
148 
149     @Override
describeContents()150     public int describeContents() {
151         return 0;
152     }
153 
154     @Override
writeToParcel(Parcel dest, int flags)155     public void writeToParcel(Parcel dest, int flags) {
156         dest.writeInt(mMinIntervalMillis);
157         dest.writeInt(mType);
158         dest.writeInt(mImageWidth);
159         dest.writeInt(mImageHeight);
160         dest.writeInt(mImageColorDepthBits);
161         dest.writeBundle(mExtra);
162     }
163 
CarNavigationInstrumentCluster(Parcel in)164     private CarNavigationInstrumentCluster(Parcel in) {
165         mMinIntervalMillis = in.readInt();
166         mType = in.readInt();
167         mImageWidth = in.readInt();
168         mImageHeight = in.readInt();
169         mImageColorDepthBits = in.readInt();
170         mExtra = in.readBundle(getClass().getClassLoader());
171     }
172 
173     /** Converts to string for debug purpose */
174     @Override
toString()175     public String toString() {
176         return CarNavigationInstrumentCluster.class.getSimpleName() + "{ " +
177                 "minIntervalMillis: " + mMinIntervalMillis + ", " +
178                 "type: " + mType + ", " +
179                 "imageWidth: " + mImageWidth + ", " +
180                 "imageHeight: " + mImageHeight + ", " +
181                 "imageColourDepthBits: " + mImageColorDepthBits +
182                 "extra: " + mExtra + " }";
183     }
184 }
185