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