Home | History | Annotate | Download | only in navigation
      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.support.car.navigation;
     17 
     18 import static androidx.annotation.RestrictTo.Scope.GROUP_ID;
     19 
     20 import android.os.Bundle;
     21 
     22 import androidx.annotation.IntDef;
     23 import androidx.annotation.Nullable;
     24 import androidx.annotation.RestrictTo;
     25 
     26 import java.lang.annotation.Retention;
     27 import java.lang.annotation.RetentionPolicy;
     28 
     29 /**
     30  * Holds options related to navigation for the car's instrument cluster.
     31  */
     32 public class CarNavigationInstrumentCluster {
     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     /** @hide */
     61     @RestrictTo(GROUP_ID)
     62     public static CarNavigationInstrumentCluster createCluster(int minIntervalMillis) {
     63         return new CarNavigationInstrumentCluster(minIntervalMillis, CLUSTER_TYPE_IMAGE_CODES_ONLY,
     64                 0, 0, 0);
     65     }
     66 
     67     /** @hide */
     68     @RestrictTo(GROUP_ID)
     69     public static CarNavigationInstrumentCluster createCustomImageCluster(int minIntervalMs,
     70             int imageWidth, int imageHeight, int imageColorDepthBits) {
     71         return new CarNavigationInstrumentCluster(minIntervalMs,
     72                 CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED,
     73                 imageWidth, imageHeight, imageColorDepthBits);
     74     }
     75 
     76     /** Minimum time between instrument cluster updates in milliseconds.*/
     77     public int getMinIntervalMillis() {
     78         return mMinIntervalMillis;
     79     }
     80 
     81     /**
     82      * Type of instrument cluster, can be {@link #CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED} or
     83      * {@link #CLUSTER_TYPE_IMAGE_CODES_ONLY}.
     84      */
     85     @ClusterType
     86     public int getType() {
     87         return mType;
     88     }
     89 
     90     /**
     91      * If instrument cluster is image, width of instrument cluster in pixels.
     92      * @return the width of the image in pixels, 0 otherwise.
     93      */
     94     public int getImageWidth() {
     95         return mImageWidth;
     96     }
     97 
     98     /**
     99      * If instrument cluster is image, height of instrument cluster in pixels.
    100      * @return the width of the image in pixels, 0 otherwise.
    101      */
    102     public int getImageHeight() {
    103         return mImageHeight;
    104     }
    105 
    106     /**
    107      * Contains extra information about instrument cluster.
    108      * @hide
    109      */
    110     public Bundle getExtra() { return mExtra; }
    111 
    112     /**
    113      * @return If instrument cluster is image, number of bits of colour depth it supports (8, 16,
    114      * or  32), 0 otherwise.
    115      */
    116     public int getImageColorDepthBits() {
    117         return mImageColorDepthBits;
    118     }
    119 
    120     /** @hide */
    121     @RestrictTo(GROUP_ID)
    122     public CarNavigationInstrumentCluster(CarNavigationInstrumentCluster that) {
    123       this(that.mMinIntervalMillis,
    124           that.mType,
    125           that.mImageWidth,
    126           that.mImageHeight,
    127           that.mImageColorDepthBits);
    128     }
    129 
    130     /**
    131      * Whether cluster support custom images or not.  If not generally the cluster will provide
    132      * its own images.
    133      * @return True if supported, false otherwise.
    134      */
    135     public boolean supportsCustomImages() {
    136       return mType == CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED;
    137     }
    138 
    139     /** @hide */
    140     @RestrictTo(GROUP_ID)
    141     CarNavigationInstrumentCluster(
    142             int minIntervalMillis,
    143             @ClusterType int type,
    144             int imageWidth,
    145             int imageHeight,
    146             int imageColorDepthBits) {
    147         this(minIntervalMillis, type, imageWidth, imageHeight, imageColorDepthBits, null);
    148     }
    149 
    150     /** @hide */
    151     @RestrictTo(GROUP_ID)
    152     CarNavigationInstrumentCluster(
    153             int minIntervalMillis,
    154             @ClusterType int type,
    155             int imageWidth,
    156             int imageHeight,
    157             int imageColorDepthBits,
    158             @Nullable Bundle extra) {
    159         mMinIntervalMillis = minIntervalMillis;
    160         mType = type;
    161         mImageWidth = imageWidth;
    162         mImageHeight = imageHeight;
    163         mImageColorDepthBits = imageColorDepthBits;
    164         mExtra = extra == null ? new Bundle() : new Bundle(extra);
    165     }
    166 
    167 
    168     /** Converts to string for debug purpose. */
    169     @Override
    170     public String toString() {
    171         return CarNavigationInstrumentCluster.class.getSimpleName() + "{ " +
    172                 "minIntervalMillis: " + mMinIntervalMillis + ", " +
    173                 "type: " + mType + ", " +
    174                 "imageWidth: " + mImageWidth + ", " +
    175                 "imageHeight: " + mImageHeight + ", " +
    176                 "imageColourDepthBits: " + mImageColorDepthBits + ", " +
    177                 "extra: " + mExtra + " }";
    178     }
    179 }
    180