17a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev/* 27a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * Copyright (C) 2016 The Android Open Source Project 37a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * 47a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * Licensed under the Apache License, Version 2.0 (the "License"); 57a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * you may not use this file except in compliance with the License. 67a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * You may obtain a copy of the License at 77a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * 87a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * http://www.apache.org/licenses/LICENSE-2.0 97a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * 107a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * Unless required by applicable law or agreed to in writing, software 117a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * distributed under the License is distributed on an "AS IS" BASIS, 127a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * See the License for the specific language governing permissions and 147a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * limitations under the License. 157a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev */ 167a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevpackage android.support.car.navigation; 177a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 187a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport android.os.Parcel; 197a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport android.os.Parcelable; 207a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport android.support.annotation.IntDef; 217a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport android.support.car.annotation.VersionDef; 227a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport android.support.car.os.ExtendableParcelable; 237a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 247a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport java.lang.annotation.Retention; 257a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport java.lang.annotation.RetentionPolicy; 267a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 277a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev/** 287a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * Holds options related to navigation for the car's instrument cluster. 297a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * @hide 307a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev */ 317a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevpublic class CarNavigationInstrumentCluster extends ExtendableParcelable { 327a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 337a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private static final int VERSION = 1; 347a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 357a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @Retention(RetentionPolicy.SOURCE) 367a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @IntDef({ 377a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev ClusterType.CUSTOM_IMAGES_SUPPORTED, 387a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev ClusterType.IMAGE_CODES_ONLY 397a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev }) 407a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public @interface ClusterType { 417a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** Navigation Next Turn messages contain an image, as well as an enum. */ 427a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int CUSTOM_IMAGES_SUPPORTED = 1; 437a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** Navigation Next Turn messages only contain an enum. */ 447a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int IMAGE_CODES_ONLY = 2; 457a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 467a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 477a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @VersionDef(version = 1) 487a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private int mMinIntervalMs; 497a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 507a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @VersionDef(version = 1) 517a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @ClusterType 527a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private int mType; 537a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 547a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @VersionDef(version = 1) 557a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private int mImageWidth; 567a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 577a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @VersionDef(version = 1) 587a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private int mImageHeight; 597a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 607a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @VersionDef(version = 1) 617a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private int mImageColorDepthBits; 627a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 637a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public static final Parcelable.Creator<CarNavigationInstrumentCluster> CREATOR 647a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev = new Parcelable.Creator<CarNavigationInstrumentCluster>() { 657a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public CarNavigationInstrumentCluster createFromParcel(Parcel in) { 667a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return new CarNavigationInstrumentCluster(in); 677a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 687a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 697a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public CarNavigationInstrumentCluster[] newArray(int size) { 707a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return new CarNavigationInstrumentCluster[size]; 717a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 727a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev }; 737a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 747a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public static CarNavigationInstrumentCluster createCluster(int minIntervalMs) { 75e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Park return new CarNavigationInstrumentCluster(minIntervalMs, ClusterType.IMAGE_CODES_ONLY, 76e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Park 0, 0, 0); 777a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 787a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 797a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public static CarNavigationInstrumentCluster createCustomImageCluster(int minIntervalMs, 807a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int imageWidth, int imageHeight, int imageColorDepthBits) { 81e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Park return new CarNavigationInstrumentCluster(minIntervalMs, 82e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Park ClusterType.CUSTOM_IMAGES_SUPPORTED, 837a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev imageWidth, imageHeight, imageColorDepthBits); 847a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 857a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 867a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** Minimum time between instrument cluster updates in milliseconds.*/ 877a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public int getMinIntervalMs() { 887a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return mMinIntervalMs; 897a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 907a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 917a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** Type of instrument cluster, can be image or enum. */ 927a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @ClusterType 937a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public int getType() { 947a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return mType; 957a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 967a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 977a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** If instrument cluster is image, width of instrument cluster in pixels. */ 987a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public int getImageWidth() { 997a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return mImageWidth; 1007a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1017a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 1027a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** If instrument cluster is image, height of instrument cluster in pixels. */ 1037a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public int getImageHeight() { 1047a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return mImageHeight; 1057a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1067a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 1077a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** If instrument cluster is image, number of bits of colour depth it supports (8, 16 or 32). */ 1087a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public int getImageColorDepthBits() { 1097a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return mImageColorDepthBits; 1107a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1117a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 1127a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public CarNavigationInstrumentCluster(CarNavigationInstrumentCluster that) { 1137a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev this(that.mMinIntervalMs, 1147a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev that.mType, 1157a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev that.mImageWidth, 1167a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev that.mImageHeight, 1177a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev that.mImageColorDepthBits); 1187a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1197a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 1207a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public boolean supportsCustomImages() { 1217a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return mType == ClusterType.CUSTOM_IMAGES_SUPPORTED; 1227a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1237a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 124e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Park /** @hide */ 125e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Park CarNavigationInstrumentCluster( 1267a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int minIntervalMs, 1277a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @ClusterType int type, 1287a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int imageWidth, 1297a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int imageHeight, 1307a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int imageColorDepthBits) { 1317a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev super(VERSION); 1327a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev this.mMinIntervalMs = minIntervalMs; 1337a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev this.mType = type; 1347a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev this.mImageWidth = imageWidth; 1357a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev this.mImageHeight = imageHeight; 1367a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev this.mImageColorDepthBits = imageColorDepthBits; 1377a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1387a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 1397a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @Override 1407a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public int describeContents() { 1417a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return 0; 1427a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1437a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 1447a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @Override 1457a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public void writeToParcel(Parcel dest, int flags) { 1467a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int startingPosition = writeHeader(dest); 1477a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev dest.writeInt(mMinIntervalMs); 1487a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev dest.writeInt(mType); 1497a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev dest.writeInt(mImageWidth); 1507a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev dest.writeInt(mImageHeight); 1517a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev dest.writeInt(mImageColorDepthBits); 1527a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev completeWriting(dest, startingPosition); 1537a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1547a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 1557a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private CarNavigationInstrumentCluster(Parcel in) { 1567a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev super(in, VERSION); 1577a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev int lastPosition = readHeader(in); 1587a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev mMinIntervalMs = in.readInt(); 1597a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev mType = in.readInt(); 1607a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev mImageWidth = in.readInt(); 1617a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev mImageHeight = in.readInt(); 1627a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev mImageColorDepthBits = in.readInt(); 1637a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev completeReading(in, lastPosition); 1647a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1657a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 1667a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** Converts to string for debug purpose */ 1677a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @Override 1687a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev public String toString() { 1697a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev return CarNavigationInstrumentCluster.class.getSimpleName() + "{ " + 1707a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev "minIntervalMs: " + mMinIntervalMs + ", " + 1717a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev "type: " + mType + ", " + 1727a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev "imageWidth: " + mImageWidth + ", " + 1737a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev "imageHeight: " + mImageHeight + ", " + 1747a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev "imageColourDepthBits: " + mImageColorDepthBits + " }"; 1757a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 1767a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev} 177