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