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 createCluster(int minIntervalMillis)71 public static CarNavigationInstrumentCluster createCluster(int minIntervalMillis) { 72 return new CarNavigationInstrumentCluster(minIntervalMillis, CLUSTER_TYPE_IMAGE_CODES_ONLY, 73 0, 0, 0); 74 } 75 createCustomImageCluster(int minIntervalMs, int imageWidth, int imageHeight, int imageColorDepthBits)76 public static CarNavigationInstrumentCluster createCustomImageCluster(int minIntervalMs, 77 int imageWidth, int imageHeight, int imageColorDepthBits) { 78 return new CarNavigationInstrumentCluster(minIntervalMs, 79 CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED, 80 imageWidth, imageHeight, imageColorDepthBits); 81 } 82 83 /** Minimum time between instrument cluster updates in milliseconds.*/ getMinIntervalMillis()84 public int getMinIntervalMillis() { 85 return mMinIntervalMillis; 86 } 87 88 /** 89 * Type of instrument cluster, can be {@link #CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED} or 90 * {@link #CLUSTER_TYPE_IMAGE_CODES_ONLY}. 91 */ 92 @ClusterType getType()93 public int getType() { 94 return mType; 95 } 96 97 /** If instrument cluster is image, width of instrument cluster in pixels. */ getImageWidth()98 public int getImageWidth() { 99 return mImageWidth; 100 } 101 102 /** If instrument cluster is image, height of instrument cluster in pixels. */ getImageHeight()103 public int getImageHeight() { 104 return mImageHeight; 105 } 106 107 /** 108 * Contains extra information about instrument cluster. 109 * @hide 110 */ getExtra()111 public Bundle getExtra() { return mExtra; } 112 113 /** 114 * If instrument cluster is image, number of bits of colour depth it supports (8, 16, or 32). 115 */ getImageColorDepthBits()116 public int getImageColorDepthBits() { 117 return mImageColorDepthBits; 118 } 119 CarNavigationInstrumentCluster(CarNavigationInstrumentCluster that)120 public CarNavigationInstrumentCluster(CarNavigationInstrumentCluster that) { 121 this(that.mMinIntervalMillis, 122 that.mType, 123 that.mImageWidth, 124 that.mImageHeight, 125 that.mImageColorDepthBits); 126 } 127 128 /** 129 * Whether cluster support custom image or not. 130 * @return 131 */ supportsCustomImages()132 public boolean supportsCustomImages() { 133 return mType == CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED; 134 } 135 CarNavigationInstrumentCluster( int minIntervalMillis, @ClusterType int type, int imageWidth, int imageHeight, int imageColorDepthBits)136 private CarNavigationInstrumentCluster( 137 int minIntervalMillis, 138 @ClusterType int type, 139 int imageWidth, 140 int imageHeight, 141 int imageColorDepthBits) { 142 mMinIntervalMillis = minIntervalMillis; 143 mType = type; 144 mImageWidth = imageWidth; 145 mImageHeight = imageHeight; 146 mImageColorDepthBits = imageColorDepthBits; 147 mExtra = new Bundle(); 148 } 149 150 @Override describeContents()151 public int describeContents() { 152 return 0; 153 } 154 155 @Override writeToParcel(Parcel dest, int flags)156 public void writeToParcel(Parcel dest, int flags) { 157 dest.writeInt(mMinIntervalMillis); 158 dest.writeInt(mType); 159 dest.writeInt(mImageWidth); 160 dest.writeInt(mImageHeight); 161 dest.writeInt(mImageColorDepthBits); 162 dest.writeBundle(mExtra); 163 } 164 CarNavigationInstrumentCluster(Parcel in)165 private CarNavigationInstrumentCluster(Parcel in) { 166 mMinIntervalMillis = in.readInt(); 167 mType = in.readInt(); 168 mImageWidth = in.readInt(); 169 mImageHeight = in.readInt(); 170 mImageColorDepthBits = in.readInt(); 171 mExtra = in.readBundle(getClass().getClassLoader()); 172 } 173 174 /** Converts to string for debug purpose */ 175 @Override toString()176 public String toString() { 177 return CarNavigationInstrumentCluster.class.getSimpleName() + "{ " + 178 "minIntervalMillis: " + mMinIntervalMillis + ", " + 179 "type: " + mType + ", " + 180 "imageWidth: " + mImageWidth + ", " + 181 "imageHeight: " + mImageHeight + ", " + 182 "imageColourDepthBits: " + mImageColorDepthBits + 183 "extra: " + mExtra + " }"; 184 } 185 } 186