GpsNavigationMessageEvent.java revision a8b7bb5a50d8ad197c6f32eb308919c11b52ce74
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.IntDef;
20import android.annotation.NonNull;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.lang.annotation.Retention;
25import java.lang.annotation.RetentionPolicy;
26import java.security.InvalidParameterException;
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 Callback}.
31 */
32public final class GpsNavigationMessageEvent implements Parcelable {
33    /** The status of GPS measurements event. */
34    @Retention(RetentionPolicy.SOURCE)
35    @IntDef({STATUS_NOT_SUPPORTED, STATUS_READY, STATUS_GPS_LOCATION_DISABLED})
36    public @interface GpsNavigationMessageStatus {}
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 final 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 final 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 final 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#registerGpsNavigationMessageCallback}.
61     */
62    public static abstract class Callback {
63
64        /**
65         * Returns the latest collected GPS Navigation Message.
66         */
67        public void onGpsNavigationMessageReceived(GpsNavigationMessageEvent event) {}
68
69        /**
70         * Returns the latest status of the GPS Navigation Messages sub-system.
71         */
72        public void onStatusChanged(@GpsNavigationMessageStatus 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
87    public static final Creator<GpsNavigationMessageEvent> CREATOR =
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}
120