Home | History | Annotate | Download | only in com.example.android.wearable.geofencing
      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 com.example.android.wearable.geofencing;
     18 
     19 import com.google.android.gms.location.Geofence;
     20 
     21 /**
     22  * A single Geofence object, defined by its center and radius.
     23  */
     24 public class SimpleGeofence {
     25 
     26     // Instance variables
     27     private final String mId;
     28     private final double mLatitude;
     29     private final double mLongitude;
     30     private final float mRadius;
     31     private long mExpirationDuration;
     32     private int mTransitionType;
     33 
     34     /**
     35      * @param geofenceId The Geofence's request ID.
     36      * @param latitude Latitude of the Geofence's center in degrees.
     37      * @param longitude Longitude of the Geofence's center in degrees.
     38      * @param radius Radius of the geofence circle in meters.
     39      * @param expiration Geofence expiration duration.
     40      * @param transition Type of Geofence transition.
     41      */
     42     public SimpleGeofence(String geofenceId, double latitude, double longitude, float radius,
     43             long expiration, int transition) {
     44         // Set the instance fields from the constructor.
     45         this.mId = geofenceId;
     46         this.mLatitude = latitude;
     47         this.mLongitude = longitude;
     48         this.mRadius = radius;
     49         this.mExpirationDuration = expiration;
     50         this.mTransitionType = transition;
     51     }
     52 
     53     // Instance field getters.
     54     public String getId() {
     55         return mId;
     56     }
     57     public double getLatitude() {
     58         return mLatitude;
     59     }
     60     public double getLongitude() {
     61         return mLongitude;
     62     }
     63     public float getRadius() {
     64         return mRadius;
     65     }
     66     public long getExpirationDuration() {
     67         return mExpirationDuration;
     68     }
     69     public int getTransitionType() {
     70         return mTransitionType;
     71     }
     72 
     73     /**
     74      * Creates a Location Services Geofence object from a SimpleGeofence.
     75      * @return A Geofence object.
     76      */
     77     public Geofence toGeofence() {
     78         // Build a new Geofence object.
     79         return new Geofence.Builder()
     80                 .setRequestId(mId)
     81                 .setTransitionTypes(mTransitionType)
     82                 .setCircularRegion(mLatitude, mLongitude, mRadius)
     83                 .setExpirationDuration(mExpirationDuration)
     84                 .build();
     85     }
     86 
     87 }
     88