GpsNavigationMessageListenerTransport.java revision 6568d709e78d6ccaf256b7d0e4a19cdfb26deafb
1/* 2 * Copyright (C) 2014 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 17package android.location; 18 19import android.content.Context; 20import android.os.RemoteException; 21 22/** 23 * A handler class to manage transport listeners for {@link GpsNavigationMessageEvent.Listener}. 24 * 25 * @hide 26 */ 27class GpsNavigationMessageListenerTransport 28 extends LocalListenerHelper<GpsNavigationMessageEvent.Listener> { 29 private final ILocationManager mLocationManager; 30 31 private final IGpsNavigationMessageListener mListenerTransport = new ListenerTransport(); 32 33 public GpsNavigationMessageListenerTransport( 34 Context context, 35 ILocationManager locationManager) { 36 super(context, "GpsNavigationMessageListenerTransport"); 37 mLocationManager = locationManager; 38 } 39 40 @Override 41 protected boolean registerWithServer() throws RemoteException { 42 return mLocationManager.addGpsNavigationMessageListener( 43 mListenerTransport, 44 getContext().getPackageName()); 45 } 46 47 @Override 48 protected void unregisterFromServer() throws RemoteException { 49 mLocationManager.removeGpsNavigationMessageListener(mListenerTransport); 50 } 51 52 private class ListenerTransport extends IGpsNavigationMessageListener.Stub { 53 @Override 54 public void onGpsNavigationMessageReceived(final GpsNavigationMessageEvent event) { 55 ListenerOperation<GpsNavigationMessageEvent.Listener> operation = 56 new ListenerOperation<GpsNavigationMessageEvent.Listener>() { 57 @Override 58 public void execute(GpsNavigationMessageEvent.Listener listener) 59 throws RemoteException { 60 listener.onGpsNavigationMessageReceived(event); 61 } 62 }; 63 foreach(operation); 64 } 65 66 @Override 67 public void onStatusChanged(final int status) { 68 ListenerOperation<GpsNavigationMessageEvent.Listener> operation = 69 new ListenerOperation<GpsNavigationMessageEvent.Listener>() { 70 @Override 71 public void execute(GpsNavigationMessageEvent.Listener listener) 72 throws RemoteException { 73 listener.onStatusChanged(status); 74 } 75 }; 76 foreach(operation); 77 } 78 } 79} 80