Commit e2df39b5 authored by wanglei's avatar wanglei

init

parent 86abada5
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<!-- Required only when requesting background location access on Android 10 (API level 29) and higher. --> <!-- 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.ACCESS_BACKGROUND_LOCATION" />
<!-- 身体活动数据 -->
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<application <application
android:name=".helper.MyApplication" android:name=".helper.MyApplication"
android:allowBackup="true" android:allowBackup="true"
...@@ -35,6 +38,8 @@ ...@@ -35,6 +38,8 @@
<activity <activity
android:name=".ui.splash.SplashActivity" android:name=".ui.splash.SplashActivity"
android:exported="true" android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/splash.theme"> android:theme="@style/splash.theme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
......
...@@ -12,6 +12,7 @@ import com.google.android.gms.maps.CameraUpdateFactory ...@@ -12,6 +12,7 @@ import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.LatLngBounds 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.MarkerOptions
import com.google.android.gms.maps.model.PolylineOptions import com.google.android.gms.maps.model.PolylineOptions
import kotlin.math.abs import kotlin.math.abs
...@@ -44,15 +45,14 @@ object MapUtils { ...@@ -44,15 +45,14 @@ object MapUtils {
marker: View, marker: View,
latLng: LatLng, latLng: LatLng,
tittle: String = "", tittle: String = "",
) { ): Marker? {
val bitmapDescriptor = getBitmapDescriptorFromLayoutResId(marker) val bitmapDescriptor = getBitmapDescriptorFromLayoutResId(marker)
addMarker( return addMarker(
MarkerOptions() MarkerOptions()
.icon(bitmapDescriptor) .icon(bitmapDescriptor)
.position(latLng) .position(latLng)
.title(tittle) .title(tittle)
) )
} }
fun GoogleMap.cameraMovePointsBounds(point1: LatLng, point2: LatLng, padding: Int) { fun GoogleMap.cameraMovePointsBounds(point1: LatLng, point2: LatLng, padding: Int) {
...@@ -62,7 +62,4 @@ object MapUtils { ...@@ -62,7 +62,4 @@ object MapUtils {
} }
} }
\ No newline at end of file
...@@ -2,7 +2,6 @@ package com.base.locationsharewhite.ui.locationmap ...@@ -2,7 +2,6 @@ package com.base.locationsharewhite.ui.locationmap
import android.graphics.Color import android.graphics.Color
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.locationsharewhite.R import com.base.locationsharewhite.R
...@@ -11,9 +10,11 @@ import com.base.locationsharewhite.helper.BaseActivity ...@@ -11,9 +10,11 @@ import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.map.MapUtils.addLocationMarker import com.base.locationsharewhite.map.MapUtils.addLocationMarker
import com.base.locationsharewhite.map.MapUtils.cameraMovePointsBounds import com.base.locationsharewhite.map.MapUtils.cameraMovePointsBounds
import com.base.locationsharewhite.map.MapUtils.getLastKnowLatLng 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.BarUtils
import com.base.locationsharewhite.utils.BitmapUtils import com.base.locationsharewhite.utils.BitmapUtils
import com.base.locationsharewhite.utils.LogEx 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.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.SupportMapFragment
...@@ -34,6 +35,9 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -34,6 +35,9 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
ActivityLocationMapBinding.inflate(layoutInflater) ActivityLocationMapBinding.inflate(layoutInflater)
} }
private var myMarker: Marker? = null
private var friendMarker: Marker? = null
override fun initView() { override fun initView() {
BarUtils.setStatusBarLightMode(this, true) BarUtils.setStatusBarLightMode(this, true)
...@@ -54,6 +58,19 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -54,6 +58,19 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
binding.ivFanhui.setOnClickListener { binding.ivFanhui.setOnClickListener {
onBackPressedDispatcher.onBackPressed() 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) { override fun onMapReady(googleMap: GoogleMap) {
...@@ -64,30 +81,42 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -64,30 +81,42 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
// showMeAndFriendLocation(sydney) // showMeAndFriendLocation(sydney)
val chunxilu = LatLng(30.655782251943407, 104.07701072527895) 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 myLatLng: LatLng = getLastKnowLatLng()
val myPair: LatLng = getLastKnowLatLng() LogEx.logDebug(TAG, "getLastKnowLocation ${myLatLng.latitude} ${myLatLng.longitude}")
LogEx.logDebug(TAG, "getLastKnowLocation ${myPair.latitude} ${myPair.longitude}")
val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null) val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null)
val friendAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_friend, null) val friendAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_friend, null)
// map?.addLocationMarker(myAvatar, myPair, "my") myMarker = map?.addLocationMarker(myAvatar, myLatLng, "my")
map?.addLocationMarker(friendAvatar, friendLatLng, "friend") friendMarker = map?.addLocationMarker(friendAvatar, friendLatLng, "friend")
val padding = resources.getDimensionPixelOffset(R.dimen.dp_150) val padding = resources.getDimensionPixelOffset(R.dimen.dp_150)
map?.cameraMovePointsBounds(myPair, friendLatLng, padding) map?.cameraMovePointsBounds(myLatLng, friendLatLng, padding)
val list = arrayListOf<LatLng>() // val list = arrayListOf<LatLng>()
list.addAll(friendTestLine) // list.addAll(friendTestLine)
list.add(friendLatLng) // list.add(friendLatLng)
addFriendPolyline(list) // 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 { ...@@ -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 = val mapFragment =
supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment? supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
......
...@@ -3,17 +3,19 @@ package com.base.locationsharewhite.ui.views ...@@ -3,17 +3,19 @@ package com.base.locationsharewhite.ui.views
import android.app.Activity import android.app.Activity
import android.app.AlertDialog import android.app.AlertDialog
import android.content.Context import android.content.Context
import android.graphics.Color
import android.view.Gravity import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import com.base.locationsharewhite.R import com.base.locationsharewhite.R
import com.base.locationsharewhite.databinding.DialogAppExitBinding import com.base.locationsharewhite.databinding.DialogAppExitBinding
import com.base.locationsharewhite.databinding.DialogMapTypeBinding import com.base.locationsharewhite.databinding.DialogMapTypeBinding
import com.base.locationsharewhite.ui.views.DialogView.showMapTypeDialog import com.google.android.gms.maps.GoogleMap
object DialogView { object DialogView {
fun Context.showMapTypeDialog() { fun Context.showMapTypeDialog(googleMap: GoogleMap) {
val dialog = AlertDialog.Builder(this).create() val dialog = AlertDialog.Builder(this).create()
val binding = DialogMapTypeBinding.inflate(LayoutInflater.from(this)) val binding = DialogMapTypeBinding.inflate(LayoutInflater.from(this))
dialog.setView(binding.root) dialog.setView(binding.root)
...@@ -24,10 +26,27 @@ object DialogView { ...@@ -24,10 +26,27 @@ object DialogView {
val params = dialog.window?.attributes val params = dialog.window?.attributes
params?.width = resources.getDimensionPixelOffset(R.dimen.dp_375) params?.width = resources.getDimensionPixelOffset(R.dimen.dp_375)
params?.height = LinearLayout.LayoutParams.WRAP_CONTENT params?.height = LinearLayout.LayoutParams.WRAP_CONTENT
params?.gravity = Gravity.CENTER params?.gravity = Gravity.BOTTOM
params?.y = 20
dialog.window?.attributes = params dialog.window?.attributes = params
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent) 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() { fun Activity.showAppExitDialog() {
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<ImageView <ImageView
android:id="@+id/iv_change_location" android:id="@+id/iv_change_map_type"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="140dp" android:layout_marginTop="140dp"
...@@ -41,13 +41,14 @@ ...@@ -41,13 +41,14 @@
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<ImageView <ImageView
android:id="@+id/iv_location"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:layout_marginEnd="14dp" android:layout_marginEnd="14dp"
android:src="@mipmap/yuandian" android:src="@mipmap/yuandian"
app:layout_constraintEnd_toEndOf="parent" 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" /> tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
tools:ignore="DisableBaselineAlignment"> tools:ignore="DisableBaselineAlignment">
<LinearLayout <LinearLayout
android:id="@+id/ll_statellite"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
tools:ignore="UseCompoundDrawables"> tools:ignore="UseCompoundDrawables">
<ImageView <ImageView
android:id="@+id/iv_statellite"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
...@@ -24,15 +26,18 @@ ...@@ -24,15 +26,18 @@
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/tv_statellite"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginBottom="24dp" android:layout_marginBottom="24dp"
android:text="@string/statellite_map" /> android:text="@string/statellite_map"
android:textColor="@color/color_language_text" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/ll_street"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
...@@ -40,16 +45,17 @@ ...@@ -40,16 +45,17 @@
tools:ignore="UseCompoundDrawables"> tools:ignore="UseCompoundDrawables">
<ImageView <ImageView
android:id="@+id/iv_street"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="26dp" android:layout_marginTop="26dp"
android:padding="1dp" android:padding="1dp"
android:src="@mipmap/streetmap" android:src="@mipmap/streetmap"
tools:background="@drawable/bg_stroke_03b988_15"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/tv_street"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" 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