GpsNavigationMessageListenerTransport.java revision 4b3e3931270f8e406fc806bc7fa1c2788256687d
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 Context mContext; 30 private final ILocationManager mLocationManager; 31 32 private final IGpsNavigationMessageListener mListenerTransport = new ListenerTransport(); 33 34 public GpsNavigationMessageListenerTransport( 35 Context context, 36 ILocationManager locationManager) { 37 super("GpsNavigationMessageListenerTransport"); 38 mContext = context; 39 mLocationManager = locationManager; 40 } 41 42 @Override 43 protected boolean registerWithServer() throws RemoteException { 44 return mLocationManager.addGpsNavigationMessageListener( 45 mListenerTransport, 46 mContext.getPackageName()); 47 } 48 49 @Override 50 protected void unregisterFromServer() throws RemoteException { 51 mLocationManager.removeGpsNavigationMessageListener(mListenerTransport); 52 } 53 54 private class ListenerTransport extends IGpsNavigationMessageListener.Stub { 55 @Override 56 public void onGpsNavigationMessageReceived(final GpsNavigationMessageEvent event) { 57 ListenerOperation<GpsNavigationMessageEvent.Listener> operation = 58 new ListenerOperation<GpsNavigationMessageEvent.Listener>() { 59 @Override 60 public void execute(GpsNavigationMessageEvent.Listener listener) 61 throws RemoteException { 62 listener.onGpsNavigationMessageReceived(event); 63 } 64 }; 65 66 foreach(operation); 67 } 68 } 69} 70