Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
L
location share white
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
location share white
Commits
1c5ad79b
Commit
1c5ad79b
authored
Oct 23, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
9f152b01
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
174 additions
and
6 deletions
+174
-6
LocationLoginUtils.kt
...om/base/locationsharewhite/location/LocationLoginUtils.kt
+1
-1
LocationPositionUtils.kt
...base/locationsharewhite/location/LocationPositionUtils.kt
+64
-0
LocationMapActivity.kt
.../locationsharewhite/ui/locationmap/LocationMapActivity.kt
+11
-1
LocationPresenter.kt
...se/locationsharewhite/ui/locationmap/LocationPresenter.kt
+40
-0
LocationShareActivity.kt
.../base/locationsharewhite/ui/main/LocationShareActivity.kt
+9
-2
MainActivity.kt
.../java/com/base/locationsharewhite/ui/main/MainActivity.kt
+2
-2
BatteryUtils.kt
...in/java/com/base/locationsharewhite/utils/BatteryUtils.kt
+28
-0
ClipboardUtils.kt
.../java/com/base/locationsharewhite/utils/ClipboardUtils.kt
+19
-0
No files found.
app/src/main/java/com/base/locationsharewhite/location/Location
Request
Utils.kt
→
app/src/main/java/com/base/locationsharewhite/location/Location
Login
Utils.kt
View file @
1c5ad79b
...
...
@@ -9,7 +9,7 @@ import com.base.locationsharewhite.utils.AppPreferences
import
com.base.locationsharewhite.utils.LogEx
import
org.json.JSONObject
object
Location
Request
Utils
{
object
Location
Login
Utils
{
var
invitationCodeSp
=
""
get
()
{
...
...
app/src/main/java/com/base/locationsharewhite/location/LocationPositionUtils.kt
0 → 100644
View file @
1c5ad79b
package
com.base.locationsharewhite.location
import
android.os.Build
import
com.base.locationsharewhite.BuildConfig
import
com.base.locationsharewhite.helper.AESHelper
import
com.base.locationsharewhite.helper.ConfigHelper
import
com.base.locationsharewhite.helper.ReportUtils
import
com.base.locationsharewhite.utils.AppPreferences
import
com.base.locationsharewhite.utils.LogEx
import
com.google.android.gms.maps.model.LatLng
import
org.json.JSONObject
object
LocationPositionUtils
{
private
val
TAG
=
"LocationPositionUtils"
/**
* 上传定位接口
*/
private
val
uploadUrl
by
lazy
{
val
pkg
=
ConfigHelper
.
packageName
val
url
=
StringBuilder
(
"${ConfigHelper.apiUrl}/dingwei/${pkg.filter { it.isLowerCase() }.substring(4, 9)}x"
)
url
.
append
(
"?pkg=$pkg"
)
url
.
toString
()
}
/**
*上传自身位置
*/
fun
uploadMyLocation
(
latLng
:
LatLng
,
power
:
Int
)
{
Thread
{
val
pkg
=
ConfigHelper
.
packageName
val
data
=
JSONObject
()
data
.
put
(
"latitude"
,
latLng
.
latitude
)
data
.
put
(
"longitude"
,
latLng
.
longitude
)
data
.
put
(
"power"
,
power
)
val
bp
=
JSONObject
()
// .put("${pkg}_1", "")
.
put
(
"${pkg}_5"
,
Build
.
VERSION
.
SDK_INT
)
.
put
(
"${pkg}_8"
,
BuildConfig
.
VERSION_NAME
)
.
put
(
"${pkg}_9"
,
AppPreferences
.
getInstance
().
getString
(
"uuid"
,
""
))
.
put
(
"${pkg}_10"
,
AppPreferences
.
getInstance
().
getString
(
"uuid"
,
""
))
//gid
.
put
(
"${pkg}_13"
,
"android"
)
.
put
(
"${pkg}_14"
,
BuildConfig
.
VERSION_CODE
)
.
put
(
"${pkg}_15"
,
"google"
)
.
put
(
"${pkg}_24"
,
BuildConfig
.
BUILD_TYPE
)
LogEx
.
logDebug
(
TAG
,
"uuid=${AppPreferences.getInstance().getString("
uuid
", "")}"
)
val
body
=
JSONObject
()
.
put
(
"data"
,
data
)
.
put
(
"bp"
,
bp
)
.
toString
()
val
paramJson
=
AESHelper
.
encrypt
(
body
)
LogEx
.
logDebug
(
TAG
,
"uploadUrl=${uploadUrl}"
)
val
result
=
ReportUtils
.
doPost
(
uploadUrl
,
HashMap
(),
paramJson
)
LogEx
.
logDebug
(
TAG
,
"result=$result"
)
}.
start
()
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/ui/locationmap/LocationMapActivity.kt
View file @
1c5ad79b
...
...
@@ -14,6 +14,7 @@ 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.base.locationsharewhite.utils.PermissionUtils.checkLocationPermission
import
com.google.android.gms.maps.CameraUpdateFactory
import
com.google.android.gms.maps.GoogleMap
import
com.google.android.gms.maps.OnMapReadyCallback
...
...
@@ -32,6 +33,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
private
val
TAG
=
"LocationMapActivity"
private
var
map
:
GoogleMap
?
=
null
private
lateinit
var
locationPresenter
:
LocationPresenter
override
val
binding
:
ActivityLocationMapBinding
by
lazy
{
ActivityLocationMapBinding
.
inflate
(
layoutInflater
)
...
...
@@ -45,7 +47,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
BarUtils
.
setStatusBarLightMode
(
this
,
true
)
BarUtils
.
setStatusBarColor
(
this
,
Color
.
TRANSPARENT
)
// binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
locationPresenter
=
LocationPresenter
(
this
,
lifecycleScope
)
val
mapFragment
=
supportFragmentManager
.
findFragmentById
(
R
.
id
.
map
)
as
SupportMapFragment
?
...
...
@@ -200,6 +202,14 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
override
fun
onPause
()
{
super
.
onPause
()
cancelSharingJob
()
locationPresenter
.
cancelUploadJob
()
}
override
fun
onResume
()
{
super
.
onResume
()
if
(
checkLocationPermission
())
{
locationPresenter
.
startUploadMyLocation
()
}
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/ui/locationmap/LocationPresenter.kt
0 → 100644
View file @
1c5ad79b
package
com.base.locationsharewhite.ui.locationmap
import
android.content.Context
import
androidx.lifecycle.LifecycleCoroutineScope
import
com.base.locationsharewhite.location.LocationPositionUtils
import
com.base.locationsharewhite.location.LocationPositionUtils.uploadMyLocation
import
com.base.locationsharewhite.map.MapUtils.getLastKnowLatLng
import
com.base.locationsharewhite.utils.BatteryUtils.getBatteryLevel
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
class
LocationPresenter
(
val
context
:
Context
,
val
lifecycleCoroutineScope
:
LifecycleCoroutineScope
)
{
private
var
uploadJob
:
Job
?
=
null
fun
startUploadMyLocation
()
{
if
(
uploadJob
==
null
)
{
uploadJob
=
lifecycleCoroutineScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
isActive
)
{
val
latLng
=
context
.
getLastKnowLatLng
()
val
power
=
context
.
getBatteryLevel
()
uploadMyLocation
(
latLng
,
power
)
delay
(
30
*
1000L
)
}
}
}
}
fun
cancelUploadJob
()
{
uploadJob
?.
cancel
()
uploadJob
=
null
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/ui/main/LocationShareActivity.kt
View file @
1c5ad79b
...
...
@@ -3,10 +3,13 @@ package com.base.locationsharewhite.ui.main
import
android.graphics.Color
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
com.base.locationsharewhite.R
import
com.base.locationsharewhite.databinding.ActivityLocationShareBinding
import
com.base.locationsharewhite.helper.BaseActivity
import
com.base.locationsharewhite.location.Location
Request
Utils
import
com.base.locationsharewhite.location.Location
Login
Utils
import
com.base.locationsharewhite.utils.BarUtils
import
com.base.locationsharewhite.utils.ClipboardUtils.copyText
import
com.base.locationsharewhite.utils.ToastUtils.toast
class
LocationShareActivity
:
BaseActivity
<
ActivityLocationShareBinding
>()
{
...
...
@@ -20,7 +23,11 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
BarUtils
.
setStatusBarColor
(
this
,
Color
.
WHITE
)
binding
.
root
.
updatePadding
(
top
=
BarUtils
.
getStatusBarHeight
())
binding
.
tvCode
.
text
=
LocationRequestUtils
.
invitationCodeSp
binding
.
tvCode
.
text
=
LocationLoginUtils
.
invitationCodeSp
binding
.
ivCopy
.
setOnClickListener
{
copyText
(
"MyLocationCode"
,
binding
.
tvCode
.
text
.
toString
())
toast
(
resources
.
getString
(
R
.
string
.
copy
))
}
}
override
fun
initListener
()
{
...
...
app/src/main/java/com/base/locationsharewhite/ui/main/MainActivity.kt
View file @
1c5ad79b
...
...
@@ -11,7 +11,7 @@ import com.base.locationsharewhite.R
import
com.base.locationsharewhite.databinding.ActivityMainBinding
import
com.base.locationsharewhite.helper.BaseActivity
import
com.base.locationsharewhite.helper.MyApplication
import
com.base.locationsharewhite.location.Location
Request
Utils
import
com.base.locationsharewhite.location.Location
Login
Utils
import
com.base.locationsharewhite.map.MapUtils.addLocationMarker
import
com.base.locationsharewhite.map.MapUtils.getLastKnowLatLng
import
com.base.locationsharewhite.ui.howuse.HowUseActivity
...
...
@@ -66,7 +66,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback {
supportFragmentManager
.
findFragmentById
(
R
.
id
.
map
)
as
SupportMapFragment
?
mapFragment
?.
getMapAsync
(
this
)
Location
Request
Utils
.
login
(
"wanglei"
)
Location
Login
Utils
.
login
(
"wanglei"
)
}
override
fun
initListener
()
{
...
...
app/src/main/java/com/base/locationsharewhite/utils/BatteryUtils.kt
0 → 100644
View file @
1c5ad79b
package
com.base.locationsharewhite.utils
import
android.content.Context
import
android.content.Intent
import
android.content.IntentFilter
import
android.os.BatteryManager
object
BatteryUtils
{
fun
Context
.
getBatteryLevel
():
Int
{
val
batteryLevel
:
Int
val
intent
=
registerReceiver
(
null
,
IntentFilter
(
Intent
.
ACTION_BATTERY_CHANGED
))
return
when
{
intent
!=
null
->
{
val
level
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_LEVEL
,
-
1
)
val
scale
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
)
batteryLevel
=
if
(
scale
!=
-
1
)
{
(
level
*
100
/
scale
).
toInt
()
}
else
{
-
1
}
batteryLevel
}
else
->
-
1
// 无法获取电量信息
}
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/utils/ClipboardUtils.kt
0 → 100644
View file @
1c5ad79b
package
com.base.locationsharewhite.utils
import
android.content.ClipData
import
android.content.ClipboardManager
import
android.content.Context
import
androidx.appcompat.app.AppCompatActivity
object
ClipboardUtils
{
fun
Context
.
copyText
(
label
:
String
,
text
:
String
)
{
val
clipboard
:
ClipboardManager
=
getSystemService
(
AppCompatActivity
.
CLIPBOARD_SERVICE
)
as
ClipboardManager
// 创建一个ClipData对象,其中包含要复制的文本
// val clip = ClipData.newPlainText("uuid", "uuid=$uuid gid=$gid")
val
clip
=
ClipData
.
newPlainText
(
label
,
text
)
// 将ClipData对象设置到剪贴板中
clipboard
.
setPrimaryClip
(
clip
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment