迁移探路模块和tanlulib代码至此
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import android.content.Context
|
||||
import com.elegant.analytics.Analytics
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.network.Utils
|
||||
import com.zhidao.roadcondition.aspect.DebugLog
|
||||
import java.util.HashMap
|
||||
|
||||
const val CarNet_Alive:String = "CarNet_Alive"//探路日活DAU埋点
|
||||
const val CarNet_Scheme_Channel:String = "CarNet_Scheme_Channel"//探路Scheme渠道区分
|
||||
const val APPENTER_FRONT:String = "appenterfront"//探路Scheme渠道区分
|
||||
|
||||
const val CarNet_auto_upload:String = "CarNet_auto_upload"//情报自动上传时间(自动上报图片)
|
||||
const val CarNet_click:String ="CarNet_click"//用户点击查看大图
|
||||
const val CarNet_right_handle:String ="CarNet_right_handle"//用户切换情报-地图切换
|
||||
const val CarNet_event_number:String ="CarNet_event_number" //用户获取的信息数量
|
||||
const val CarNet_user_upload:String ="CarNet_user_upload" //用户主动上报视频type=1 手动点击 type=2 语音
|
||||
const val CarNet_auto_upload_video:String ="CarNet_auto_upload_video"//自动上报视频
|
||||
const val CarNet_click_search:String = "CarNet_click_search" //点击地图搜索
|
||||
const val CarNet_user_get:String = "CarNet_user_get"//用户查看情报(首页视频/图片,开始播放即算做用户查看)type=1 视频 type=2 图片
|
||||
const val CarNet_road_search:String = "CarNet_road_search"//有导航路线时的沿途查询
|
||||
|
||||
const val CarNet_MainService:String = "CarNet_MainService" //开机
|
||||
const val CarNet_MainService_Start:String ="CarNet_MainService_Start" //服务开启
|
||||
const val CarNet_MainService_Destory:String ="CarNet_MainService_Destory" //服务销毁
|
||||
const val CarNet_Get_Strategy:String = "CarNet_Get_Strategy" //策略拉取成功
|
||||
const val CarNet_Create_Task:String = "CarNet_Create_Task" //创建定时任务
|
||||
const val CarNet_Get_Picture:String = "CarNet_Get_Picture" //获取图片,type=1 调用, type=2 成功, type=3 失败
|
||||
const val CarNet_Get_Video:String = "CarNet_Get_Video" //获取视频,type=1 调用,type=2 成功,type=3 失败
|
||||
const val CarNet_Cos_Upload:String = "CarNet_Cos_Upload" //上传COS, type=1 成功, type=2 失败, type=3 开始
|
||||
const val CarNet_Servers_Upload:String = "CarNet_Servers_Upload" //上传服务端, type=1 成功,type=2 失败, type=3 开始
|
||||
const val CarNet_Voice_Search:String = "CarNet_Voice_Search" //语音搜索路况,type=1 成功,type=2 失败
|
||||
const val CarNet_USER_SHOW:String = "CarNet_user_show" //情报展示时长,showtime 加载列表时长
|
||||
const val CarNet_USER_LOAD:String = "CarNet_user_load" //情报加载时长,type=1 视频,2图片
|
||||
|
||||
const val CarNet_live_broadcast = "CarNet_live_broadcast" // 地图页面点击直播(在线可直播车机)
|
||||
//自定义埋点
|
||||
@DebugLog
|
||||
fun trackNormalEvent(event: String, data: MutableMap<String, Any>?, context: Context = AbsMogoApplication.getApp().applicationContext) {
|
||||
var data = data
|
||||
if (data == null) {
|
||||
data = HashMap()
|
||||
}
|
||||
val localParams = HashMap<String, Any>()
|
||||
//公共参数 time sn
|
||||
localParams["time"] = System.currentTimeMillis()
|
||||
localParams["systemversion"] = getSystemVersion(context)
|
||||
localParams["sn"] = Utils.getSn()
|
||||
|
||||
// Log.d("liyz", "data =" + data.toString() + ">>>>event=" + event)
|
||||
Analytics.getInstance().setCustomParams(localParams)
|
||||
Analytics.getInstance().track(event, data)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
@file:JvmName("DeviceInfo")
|
||||
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import android.content.Context
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
|
||||
private const val SN_INFO: String = "gsm.serial"
|
||||
|
||||
fun getSn(): String {
|
||||
var serial = ""
|
||||
try {
|
||||
var cls = Class.forName("android.os.SystemProperties")
|
||||
var method = cls.getMethod("get", String::class.java)
|
||||
serial = method.invoke(cls, SN_INFO) as String
|
||||
} catch (var4: ClassNotFoundException) {
|
||||
var4.printStackTrace()
|
||||
} catch (var5: NoSuchMethodException) {
|
||||
var5.printStackTrace()
|
||||
} catch (var6: InvocationTargetException) {
|
||||
var6.printStackTrace()
|
||||
} catch (var7: IllegalAccessException) {
|
||||
var7.printStackTrace()
|
||||
}
|
||||
return serial
|
||||
}
|
||||
|
||||
fun getSystemVersion(context: Context): String {
|
||||
try {
|
||||
var cls = context.classLoader
|
||||
var systemProperties = cls.loadClass("android.os.SystemProperties")
|
||||
var paramTypes = String::class.java
|
||||
val get = systemProperties.getMethod("get", paramTypes)
|
||||
val version = get.invoke(systemProperties, *arrayOf<Any>("ro.fota.version")) as String
|
||||
return if (!version.trim().isNullOrEmpty()) version.trim() else ""
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import java.io.*
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
||||
//创建文件上传请求体
|
||||
fun fileToMultiPart(fileUrl: String): MultipartBody.Part? {
|
||||
var file = File(fileUrl)
|
||||
if (file.exists()) {
|
||||
var requestBody = RequestBody.create(MediaType.parse("image/jpg"), file)
|
||||
return MultipartBody.Part.createFormData("file", file.name, requestBody)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun deletePicFile(filePath: String?): Boolean {
|
||||
var file = File(filePath)
|
||||
if (file.exists()) {
|
||||
//如果图片地址包含此路径则是C上面的拍照,需要再删除后摄图片
|
||||
if (filePath!!.contains("usbotg-1-1.1")) {
|
||||
//将地址替换成后摄图片地址
|
||||
var backFile =
|
||||
File(filePath.replace("frontPic", "backPic").replace("PhotoFront", "PhotoBack"))
|
||||
if (backFile.exists()) {
|
||||
return backFile.delete()
|
||||
}
|
||||
return file.delete()
|
||||
} else
|
||||
return file.delete()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//删除某个目录下所有文件
|
||||
fun deleteAllFile(file: File?) { //判断文件不为null或文件目录存在
|
||||
if (file == null || !file.exists()) {
|
||||
Log.e("liyz", "文件删除失败,请检查文件路径是否正确")
|
||||
return
|
||||
}
|
||||
//取得这个目录下的所有子文件对象
|
||||
val files: Array<File> = file.listFiles()
|
||||
//遍历该目录下的文件对象
|
||||
for (f in files) {
|
||||
val name: String = file.getName()
|
||||
Log.e("liyz", name)
|
||||
//判断子目录是否存在子目录,如果是文件则删除
|
||||
if (f.isDirectory()) {
|
||||
deleteAllFile(f)
|
||||
} else {
|
||||
f.delete()
|
||||
}
|
||||
}
|
||||
//删除空文件夹 for循环已经把上一层节点的目录清空。
|
||||
// file.delete()
|
||||
}
|
||||
|
||||
|
||||
//根据本地视频文件生成缩略图文件
|
||||
fun getVideoThumbnail(filePath: String, picPath: String): Boolean {
|
||||
var b: Bitmap? = null
|
||||
var retriever = MediaMetadataRetriever()
|
||||
try {
|
||||
retriever.setDataSource(filePath)
|
||||
b = retriever.getFrameAtTime(0)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: RuntimeException) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
try {
|
||||
retriever.release()
|
||||
} catch (e: RuntimeException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
return bitmapToFile(b, picPath)
|
||||
}
|
||||
|
||||
//bitmap转为file
|
||||
fun bitmapToFile(bitmap: Bitmap?, filePath: String): Boolean {
|
||||
val baos = ByteArrayOutputStream()
|
||||
bitmap?.compress(Bitmap.CompressFormat.JPEG, 50, baos)
|
||||
val file = File(filePath)
|
||||
try {
|
||||
if (file.exists())
|
||||
file.delete()
|
||||
file.createNewFile()
|
||||
val fos = FileOutputStream(file)
|
||||
var ins = ByteArrayInputStream(baos.toByteArray())
|
||||
var x = 0
|
||||
val b = ByteArray(1024 * 100)
|
||||
while ({ x = ins.read(b);x }() != -1) {
|
||||
fos.write(b, 0, x)
|
||||
}
|
||||
fos.close()
|
||||
bitmap?.recycle()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
//获取压缩后的视频路径
|
||||
fun getCompressVideoPath(): String {
|
||||
val moviesDir = Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_MOVIES
|
||||
)
|
||||
moviesDir.mkdirs()
|
||||
|
||||
val builder = StringBuilder()
|
||||
builder.append("compress_video_")
|
||||
.append(SimpleDateFormat("yyyyMMddHHmmss").format(Date()))
|
||||
val filePrefix = builder.toString()
|
||||
val fileExtn = ".mp4"
|
||||
var destPath = File(moviesDir, filePrefix + fileExtn)
|
||||
|
||||
var fileNo = 0
|
||||
while (destPath.exists()) {
|
||||
fileNo++
|
||||
destPath = File(moviesDir, filePrefix + fileNo + fileExtn)
|
||||
}
|
||||
|
||||
return destPath.absolutePath
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存图片到本地
|
||||
*/
|
||||
fun saveImageToSdcard(bmp: Bitmap): Boolean {
|
||||
var currentFile: File
|
||||
lateinit var fos: FileOutputStream
|
||||
|
||||
var picFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
picFile.mkdirs()
|
||||
|
||||
val builder = StringBuilder()
|
||||
builder.append("splash_bg")
|
||||
val filePrefix = builder.toString()
|
||||
val fileOut = ".jpg"
|
||||
currentFile = File(picFile, filePrefix + fileOut)
|
||||
|
||||
try {
|
||||
fos = FileOutputStream(currentFile)
|
||||
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos)
|
||||
fos.flush()
|
||||
} catch (e: FileNotFoundException) {
|
||||
e.printStackTrace()
|
||||
return false
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
return false
|
||||
} finally {
|
||||
try {
|
||||
if (fos != null) {
|
||||
fos.close()
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取本地保存的图片地址
|
||||
*/
|
||||
fun getImagePath(): String {
|
||||
return "/mnt/sdcard/Pictures/splash_bg.jpg"
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import android.util.Log
|
||||
import com.amap.api.location.AMapLocation
|
||||
import com.amap.api.location.AMapLocationClient
|
||||
import com.amap.api.location.AMapLocationClientOption
|
||||
import com.amap.api.location.AMapLocationListener
|
||||
import com.amap.api.services.core.LatLonPoint
|
||||
import com.amap.api.services.geocoder.*
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.zhidao.roadcondition.model.LocationInfo
|
||||
|
||||
|
||||
private fun RegeocodeAddress.toLocInfo(
|
||||
address: RegeocodeAddress,
|
||||
latlngPoint: LatLonPoint
|
||||
): LocationInfo {
|
||||
return LocationInfo(
|
||||
address.province,
|
||||
address.city,
|
||||
address.cityCode,
|
||||
address.district,
|
||||
address.adCode,
|
||||
address.roads[0].name,
|
||||
latlngPoint.longitude,
|
||||
latlngPoint.latitude,
|
||||
address.formatAddress,
|
||||
System.currentTimeMillis()
|
||||
)
|
||||
}
|
||||
|
||||
private fun AMapLocation.toLocInfo(location: AMapLocation): LocationInfo {
|
||||
return LocationInfo(
|
||||
location.province,
|
||||
location.city,
|
||||
location.cityCode,
|
||||
location.district,
|
||||
location.adCode,
|
||||
location.street,
|
||||
location.longitude,
|
||||
location.latitude,
|
||||
location.address,
|
||||
location.time,
|
||||
location.bearing
|
||||
)
|
||||
}
|
||||
|
||||
class LocationUtil private constructor() {
|
||||
|
||||
companion object {
|
||||
|
||||
private const val TAG = "LocationUtil"
|
||||
private var instance: LocationUtil? = null
|
||||
|
||||
@Synchronized
|
||||
fun getInstance(): LocationUtil {
|
||||
if (instance == null) {
|
||||
instance = LocationUtil()
|
||||
}
|
||||
return instance!!
|
||||
}
|
||||
}
|
||||
|
||||
interface OnMapLocationChangedListener {
|
||||
fun onChanged(locationInfo: LocationInfo)
|
||||
}
|
||||
|
||||
private var listener: OnMapLocationChangedListener? = null
|
||||
|
||||
private var init: Boolean = false
|
||||
private var mContext = AbsMogoApplication.getApp().applicationContext
|
||||
private var locationClient: AMapLocationClient? = null
|
||||
private var locationOption: AMapLocationClientOption? = null
|
||||
private var speedListener: SpeedListener? = null
|
||||
private var locationInfo: LocationInfo = LocationInfo()
|
||||
private var speed: Float = 0.0f
|
||||
|
||||
fun initLocation() {
|
||||
//初始化client
|
||||
locationOption = getDefaultOption()
|
||||
locationClient = AMapLocationClient(mContext)
|
||||
//设置定位参数
|
||||
locationClient!!.setLocationOption(locationOption)
|
||||
// 设置定位监听
|
||||
locationClient!!.setLocationListener(locationListener)
|
||||
init = true
|
||||
startLocation()
|
||||
}
|
||||
|
||||
private fun getDefaultOption(): AMapLocationClientOption {
|
||||
val mOption = AMapLocationClientOption()
|
||||
mOption.locationMode =
|
||||
AMapLocationClientOption.AMapLocationMode.Hight_Accuracy//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
|
||||
mOption.isGpsFirst = true//可选,设置是否gps优先,只在高精度模式下有效。默认关闭
|
||||
mOption.httpTimeOut = 30000//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
|
||||
mOption.interval = 5000//可选,设置定位间隔。默认为2秒
|
||||
mOption.isNeedAddress = true//可选,设置是否返回逆地理地址信息。默认是true
|
||||
mOption.isOnceLocation = false//可选,设置是否单次定位。默认是false
|
||||
mOption.isOnceLocationLatest = false//可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用
|
||||
AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP)//可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
|
||||
mOption.isSensorEnable = true//可选,设置是否使用传感器。默认是false
|
||||
mOption.isWifiScan =
|
||||
true //可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差
|
||||
mOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true
|
||||
mOption.geoLanguage =
|
||||
AMapLocationClientOption.GeoLanguage.DEFAULT//可选,设置逆地理信息的语言,默认值为默认语言(根据所在地区选择语言)
|
||||
return mOption
|
||||
}
|
||||
|
||||
private fun startLocation() {
|
||||
if (checkInit()) {
|
||||
// 设置定位参数
|
||||
locationClient!!.setLocationOption(locationOption)
|
||||
// 启动定位
|
||||
locationClient!!.startLocation()
|
||||
}
|
||||
}
|
||||
|
||||
fun setOnMapLocationChangedListener(listener: OnMapLocationChangedListener) {
|
||||
this.listener = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位监听
|
||||
*/
|
||||
private var locationListener: AMapLocationListener = AMapLocationListener { location ->
|
||||
if (null != location) {
|
||||
locationInfo.longitude = location.longitude
|
||||
locationInfo.latitude = location.latitude
|
||||
locationInfo.address = location.address
|
||||
locationInfo.time = location.time
|
||||
locationInfo.provinceName = location.province
|
||||
locationInfo.cityName = location.city
|
||||
locationInfo.cityCode = location.cityCode
|
||||
locationInfo.areaName = location.district
|
||||
locationInfo.areaCode = location.adCode
|
||||
locationInfo.street = location.street
|
||||
locationInfo.direction = location.bearing
|
||||
listener?.let {
|
||||
it.onChanged(locationInfo)
|
||||
}
|
||||
speed = location.speed
|
||||
speedListener?.let {
|
||||
it.onSpeedGet(location.speed)
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "定位失败 -> location is null")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun checkInit(): Boolean {
|
||||
return if (!init) {
|
||||
initLocation()
|
||||
init
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fun getLocationInfo(): LocationInfo {
|
||||
return if (null != locationInfo) {
|
||||
locationInfo
|
||||
} else {
|
||||
if (null == locationClient) {
|
||||
locationClient = AMapLocationClient(mContext)
|
||||
this.locationClient = locationClient
|
||||
}
|
||||
var location = locationClient!!.lastKnownLocation
|
||||
location.toLocInfo(location)
|
||||
}
|
||||
}
|
||||
|
||||
//如果获取到的location address为空可以通过高德逆地理编码获得
|
||||
fun geoCodeLocation(
|
||||
latlngPoint: LatLonPoint,
|
||||
locGeoCode: (((locInfo: LocationInfo) -> Unit)),
|
||||
onError: ((msg: String) -> Unit)
|
||||
) {
|
||||
var geocoderSearch = GeocodeSearch(AbsMogoApplication.getApp().applicationContext)
|
||||
var regeocodeQuery = RegeocodeQuery(latlngPoint, 200f, GeocodeSearch.AMAP)
|
||||
geocoderSearch.getFromLocationAsyn(regeocodeQuery)
|
||||
geocoderSearch.setOnGeocodeSearchListener(object : GeocodeSearch.OnGeocodeSearchListener {
|
||||
override fun onRegeocodeSearched(p0: RegeocodeResult?, p1: Int) {
|
||||
if (p1 == 1000) {
|
||||
var regeocodeAddress = p0?.regeocodeAddress
|
||||
regeocodeAddress?.let {
|
||||
var locInfo = regeocodeAddress.toLocInfo(regeocodeAddress, latlngPoint)
|
||||
locGeoCode.invoke(locInfo)
|
||||
}
|
||||
} else {
|
||||
onError.invoke("geoCode -> $p1")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onGeocodeSearched(p0: GeocodeResult?, p1: Int) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getSpeed():Float{
|
||||
return speed
|
||||
}
|
||||
|
||||
fun setonSpeedlistenner(speedListener: SpeedListener) {
|
||||
this.speedListener = speedListener
|
||||
}
|
||||
|
||||
interface SpeedListener {
|
||||
fun onSpeedGet(speed: Float)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.network.Utils
|
||||
import com.zhidao.roadcondition.model.InformationBody
|
||||
import com.zhidao.roadcondition.model.LocationInfo
|
||||
import com.zhidao.roadcondition.model.proxy.INFO_TYPE_IMG
|
||||
import com.zhidao.roadcondition.model.proxy.INFO_TYPE_VIDEO
|
||||
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyType
|
||||
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyValidity
|
||||
|
||||
var array: Array<LocationInfo> = arrayOf(
|
||||
LocationInfo(116.40320588562773, 39.96661385462713, "测试数据1", 123123213),
|
||||
LocationInfo(116.41309250805662, 39.970285228355976, "测试数据2", 123123213),
|
||||
LocationInfo(116.40749205563353, 39.97317943101997, "测试数据3", 12321321321),
|
||||
LocationInfo(116.39925230953978, 39.97314654304226, "测试数据4", 123123123),
|
||||
LocationInfo(116.439366, 39.868472, "测试数据5", 123123123),
|
||||
LocationInfo(116.288164, 39.910547, "测试数据6", 123123123),
|
||||
LocationInfo(116.330132, 39.989311, "测试数据7", 123123123)
|
||||
)
|
||||
|
||||
fun getInformationBody(
|
||||
types: Int,
|
||||
urls: Map<String, String>,
|
||||
locationInfo: LocationInfo,
|
||||
isCustom: Boolean,
|
||||
trafficInfoType:String = "",
|
||||
isShare:Boolean,
|
||||
poiType: String
|
||||
): InformationBody {
|
||||
var jsonArray = JsonArray()
|
||||
var type: Int
|
||||
type = if (types == INFO_TYPE_VIDEO) {
|
||||
var videoObject = JsonObject()
|
||||
videoObject.addProperty("thumbnail", urls["thumb"])
|
||||
videoObject.addProperty("url", urls["video"])
|
||||
jsonArray.add(videoObject)
|
||||
INFO_TYPE_VIDEO
|
||||
} else {
|
||||
var urlObject = JsonObject()
|
||||
urlObject.addProperty("url", urls["pic"])
|
||||
jsonArray.add(urlObject)
|
||||
INFO_TYPE_IMG
|
||||
}
|
||||
var infoType = if (isCustom) 1 else 0
|
||||
return InformationBody(
|
||||
jsonArray.toString(),
|
||||
locationInfo.address,
|
||||
locationInfo.areaCode,
|
||||
locationInfo.areaName,
|
||||
locationInfo.cityCode,
|
||||
locationInfo.cityName,
|
||||
System.currentTimeMillis(),
|
||||
locationInfo.latitude,
|
||||
locationInfo.longitude,
|
||||
locationInfo.provinceName,
|
||||
Utils.getSn(),
|
||||
locationInfo.street,
|
||||
type,
|
||||
0,
|
||||
infoType,
|
||||
getStrategyValidity(AbsMogoApplication.getApp().applicationContext, convertUploadTypeOfSP(type), getStrategyType(convertUploadTypeOfSP(type))),
|
||||
trafficInfoType,
|
||||
isShare,
|
||||
locationInfo.direction,
|
||||
poiType
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertUploadTypeOfSP(type: Int): String {
|
||||
return when (type) {
|
||||
INFO_TYPE_IMG -> "pic"
|
||||
INFO_TYPE_VIDEO -> "video"
|
||||
else -> "pic"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.core.content.edit
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.zhidao.roadcondition.aspect.DebugLog
|
||||
|
||||
const val FILE_NAME = "settings_data"
|
||||
const val FILE_NAME_NAVI = "settings_navi_data"
|
||||
const val FILE_NAME_ACTIVE = "settings_active_data"
|
||||
|
||||
const val NAVI_INFO = "NAVI_INFO" //沿途导航数据存储
|
||||
const val NAVI_INFO_STATUS = "NAVI_INFO_STATUS" //沿途导航路线是否存在
|
||||
|
||||
const val PARAM_AUTHORIZATION = "PARAM_AUTHORIZATION"
|
||||
const val PARAM_PROMOTION_CONTENT = "PARAM_PROMOTION_CONTENT"
|
||||
const val PARAM_ACTIVE_WEB_URL = "PARAM_ACTIVE_WEB_URL"
|
||||
const val PARAM_ACTIVE_IMG_URL = "PARAM_ACTIVE_IMG_URL"
|
||||
const val PARAM_ACTIVE_STATUS = "PARAM_ACTIVE_STATUS"
|
||||
|
||||
|
||||
const val LAST_ENTER_TIME = "LAST_ENTER_TIME"
|
||||
const val PIC_NUMBER = "PIC_NUMBER" //图片拍摄张数
|
||||
const val VIDEO_DURATION_DEFAULT = 15_000L //视频拍摄时长
|
||||
const val PIC_NUMBER_DEFAULT = 1L //图片拍摄张数
|
||||
|
||||
const val TIME_QUANTUM = "time_quantum" //时间段
|
||||
const val COUNT_DOWN_TIME = "count_down" //倒计时
|
||||
const val VOICE_TEXT = "voice_text" //语音播报内容
|
||||
const val IS_SAVE_SPLASH = "is_save_splash" //是否保存了
|
||||
|
||||
//播放开始时间
|
||||
const val PLAYER_START_TIME = "first_time"
|
||||
|
||||
|
||||
fun clearActiveInfo(context: Context = AbsMogoApplication.getApp().applicationContext) {
|
||||
var sharedPreferences = context.getSharedPreferences(FILE_NAME_ACTIVE, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
clear()
|
||||
val clearActiveInfo = commit()
|
||||
Log.d(FILE_NAME_NAVI, "clearActiveInfo = $clearActiveInfo")
|
||||
}
|
||||
}
|
||||
|
||||
fun setActiveWebUrl(content: String, context: Context = AbsMogoApplication.getApp().applicationContext) {
|
||||
var sharedPreferences = context.getSharedPreferences(FILE_NAME_ACTIVE, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putString(PARAM_ACTIVE_WEB_URL, content)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun setActiveStatus(status: Int, context: Context = AbsMogoApplication.getApp().applicationContext) {
|
||||
var sharedPreferences = context.getSharedPreferences(FILE_NAME_ACTIVE, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putInt(PARAM_ACTIVE_STATUS, status)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun getActiveStatus(context: Context): Int {
|
||||
return context.getSharedPreferences(FILE_NAME_ACTIVE, Context.MODE_PRIVATE)
|
||||
.getInt(PARAM_ACTIVE_STATUS, 0)
|
||||
}
|
||||
|
||||
fun setPromotionContent(content: String, context: Context = AbsMogoApplication.getApp().applicationContext) {
|
||||
var sharedPreferences = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putString(PARAM_PROMOTION_CONTENT, content)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun isAuthorization(context: Context): Boolean {
|
||||
return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getBoolean(PARAM_AUTHORIZATION, false)
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
fun setAuthorization(context: Context, authorization: Boolean) {
|
||||
var sharedPreferences = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putBoolean(PARAM_AUTHORIZATION, authorization)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DebugLog
|
||||
fun setNaviInfo(context: Context, naviInfo: String) {
|
||||
var sharedPreferences = context.getSharedPreferences(FILE_NAME_NAVI, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
val naviInfoSave = putString(NAVI_INFO, naviInfo)
|
||||
.commit()
|
||||
Log.d(FILE_NAME_NAVI, "naviInfoSave = $naviInfoSave")
|
||||
}
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
fun setNaviInfoStatus(context: Context, naviInfoStatus: Boolean) {
|
||||
var sharedPreferences = context.getSharedPreferences(FILE_NAME_NAVI, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
val naviInfoSaveStatus = putBoolean(NAVI_INFO_STATUS, naviInfoStatus)
|
||||
.commit()
|
||||
Log.d(FILE_NAME_NAVI, "naviInfoSaveStatus = $naviInfoSaveStatus")
|
||||
}
|
||||
}
|
||||
|
||||
fun clearAllNaviInfo(context: Context) {
|
||||
var sharedPreferences = context.getSharedPreferences(FILE_NAME_NAVI, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
clear()
|
||||
val naviInfoAllClear = commit()
|
||||
Log.d(FILE_NAME_NAVI, "naviInfoAllClear = $naviInfoAllClear")
|
||||
}
|
||||
}
|
||||
|
||||
fun putLong(key: String, value: Long) {
|
||||
var sharedPreferences =
|
||||
AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putLong(key, value).apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun getLong(key: String, defaultValue: Long): Long {
|
||||
return AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getLong(key, defaultValue)
|
||||
}
|
||||
|
||||
|
||||
fun putInt(key: String, value: Int) {
|
||||
var sharedPreferences =
|
||||
AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putInt(key, value).apply()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun getInt(key: String, defaultValue: Int): Int {
|
||||
return AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getInt(key, defaultValue)
|
||||
}
|
||||
|
||||
fun putCommonString(key: String, value: String) {
|
||||
var sharedPreferences =
|
||||
AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putString(key, value).apply()
|
||||
}
|
||||
}
|
||||
|
||||
//fun getCommonString(key: String?, defaultValue: String?): String {
|
||||
// return AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
// .getString(key, defaultValue)
|
||||
//}
|
||||
//
|
||||
//fun putCommonBoolean(key: String, value: Boolean) {
|
||||
// var sharedPreferences =
|
||||
// AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
// sharedPreferences.edit {
|
||||
// putBoolean(key, value).apply()
|
||||
// }
|
||||
//}
|
||||
|
||||
fun getCommonBoolean(key: String, defaultValue: Boolean): Boolean {
|
||||
return AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getBoolean(key, defaultValue)
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.core.content.edit
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
|
||||
const val STRATEGY_FILE_NAME = "strategy_data"
|
||||
|
||||
const val STRATEGY_TYPE_COPY = "strategy_data_copy"
|
||||
|
||||
/**
|
||||
* 策略SP存储模式:STRATEGY_TYPE + 策略类型 + 情报类型 + 对应项
|
||||
*/
|
||||
const val STRATEGY_TYPE = "STRATEGY_"
|
||||
|
||||
const val FREQUENCY = "FREQUENCY"
|
||||
const val DEFAULT_FREQUENCY_PIC = 2 //默认上报类型:周期性上报
|
||||
const val DEFAULT_FREQUENCY_VIDEO = 1 //默认上报类型:单次上报
|
||||
|
||||
const val INTERVAL = "INTERVAL"
|
||||
const val DEFAULT_INTERVAL_PIC = 600_000L //默认图片定时任务默认间隔
|
||||
const val DEFAULT_INTERVAL_VIDEO = 900_000L //默认视频定时任务默认间隔
|
||||
|
||||
const val VALIDITY = "VALIDITY"
|
||||
const val DEFAULT_VALIDITY = 4 * 60 //默认情报有效期:4小时
|
||||
|
||||
const val MAX_SPEED = "MAX_SPEED"
|
||||
const val MIN_SPEED = "MIN_SPEED"
|
||||
const val DEFAULT_MAX_SPEED = -1
|
||||
const val DEFAULT_MIN_SPEED = -1
|
||||
|
||||
|
||||
class StrategyPreferenceUtil {
|
||||
companion object {
|
||||
//保存策略类型,在AccOff的时候清除数据,更新时需要在没有情报上传时操作
|
||||
fun setStrategyType(context: Context, strategyType: Int, type: String) {
|
||||
var sharedPreferences =
|
||||
context.getSharedPreferences(STRATEGY_TYPE_COPY, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putInt(STRATEGY_TYPE + type, strategyType).commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun getStrategyType(
|
||||
type: String,
|
||||
context: Context = AbsMogoApplication.getApp().applicationContext
|
||||
): Int {
|
||||
return context.getSharedPreferences(STRATEGY_TYPE_COPY, Context.MODE_PRIVATE)
|
||||
.getInt(STRATEGY_TYPE + type, 1)
|
||||
}
|
||||
|
||||
fun clearStrategyType(context: Context) {
|
||||
var sharedPreferences =
|
||||
context.getSharedPreferences(STRATEGY_TYPE_COPY, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
clear()
|
||||
val clearStrategyType = commit()
|
||||
Log.d(STRATEGY_TYPE_COPY, "clearStrategyType = $clearStrategyType")
|
||||
}
|
||||
}
|
||||
|
||||
fun setStrategyFrequency(
|
||||
context: Context,
|
||||
strategyType: Int,
|
||||
infoType: String,
|
||||
frequency: Int
|
||||
) {
|
||||
var sharedPreferences =
|
||||
context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putInt(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + FREQUENCY,
|
||||
frequency
|
||||
).commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun getStrategyFrequency(context: Context, infoType: String, strategyType: Int = 1): Int {
|
||||
return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getInt(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + FREQUENCY,
|
||||
convertFrequencyOfInfoType(infoType)
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertFrequencyOfInfoType(infoType: String): Int {
|
||||
return when (infoType) {
|
||||
"pic" -> DEFAULT_FREQUENCY_PIC
|
||||
"video" -> DEFAULT_FREQUENCY_VIDEO
|
||||
else -> DEFAULT_FREQUENCY_PIC
|
||||
}
|
||||
}
|
||||
|
||||
fun setStrategyInterval(
|
||||
context: Context,
|
||||
strategyType: Int,
|
||||
infoType: String,
|
||||
interval: Long
|
||||
) {
|
||||
var sharedPreferences =
|
||||
context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putLong(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + INTERVAL,
|
||||
interval
|
||||
).commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun getStrategyInterval(context: Context, infoType: String, strategyType: Int = 1): Long {
|
||||
return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getLong(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + INTERVAL,
|
||||
convertIntervalOfInfoType(infoType)
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertIntervalOfInfoType(infoType: String): Long {
|
||||
return when (infoType) {
|
||||
"pic" -> DEFAULT_INTERVAL_PIC
|
||||
"video" -> DEFAULT_INTERVAL_VIDEO
|
||||
else -> DEFAULT_INTERVAL_PIC
|
||||
}
|
||||
}
|
||||
|
||||
fun setStrategyValidity(
|
||||
context: Context,
|
||||
strategyType: Int,
|
||||
infoType: String,
|
||||
validity: Int
|
||||
) {
|
||||
var sharedPreferences =
|
||||
context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putInt(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + VALIDITY,
|
||||
validity
|
||||
).commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun getStrategyValidity(context: Context, infoType: String, strategyType: Int = 1): Int {
|
||||
return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getInt(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + VALIDITY,
|
||||
DEFAULT_VALIDITY
|
||||
)
|
||||
}
|
||||
|
||||
fun setStrategyMaxSpeed(
|
||||
context: Context,
|
||||
strategyType: Int,
|
||||
infoType: String,
|
||||
maxSpeed: Int
|
||||
) {
|
||||
var sharedPreferences =
|
||||
context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putInt(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + MAX_SPEED,
|
||||
maxSpeed
|
||||
).commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun getStrategyMaxSpeed(context: Context, infoType: String, strategyType: Int = 1): Int {
|
||||
return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getInt(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + MAX_SPEED,
|
||||
DEFAULT_MAX_SPEED
|
||||
)
|
||||
}
|
||||
|
||||
fun setStrategyMinSpeed(
|
||||
context: Context,
|
||||
strategyType: Int,
|
||||
infoType: String,
|
||||
minSpeed: Int
|
||||
) {
|
||||
var sharedPreferences =
|
||||
context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putInt(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + MIN_SPEED,
|
||||
minSpeed
|
||||
).commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun getStrategyMinSpeed(context: Context, infoType: String, strategyType: Int = 1): Int {
|
||||
return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE)
|
||||
.getInt(
|
||||
STRATEGY_TYPE + strategyType + "_" + infoType + MIN_SPEED,
|
||||
DEFAULT_MIN_SPEED
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import android.text.format.DateFormat
|
||||
|
||||
const val format = "yy/MM/dd kk:mm:ss"
|
||||
|
||||
fun formatDate(time: Long): String {
|
||||
return DateFormat.format(format, time).toString()
|
||||
}
|
||||
|
||||
fun convertVar(param: Any?): Any? {
|
||||
return if (param is String) {
|
||||
"\"$param\""
|
||||
} else {
|
||||
param
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
||||
fun isReiceverRegist(context: Context, intentAction: String): Boolean {
|
||||
val intent = Intent()
|
||||
intent.action = intentAction
|
||||
val pm = context.packageManager
|
||||
val resolveInfos = pm.queryBroadcastReceivers(intent, 0)
|
||||
return resolveInfos != null && resolveInfos.isNotEmpty()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.zhidao.roadcondition.util
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
@PublishedApi
|
||||
internal var ThreadPool =
|
||||
newFixedThreadPoolContext(Runtime.getRuntime().availableProcessors() * 2, "ThreadPool")
|
||||
|
||||
|
||||
/**
|
||||
* 在主线程中顺序执行,协程函数,一般用于最外层
|
||||
* 该函数会阻塞代码继续执行
|
||||
*/
|
||||
inline fun taskBlockOnMainThread(delayTime: Long = 0, noinline job: suspend () -> Unit) = runBlocking {
|
||||
delay(delayTime)
|
||||
job()
|
||||
}
|
||||
|
||||
/**
|
||||
* 并发执行,常用于最外层
|
||||
* 特点带返回值
|
||||
*/
|
||||
inline fun <T> taskAsync(delayTime: Long = 0, noinline job: suspend () -> T) = GlobalScope.async(ThreadPool) {
|
||||
delay(delayTime)
|
||||
job()
|
||||
}
|
||||
Reference in New Issue
Block a user