Skip to content

Commit

Permalink
feat: add location feature
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyOxyethylene committed May 8, 2024
1 parent aa8f065 commit 06401fa
Show file tree
Hide file tree
Showing 38 changed files with 944 additions and 283 deletions.
21 changes: 17 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "0.4.5.6-beta"
versionName = "0.4.6.0-beta"

// 使 DialogX 的实时模糊效果生效
renderscriptTargetApi = 21
renderscriptSupportModeEnabled = true

ndk {
abiFilters.add("armeabi")
abiFilters.add("armeabi-v7a")
abiFilters.add("arm64-v8a")
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
Expand Down Expand Up @@ -150,9 +156,6 @@ dependencies {
//文件选择对话框
implementation("com.github.kongzue.DialogXSample:FileDialog:$dialogx_sample_version")

// PermissionX
implementation("com.guolindev.permissionx:permissionx:1.7.1")

// Cascade 下拉菜单
val cascade_version = "2.3.0"
implementation("me.saket.cascade:cascade-compose:$cascade_version")
Expand Down Expand Up @@ -190,4 +193,14 @@ dependencies {
val net_version = "3.6.4"
implementation("com.github.liangjingkanji:Net:$net_version")

// 权限请求框架:https://github.com/getActivity/XXPermissions
val xxpermission_version = "18.63"
implementation ("com.github.getActivity:XXPermissions:$xxpermission_version")

// 百度地图 SDK
// 地图组件
// implementation ("com.baidu.lbsyun:BaiduMapSDK_Map:7.6.1")
// 基础定位组件
implementation ("com.baidu.lbsyun:BaiduMapSDK_Location:9.3.7")

}
4 changes: 3 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

-keep class com.baidu.location.** {*;}
37 changes: 30 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" /> <!-- Android 13 及以上的新权限 -->
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> <!-- 读写外部存储 -->
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<!-- 这个权限用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 这个权限用于访问系统接口提供的卫星定位信息-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 获取运营商信息,用于支持提供运营商信息相关的接口-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- 访问网络,网络定位需要上网-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Android 13 及以上的访问外存权限 -->
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<!-- 读写外部存储 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
Expand All @@ -22,11 +35,15 @@
android:supportsRtl="true"
android:theme="@style/Theme.EasyNoteDemo"
tools:targetApi="31">

<service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote"/>

<!-- 备份设置界面 -->
<activity
android:name=".BackupSettingActivity"
android:exported="false"
android:label="@string/title_activity_backup_setting"
android:screenOrientation="portrait"
android:theme="@style/Theme.EasyNoteDemo" >
<intent-filter>
<action android:name="com.oxyethylene.BACKUP" />
Expand All @@ -39,6 +56,7 @@
android:name=".CommonActivity"
android:exported="false"
android:label="@string/title_activity_common"
android:screenOrientation="portrait"
android:theme="@style/Theme.EasyNoteDemo"
android:windowSoftInputMode="adjustResize">
<intent-filter>
Expand All @@ -51,6 +69,7 @@
android:name=".EventActivity"
android:exported="false"
android:label="@string/title_activity_event"
android:screenOrientation="portrait"
android:theme="@style/Theme.EasyNoteDemo"
android:windowSoftInputMode="adjustResize">
<intent-filter>
Expand All @@ -63,6 +82,7 @@
android:name=".AppInfoActivity"
android:exported="false"
android:label="@string/title_activity_app_info"
android:screenOrientation="portrait"
android:theme="@style/Theme.EasyNoteDemo"
android:windowSoftInputMode="adjustNothing">
<intent-filter>
Expand All @@ -75,6 +95,7 @@
android:name=".EditActivity"
android:exported="false"
android:label="@string/title_activity_edit"
android:screenOrientation="portrait"
android:theme="@style/Theme.EasyNoteDemo">
<intent-filter>
<action android:name="com.oxyethylene.EDIT" />
Expand All @@ -86,6 +107,7 @@
android:name=".SettingActivity"
android:exported="false"
android:label="@string/title_activity_setting"
android:screenOrientation="portrait"
android:theme="@style/Theme.EasyNoteDemo">
<intent-filter>
<action android:name="com.oxyethylene.SETTING" />
Expand All @@ -97,6 +119,7 @@
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.EasyNoteDemo"
android:windowSoftInputMode="adjustResize">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BackupSettingActivity : ComponentActivity() {
val backupSettingList =
listOf<SettingEntry>(
DialogSetting(
SettingName = "修改备份/导出文件夹"
settingName = "修改备份/导出文件夹"
) {
MessageDialog.build(MIUIStyle())
.setTitle("修改备份文件夹")
Expand All @@ -63,7 +63,7 @@ class BackupSettingActivity : ComponentActivity() {
.show()
},
DialogSetting(
SettingName = "恢复默认导出文件夹",
settingName = "恢复默认导出文件夹",
warning = "原备份文件夹下的文件将会保留,需要自行删除"
) {
MessageDialog.build(MIUIStyle())
Expand All @@ -81,13 +81,13 @@ class BackupSettingActivity : ComponentActivity() {
.show()
},
DialogSetting(
SettingName = "手动备份",
settingName = "手动备份",
description = "将所有文章备份到指定的文件夹"
) {
DebugInfoDial.todoDialog("手动备份")
},
DialogSetting(
SettingName = "从本地恢复文章备份",
settingName = "从本地恢复文章备份",
description = "将所有文章备份到指定的文件夹"
) {
DebugInfoDial.todoDialog("从本地恢复文章备份")
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/oxyethylene/easynote/CommonActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.kongzue.dialogx.DialogX
import com.oxyethylene.easynote.ui.commonactivity.EditorSettingPageUI
import com.oxyethylene.easynote.ui.commonactivity.KeywordPageUI
import com.oxyethylene.easynote.ui.commonactivity.LabSettingPageUI
Expand All @@ -29,6 +30,8 @@ class CommonActivity : ComponentActivity() {

val UITitle = intent.getStringExtra("title") ?: ""

DialogX.init(applicationContext)

setContent {
EasyNoteTheme {
Surface(
Expand Down
78 changes: 66 additions & 12 deletions app/src/main/java/com/oxyethylene/easynote/EditActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.baidu.location.BDAbstractLocationListener
import com.baidu.location.BDLocation
import com.baidu.location.LocationClient
import com.baidu.location.LocationClientOption
import com.drake.net.utils.TipUtils
import com.kongzue.albumdialog.PhotoAlbumDialog
import com.kongzue.albumdialog.util.SelectPhotoCallback
import com.kongzue.filedialog.FileDialog
Expand All @@ -43,9 +48,11 @@ import com.oxyethylene.easynote.ui.editactivity.EditActionBarButton
import com.oxyethylene.easynote.ui.editactivity.EditActionBarHelper
import com.oxyethylene.easynote.ui.editactivity.EditActionBarMenu
import com.oxyethylene.easynote.ui.editactivity.KeywordUtilButton
import com.oxyethylene.easynote.ui.editactivity.LocationInfoButton
import com.oxyethylene.easynote.ui.editactivity.TitleLine
import com.oxyethylene.easynote.ui.theme.BackGround
import com.oxyethylene.easynote.ui.theme.EasyNoteTheme
import com.oxyethylene.easynote.util.DateUtil
import com.oxyethylene.easynote.util.FileUtil
import com.oxyethylene.easynote.util.KeywordUtil
import com.oxyethylene.easynote.util.NoteUtil
Expand All @@ -55,18 +62,62 @@ import java.io.File

class EditActivity : ComponentActivity() {

// 富文本编辑器
/**
* 富文本编辑器
*/
private lateinit var richEditor: RichEditor

// 编辑器纯文本内容
/**
* 编辑器纯文本内容
*/
private var plainText = ""

// 获取当前编辑的文章
/**
* 文本是否被修改过
*/
private var modified = false

/**
* 当前编辑的文章
*/
private val note = FileUtil.getNote(NoteUtil.getNoteId())

/**
* 百度地图 SDK 请求客户端
*/
private var mLocationClient: LocationClient? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

try {
mLocationClient = LocationClient(applicationContext)
} catch (ex : Exception) {
TipUtils.toast(ex.message)
}

val option = LocationClientOption().apply {
setIsNeedAddress(true)
}

mLocationClient?.locOption = option

mLocationClient?.registerLocationListener(
object : BDAbstractLocationListener() {
override fun onReceiveLocation(location: BDLocation?) {
val updateTime = DateUtil.getCurrentDateTime()

val address = location?.addrStr ?: SettingUtil.defaultLocation

// 更新修改地点
NoteUtil.updateRecord(address, updateTime)

FileUtil.setNoteUpdateTime(NoteUtil.getNoteId(), updateTime)
mLocationClient!!.stop()
}
}
)

setContent {
EasyNoteTheme {

Expand All @@ -91,6 +142,9 @@ class EditActivity : ComponentActivity() {
onKeywordUpdate = { keywordMap = KeywordUtil.getBindedKeywords(note!!.keywordList) }
) { plainText }
}
if (SettingUtil.enableLocation) {
LocationInfoButton(Modifier.align(Alignment.CenterVertically).padding(start = 20.dp))
}
KeywordUtilButton(NoteUtil.getNoteId()) {
keywordMap = KeywordUtil.getBindedKeywords(note!!.keywordList)
}
Expand Down Expand Up @@ -121,22 +175,18 @@ class EditActivity : ComponentActivity() {
}
// 字体加粗
EditActionBarButton(R.mipmap.ic_set_bold) {
// richEditor.focusEditor()
richEditor.setBold()
}
// 字体倾斜
EditActionBarButton(R.mipmap.ic_set_italic) {
// richEditor.focusEditor()
richEditor.setItalic()
}
// 添加下划线
EditActionBarButton(R.mipmap.ic_set_underline) {
// richEditor.focusEditor()
richEditor.setUnderline()
}
// 添加删除线
EditActionBarButton(R.mipmap.ic_set_strike_through) {
// richEditor.focusEditor()
richEditor.setStrikeThrough()
}
// 文本对齐方式
Expand All @@ -159,7 +209,6 @@ class EditActivity : ComponentActivity() {
}
// 插入图片
EditActionBarButton(R.mipmap.ic_insert_photo) {
// richEditor.focusEditor()
PhotoAlbumDialog.build()
.setMaxSelectPhotoCount(1)
.setCompressQuality(80)
Expand All @@ -181,7 +230,6 @@ class EditActivity : ComponentActivity() {
}
// 插入视频
EditActionBarButton(R.mipmap.ic_insert_video) {
// richEditor.focusEditor()
FileDialog.build()
.setShowFileDate(true)
.setSuffixArray(arrayOf(".mp4"))
Expand All @@ -196,7 +244,6 @@ class EditActivity : ComponentActivity() {
}
// 插入音频
EditActionBarButton(R.mipmap.ic_insert_audio) {
// richEditor.focusEditor()
FileDialog.build()
.setShowFileDate(true)
.setSuffixArray(arrayOf(".ogg", ".mp3", ".flac"))
Expand Down Expand Up @@ -227,7 +274,12 @@ class EditActivity : ComponentActivity() {
richEditor = findViewById(R.id.editor)
richEditor.setBackgroundColor(Color.Transparent.toArgb())
richEditor.settings.allowFileAccess = true
richEditor.setOnTextChangeListener { plainText = richEditor.plainText }
richEditor.setOnTextChangeListener {
// 更新纯文本内容
plainText = richEditor.plainText
// 更新修改标记
modified = true
}
// 加载已有内容
richEditor.html = NoteUtil.loadFile(this@EditActivity)
// 初始化纯文本内容
Expand Down Expand Up @@ -257,7 +309,9 @@ class EditActivity : ComponentActivity() {
super.onDestroy()
richEditor.html?.let { NoteUtil.saveFile(this, it) }
richEditor.pauseMediaPlayers()
FileUtil.setNoteUpdateTime(NoteUtil.getNoteId())
if (modified && SettingUtil.enableLocation) {
mLocationClient?.start()
}
}

override fun onStop() {
Expand Down
Loading

0 comments on commit 06401fa

Please sign in to comment.