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 android.graphics.Bitmap;
     19 import android.os.Bundle;
     20 import android.support.car.CarNotConnectedException;
     21 
     22 /**
     23  * @hide
     24  */
     25 public class CarNavigationStatusManagerEmbedded extends CarNavigationStatusManager {
     26 
     27     private final android.car.navigation.CarNavigationStatusManager mManager;
     28 
     29     public CarNavigationStatusManagerEmbedded(Object manager) {
     30         mManager = (android.car.navigation.CarNavigationStatusManager) manager;
     31     }
     32 
     33     /**
     34      * @param status new instrument cluster navigation status.
     35      * @throws CarNotConnectedException if the connection to the car service has been lost.
     36      */
     37     @Override
     38     public void sendNavigationStatus(int status) throws CarNotConnectedException {
     39         try {
     40             mManager.sendNavigationStatus(status);
     41         } catch (android.car.CarNotConnectedException e) {
     42            throw new CarNotConnectedException(e);
     43         }
     44     }
     45 
     46     @Override
     47     public void sendNavigationTurnEvent(int event, CharSequence eventName, int turnAngle,
     48             int turnNumber, int turnSide) throws CarNotConnectedException {
     49         sendNavigationTurnEvent(event, eventName, turnAngle, turnNumber, null, turnSide);
     50     }
     51 
     52     @Override
     53     public void sendNavigationTurnEvent(int event, CharSequence eventName, int turnAngle,
     54             int turnNumber, Bitmap image, int turnSide) throws CarNotConnectedException {
     55         try {
     56             mManager.sendNavigationTurnEvent(event, eventName, turnAngle, turnNumber, image,
     57                     turnSide);
     58         } catch (android.car.CarNotConnectedException e) {
     59             throw new CarNotConnectedException(e);
     60         }
     61     }
     62 
     63     @Override
     64     public void sendNavigationTurnDistanceEvent(int distanceMeters, int timeSeconds,
     65             int displayDistanceMillis, int displayDistanceUnit) throws CarNotConnectedException {
     66         try {
     67             mManager.sendNavigationTurnDistanceEvent(distanceMeters, timeSeconds,
     68                     displayDistanceMillis, displayDistanceUnit);
     69         } catch (android.car.CarNotConnectedException e) {
     70             throw new CarNotConnectedException(e);
     71         }
     72     }
     73 
     74     @Override
     75     public void sendEvent(int eventType, Bundle bundle) throws CarNotConnectedException {
     76         try {
     77             mManager.sendEvent(eventType, bundle);
     78         } catch (android.car.CarNotConnectedException e) {
     79             throw new CarNotConnectedException(e);
     80         }
     81     }
     82 
     83     @Override
     84     public void onCarDisconnected() {
     85         //nothing to do
     86     }
     87 
     88     /**
     89      * In this implementation we just immediately call {@code listener#onInstrumentClusterStarted}
     90      * as we expect instrument cluster to be working all the time.
     91      *
     92      * @throws CarNotConnectedException if the connection to the car service has been lost.
     93      */
     94     @Override
     95     public void addListener(CarNavigationCallback callback)
     96             throws CarNotConnectedException {
     97 
     98         try {
     99             callback.onInstrumentClusterStarted(this, convert(mManager.getInstrumentClusterInfo()));
    100         } catch (android.car.CarNotConnectedException e) {
    101             throw new CarNotConnectedException(e);
    102         }
    103     }
    104 
    105     @Override
    106     public void removeListener() {
    107         // Nothing to do.
    108     }
    109 
    110     private static CarNavigationInstrumentCluster convert(
    111             android.car.navigation.CarNavigationInstrumentCluster ic) {
    112         if (ic == null) {
    113             return null;
    114         }
    115         return new CarNavigationInstrumentCluster(ic.getMinIntervalMillis(), ic.getType(),
    116                 ic.getImageWidth(), ic.getImageHeight(), ic.getImageColorDepthBits(),
    117                 ic.getExtra());
    118     }
    119 }
    120