GpsNavigationMessageEvent.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.annotation.NonNull; 20import android.os.Parcel; 21import android.os.Parcelable; 22 23import java.security.InvalidParameterException; 24import java.util.Arrays; 25import java.util.Collection; 26import java.util.Collections; 27 28/** 29 * A class implementing a container for data associated with a navigation message event. 30 * Events are delivered to registered instances of {@link Listener}. 31 * 32 * @hide 33 */ 34public class GpsNavigationMessageEvent implements Parcelable { 35 private final GpsNavigationMessage mNavigationMessage; 36 37 /** 38 * Used for receiving GPS satellite Navigation Messages from the GPS engine. 39 * You can implement this interface and call 40 * {@link LocationManager#addGpsNavigationMessageListener}. 41 * 42 * @hide 43 */ 44 public interface Listener { 45 void onGpsNavigationMessageReceived(GpsNavigationMessageEvent event); 46 } 47 48 public GpsNavigationMessageEvent(GpsNavigationMessage message) { 49 if (message == null) { 50 throw new InvalidParameterException("Parameter 'message' must not be null."); 51 } 52 mNavigationMessage = message; 53 } 54 55 @NonNull 56 public GpsNavigationMessage getNavigationMessage() { 57 return mNavigationMessage; 58 } 59 60 public static final Creator<GpsNavigationMessageEvent> CREATOR = 61 new Creator<GpsNavigationMessageEvent>() { 62 @Override 63 public GpsNavigationMessageEvent createFromParcel(Parcel in) { 64 ClassLoader classLoader = getClass().getClassLoader(); 65 GpsNavigationMessage navigationMessage = in.readParcelable(classLoader); 66 return new GpsNavigationMessageEvent(navigationMessage); 67 } 68 69 @Override 70 public GpsNavigationMessageEvent[] newArray(int size) { 71 return new GpsNavigationMessageEvent[size]; 72 } 73 }; 74 75 @Override 76 public int describeContents() { 77 return 0; 78 } 79 80 @Override 81 public void writeToParcel(Parcel parcel, int flags) { 82 parcel.writeParcelable(mNavigationMessage, flags); 83 } 84 85 @Override 86 public String toString() { 87 StringBuilder builder = new StringBuilder("[ GpsNavigationMessageEvent:\n\n"); 88 builder.append(mNavigationMessage.toString()); 89 builder.append("\n]"); 90 return builder.toString(); 91 } 92} 93