GpsNavigationMessageEvent.java revision a62050d42c7d76d57ae555ffcb6d8efc5cf79de1
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.annotation.SystemApi; 21import android.os.Parcel; 22import android.os.Parcelable; 23 24import java.security.InvalidParameterException; 25 26/** 27 * A class implementing a container for data associated with a navigation message event. 28 * Events are delivered to registered instances of {@link Listener}. 29 * 30 * @hide 31 */ 32@SystemApi 33public class GpsNavigationMessageEvent implements Parcelable { 34 private final GpsNavigationMessage mNavigationMessage; 35 36 /** 37 * Used for receiving GPS satellite Navigation Messages from the GPS engine. 38 * You can implement this interface and call 39 * {@link LocationManager#addGpsNavigationMessageListener}. 40 * 41 * @hide 42 */ 43 @SystemApi 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