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