GpsNavigationMessageEvent.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.annotation.NonNull; 20import android.os.Parcel; 21import android.os.Parcelable; 22 23import java.security.InvalidParameterException; 24 25/** 26 * A class implementing a container for data associated with a navigation message event. 27 * Events are delivered to registered instances of {@link Listener}. 28 * 29 * @hide 30 */ 31public class GpsNavigationMessageEvent implements Parcelable { 32 33 /** 34 * The system does not support tracking of GPS Navigation Messages. This status will not change 35 * in the future. 36 */ 37 public static int STATUS_NOT_SUPPORTED = 0; 38 39 /** 40 * GPS Navigation Messages are successfully being tracked, it will receive updates once they are 41 * available. 42 */ 43 public static int STATUS_READY = 1; 44 45 /** 46 * GPS provider or Location is disabled, updated will not be received until they are enabled. 47 */ 48 public static int STATUS_GPS_LOCATION_DISABLED = 2; 49 50 private final GpsNavigationMessage mNavigationMessage; 51 52 /** 53 * Used for receiving GPS satellite Navigation Messages from the GPS engine. 54 * You can implement this interface and call 55 * {@link LocationManager#addGpsNavigationMessageListener}. 56 * 57 * @hide 58 */ 59 public interface Listener { 60 61 /** 62 * Returns the latest collected GPS Navigation Message. 63 */ 64 void onGpsNavigationMessageReceived(GpsNavigationMessageEvent event); 65 66 /** 67 * Returns the latest status of the GPS Navigation Messages sub-system. 68 */ 69 void onStatusChanged(int status); 70 } 71 72 public GpsNavigationMessageEvent(GpsNavigationMessage message) { 73 if (message == null) { 74 throw new InvalidParameterException("Parameter 'message' must not be null."); 75 } 76 mNavigationMessage = message; 77 } 78 79 @NonNull 80 public GpsNavigationMessage getNavigationMessage() { 81 return mNavigationMessage; 82 } 83 84 public static final Creator<GpsNavigationMessageEvent> CREATOR = 85 new Creator<GpsNavigationMessageEvent>() { 86 @Override 87 public GpsNavigationMessageEvent createFromParcel(Parcel in) { 88 ClassLoader classLoader = getClass().getClassLoader(); 89 GpsNavigationMessage navigationMessage = in.readParcelable(classLoader); 90 return new GpsNavigationMessageEvent(navigationMessage); 91 } 92 93 @Override 94 public GpsNavigationMessageEvent[] newArray(int size) { 95 return new GpsNavigationMessageEvent[size]; 96 } 97 }; 98 99 @Override 100 public int describeContents() { 101 return 0; 102 } 103 104 @Override 105 public void writeToParcel(Parcel parcel, int flags) { 106 parcel.writeParcelable(mNavigationMessage, flags); 107 } 108 109 @Override 110 public String toString() { 111 StringBuilder builder = new StringBuilder("[ GpsNavigationMessageEvent:\n\n"); 112 builder.append(mNavigationMessage.toString()); 113 builder.append("\n]"); 114 return builder.toString(); 115 } 116} 117