Commit 05c16e7b authored by p x's avatar p x
Browse files

造一条经过亦庄园区的路径

parent fe30889a
......@@ -56,6 +56,8 @@ dependencies {
androidTestImplementation(libs.androidx.espresso.core)
implementation(project(":mapapi"))
implementation("com.google.code.gson:gson:2.12.0")
// https://github.com/CymChad/BaseRecyclerViewAdapterHelper/ RecyclerView 适配器
implementation("io.github.cymchad:BaseRecyclerViewAdapterHelper4:4.1.7")
}
\ No newline at end of file
......@@ -4,22 +4,30 @@ package com.sd.demo.ui
//import com.sd.maplibrary.core.MSRoutePlans.OnDriveRoute
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.Gson
import com.minedata.minenavi.navi.GuidanceText
import com.minedata.minenavi.navi.NaviProgressData
import com.minedata.minenavi.navi.SmoothNaviData
import com.minedata.minenavi.navi.TmcSections
import com.minedata.minenavi.util.Tools
import com.sd.api.bean.DriverRouteBean
import com.sd.api.maps.cdata.MSLatLng
import com.sd.api.bean.WayPoi
import com.sd.api.ui.MapReadyView
import com.sd.api.intfaces.OnNaviPresenterListener
import com.sd.api.maps.MSNavi
import com.sd.api.maps.MSRoutePlans
import com.sd.api.maps.inters.OnDriveRoute
import com.sd.api.ui.MapMultiView.OnMapReadyLis
import com.sd.demo.databinding.ActivityTdriveRouteBinding
import com.sd.demo.utils.FileIoUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
/***驾车路径规划***/
class TDriveRouteActivity : AppCompatActivity() ,OnNaviPresenterListener{
class TDriveRouteActivity : AppCompatActivity(), OnNaviPresenterListener {
private lateinit var binding: ActivityTdriveRouteBinding
......@@ -40,20 +48,46 @@ class TDriveRouteActivity : AppCompatActivity() ,OnNaviPresenterListener{
binding.starplan.setOnClickListener {
if (mapReadView == null) return@setOnClickListener
// 起点坐标 116.3215,39.8919
val startPoint = MSLatLng(39.806898, 116.490682)
val startPoint = MSLatLng(39.801693,116.49972)//一品亦庄1号楼
// 终点坐标116.3793,39.8643
val endPoint = MSLatLng(39.864311, 116.379311)
val endPoint = MSLatLng(39.812515232947106,116.50831514180288)
// 终点名称
val endName = "沈阳火车站"
// val endName = "沈阳火车站"
val endName = "广汽本田亦庄店"
var wayPoi = WayPoi(
passName = "鸟巢", passPoint = MSLatLng(39.99300, 116.39524)
passName = "联通大楼", passPoint = MSLatLng(39.80789697646307,116.5032203588201)
)
var ways = listOf<WayPoi>(wayPoi)
//开始路径规划
MSRoutePlans.drivingPathPlanning(
startPoint, "当前位置", endPoint, endName, ways, mapReadView,null
startPoint,
"当前位置",
endPoint,
endName,
ways,
mapReadView,
object : OnDriveRoute {
override fun onDriverRoute(driverRouteBean: DriverRouteBean) {
var mRouteBase = driverRouteBean.routeBase
var size = mRouteBase?.segmentNumber ?: 0
if (size > 2) {
var pos = mutableListOf<MSLatLng>()
for (i in 0 until size) {
var pointArr = mRouteBase!!.getSegmentFinePoints(i)
var points = pointArr.map {
var po = Tools.pointToLatLng(it)
var ms = MSLatLng(po.latitude, po.longitude)
return@map ms
}
pos.addAll(points)
}
CoroutineScope(Dispatchers.IO).launch {
FileIoUtils.writeToFile(Gson().toJson(pos), "troute.txt")
}
}
}
}
)
// MSRoutePlans.drivingPathPlanning(startPoint, endPoint, ways, endName)
......@@ -69,7 +103,7 @@ class TDriveRouteActivity : AppCompatActivity() ,OnNaviPresenterListener{
// 起点坐标 116.3215,39.8919
val startPoint = MSLatLng(39.806898, 116.490682)
// 终点坐标116.3793,39.8643
// 终点坐标116.3793,39.8643
val endPoint = MSLatLng(39.864311, 116.379311)
// 终点名称
val endName = "沈阳火车站"
......@@ -79,15 +113,24 @@ class TDriveRouteActivity : AppCompatActivity() ,OnNaviPresenterListener{
)
var ways = listOf<WayPoi>(wayPoi)
MSNavi.startNavi(mapReadView, 2/*1=自己实现回调 2=直接调用导航组件*/, startPoint, "当前位置", endPoint, endName, ways,this)
MSNavi.startNavi(
mapReadView,
2/*1=自己实现回调 2=直接调用导航组件*/,
startPoint,
"当前位置",
endPoint,
endName,
ways,
this
)
}
}
/* 参考DEMO https://gitee.com/cennavi_sy/MineNaviDemo.git
中的 app/src/main/java/com/cennavi/minenavidemo/activity/navi/NaviActivity.java
和 app/src/main/java/com/cennavi/minenavidemo/presenter/NaviPresenter.java*/
/* 参考DEMO https://gitee.com/cennavi_sy/MineNaviDemo.git
中的 app/src/main/java/com/cennavi/minenavidemo/activity/navi/NaviActivity.java
和 app/src/main/java/com/cennavi/minenavidemo/presenter/NaviPresenter.java*/
//车位置发生改变
override fun onTracking(ratio: Float) {
......
package com.sd.demo.utils
import android.content.ContentValues
import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.*
import java.math.BigDecimal
import kotlin.also
import kotlin.collections.indices
import kotlin.io.deleteRecursively
import kotlin.run
import kotlin.text.isNullOrEmpty
object FileIoUtils {
/**
* 读取asset 文件
*/
fun getAssetContent(context: Context, fileName: String): String {
val assetManager = context.assets
var stringBuilder = StringBuilder()
var bf: BufferedReader? = null
try {
val inputReader = InputStreamReader(assetManager.open(fileName))
bf = BufferedReader(inputReader)
var line = ""
while (!bf.run {
line = readLine()
return@run line
}.isNullOrEmpty()) {
stringBuilder.append(line)
}
bf?.close()
assetManager.close()
return stringBuilder.toString()
} catch (e: IOException) {
e.printStackTrace()
return ""
} finally {
bf?.close()
assetManager.close()
}
}
/**
* 复制assets 到手机内存里
* @param prePath 为路径前缀
* @param assetName 为文件名
* **/
suspend fun assetFilePath(context: Context, assetName: String): String {
return withContext(Dispatchers.IO) {
val file = File(context.filesDir, assetName)
if (file.exists() && file.length() > 0) {
return@withContext file.absolutePath
}
try {
var inputs = context.assets.open(assetName)
var os: OutputStream = FileOutputStream(file)
val buffer = ByteArray(4 * 1024)
var read: Int
while ((inputs.read(buffer).also { read = it }) != -1) {
os.write(buffer, 0, read)
}
os.flush()
return@withContext file.absolutePath
} catch (e: IOException) {
e.printStackTrace()
return@withContext ""
}
}
}
suspend fun getAssetMock(context: Context, fileName: String, dst: MutableList<String>): Int {
val assetManager = context.assets
var bf: BufferedReader? = null
try {
val inputReader = InputStreamReader(assetManager.open(fileName))
bf = BufferedReader(inputReader)
var line = ""
while (!bf.run {
line = readLine()
return@run line
}.isNullOrEmpty()) {
dst.add(line)
}
bf?.close()
return 1
} catch (e: IOException) {
e.printStackTrace()
} finally {
bf?.close()
}
return 0
}
suspend fun getAssetMock(context: Context, fileName: String): String {
val assetManager = context.assets
var bf: BufferedReader? = null
var sb = StringBuffer()
try {
val inputReader = InputStreamReader(assetManager.open(fileName))
bf = BufferedReader(inputReader)
var line = ""
while (!bf.run {
line = readLine()
sb.append(line)
return@run line
}.isNullOrEmpty()) {
}
bf?.close()
return sb.toString()
} catch (e: IOException) {
e.printStackTrace()
} finally {
bf?.close()
}
return sb.toString()
}
/**
* 读取asset 文件
*/
fun getAsset(context: Context, fileName: String): String {
val assetManager = context.assets
var inputStream: InputStream? = null
var str = ""
try {
inputStream = assetManager.open(fileName)
val size = inputStream.available()
val bytes = ByteArray(size)
inputStream.read(bytes)
str = String(bytes)
} catch (e: IOException) {
e.printStackTrace()
} finally {
inputStream?.close()
// assetManager.close()
}
return str
}
private var fileWriter: FileWriter? = null
suspend fun writeToFile(message: String, fileName: String) {
withContext(Dispatchers.IO) {
try {
val file = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
fileName
)
fileWriter = FileWriter(file, true) // true for append mode
fileWriter!!.append("$message\n")
fileWriter!!.flush() // Optional, to ensure immediate writing to file
} catch (e: IOException) {
Log.e("------writeToFile", "Error initializing log file", e)
}
}
}
//Uri获取真实路径转换成File的方法
fun getAbsoluteImagePath(contentUri: Uri, context: Context): String { // can post image
var res = ""
val proj = arrayOf(MediaStore.Images.Media.DATA)
val cursor = context.contentResolver.query(contentUri, proj, null, null, null)
if (cursor!!.moveToFirst()) {
val column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
res = cursor.getString(column_index)
}
cursor.close()
return res
}
/**
* 把图片复制到应用缓存里
*/
fun copyHeImgFileToPath(
context: Context,
fileName: String,
source: File,
isRemove: Boolean = true
): File? {
try {
var dir = File(context.externalCacheDir, "xunhepic")
if (!dir.exists()) {
dir.mkdirs()
}
var imgFile = File(dir, fileName)
if (!dir.exists()) {
imgFile.createNewFile()
}
var fosfrom = FileInputStream(source)
var fosto = FileOutputStream(imgFile)
var bt = ByteArray(1024)
var c = 0
while (fosfrom.run {
c = read(bt)
return@run c
} > 0) {
fosto.write(bt, 0, c) //将内容写到新文件当
}
if (isRemove) {
// source.deleteOnExit()
}
fosfrom.close()
fosto.close()
return imgFile
} catch (e: IOException) {
return null
}
}
//file文件读取成byte[]
fun readFileToByte(file: File?): ByteArray? {
val byte_size = 1024
val b = ByteArray(byte_size)
try {
val fileInputStream = FileInputStream(file)
val outputStream = ByteArrayOutputStream(
byte_size
)
var length: Int
while (fileInputStream.read(b).also { length = it } != -1) {
outputStream.write(b, 0, length)
}
fileInputStream.close()
outputStream.close()
return outputStream.toByteArray()
} catch (e: IOException) {
e.printStackTrace()
}
return null
}
/**
* 获取总共的缓存
*/
fun getTotalCacheSize(context: Context): Long {
var size: Long = 0
return try {
size = getFolderSize(context.cacheDir)
size += getFolderSize(context.filesDir)
// size += getFolderSize(context.externalCacheDir)
size
} catch (e: Exception) {
e.printStackTrace()
0
}
}
/**
* 获取文件夹大小
*/
private fun getFolderSize(file: File?): Long {
if (file == null) {
return 0
}
var size: Long = 0
try {
val fileList = file!!.listFiles()
for (i in fileList.indices) {
// 如果下面还有文件
size = if (fileList[i].isDirectory) {
size + getFolderSize(fileList[i])
} else {
size + fileList[i].length()
}
}
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
return size
}
/**
* 删除总共的缓存
*/
fun deleteTotalCacheSize(context: Context) {
runBlocking {
coroutineScope {
withContext(Dispatchers.IO) {
context.cacheDir.deleteRecursively()
context.filesDir.deleteRecursively()
// if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
// context.externalCacheDir?.deleteRecursively()
// }
}
}
}
}
/**
* 格式化单位
*/
fun getFormatSize(size: Double): String? {
val kiloByte = size / 1024
if (kiloByte < 1) {
return size.toString() + "Byte"
}
val megaByte = kiloByte / 1024
if (megaByte < 1) {
val result1 = BigDecimal(kiloByte.toString())
return result1.setScale(2, BigDecimal.ROUND_HALF_UP)
.toPlainString().toString() + "KB"
}
val gigaByte = megaByte / 1024
if (gigaByte < 1) {
val result2 = BigDecimal(megaByte.toString())
return result2.setScale(1, BigDecimal.ROUND_HALF_UP)
.toPlainString().toString() + "MB"
}
val teraBytes = gigaByte / 1024
if (teraBytes < 1) {
val result3 = BigDecimal(gigaByte.toString())
return result3.setScale(2, BigDecimal.ROUND_HALF_UP)
.toPlainString().toString() + "GB"
}
val result4 = BigDecimal(teraBytes)
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()
.toString() + "TB"
}
/**
* 保存图片到本地相册
*/
fun saveBitmapToGalley(context: Context, bitmap: Bitmap) {
try {
var parentDir: File
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
parentDir = context.getExternalFilesDir(Environment.DIRECTORY_DCIM)!!
} else {
return
}
} else {
parentDir =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
}
var fileName = "firend.jpg"
var file = File(parentDir, fileName)
val contentValues = ContentValues()
contentValues.put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
contentValues.put(MediaStore.Images.Media.MIME_TYPE, "image/JPEG")
//兼容Android Q和以下版本
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//android Q中不再使用DATA字段,而用RELATIVE_PATH代替
//RELATIVE_PATH是相对路径不是绝对路径
//DCIM是系统文件夹,关于系统文件夹可以到系统自带的文件管理器中查看,不可以写没存在的名字
contentValues.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_DCIM)
var uri = context.contentResolver.insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
contentValues
)
// LogUtil.v("-------uri= " + uri)
if (uri != null) {
//若生成了uri,则表示该文件添加成功
//使用流将内容写入该uri中即可
val outputStream = context.contentResolver.openOutputStream(uri)
if (outputStream != null) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, outputStream)
outputStream.flush()
outputStream.close()
}
}
} else {
contentValues.put(MediaStore.Images.Media.DATA, Environment.DIRECTORY_DCIM)
MediaStore.Images.Media.insertImage(
context.contentResolver,
bitmap,
fileName,
null
)
var outputStream = FileOutputStream(file)
if (file.exists()) {
file.delete()
} else {
file.createNewFile()
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, outputStream)
outputStream.flush()
outputStream.close()
}
// LogUtil.e("------ " + file?.toUri())
// context.sendBroadcast(
// Intent(
// Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
// file?.toUri()
// )
// )
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
}
}
\ No newline at end of file
......@@ -18,21 +18,21 @@ pluginManagement {
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
// maven { setUrl("https://maven.aliyun.com/repository/central") }
// maven { setUrl("https://maven.aliyun.com/repository/jcenter") }
// maven { setUrl("https://maven.aliyun.com/repository/google") }
// maven { setUrl("https://maven.aliyun.com/repository/gradle-plugin") }
// maven { setUrl("https://maven.aliyun.com/repository/public") }
maven { setUrl("https://maven.aliyun.com/repository/central") }
maven { setUrl("https://maven.aliyun.com/repository/jcenter") }
maven { setUrl("https://maven.aliyun.com/repository/google") }
maven { setUrl("https://maven.aliyun.com/repository/gradle-plugin") }
maven { setUrl("https://maven.aliyun.com/repository/public") }
//四维高精地图仓库
maven {
isAllowInsecureProtocol = true
setUrl("http://29266411xv.wicp.vip/repository/daohang-tingche/")
credentials {
username = "admin"
password = "Nexus"
}
}
// maven {
// isAllowInsecureProtocol = true
// setUrl("http://29266411xv.wicp.vip/repository/daohang-tingche/")
// credentials {
// username = "admin"
// password = "Nexus"
// }
// }
google()
mavenCentral()
mavenLocal()
......
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