GeofenceHardwareMonitorEvent.java revision f9a274c9b8578dda6afeda422bff18b1577028b9
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.hardware.location;
18
19import android.location.Location;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
24 * A class that represents an event for each change in the state of a monitoring system.
25 */
26public class GeofenceHardwareMonitorEvent implements Parcelable {
27    private final int mMonitoringType;
28    private final int mMonitoringStatus;
29    private final int mSourceTechnologies;
30    private final Location mLocation;
31
32    public GeofenceHardwareMonitorEvent(
33            int monitoringType,
34            int monitoringStatus,
35            int sourceTechnologies,
36            Location location) {
37        mMonitoringType = monitoringType;
38        mMonitoringStatus = monitoringStatus;
39        mSourceTechnologies = sourceTechnologies;
40        mLocation = location;
41    }
42
43    /**
44     * Returns the type of the monitoring system that has a change on its state.
45     */
46    public int getMonitoringType() {
47        return mMonitoringType;
48    }
49
50    /**
51     * Returns the new status associated with the monitoring system.
52     */
53    public int getMonitoringStatus() {
54        return mMonitoringStatus;
55    }
56
57    /**
58     * Returns the source technologies that the status is associated to.
59     */
60    public int getSourceTechnologies() {
61        return mSourceTechnologies;
62    }
63
64    /**
65     * Returns the last known location according to the monitoring system.
66     */
67    public Location getLocation() {
68        return mLocation;
69    }
70
71    public static final Creator<GeofenceHardwareMonitorEvent> CREATOR =
72            new Creator<GeofenceHardwareMonitorEvent>() {
73                @Override
74                public GeofenceHardwareMonitorEvent createFromParcel(Parcel source) {
75                    ClassLoader classLoader = GeofenceHardwareMonitorEvent.class.getClassLoader();
76                    int monitoringType = source.readInt();
77                    int monitoringStatus = source.readInt();
78                    int sourceTechnologies = source.readInt();
79                    Location location = source.readParcelable(classLoader);
80
81                    return new GeofenceHardwareMonitorEvent(
82                            monitoringType,
83                            monitoringStatus,
84                            sourceTechnologies,
85                            location);
86                }
87
88                @Override
89                public GeofenceHardwareMonitorEvent[] newArray(int size) {
90                    return new GeofenceHardwareMonitorEvent[size];
91                }
92            };
93
94    @Override
95    public int describeContents() {
96        return 0;
97    }
98
99    @Override
100    public void writeToParcel(Parcel parcel, int flags) {
101        parcel.writeInt(mMonitoringType);
102        parcel.writeInt(mMonitoringStatus);
103        parcel.writeInt(mSourceTechnologies);
104        parcel.writeParcelable(mLocation, flags);
105    }
106
107    @Override
108    public String toString() {
109        return String.format(
110                "GeofenceHardwareMonitorEvent: type=%d, status=%d, sources=%d, location=%s",
111                mMonitoringType,
112                mMonitoringStatus,
113                mSourceTechnologies,
114                mLocation);
115    }
116}
117