Commit e2df39b5 authored by wanglei's avatar wanglei

init

parent 86abada5
......@@ -15,6 +15,9 @@
<!-- Required only when requesting background location access on Android 10 (API level 29) and higher. -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- 身体活动数据 -->
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<application
android:name=".helper.MyApplication"
android:allowBackup="true"
......@@ -35,6 +38,8 @@
<activity
android:name=".ui.splash.SplashActivity"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/splash.theme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -12,6 +12,7 @@ import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.LatLngBounds
import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.gms.maps.model.PolylineOptions
import kotlin.math.abs
......@@ -44,15 +45,14 @@ object MapUtils {
marker: View,
latLng: LatLng,
tittle: String = "",
) {
): Marker? {
val bitmapDescriptor = getBitmapDescriptorFromLayoutResId(marker)
addMarker(
return addMarker(
MarkerOptions()
.icon(bitmapDescriptor)
.position(latLng)
.title(tittle)
)
}
fun GoogleMap.cameraMovePointsBounds(point1: LatLng, point2: LatLng, padding: Int) {
......@@ -62,7 +62,4 @@ object MapUtils {
}
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ package com.base.locationsharewhite.ui.locationmap
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.locationsharewhite.R
......@@ -11,9 +10,11 @@ import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.map.MapUtils.addLocationMarker
import com.base.locationsharewhite.map.MapUtils.cameraMovePointsBounds
import com.base.locationsharewhite.map.MapUtils.getLastKnowLatLng
import com.base.locationsharewhite.ui.views.DialogView.showMapTypeDialog
import com.base.locationsharewhite.utils.BarUtils
import com.base.locationsharewhite.utils.BitmapUtils
import com.base.locationsharewhite.utils.LogEx
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
......@@ -34,6 +35,9 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
ActivityLocationMapBinding.inflate(layoutInflater)
}
private var myMarker: Marker? = null
private var friendMarker: Marker? = null
override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
......@@ -54,6 +58,19 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
binding.ivFanhui.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.ivChangeMapType.setOnClickListener {
map?.let { showMapTypeDialog(it) }
}
binding.ivLocation.setOnClickListener {
val i = 2
if (i == 2) {
val chunxilu = LatLng(30.655782251943407, 104.07701072527895)
upDateMeAndFriendLocation(chunxilu)
} else {
resetMyLocation()
}
}
}
override fun onMapReady(googleMap: GoogleMap) {
......@@ -64,30 +81,42 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
// showMeAndFriendLocation(sydney)
val chunxilu = LatLng(30.655782251943407, 104.07701072527895)
showMeAndFriendLocation(chunxilu)
initMyAndFriendLocation(chunxilu)
}
rotateMarker()
fun resetMyLocation() {
val myLatLng: LatLng = getLastKnowLatLng()
myMarker?.position = myLatLng
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(myLatLng, 15f))
}
private fun initMyAndFriendLocation(friendLatLng: LatLng) {
private fun showMeAndFriendLocation(friendLatLng: LatLng) {
val myPair: LatLng = getLastKnowLatLng()
LogEx.logDebug(TAG, "getLastKnowLocation ${myPair.latitude} ${myPair.longitude}")
val myLatLng: LatLng = getLastKnowLatLng()
LogEx.logDebug(TAG, "getLastKnowLocation ${myLatLng.latitude} ${myLatLng.longitude}")
val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null)
val friendAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_friend, null)
// map?.addLocationMarker(myAvatar, myPair, "my")
map?.addLocationMarker(friendAvatar, friendLatLng, "friend")
myMarker = map?.addLocationMarker(myAvatar, myLatLng, "my")
friendMarker = map?.addLocationMarker(friendAvatar, friendLatLng, "friend")
val padding = resources.getDimensionPixelOffset(R.dimen.dp_150)
map?.cameraMovePointsBounds(myPair, friendLatLng, padding)
map?.cameraMovePointsBounds(myLatLng, friendLatLng, padding)
val list = arrayListOf<LatLng>()
list.addAll(friendTestLine)
list.add(friendLatLng)
addFriendPolyline(list)
// val list = arrayListOf<LatLng>()
// list.addAll(friendTestLine)
// list.add(friendLatLng)
// addFriendPolyline(list)
}
private fun upDateMeAndFriendLocation(friendLatLng: LatLng) {
val myLatLng: LatLng = getLastKnowLatLng()
myMarker?.position = myLatLng
friendMarker?.position = friendLatLng
val padding = resources.getDimensionPixelOffset(R.dimen.dp_150)
map?.cameraMovePointsBounds(myLatLng, friendLatLng, padding)
}
......
......@@ -53,6 +53,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback {
}
}
//访问运动数据
//https://developer.android.com/develop/sensors-and-location/location/transitions?hl=zh-cn
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
launcher.launch(arrayOf(Manifest.permission.ACTIVITY_RECOGNITION)) {
}
}
val mapFragment =
supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
......
......@@ -3,17 +3,19 @@ package com.base.locationsharewhite.ui.views
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.graphics.Color
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import com.base.locationsharewhite.R
import com.base.locationsharewhite.databinding.DialogAppExitBinding
import com.base.locationsharewhite.databinding.DialogMapTypeBinding
import com.base.locationsharewhite.ui.views.DialogView.showMapTypeDialog
import com.google.android.gms.maps.GoogleMap
object DialogView {
fun Context.showMapTypeDialog() {
fun Context.showMapTypeDialog(googleMap: GoogleMap) {
val dialog = AlertDialog.Builder(this).create()
val binding = DialogMapTypeBinding.inflate(LayoutInflater.from(this))
dialog.setView(binding.root)
......@@ -24,10 +26,27 @@ object DialogView {
val params = dialog.window?.attributes
params?.width = resources.getDimensionPixelOffset(R.dimen.dp_375)
params?.height = LinearLayout.LayoutParams.WRAP_CONTENT
params?.gravity = Gravity.CENTER
params?.gravity = Gravity.BOTTOM
params?.y = 20
dialog.window?.attributes = params
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
if (googleMap.mapType == GoogleMap.MAP_TYPE_SATELLITE) {
binding.ivStatellite.background = ContextCompat.getDrawable(this, R.drawable.bg_stroke_03b988_15)
binding.tvStatellite.setTextColor(Color.parseColor("#03B988"))
} else {
binding.ivStreet.background = ContextCompat.getDrawable(this, R.drawable.bg_stroke_03b988_15)
binding.tvStreet.setTextColor(Color.parseColor("#03B988"))
}
binding.llStatellite.setOnClickListener {
dialog.dismiss()
googleMap.mapType = GoogleMap.MAP_TYPE_SATELLITE
}
binding.llStreet.setOnClickListener {
dialog.dismiss()
googleMap.mapType = GoogleMap.MAP_TYPE_NORMAL
}
}
fun Activity.showAppExitDialog() {
......
......@@ -30,7 +30,7 @@
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_change_location"
android:id="@+id/iv_change_map_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
......@@ -41,13 +41,14 @@
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="14dp"
android:src="@mipmap/yuandian"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_change_location"
app:layout_constraintTop_toBottomOf="@id/iv_change_map_type"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
......
......@@ -8,6 +8,7 @@
tools:ignore="DisableBaselineAlignment">
<LinearLayout
android:id="@+id/ll_statellite"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
......@@ -15,6 +16,7 @@
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/iv_statellite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
......@@ -24,15 +26,18 @@
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_statellite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:layout_marginBottom="24dp"
android:text="@string/statellite_map" />
android:text="@string/statellite_map"
android:textColor="@color/color_language_text" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_street"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
......@@ -40,16 +45,17 @@
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/iv_street"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="26dp"
android:padding="1dp"
android:src="@mipmap/streetmap"
tools:background="@drawable/bg_stroke_03b988_15"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_street"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment