fix: 增加文件选择功能
This commit is contained in:
@@ -24,8 +24,8 @@ android {
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
|
||||
@@ -1,7 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.navinfo.omqs">
|
||||
<!-- 这个权限用于进行网络定位-->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<!-- 这个权限用于访问GPS定位-->
|
||||
<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" />
|
||||
<!-- 允许访问振动设备 -->
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<!-- 允许使用PowerManager的 WakeLocks保持进程在休眠时从屏幕消失 -->
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<!-- android 9.0上使用前台服务,需要添加权限 -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<!-- 用于读取手机当前的状态 -->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<!-- 读取缓存数据 -->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
@@ -12,8 +36,9 @@
|
||||
android:theme="@style/Theme.OMQualityInspection"
|
||||
android:requestLegacyExternalStorage="true">
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:name=".ui.activity.LoginActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="landscape"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.OMQualityInspection">
|
||||
<intent-filter>
|
||||
@@ -22,6 +47,16 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activity.MainActivity"
|
||||
android:screenOrientation="landscape"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.OMQualityInspection"></activity>
|
||||
<activity
|
||||
android:name=".ui.activity.MapTestActivity"
|
||||
android:screenOrientation="landscape"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.OMQualityInspection"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
95
app/src/main/assets/MergeOMDB.py
Normal file
95
app/src/main/assets/MergeOMDB.py
Normal file
@@ -0,0 +1,95 @@
|
||||
# coding:utf-8
|
||||
# 合并指定目录下的omdb(sqlite)数据
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import sqlite3
|
||||
|
||||
|
||||
# 定义遍历目录的函数
|
||||
def traverse_dir(path):
|
||||
fileList = list()
|
||||
for root, dirs, files in os.walk(path):
|
||||
for file in files:
|
||||
if str(file).endswith(".omdb"):
|
||||
# 文件的完整路径
|
||||
file_path = os.path.join(root, file)
|
||||
# 处理文件,例如读取文件内容等
|
||||
print(file_path)
|
||||
fileList.append(file_path)
|
||||
return fileList
|
||||
|
||||
|
||||
# 打开配置文件,读取用户配置的
|
||||
def openConfigJson(path):
|
||||
# 读取json配置,获取要抽取的表名
|
||||
with open(path, "r") as f:
|
||||
configMap = json.load(f)
|
||||
return configMap
|
||||
|
||||
|
||||
# 按照tableList中指定的表名合并多个源数据库到指定目标数据库中
|
||||
def mergeSqliteData(originSqliteList, destSqlite, tableList):
|
||||
destConn = sqlite3.connect(destSqlite)
|
||||
destCursor = destConn.cursor()
|
||||
|
||||
for originSqlite in originSqliteList:
|
||||
originConn = sqlite3.connect(originSqlite)
|
||||
originCursor = originConn.cursor()
|
||||
# 从源数据库中遍历取出表list中的数据
|
||||
for table in tableList:
|
||||
# 检查目标数据库中是否存在指定的表
|
||||
containsTable = destCursor.execute(
|
||||
"SELECT sql FROM sqlite_master WHERE type='table' AND name='%s'" % (table)).fetchall()
|
||||
if not containsTable or len(containsTable) <= 0:
|
||||
# 复制表结构
|
||||
originCursor.execute("SELECT sql FROM sqlite_master WHERE type='table' AND name='%s'" % (table))
|
||||
createTableSql = originCursor.fetchone()[0]
|
||||
destCursor.execute(createTableSql)
|
||||
destConn.commit()
|
||||
|
||||
originCursor.execute("Select * From " + table)
|
||||
# 获取到源数据库中该表的所有数据
|
||||
originData = originCursor.fetchall()
|
||||
# 获取一行数据中包含多少列,以此动态设置sql语句中的?个数
|
||||
if originData and len(originData)>0:
|
||||
num_cols = len(originData[0])
|
||||
placeholders = ",".join(["?"] * num_cols)
|
||||
for row in originData:
|
||||
destCursor.execute("INSERT INTO "+table+" VALUES ({})".format(placeholders), row)
|
||||
|
||||
print("{}数据已导入!".format(originSqlite))
|
||||
originCursor.close()
|
||||
originConn.close()
|
||||
destConn.commit()
|
||||
destCursor.close()
|
||||
destConn.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
params = sys.argv[1:] # 截取参数
|
||||
if params:
|
||||
if not params[0]:
|
||||
print("请输入要合并的omdb数据的文件夹")
|
||||
raise AttributeError("请输入要合并的omdb数据的文件夹")
|
||||
# 获取导出文件的表配置
|
||||
jsonPath = params[0] + "/config.json"
|
||||
if not os.path.exists(jsonPath):
|
||||
raise AttributeError("指定目录下缺少config.json配置文件")
|
||||
omdbDir = params[0]
|
||||
originSqliteList = traverse_dir(omdbDir) # 获取到所有的omdb数据库的路径
|
||||
|
||||
tableNameList = list()
|
||||
configMap = openConfigJson(jsonPath)
|
||||
if configMap["tables"] and len(configMap["tables"]) > 0:
|
||||
for tableName in set(configMap["tables"]):
|
||||
tableNameList.append(tableName)
|
||||
print(tableNameList)
|
||||
else:
|
||||
raise AttributeError("config.json文件中没有配置抽取数据的表名")
|
||||
|
||||
# 开始分别连接Sqlite数据库,按照指定表名合并数据
|
||||
mergeSqliteData(originSqliteList, params[0]+"/output.sqlite", tableNameList)
|
||||
else:
|
||||
raise AttributeError("缺少参数:请输入要合并的omdb数据的文件夹")
|
||||
10
app/src/main/java/com/navinfo/omqs/QAApplication.kt
Normal file
10
app/src/main/java/com/navinfo/omqs/QAApplication.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.navinfo.omqs
|
||||
|
||||
import android.app.Application
|
||||
|
||||
class QAApplication: Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
}
|
||||
}
|
||||
6
app/src/main/java/com/navinfo/omqs/model/LoginUser.kt
Normal file
6
app/src/main/java/com/navinfo/omqs/model/LoginUser.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.navinfo.omqs.model
|
||||
|
||||
data class LoginUser(
|
||||
var username: String = "",
|
||||
var password: String = ""
|
||||
)
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.navinfo.omqs.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import androidx.activity.viewModels
|
||||
import com.navinfo.omqs.databinding.ActivityLoginBinding
|
||||
|
||||
class LoginActivity : PermissionsActivity() {
|
||||
|
||||
private lateinit var binding: ActivityLoginBinding
|
||||
private val viewModel by viewModels<LoginActivityViewModel>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
|
||||
super.onCreate(savedInstanceState, persistentState)
|
||||
binding = ActivityLoginBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
}
|
||||
|
||||
override fun onPermissionsGranted() {
|
||||
initView()
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
|
||||
}
|
||||
|
||||
override fun onPermissionsDenied() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.navinfo.omqs.ui
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class LoginActivityViewModel : ViewModel() {
|
||||
|
||||
}
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.navinfo.omqs.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.FileUtils
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
@@ -13,20 +9,11 @@ import androidx.navigation.ui.navigateUp
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import androidx.core.net.toFile
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.blankj.utilcode.util.UriUtils
|
||||
import com.github.k1rakishou.fsaf.FileChooser
|
||||
import com.github.k1rakishou.fsaf.FileManager
|
||||
import com.github.k1rakishou.fsaf.callback.FSAFActivityCallbacks
|
||||
import com.github.k1rakishou.fsaf.callback.FileChooserCallback
|
||||
import com.hjq.permissions.OnPermissionCallback
|
||||
import com.hjq.permissions.Permission
|
||||
import com.hjq.permissions.XXPermissions
|
||||
import com.navinfo.omqs.R
|
||||
import com.navinfo.omqs.databinding.ActivityMainBinding
|
||||
import java.io.File
|
||||
import com.navinfo.omqs.ui.activity.PermissionsActivity
|
||||
|
||||
class MainActivity : PermissionsActivity(), FSAFActivityCallbacks {
|
||||
|
||||
@@ -41,29 +28,27 @@ class MainActivity : PermissionsActivity(), FSAFActivityCallbacks {
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
||||
val navController = findNavController(R.id.nav_host_fragment_content_main)
|
||||
appBarConfiguration = AppBarConfiguration(navController.graph)
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
|
||||
fileChooser.setCallbacks(this@MainActivity)
|
||||
binding.fab.setOnClickListener { view ->
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAnchorView(R.id.fab)
|
||||
.setAction("Action", null).show()
|
||||
// 开始数据导入功能
|
||||
fileChooser.openChooseFileDialog(object: FileChooserCallback() {
|
||||
override fun onCancel(reason: String) {
|
||||
}
|
||||
|
||||
override fun onResult(uri: Uri) {
|
||||
val file = UriUtils.uri2File(uri)
|
||||
Snackbar.make(view, "文件大小为:${file.length()}", Snackbar.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
})
|
||||
}
|
||||
// binding.fab.setOnClickListener { view ->
|
||||
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
// .setAnchorView(R.id.fab)
|
||||
// .setAction("Action", null).show()
|
||||
// // 开始数据导入功能
|
||||
// fileChooser.openChooseFileDialog(object: FileChooserCallback() {
|
||||
// override fun onCancel(reason: String) {
|
||||
// }
|
||||
//
|
||||
// override fun onResult(uri: Uri) {
|
||||
// val file = UriUtils.uri2File(uri)
|
||||
// Snackbar.make(view, "文件大小为:${file.length()}", Snackbar.LENGTH_LONG)
|
||||
// .show()
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onPermissionsGranted() {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.navinfo.omqs.ui.activity
|
||||
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
/**
|
||||
* 基类
|
||||
*/
|
||||
open class BaseActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE//横屏
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.navinfo.omqs.ui.activity
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.viewModels
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import com.navinfo.omqs.R
|
||||
import com.navinfo.omqs.databinding.ActivityLoginBinding
|
||||
|
||||
/**
|
||||
* 登陆页面
|
||||
*/
|
||||
class LoginActivity : PermissionsActivity() {
|
||||
|
||||
private lateinit var binding: ActivityLoginBinding
|
||||
private val viewModel by viewModels<LoginViewModel>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_login)
|
||||
binding.loginUserModel = viewModel
|
||||
binding.lifecycleOwner = this
|
||||
binding.activity = this
|
||||
}
|
||||
|
||||
override fun onPermissionsGranted() {
|
||||
}
|
||||
|
||||
override fun onPermissionsDenied() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理登录按钮
|
||||
*/
|
||||
fun onClickLoginButton() {
|
||||
val intent = Intent(this@LoginActivity, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.navinfo.omqs.ui.activity
|
||||
|
||||
import android.view.View
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.navinfo.omqs.model.LoginUser
|
||||
|
||||
class LoginViewModel : ViewModel() {
|
||||
val loginUser: MutableLiveData<LoginUser> = MutableLiveData()
|
||||
|
||||
init {
|
||||
loginUser.value = LoginUser(username = "admin", password = "123456")
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理注册按钮
|
||||
*/
|
||||
fun onClick(view: View) {
|
||||
loginUser.value!!.username = "admin2"
|
||||
loginUser.postValue(loginUser.value)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.navinfo.omqs.ui.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.navinfo.omqs.R
|
||||
import com.navinfo.omqs.databinding.ActivityMainBinding
|
||||
|
||||
/**
|
||||
* 地图主页面
|
||||
*/
|
||||
class MainActivity : BaseActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private val viewModel by viewModels<MainViewModel>()
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
|
||||
//关联生命周期
|
||||
binding.lifecycleOwner = this
|
||||
//给xml转递对象
|
||||
binding.mainActivity = this
|
||||
//给xml传递viewModel对象
|
||||
binding.viewModel = viewModel
|
||||
//初始化地图
|
||||
viewModel.initMap(this, binding.mapView.mainActivityMap)
|
||||
//让viewModel监听activity生命周期
|
||||
lifecycle.addObserver(viewModel)
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开个人中菜单
|
||||
*/
|
||||
fun openMenu() {
|
||||
binding.mainActivityDrawer.open()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.navinfo.omqs.ui.activity
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.navinfo.collect.library.map.NIMapController
|
||||
import com.navinfo.collect.library.map.NIMapView
|
||||
|
||||
class MainViewModel(val app: Application) : AndroidViewModel(app), DefaultLifecycleObserver {
|
||||
/**
|
||||
* 地图控制器
|
||||
*/
|
||||
private lateinit var mapController: NIMapController
|
||||
|
||||
/**
|
||||
* 初始化地图
|
||||
*/
|
||||
fun initMap(context: Context, mapView: NIMapView) {
|
||||
mapController = NIMapController(context = app, mapView = mapView)
|
||||
|
||||
}
|
||||
|
||||
override fun onStart(owner: LifecycleOwner) {
|
||||
super.onStart(owner)
|
||||
//开启定位
|
||||
mapController.locationLayerHandler.startLocation()
|
||||
}
|
||||
|
||||
override fun onPause(owner: LifecycleOwner) {
|
||||
mapController.mMapView.onPause()
|
||||
}
|
||||
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
mapController.mMapView.onDestroy()
|
||||
//结束定位
|
||||
mapController.locationLayerHandler.stopLocation()
|
||||
}
|
||||
|
||||
override fun onResume(owner: LifecycleOwner) {
|
||||
mapController.mMapView.onResume()
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击我的位置,回到我的位置
|
||||
*/
|
||||
fun onClickLocationButton() {
|
||||
mapController.locationLayerHandler.animateToCurrentPosition()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.navinfo.omqs.ui.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import com.navinfo.collect.library.map.NIMapController
|
||||
import com.navinfo.collect.library.map.NIMapView
|
||||
import com.navinfo.omqs.R
|
||||
|
||||
class MapTestActivity: BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_map_test)
|
||||
|
||||
val mapController = NIMapController(context = this, mapView = findViewById<NIMapView>(R.id.main_activity_map1))
|
||||
mapController.locationLayerHandler.startLocation()
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.navinfo.omqs.ui
|
||||
package com.navinfo.omqs.ui.activity
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.hjq.permissions.OnPermissionCallback
|
||||
import com.hjq.permissions.Permission
|
||||
import com.hjq.permissions.XXPermissions
|
||||
@@ -11,18 +10,31 @@ import com.hjq.permissions.XXPermissions
|
||||
/**
|
||||
* 权限申请Activity
|
||||
*/
|
||||
abstract class PermissionsActivity : AppCompatActivity() {
|
||||
open class PermissionsActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val permissionList = mutableListOf<String>()
|
||||
if (applicationInfo.targetSdkVersion >= Build.VERSION_CODES.TIRAMISU) {
|
||||
//文件读写
|
||||
// permissionList.add(Permission.READ_MEDIA_IMAGES)
|
||||
// permissionList.add(Permission.READ_MEDIA_AUDIO)
|
||||
// permissionList.add(Permission.READ_MEDIA_VIDEO)
|
||||
permissionList.add(Permission.MANAGE_EXTERNAL_STORAGE)
|
||||
} else {
|
||||
//文件读写
|
||||
permissionList.add(Permission.WRITE_EXTERNAL_STORAGE)
|
||||
permissionList.add(Permission.READ_EXTERNAL_STORAGE)
|
||||
permissionList.add(Permission.READ_MEDIA_VIDEO)
|
||||
}
|
||||
//定位权限
|
||||
permissionList.add(Permission.ACCESS_FINE_LOCATION)
|
||||
permissionList.add(Permission.ACCESS_COARSE_LOCATION)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
permissionList.add(Permission.ACCESS_BACKGROUND_LOCATION)
|
||||
}
|
||||
XXPermissions.with(this)
|
||||
// 申请单个权限
|
||||
// .permission(Permission.WRITE_EXTERNAL_STORAGE)
|
||||
// .permission(Permission.READ_EXTERNAL_STORAGE)
|
||||
// .permission(Permission.READ_MEDIA_IMAGES)
|
||||
// .permission(Permission.READ_MEDIA_AUDIO)
|
||||
// .permission(Permission.READ_MEDIA_VIDEO)
|
||||
.permission(Permission.MANAGE_EXTERNAL_STORAGE)
|
||||
.permission(permissionList)
|
||||
// 设置权限请求拦截器(局部设置)
|
||||
//.interceptor(new PermissionInterceptor())
|
||||
// 设置不触发错误检测机制(局部设置)
|
||||
@@ -39,6 +51,8 @@ abstract class PermissionsActivity : AppCompatActivity() {
|
||||
.show()
|
||||
onPermissionsGranted()
|
||||
return
|
||||
} else {
|
||||
onPermissionsDenied()
|
||||
}
|
||||
// 在SD卡创建项目目录
|
||||
}
|
||||
@@ -55,11 +69,23 @@ abstract class PermissionsActivity : AppCompatActivity() {
|
||||
XXPermissions.startPermissionActivity(this@PermissionsActivity, permissions)
|
||||
onPermissionsDenied()
|
||||
} else {
|
||||
onPermissionsDenied()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
abstract fun onPermissionsGranted()
|
||||
abstract fun onPermissionsDenied()
|
||||
/**
|
||||
* 权限全部同意
|
||||
*/
|
||||
open fun onPermissionsGranted() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限
|
||||
*/
|
||||
open fun onPermissionsDenied() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.navinfo.omqs
|
||||
package com.navinfo.omqs.ui.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.navinfo.omqs.R
|
||||
import com.navinfo.omqs.databinding.FragmentFirstBinding
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.navinfo.omqs
|
||||
package com.navinfo.omqs.ui.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.navinfo.omqs.R
|
||||
import com.navinfo.omqs.databinding.FragmentSecondBinding
|
||||
|
||||
/**
|
||||
@@ -22,7 +23,7 @@ class SecondFragment : Fragment() {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
): View {
|
||||
|
||||
_binding = FragmentSecondBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
5
app/src/main/res/drawable/baseline_my_location_24.xml
Normal file
5
app/src/main/res/drawable/baseline_my_location_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#18FD00"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94L13,1h-2v2.06C6.83,3.52 3.52,6.83 3.06,11L1,11v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94L11,23h2v-2.06c4.17,-0.46 7.48,-3.77 7.94,-7.94L23,13v-2h-2.06zM12,19c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z"/>
|
||||
</vector>
|
||||
5
app/src/main/res/drawable/baseline_person_24.xml
Normal file
5
app/src/main/res/drawable/baseline_person_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#18FD00"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
||||
</vector>
|
||||
@@ -1,9 +1,101 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context=".ui.LoginActivity">
|
||||
tools:context=".ui.activity.LoginActivity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="activity"
|
||||
type="com.navinfo.omqs.ui.activity.LoginActivity" />
|
||||
|
||||
<variable
|
||||
name="loginUserModel"
|
||||
type="com.navinfo.omqs.ui.activity.LoginViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/login_fragment_logo"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:contentDescription="@string/imagedescription"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.1"
|
||||
app:roundPercent="0.2" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/login_fragment_user_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:scrollbarAlwaysDrawHorizontalTrack="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.4">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/login_username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/input_user_name"
|
||||
android:text="@{loginUserModel.loginUser.username}" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/login_fragment_user_layout">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/login_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/input_password"
|
||||
android:inputType="textPassword"
|
||||
android:text="@{loginUserModel.loginUser.password}" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/login_fragment_register_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="@{(view)->loginUserModel.onClick(view)}"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:text="@string/logon"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintHorizontal_chainStyle="spread"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@id/login_activity_login_button"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.8" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/login_activity_login_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="@{()->activity.onClickLoginButton()}"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:text="@string/login"
|
||||
app:layout_constraintBaseline_toBaselineOf="@id/login_fragment_register_button"
|
||||
app:layout_constraintLeft_toRightOf="@id/login_fragment_register_button"
|
||||
app:layout_constraintRight_toRightOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
@@ -1,34 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context=".ui.MainActivity">
|
||||
tools:context=".ui.activity.MainActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="mainActivity"
|
||||
type="com.navinfo.omqs.ui.activity.MainActivity" />
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.navinfo.omqs.ui.activity.MainViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.drawerlayout.widget.DrawerLayout
|
||||
android:id="@+id/main_activity_drawer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/toolbar"
|
||||
<include
|
||||
android:id="@+id/map_view"
|
||||
layout="@layout/map_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize" />
|
||||
android:layout_height="match_parent"
|
||||
app:mainActivity="@{mainActivity}"
|
||||
app:viewModel="@{viewModel}"/>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_main" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="@dimen/fab_margin"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:srcCompat="@android:drawable/ic_dialog_email" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="left"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/activity_main_drawer" />
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
</layout>
|
||||
9
app/src/main/res/layout/activity_map_test.xml
Normal file
9
app/src/main/res/layout/activity_map_test.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<com.navinfo.collect.library.map.NIMapView
|
||||
android:id="@+id/main_activity_map1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".FirstFragment">
|
||||
tools:context=".ui.fragment.FirstFragment">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".SecondFragment">
|
||||
tools:context=".ui.fragment.SecondFragment">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
48
app/src/main/res/layout/map_view.xml
Normal file
48
app/src/main/res/layout/map_view.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
<variable
|
||||
name="mainActivity"
|
||||
type="com.navinfo.omqs.ui.activity.MainActivity" />
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.navinfo.omqs.ui.activity.MainViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.activity.MainActivity">
|
||||
|
||||
<com.navinfo.collect.library.map.NIMapView
|
||||
android:id="@+id/main_activity_map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/main_activity_person_center"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:onClick="@{()->mainActivity.openMenu()}"
|
||||
android:src="@drawable/baseline_person_24"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/main_activity_location"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginBottom="80dp"
|
||||
android:onClick="@{()->viewModel.onClickLocationButton()}"
|
||||
android:src="@drawable/baseline_my_location_24"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
35
app/src/main/res/layout/nav_header_main.xml
Normal file
35
app/src/main/res/layout/nav_header_main.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/nav_header_height"
|
||||
android:background="@color/default_blue"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/nav_header_desc"
|
||||
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
||||
app:srcCompat="@mipmap/ic_launcher_round" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
||||
android:text="@string/nav_header_title"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/nav_header_subtitle" />
|
||||
</LinearLayout>
|
||||
20
app/src/main/res/menu/activity_main_drawer.xml
Normal file
20
app/src/main/res/menu/activity_main_drawer.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:showIn="navigation_view">
|
||||
|
||||
<group android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/nav_home"
|
||||
android:icon="@drawable/icon_map_zoom_in"
|
||||
android:title="menu_home" />
|
||||
<item
|
||||
android:id="@+id/nav_gallery"
|
||||
android:icon="@drawable/icon_map_zoom_in"
|
||||
android:title="menu_gallery" />
|
||||
<item
|
||||
android:id="@+id/nav_slideshow"
|
||||
android:icon="@drawable/icon_map_zoom_in"
|
||||
android:title="menu_slideshow" />
|
||||
</group>
|
||||
</menu>
|
||||
@@ -1,7 +1,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.navinfo.omqs.ui.MainActivity">
|
||||
tools:context="com.navinfo.omqs.ui.activity.MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<fragment
|
||||
android:id="@+id/FirstFragment"
|
||||
android:name="com.navinfo.omqs.FirstFragment"
|
||||
android:name="com.navinfo.omqs.ui.fragment.FirstFragment"
|
||||
android:label="@string/first_fragment_label"
|
||||
tools:layout="@layout/fragment_first">
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/SecondFragment"
|
||||
android:name="com.navinfo.omqs.SecondFragment"
|
||||
android:name="com.navinfo.omqs.ui.fragment.SecondFragment"
|
||||
android:label="@string/second_fragment_label"
|
||||
tools:layout="@layout/fragment_second">
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
<resources>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="nav_header_vertical_spacing">8dp</dimen>
|
||||
<dimen name="nav_header_height">176dp</dimen>
|
||||
</resources>
|
||||
@@ -43,4 +43,18 @@
|
||||
libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
|
||||
vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
|
||||
</string>
|
||||
<string name="input_user_name">请输入用户名</string>
|
||||
<string name="input_password">请输入密码</string>
|
||||
<string name="login">登录</string>
|
||||
<string name="logon">注册</string>
|
||||
<string name="imagedescription">imageDescription</string>
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
<string name="nav_header_title">Android Studio</string>
|
||||
<string name="nav_header_subtitle">android.studio@android.com</string>
|
||||
<string name="nav_header_desc">Navigation header</string>
|
||||
|
||||
<string name="menu_home">Home</string>
|
||||
<string name="menu_gallery">Gallery</string>
|
||||
<string name="menu_slideshow">Slideshow</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user