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