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.Parcel; 21 import android.os.Parcelable; 22 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 @Retention(RetentionPolicy.SOURCE) 34 @IntDef({ 35 ClusterType.CUSTOM_IMAGES_SUPPORTED, 36 ClusterType.IMAGE_CODES_ONLY 37 }) 38 public @interface ClusterType { 39 /** Navigation Next Turn messages contain an image, as well as an enum. */ 40 int CUSTOM_IMAGES_SUPPORTED = 1; 41 /** Navigation Next Turn messages only contain an enum. */ 42 int IMAGE_CODES_ONLY = 2; 43 } 44 45 private int mMinIntervalMs; 46 47 @ClusterType 48 private int mType; 49 50 private int mImageWidth; 51 52 private int mImageHeight; 53 54 private int mImageColorDepthBits; 55 56 public static final Parcelable.Creator<CarNavigationInstrumentCluster> CREATOR 57 = new Parcelable.Creator<CarNavigationInstrumentCluster>() { 58 public CarNavigationInstrumentCluster createFromParcel(Parcel in) { 59 return new CarNavigationInstrumentCluster(in); 60 } 61 62 public CarNavigationInstrumentCluster[] newArray(int size) { 63 return new CarNavigationInstrumentCluster[size]; 64 } 65 }; 66 createCluster(int minIntervalMs)67 public static CarNavigationInstrumentCluster createCluster(int minIntervalMs) { 68 return new CarNavigationInstrumentCluster(minIntervalMs, ClusterType.IMAGE_CODES_ONLY, 0, 0, 69 0); 70 } 71 createCustomImageCluster(int minIntervalMs, int imageWidth, int imageHeight, int imageColorDepthBits)72 public static CarNavigationInstrumentCluster createCustomImageCluster(int minIntervalMs, 73 int imageWidth, int imageHeight, int imageColorDepthBits) { 74 return new CarNavigationInstrumentCluster(minIntervalMs, 75 ClusterType.CUSTOM_IMAGES_SUPPORTED, 76 imageWidth, imageHeight, imageColorDepthBits); 77 } 78 79 /** Minimum time between instrument cluster updates in milliseconds.*/ getMinIntervalMs()80 public int getMinIntervalMs() { 81 return mMinIntervalMs; 82 } 83 84 /** Type of instrument cluster, can be image or enum. */ 85 @ClusterType getType()86 public int getType() { 87 return mType; 88 } 89 90 /** If instrument cluster is image, width of instrument cluster in pixels. */ getImageWidth()91 public int getImageWidth() { 92 return mImageWidth; 93 } 94 95 /** If instrument cluster is image, height of instrument cluster in pixels. */ getImageHeight()96 public int getImageHeight() { 97 return mImageHeight; 98 } 99 100 /** If instrument cluster is image, number of bits of colour depth it supports (8, 16 or 32). */ getImageColorDepthBits()101 public int getImageColorDepthBits() { 102 return mImageColorDepthBits; 103 } 104 CarNavigationInstrumentCluster(CarNavigationInstrumentCluster that)105 public CarNavigationInstrumentCluster(CarNavigationInstrumentCluster that) { 106 this(that.mMinIntervalMs, 107 that.mType, 108 that.mImageWidth, 109 that.mImageHeight, 110 that.mImageColorDepthBits); 111 } 112 supportsCustomImages()113 public boolean supportsCustomImages() { 114 return mType == ClusterType.CUSTOM_IMAGES_SUPPORTED; 115 } 116 CarNavigationInstrumentCluster( int minIntervalMs, @ClusterType int type, int imageWidth, int imageHeight, int imageColorDepthBits)117 private CarNavigationInstrumentCluster( 118 int minIntervalMs, 119 @ClusterType int type, 120 int imageWidth, 121 int imageHeight, 122 int imageColorDepthBits) { 123 this.mMinIntervalMs = minIntervalMs; 124 this.mType = type; 125 this.mImageWidth = imageWidth; 126 this.mImageHeight = imageHeight; 127 this.mImageColorDepthBits = imageColorDepthBits; 128 } 129 130 @Override describeContents()131 public int describeContents() { 132 return 0; 133 } 134 135 @Override writeToParcel(Parcel dest, int flags)136 public void writeToParcel(Parcel dest, int flags) { 137 dest.writeInt(mMinIntervalMs); 138 dest.writeInt(mType); 139 dest.writeInt(mImageWidth); 140 dest.writeInt(mImageHeight); 141 dest.writeInt(mImageColorDepthBits); 142 } 143 CarNavigationInstrumentCluster(Parcel in)144 private CarNavigationInstrumentCluster(Parcel in) { 145 mMinIntervalMs = in.readInt(); 146 mType = in.readInt(); 147 mImageWidth = in.readInt(); 148 mImageHeight = in.readInt(); 149 mImageColorDepthBits = in.readInt(); 150 } 151 152 /** Converts to string for debug purpose */ 153 @Override toString()154 public String toString() { 155 return CarNavigationInstrumentCluster.class.getSimpleName() + "{ " + 156 "minIntervalMs: " + mMinIntervalMs + ", " + 157 "type: " + mType + ", " + 158 "imageWidth: " + mImageWidth + ", " + 159 "imageHeight: " + mImageHeight + ", " + 160 "imageColourDepthBits: " + mImageColorDepthBits + " }"; 161 } 162 } 163