|
@@ -5,7 +5,9 @@ import android.content.Intent
|
|
|
import android.content.pm.PackageManager
|
|
|
import android.graphics.Point
|
|
|
import android.location.Location
|
|
|
+import android.location.LocationRequest
|
|
|
import android.os.Bundle
|
|
|
+import android.os.Handler
|
|
|
import android.os.Looper
|
|
|
import android.util.Log
|
|
|
import android.view.LayoutInflater
|
|
@@ -21,34 +23,33 @@ import android.widget.Toast
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
import androidx.core.app.ActivityCompat
|
|
|
import androidx.core.content.ContextCompat
|
|
|
+import com.amap.api.maps.AMap
|
|
|
+import com.amap.api.maps.CameraUpdateFactory
|
|
|
+import com.amap.api.maps.SupportMapFragment
|
|
|
+import com.amap.api.maps.model.BitmapDescriptorFactory
|
|
|
+import com.amap.api.maps.model.CameraPosition
|
|
|
+import com.amap.api.maps.model.CircleOptions
|
|
|
+import com.amap.api.maps.model.LatLng
|
|
|
+import com.amap.api.maps.model.LatLngBounds
|
|
|
+import com.amap.api.maps.model.MarkerOptions
|
|
|
+import com.amap.api.location.AMapLocation
|
|
|
+import com.amap.api.location.AMapLocationClient
|
|
|
+import com.amap.api.location.AMapLocationClientOption
|
|
|
+import com.amap.api.location.AMapLocationListener
|
|
|
+import com.amap.api.maps.LocationSource
|
|
|
+import com.amap.api.services.core.LatLonPoint
|
|
|
+import com.amap.api.services.geocoder.GeocodeResult
|
|
|
+import com.amap.api.services.geocoder.GeocodeSearch
|
|
|
+import com.amap.api.services.geocoder.RegeocodeQuery
|
|
|
+import com.amap.api.services.geocoder.RegeocodeResult
|
|
|
import com.android.volley.toolbox.StringRequest
|
|
|
import com.github.pengrad.mapscaleview.MapScaleView
|
|
|
import com.google.android.gms.common.ConnectionResult
|
|
|
import com.google.android.gms.common.api.GoogleApiClient
|
|
|
import com.google.android.gms.common.api.Status
|
|
|
-import com.google.android.gms.location.FusedLocationProviderClient
|
|
|
import com.google.android.gms.location.LocationCallback
|
|
|
-import com.google.android.gms.location.LocationRequest
|
|
|
-import com.google.android.gms.location.LocationResult
|
|
|
-import com.google.android.gms.location.LocationServices
|
|
|
-import com.google.android.gms.maps.CameraUpdateFactory
|
|
|
-import com.google.android.gms.maps.GoogleMap
|
|
|
-import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener
|
|
|
-import com.google.android.gms.maps.GoogleMap.OnCameraIdleListener
|
|
|
-import com.google.android.gms.maps.GoogleMap.OnCameraMoveListener
|
|
|
-import com.google.android.gms.maps.OnMapReadyCallback
|
|
|
-import com.google.android.gms.maps.SupportMapFragment
|
|
|
-import com.google.android.gms.maps.model.BitmapDescriptorFactory
|
|
|
-import com.google.android.gms.maps.model.CameraPosition
|
|
|
-import com.google.android.gms.maps.model.CircleOptions
|
|
|
-import com.google.android.gms.maps.model.LatLng
|
|
|
-import com.google.android.gms.maps.model.LatLngBounds
|
|
|
-import com.google.android.gms.maps.model.MarkerOptions
|
|
|
-import com.google.android.libraries.places.api.Places
|
|
|
-import com.google.android.libraries.places.api.model.Place
|
|
|
-import com.google.android.libraries.places.widget.AutocompleteSupportFragment
|
|
|
-import com.google.android.libraries.places.widget.listener.PlaceSelectionListener
|
|
|
import com.sikey.veryfit.R
|
|
|
+import com.sikey.veryfit.app.DataManager
|
|
|
import com.sikey.veryfit.app.DataManager.Companion.instance
|
|
|
import com.sikey.veryfit.component.helper.FenceHelper
|
|
|
import com.sikey.veryfit.component.log.Logger
|
|
@@ -63,6 +64,7 @@ import com.sikey.veryfit.ui.avtivity.base.BaseNoActionBarActivity
|
|
|
import com.sikey.veryfit.ui.avtivity.component.left.BabyDetailActivity
|
|
|
import com.sikey.veryfit.ui.custom.layout.DrawFenceRelativeLayout
|
|
|
import com.sikey.veryfit.ui.custom.layout.DrawFenceRelativeLayout.OnDrawPolygonListener
|
|
|
+import com.sikey.veryfit.ui.fragment.avatar.ChildInfoPageFragment
|
|
|
import com.sikey.veryfit.utils.PermissionUtils
|
|
|
import com.sikey.veryfit.utils.ToastUtils
|
|
|
import com.tbruyelle.rxpermissions2.RxPermissions
|
|
@@ -71,9 +73,8 @@ import org.json.JSONException
|
|
|
import org.json.JSONObject
|
|
|
|
|
|
class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, OnDrawPolygonListener,
|
|
|
- OnMapReadyCallback, OnCameraMoveListener, OnCameraIdleListener, OnCameraChangeListener,
|
|
|
- CompoundButton.OnCheckedChangeListener, GoogleApiClient.ConnectionCallbacks,
|
|
|
- GoogleApiClient.OnConnectionFailedListener {
|
|
|
+ AMap.OnCameraChangeListener,
|
|
|
+ CompoundButton.OnCheckedChangeListener, GeocodeSearch.OnGeocodeSearchListener {
|
|
|
private var fenceFillColor = 0
|
|
|
private var latlngTemp: String? = null
|
|
|
private var mTvArea: TextView? = null
|
|
@@ -91,7 +92,7 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
private var mFenceType: Int = 1
|
|
|
|
|
|
/////////////////locate related/////////////////
|
|
|
- private var map: GoogleMap? = null
|
|
|
+ private var map: AMap? = null
|
|
|
var scaleView: MapScaleView? = null
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
@@ -102,20 +103,34 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
private var mName: TextView? = null
|
|
|
private var mBack: ImageView? = null
|
|
|
private var mRightTv: TextView? = null
|
|
|
- var mGoogleApiClient: GoogleApiClient? = null
|
|
|
+ //var mGoogleApiClient: GoogleApiClient? = null
|
|
|
var mLastLocation: Location? = null
|
|
|
private var needLocate = false
|
|
|
- internal lateinit var mLocationCallback: LocationCallback
|
|
|
+ //internal lateinit var mLocationCallback: LocationCallback
|
|
|
internal lateinit var mLocationRequest: LocationRequest
|
|
|
- internal var mFusedLocationClient: FusedLocationProviderClient? = null
|
|
|
+ //internal var mFusedLocationClient: FusedLocationProviderClient? = null
|
|
|
+ private lateinit var geocodeSearch: GeocodeSearch
|
|
|
+
|
|
|
private fun initMap() {
|
|
|
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
|
|
|
- mapFragment!!.getMapAsync(this)
|
|
|
+/* mapFragment!!.getMapAsync(this)
|
|
|
mGoogleApiClient = GoogleApiClient.Builder(this)
|
|
|
.addConnectionCallbacks(this)
|
|
|
.addOnConnectionFailedListener(this)
|
|
|
.addApi(LocationServices.API)
|
|
|
- .build()
|
|
|
+ .build()*/
|
|
|
+ map = mapFragment?.getMap()
|
|
|
+ map!!.uiSettings.isMyLocationButtonEnabled = false
|
|
|
+ map!!.setOnMapClickListener { latLng ->
|
|
|
+ drawPolygon(latLng, mDotsFenceInfoBean?.circleRadius ?: DEFAULT_RADIUS, mFenceType)
|
|
|
+ getGeoAdress(latLng)
|
|
|
+ }
|
|
|
+ map!!.setOnCameraChangeListener(this)
|
|
|
+ val cameraPosition = map!!.cameraPosition
|
|
|
+ // need to pass zoom and latitude
|
|
|
+ scaleView!!.update(cameraPosition.zoom, cameraPosition.target.latitude)
|
|
|
+ initData()
|
|
|
+ refreshMapZoom()
|
|
|
}
|
|
|
|
|
|
private fun initView() {
|
|
@@ -170,7 +185,7 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
}
|
|
|
|
|
|
fun initSearchLayout() {
|
|
|
- if (!Places.isInitialized()) {
|
|
|
+/* if (!Places.isInitialized()) {
|
|
|
Places.initialize(applicationContext, getString(R.string.google_maps_key))
|
|
|
}
|
|
|
val autocompleteFragment =
|
|
@@ -195,7 +210,7 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
override fun onError(status: Status) {
|
|
|
Log.i(TAG, "An error occurred: $status")
|
|
|
}
|
|
|
- })
|
|
|
+ })*/
|
|
|
}
|
|
|
|
|
|
override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
|
|
@@ -332,7 +347,7 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
}
|
|
|
|
|
|
private fun updateMap(bounds: LatLngBounds) {
|
|
|
- map!!.setLatLngBoundsForCameraTarget(bounds)
|
|
|
+ //map!!.setMapStatusLimits(bounds)
|
|
|
}
|
|
|
|
|
|
private fun getChildLocation(beanList: List<ChildInfo>?): LatLng? {
|
|
@@ -358,23 +373,26 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
|
|
|
private fun drawPolygon(center: LatLng?, radiu: Int, fenceType:Int) {
|
|
|
map!!.clear()
|
|
|
- mDotsFenceInfoBean?.lat = center?.latitude ?: 200.0
|
|
|
- mDotsFenceInfoBean?.lng = center?.longitude ?: 200.0
|
|
|
- val circle = map!!.addCircle(
|
|
|
- CircleOptions().center(center!!)
|
|
|
- .radius(radiu.toDouble())
|
|
|
- .strokeColor(fenceFillColor)
|
|
|
- .fillColor(fenceFillColor)
|
|
|
- )
|
|
|
- val view: View = if (fenceType == 1) {
|
|
|
- LayoutInflater.from(this).inflate(R.layout.fence_safe_layout, null)
|
|
|
- } else {
|
|
|
- LayoutInflater.from(this).inflate(R.layout.fence_danger_layout, null)
|
|
|
- }
|
|
|
- val descriptor = BitmapDescriptorFactory.fromBitmap(BitmapUtils.getBitmapFromView(view))
|
|
|
- val option = MarkerOptions().position(center).icon(descriptor)
|
|
|
- .zIndex(1f).draggable(false)
|
|
|
- val marker = map!!.addMarker(option)
|
|
|
+ Handler(Looper.getMainLooper()).postDelayed({
|
|
|
+ mDotsFenceInfoBean?.lat = center?.latitude ?: 200.0
|
|
|
+ mDotsFenceInfoBean?.lng = center?.longitude ?: 200.0
|
|
|
+ val circle = map!!.addCircle(
|
|
|
+ CircleOptions().center(center!!)
|
|
|
+ .radius(radiu.toDouble())
|
|
|
+ .strokeColor(fenceFillColor)
|
|
|
+ .fillColor(fenceFillColor)
|
|
|
+ )
|
|
|
+
|
|
|
+ val view: View = if (fenceType == 1) {
|
|
|
+ LayoutInflater.from(this).inflate(R.layout.fence_safe_layout, null)
|
|
|
+ } else {
|
|
|
+ LayoutInflater.from(this).inflate(R.layout.fence_danger_layout, null)
|
|
|
+ }
|
|
|
+ val descriptor = BitmapDescriptorFactory.fromBitmap(BitmapUtils.getBitmapFromView(view))
|
|
|
+ val option = MarkerOptions().position(center).icon(descriptor)
|
|
|
+ .zIndex(1f).draggable(false)
|
|
|
+ val marker = map!!.addMarker(option)
|
|
|
+ }, 200)
|
|
|
}
|
|
|
|
|
|
private fun drawPolygon() {
|
|
@@ -384,6 +402,7 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
mDotsFenceInfoBean!!.lng
|
|
|
)
|
|
|
animateMapStatus(tempLatLng)
|
|
|
+ map?.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(mDotsFenceInfoBean!!.lat, mDotsFenceInfoBean!!.lng), 15f))
|
|
|
drawPolygon(
|
|
|
tempLatLng,
|
|
|
mDotsFenceInfoBean?.circleRadius ?: DEFAULT_RADIUS,
|
|
@@ -447,10 +466,14 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
drawPolygon(DEFAULT_RADIUS)
|
|
|
} else {
|
|
|
needLocate = true
|
|
|
+ val tempLatLng = getChildLocation(instance.childTrackInfos)
|
|
|
+ Logger.d(TAG, "initData latitude:$tempLatLng?.latitude, longitude:$tempLatLng?.longitude")
|
|
|
+ map?.moveCamera(CameraUpdateFactory.newLatLngZoom(tempLatLng, 15f))
|
|
|
+ map?.addMarker(MarkerOptions().position(tempLatLng))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun getGeoAdress(latLng: LatLng) {
|
|
|
+/* private fun getGeoAdress(latLng: LatLng) {
|
|
|
val latlngStr = latLng.latitude.toString() + "," + latLng.longitude
|
|
|
Logger.d(TAG, "getGeoAdress -- $latlngStr")
|
|
|
if (latlngStr != null && latlngStr == latlngTemp) {
|
|
@@ -488,8 +511,40 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
/* ToastUtils.showLongToast(R.string.network_exception) */
|
|
|
}
|
|
|
RequestManager.getInstance(this).addToRequestQueue(request)
|
|
|
+ }*/
|
|
|
+
|
|
|
+ private fun getGeoAdress(latLng: LatLng) {
|
|
|
+ val latlngStr = latLng.latitude.toString() + "," + latLng.longitude
|
|
|
+ Logger.d(TAG, "getAddressFromLocation -- $latlngStr")
|
|
|
+ if (latlngStr != null && latlngStr == latlngTemp) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Logger.d(TAG, "getAddressFromLocation")
|
|
|
+ geocodeSearch = GeocodeSearch(applicationContext)
|
|
|
+ geocodeSearch?.setOnGeocodeSearchListener(this)
|
|
|
+ val latLonPoint = latLng.latitude.toString()?.let {
|
|
|
+ latLng.longitude.toString()?.let { it1 ->
|
|
|
+ LatLonPoint(
|
|
|
+ it.toDouble(), it1.toDouble())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ latlngTemp = latlngStr
|
|
|
+ val query = RegeocodeQuery(latLonPoint, 200f, GeocodeSearch.AMAP)
|
|
|
+ geocodeSearch?.getFromLocationAsyn(query)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) {
|
|
|
+ Logger.d(TAG, "onRegeocodeSearched")
|
|
|
+ if (rCode == 1000 && result != null) {
|
|
|
+ Logger.d(TAG, "onRegeocodeSearched successfully")
|
|
|
+ val address = result.regeocodeAddress
|
|
|
+ mDotsFenceInfoBean?.fenceLocation = address?.formatAddress
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) {
|
|
|
+ // This method is not used for reverse geocoding
|
|
|
+ }
|
|
|
|
|
|
override fun onDrawPolygon(pointList: List<Point>) {
|
|
|
Logger.d(TAG, "onDrawPolygon,pointList.size():" + pointList.size)
|
|
@@ -500,12 +555,12 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
|
|
|
override fun onStart() {
|
|
|
//startToLocate();
|
|
|
- mGoogleApiClient!!.connect()
|
|
|
+ //mGoogleApiClient!!.connect()
|
|
|
super.onStart()
|
|
|
}
|
|
|
|
|
|
override fun onStop() {
|
|
|
- mGoogleApiClient!!.disconnect()
|
|
|
+ //mGoogleApiClient!!.disconnect()
|
|
|
super.onStop()
|
|
|
}
|
|
|
|
|
@@ -520,33 +575,21 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
scaleView!!.update(cameraPosition.zoom, cameraPosition.target.latitude)
|
|
|
}
|
|
|
|
|
|
- override fun onCameraIdle() {
|
|
|
- val cameraPosition = map!!.cameraPosition
|
|
|
+ override fun onCameraChangeFinish(cameraPosition: CameraPosition) {
|
|
|
scaleView!!.update(cameraPosition.zoom, cameraPosition.target.latitude)
|
|
|
}
|
|
|
|
|
|
- override fun onCameraMove() {
|
|
|
+/*
|
|
|
+ override fun onCameraIdle() {
|
|
|
val cameraPosition = map!!.cameraPosition
|
|
|
scaleView!!.update(cameraPosition.zoom, cameraPosition.target.latitude)
|
|
|
}
|
|
|
|
|
|
- override fun onMapReady(googleMap: GoogleMap) {
|
|
|
- map = googleMap
|
|
|
- // enableMyLocation();
|
|
|
- map!!.uiSettings.isMyLocationButtonEnabled = false
|
|
|
- map!!.setOnMapClickListener { latLng ->
|
|
|
- drawPolygon(latLng, mDotsFenceInfoBean?.circleRadius ?: DEFAULT_RADIUS, mFenceType)
|
|
|
- getGeoAdress(latLng)
|
|
|
- }
|
|
|
- googleMap.setOnCameraMoveListener(this)
|
|
|
- googleMap.setOnCameraIdleListener(this)
|
|
|
- googleMap.setOnCameraChangeListener(this)
|
|
|
+ override fun onCameraMove() {
|
|
|
val cameraPosition = map!!.cameraPosition
|
|
|
- // need to pass zoom and latitude
|
|
|
scaleView!!.update(cameraPosition.zoom, cameraPosition.target.latitude)
|
|
|
- initData()
|
|
|
- refreshMapZoom()
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
/**
|
|
|
* Enables the My Location layer if the fine location permission has been granted.
|
|
@@ -573,7 +616,7 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
map!!.animateCamera(CameraUpdateFactory.newCameraPosition(position))
|
|
|
}
|
|
|
|
|
|
- override fun onConnected(bundle: Bundle?) {
|
|
|
+/* override fun onConnected(bundle: Bundle?) {
|
|
|
if (ActivityCompat.checkSelfPermission(
|
|
|
this,
|
|
|
Manifest.permission.ACCESS_FINE_LOCATION
|
|
@@ -611,6 +654,7 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
Toast.LENGTH_SHORT
|
|
|
).show()
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
companion object {
|
|
|
private val TAG = FenceSettingActivity::class.java.simpleName
|
|
@@ -623,7 +667,7 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
}
|
|
|
|
|
|
private fun requestSelfLocation() {
|
|
|
- mLocationRequest = LocationRequest()
|
|
|
+/* mLocationRequest = LocationRequest()
|
|
|
mLocationRequest.interval = 1000
|
|
|
mLocationRequest.fastestInterval = 1000
|
|
|
mLocationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
|
|
@@ -656,6 +700,6 @@ class FenceSettingActivity : BaseNoActionBarActivity(), View.OnClickListener, On
|
|
|
mLocationCallback,
|
|
|
Looper.myLooper()
|
|
|
)
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|