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