GeoFence View
Introduction
A ready to use UI Widget to create/edit GeoFence in an Android application.
Add the dependency
Add below dependency in app level build.gradle file
implementation 'com.mappls.sdk:geofence-ui:1.0.0'
Add GeoFence View to your application
You can add GeoFence view in two ways
- Using XML
- Using Java
Using XML
<com.mappls.sdk.geofence.ui.views.GeoFenceView  
  android:id="@+id/geo_fence_view" 
  android:layout_width="match_parent"  
  android:layout_height="match_parent" />
We can set the following properties:
- mappls_geoFence_circleButtonDrawable: To change the circle Button Drawable 
- mappls_geoFence_polygonButtonDrawable: To change the polygon selector button drawable 
- mappls_geoFence_circleFillColor: To change Circle Fill colors 
- mappls_geoFence_circleFillOutlineColor: To change circle Outline color 
- mappls_geoFence_circleCenterDrawable: To change the image of the center of circle 
- mappls_geoFence_handToolDrawable: To change action button icon which is visible when polygon is selected 
- mappls_geoFence_polygonMidPointDrawable: To change midpoint icon of the polygon boundaries 
- mappls_geoFence_polygonEdgeDrawable: To change polygon corners icon 
- mappls_geoFence_polygonIntersectionDrawable: To change polygon intersection point icon of polygon 
- mappls_geoFence_polygonFillColor: To change fill color of polygon 
- mappls_geoFence_polygonFillOutlineColor: To change outline color of polygon 
- mappls_geoFence_seekBarThumbDrawable: To change seekbar thumb icon 
- mappls_geoFence_seekBarProgressPrimaryColor: To change seekbar Progress bar primary color 
- mappls_geoFence_seekBarProgressSecondaryColor: To change seekbar Progress bar secondary color 
- mappls_geoFence_seekBarProgressRadius: To change seekbar corner radius 
- mappls_geoFence_deleteButtonDrawable: To change drawable of Delete button icon 
- mappls_geoFence_showSeekbar: If its value is false than it hides the seekbar and if its true than it show seekbar 
- mappls_geoFence_showToolView: If its value is false than it hides the geofence shape toggle buttons and if its true than it show geofence shape toggle buttons 
- mappls_geoFence_showActionButton: If its value is false than it hides the polygon draw enable/disable button and if its true than it show polygon draw enable/disable button 
- mappls_geoFence_showUI: If its value is false than it hide all control buttons and if its true than it show all control buttons 
- mappls_geoFence_showDeleteButton: If its value is false than it hides polygon delete button. 
- mappls_geoFence_polygonDrawingBackgroundColor: To change the color of Polygon drawing board color. 
- mappls_geoFence_showPolygonMidPointIcon: To hide polygon mid points icon 
- mappls_geoFence_polygonOutlineWidth: To set the polygon outline width 
- mappls_geoFence_circleOutlineWidth: To change the circle outline width 
- mappls_geoFence_polygonDrawingLineColor: To set the polygon sketch drawing line. 
- mappls_geoFence_draggingLineColor: To change the dragging line of Polygon edges and circle radius changing line. 
- mappls_geoFence_minRadius: To set minimum radius of circle. 
- mappls_geoFence_maxRadius: To set maximum radius of circle 
- mappls_geoFence_radiusInterval: To set the step size of radius changing 
- mappls_geoFence_showPolygonCentreIcon: To show/hide centre point of the Polygon 
- mappls_geoFence_polygonCentreDrawable: To set the drawable for centre point of the Polygon 
Using Java
//To create with default ui and styles
geoFenceView = GeoFenceView(this)
//Or If you want to change the properties of view
geoFenceView = GeoFenceView(this, GeoFenceOptions.builder().showUI(false).build())
GeoFenceOptions has following methods to change the Properties:
- cicleButtonDrawable(int): To change the circle Button drawable 
- polygonButtonDrawable(int): To change the polygon selector button drawable 
- circleFillColor(int): To change Circle Fill colors 
- circleFillOutlineColor(int): To change circle Outline color 
- circleCentreDrawable(int): To change the image of the center of circle 
- actionButtonDrawable(int): To change action button icon which is visible when polygon is selected 
- polygonMidPointDrawable(int): To change midpoint icon of the polygon boundaries 
- polygonEdgeDrawable(int): To change polygon corners icon 
- polygonIntersectionDrawable(int): To change polygon intersection point icon of polygon 
- polygonFillColor(int): To change fill color of polygon 
- polygonFillOutlineColor(int): To change outline color of polygon 
- seekbarThumbDrawable(int): To change seekbar thumb icon 
- seekbarPrimaryColor(int): To change seekbar Progress bar primary color 
- seekbarSecondaryColor(int): To change seekbar Progress bar secondary color 
- seekbarCornerRadius(int): To change seekbar corner radius 
- deleteButtonDrawable(int): To change drawable of Delete button icon 
- showSeekBar(boolean): If its value is false than it hides the seekbar and if its true than it show seekbar 
- showToolsButton(boolean): If its value is false than it hides the geofence shape toggle buttons and if its true than it show geofence shape toggle buttons 
- showActionButton(boolean): If its value is false than it hides the polygon draw enable/disable button and if its true than it show polygon draw enable/disable button 
- showUI(boolean): If its value is false than it hide all control buttons and if its true than it show all control buttons 
- showDeleteButton(boolean): If its value is false than it hides polygon delete button. 
- polygonDrawingBackgroundColor(int): To change the color of Polygon drawing board color. 
- showPolygonMidPointIcon(boolean): To hide polygon mid points icon 
- polygonOutlineWidth(Float): To set the polygon outline width 
- circleOutlineWidth(Float): To change the circle outline width 
- polygonDrawingLineColor(int): To set the polygon sketch drawing line. 
- draggingLineColor(int): To change the dragging line of Polygon edges and circle radius changing line. 
- minRadius(int): To set minimum radius of circle. 
- maxRadius(int): To set maximum radius of circle 
- radiusInterval(int): To set the step size of radius changing 
- showPolygonCentreIcon(boolean): To show/hide centre point of the Polygon 
- polygonCentreDrawable(int): To set the drawable for centre point of the Polygon 
Initialise geofence view
  override fun onCreate(savedInstanceState: Bundle?) {  
        super.onCreate(savedInstanceState)  
  
  
        setContentView(R.layout.activity_home)  
        geoFenceView = findViewById<GeoFenceView>(R.id.geo_fence_view)  
        geoFenceView.onCreate(savedInstanceState)  
        geoFenceView.setGeoFenceViewCallback(this)  
        val geoFence = GeoFence()  
        geoFence.geoFenceType = GeoFenceType.CIRCLE  
        geoFence.circleCenter = LatLng(25.4358, 81.8463)  
        geoFence.circleRadius = 200  
        geoFenceView.geoFence = geoFence  
  
     
    } 
      
    override fun onResume() {  
        super.onResume()  
        geoFenceView.onResume()  
    }  
  
    override fun onStop() {  
        super.onStop()  
        geoFenceView.onStop()  
    }  
  
    override fun onStart() {  
        super.onStart()  
        geoFenceView.onStart()  
    }  
  
    override fun onLowMemory() {  
        super.onLowMemory()  
        geoFenceView.onLowMemory()  
    }  
  
    override fun onDestroy() {  
        super.onDestroy()  
        geoFenceView.onDestroy()  
    }  
  
    override fun onSaveInstanceState(outState: Bundle) {  
        super.onSaveInstanceState(outState)  
        geoFenceView.onSaveInstanceState(outState)  
    }
Callbacks getting from GeoFence View
Implement from GeoFenceViewCallback interface
- void onGeoFenceReady(MapplsMap mapplsMap): When map is loaded successfully
- void geoFenceType(GeoFenceType geofenceType): When toggle between geofence type
- void onCircleRadiusChanging(int radius): When radius of the circle changes
- void onUpdateGeoFence(GeoFence geoFence): On update geofence data
- void hasIntersectionPoints(): When Polygon is intersecting
To change the circle Radius
On circle radius changing:
geoFenceView.onRadiusChange(progress)
On circle radius change finish
geoFenceView.radiusChangeFinish(seekBar?.progress!!)
Toggle draw polygon enable/disable
geoFenceView.enablePolygonDrawing(isChecked)
Toggle Geofence type
To draw circle Geofence
geoFenceView.drawCircleGeoFence()
To draw polygon Geofence
geoFenceView.drawPolygonGeofence()
To draw Rectangle Geofence
geoFenceView.drawQuadrilateralGeofence()
Restrict number of points in a polygon
geofenceView.setMaxAllowedEdgesInAPolygon(12);
Callback when user tries to add more than restricted points in a polygon
geoFenceView.setOnPolygonReachedMaxPointListener(new OnPolygonReachedMaxPointListener() {
            @Override
            public void onReachedMaxPoint() {
                   //show a message to the user
            }
        })
Auto correct self intersecting polygon
geofenceView.simplifyWhenIntersectingPolygonDetected(true);
Set Normal/Rectangle Polygon
geoFence.setPolygonType(PolygonType.QUADRILATERAL);
             //Normal
geoFence.setPolygonType(PolygonType.NORMAL);
get center of plotted polygon
geofence.getPolygonCentre()
get Polygon points in clockwise/anti-clockwise directions
geoFenceView.convertPointsToClockWise(Orientation.CLOCKWISE);
To set Camera Padding for zoom on change geofence
geoFenceView.setCameraPadding(left, top, right, bottom);
To disable zoom on change geofence
geoFenceView.shouldAllowAutoZoom(false)