1/*
2 * Copyright (C) 2013 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;
20
21/**
22 * This class represents the characteristics of the geofence.
23 *
24 * <p> Use this in conjunction with {@link GeofenceHardware} APIs.
25 */
26
27public final class GeofenceHardwareRequest {
28    static final int GEOFENCE_TYPE_CIRCLE = 0;
29    private int mType;
30    private double mLatitude;
31    private double mLongitude;
32    private double mRadius;
33    private int mLastTransition = GeofenceHardware.GEOFENCE_UNCERTAIN;
34    private int mUnknownTimer = 30000; // 30 secs
35    private int mMonitorTransitions = GeofenceHardware.GEOFENCE_UNCERTAIN |
36        GeofenceHardware.GEOFENCE_ENTERED | GeofenceHardware.GEOFENCE_EXITED;
37    private int mNotificationResponsiveness = 5000; // 5 secs
38
39    private void setCircularGeofence(double latitude, double longitude, double radius) {
40        mLatitude = latitude;
41        mLongitude = longitude;
42        mRadius = radius;
43        mType  = GEOFENCE_TYPE_CIRCLE;
44    }
45
46    /**
47     * Create a circular geofence.
48     *
49     * @param latitude Latitude of the geofence
50     * @param longitude Longitude of the geofence
51     * @param radius Radius of the geofence (in meters)
52     */
53    public static GeofenceHardwareRequest createCircularGeofence(double latitude,
54            double longitude, double radius) {
55        GeofenceHardwareRequest geofenceRequest = new GeofenceHardwareRequest();
56        geofenceRequest.setCircularGeofence(latitude, longitude, radius);
57        return geofenceRequest;
58    }
59
60    /**
61     * Set the last known transition of the geofence.
62     *
63     * @param lastTransition The current state of the geofence. Can be one of
64     *        {@link GeofenceHardware#GEOFENCE_ENTERED}, {@link GeofenceHardware#GEOFENCE_EXITED},
65     *        {@link GeofenceHardware#GEOFENCE_UNCERTAIN}.
66     */
67    public void setLastTransition(int lastTransition) {
68        mLastTransition = lastTransition;
69    }
70
71    /**
72     * Set the unknown timer for this geofence.
73     *
74     * @param unknownTimer  The time limit after which the
75     *        {@link GeofenceHardware#GEOFENCE_UNCERTAIN} transition
76     *        should be triggered. This paramter is defined in milliseconds.
77     */
78    public void setUnknownTimer(int unknownTimer) {
79        mUnknownTimer = unknownTimer;
80    }
81
82    /**
83     * Set the transitions to be monitored.
84     *
85     * @param monitorTransitions Bitwise OR of {@link GeofenceHardware#GEOFENCE_ENTERED},
86     *        {@link GeofenceHardware#GEOFENCE_EXITED}, {@link GeofenceHardware#GEOFENCE_UNCERTAIN}
87     */
88    public void setMonitorTransitions(int monitorTransitions) {
89        mMonitorTransitions = monitorTransitions;
90    }
91
92    /**
93     * Set the notification responsiveness of the geofence.
94     *
95     * @param notificationResponsiveness (milliseconds) Defines the best-effort description
96     *        of how soon should the callback be called when the transition
97     *        associated with the Geofence is triggered. For instance, if
98     *        set to 1000 millseconds with {@link GeofenceHardware#GEOFENCE_ENTERED},
99     *        the callback will be called 1000 milliseconds within entering
100     *        the geofence.
101     */
102    public void setNotificationResponsiveness(int notificationResponsiveness) {
103       mNotificationResponsiveness = notificationResponsiveness;
104    }
105
106    /**
107     * Returns the latitude of this geofence.
108     */
109    public double getLatitude() {
110        return mLatitude;
111    }
112
113    /**
114     * Returns the longitude of this geofence.
115     */
116    public double getLongitude() {
117        return mLongitude;
118    }
119
120    /**
121     * Returns the radius of this geofence.
122     */
123    public double getRadius() {
124        return mRadius;
125    }
126
127    /**
128     * Returns transitions monitored for this geofence.
129     */
130    public int getMonitorTransitions() {
131        return mMonitorTransitions;
132    }
133
134    /**
135     * Returns the unknownTimer of this geofence.
136     */
137    public int getUnknownTimer() {
138        return mUnknownTimer;
139    }
140
141    /**
142     * Returns the notification responsiveness of this geofence.
143     */
144    public int getNotificationResponsiveness() {
145        return mNotificationResponsiveness;
146    }
147
148    /**
149     * Returns the last transition of this geofence.
150     */
151    public int getLastTransition() {
152        return mLastTransition;
153    }
154
155    int getType() {
156        return mType;
157    }
158}
159