merge tanlu function
This commit is contained in:
@@ -229,7 +229,7 @@ dependencies {
|
||||
implementation project(':modules:mogo-module-service')
|
||||
implementation project(':modules:mogo-module-v2x')
|
||||
implementation project(':modules:mogo-module-share')
|
||||
implementation project(':modules:tanlulib')
|
||||
// implementation project(':modules:tanlulib')
|
||||
implementation project(':modules:mogo-module-monitor')
|
||||
implementation project(':modules:mogo-module-extensions')
|
||||
implementation project(':modules:mogo-module-map')
|
||||
|
||||
@@ -103,7 +103,7 @@ dependencies {
|
||||
implementation project(':modules:mogo-module-service')
|
||||
implementation project(':modules:mogo-module-v2x')
|
||||
implementation project(':modules:mogo-module-share')
|
||||
implementation project(':modules:tanlulib')
|
||||
// implementation project(':modules:tanlulib')
|
||||
implementation project(':modules:mogo-module-monitor')
|
||||
implementation project(':modules:mogo-module-extensions')
|
||||
implementation project(':modules:mogo-module-map')
|
||||
|
||||
@@ -91,7 +91,6 @@ class MogoMainService extends Service implements IMogoLocationListener {
|
||||
|
||||
private void startTanluService() {
|
||||
UiThreadHandler.postDelayed(() -> {
|
||||
Logger.d(TAG, "startTanluService ---------- ");
|
||||
if (mServiceApis != null) {
|
||||
mServiceApis.getTanluApi().startTanluService();
|
||||
}
|
||||
|
||||
@@ -46,29 +46,33 @@ dependencies {
|
||||
implementation rootProject.ext.dependencies.androidxrecyclerview
|
||||
implementation rootProject.ext.dependencies.androidxccorektx
|
||||
implementation rootProject.ext.dependencies.androidxconstraintlayout
|
||||
|
||||
implementation rootProject.ext.dependencies.okhttpinterceptor
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
kapt rootProject.ext.dependencies.aroutercompiler
|
||||
|
||||
implementation rootProject.ext.dependencies.rxjava
|
||||
implementation rootProject.ext.dependencies.rxandroid
|
||||
implementation rootProject.ext.dependencies.mogoaicloudtanlu
|
||||
implementation rootProject.ext.dependencies.analytics
|
||||
implementation rootProject.ext.dependencies.eventbus
|
||||
implementation rootProject.ext.dependencies.coroutinescore
|
||||
implementation rootProject.ext.dependencies.coroutinesandroid
|
||||
implementation rootProject.ext.dependencies.retrofit
|
||||
implementation rootProject.ext.dependencies.retrofitconvertergson
|
||||
implementation 'com.zhidaoauto.controller:api:1.0.8'
|
||||
|
||||
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
||||
implementation rootProject.ext.dependencies.mogoutils
|
||||
implementation rootProject.ext.dependencies.mogocommons
|
||||
implementation rootProject.ext.dependencies.modulecommon
|
||||
implementation rootProject.ext.dependencies.moduleservice
|
||||
|
||||
implementation rootProject.ext.dependencies.mogo_core_utils
|
||||
implementation rootProject.ext.dependencies.mogo_core_data
|
||||
|
||||
} else {
|
||||
implementation project(":foudations:mogo-utils")
|
||||
implementation project(":foudations:mogo-commons")
|
||||
implementation project(':modules:mogo-module-common')
|
||||
implementation project(':modules:mogo-module-service')
|
||||
|
||||
implementation project(':core:mogo-core-utils')
|
||||
implementation project(':core:mogo-core-data')
|
||||
}
|
||||
|
||||
@@ -3,30 +3,38 @@
|
||||
package com.mogo.module.share
|
||||
|
||||
import android.content.Context
|
||||
import android.util.ArrayMap
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.alibaba.android.arouter.facade.template.IProvider
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.commons.analytics.AnalyticsUtils
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths
|
||||
import com.mogo.eagle.core.network.utils.GsonUtil
|
||||
import com.mogo.module.common.MogoApisHandler
|
||||
import com.mogo.module.share.adas.AdasFrontCarDistanceY
|
||||
import com.mogo.module.share.constant.ACCIDENT_STRATEGY_SHARE_PUSH_TYPE
|
||||
import com.mogo.module.share.constant.S_TAG
|
||||
import com.mogo.module.share.service.MainService.Companion.launchService
|
||||
import com.mogo.module.share.service.UploadParams
|
||||
import com.mogo.module.share.strategyreceiver.AccidentStrategyReceiver
|
||||
import com.mogo.module.share.strategyreceiver.BlockStrategy
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths
|
||||
import com.mogo.eagle.core.network.utils.GsonUtil
|
||||
import com.mogo.service.share.IMogoTanluProvider
|
||||
import com.mogo.service.share.TanluUploadParams
|
||||
import com.mogo.utils.logger.Logger
|
||||
import org.json.JSONObject
|
||||
|
||||
/**
|
||||
* 策略上报入口,服务端策略上报Push的接收地,接收后再调用tanlu相关接口进行视频抓取
|
||||
*
|
||||
* @author tongchenfei
|
||||
* @author lixiaopeng
|
||||
*/
|
||||
@Route(path = MogoServicePaths.PATH_STRATEGY_SHARE)
|
||||
class StrategyShareProvider : IProvider {
|
||||
class StrategyShareProvider : IMogoTanluProvider {
|
||||
private lateinit var blockStrategy: BlockStrategy
|
||||
private var mContext: Context? = null
|
||||
|
||||
override fun init(context: Context) {
|
||||
mContext = context
|
||||
Logger.d(S_TAG, "策略上报Provider初始化====")
|
||||
val apis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis
|
||||
blockStrategy = BlockStrategy(context, apis)
|
||||
@@ -58,5 +66,33 @@ class StrategyShareProvider : IProvider {
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传情报
|
||||
*
|
||||
* @param params 情报类型
|
||||
*/
|
||||
override fun uploadRoadCondition(params: TanluUploadParams?) {
|
||||
if (params != null) {
|
||||
Logger.d(S_TAG, "uploadRoadCondition: $params")
|
||||
val properties: MutableMap<String, Any> = ArrayMap()
|
||||
properties["type"] = params.eventType
|
||||
properties["from"] = params.fromType
|
||||
AnalyticsUtils.track("v2x_share_type", properties)
|
||||
val location = MogoApisHandler.getInstance().apis.mapServiceApi.getSingletonLocationClient(mContext).lastKnowLocation
|
||||
launchService(mContext!!, UploadParams(params.eventType,
|
||||
params.fromType, params.duration, params.parentId,
|
||||
params.location.lat, params.location.lon, location.address, location.bearing, location.adCode, location.cityCode))
|
||||
} else {
|
||||
Logger.e(S_TAG, "params为空,无法上报情报")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启探路业务服务
|
||||
*/
|
||||
override fun startTanluService() {
|
||||
Logger.d(S_TAG, "startTanluService")
|
||||
launchService(mContext!!, null)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
open class BaseRepository {
|
||||
|
||||
suspend fun <T : Any> apiCall(call: suspend () -> BaseResponse<T>): BaseResponse<T> {
|
||||
return call.invoke()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
import com.mogo.module.share.constant.HttpConstant
|
||||
|
||||
|
||||
class BaseResponse<out T>(val code: Int, val msg: String, val result: T) {
|
||||
fun isSuccess(baseUrl: String): Boolean {
|
||||
return when (baseUrl) {
|
||||
HttpConstant.getNetHost() -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
class CityStrategy(video: Video, pic: Pic) {
|
||||
var video: Video? = video
|
||||
var pic: Pic? = pic
|
||||
}
|
||||
|
||||
fun Video.getMaxSpeed(): Int {
|
||||
return if (maxSpeed == 0) {
|
||||
-1
|
||||
} else {
|
||||
maxSpeed
|
||||
}
|
||||
}
|
||||
|
||||
class Video {
|
||||
var strategyId: String //策略ID
|
||||
var reportType: Int //一次性、周期性
|
||||
var reportTimeInterval: Int //上传时间间隔 单位:分钟
|
||||
var infoTimeout: Int //情报失效时间 单位:分钟
|
||||
var minSpeed: Int = -1//最小速度
|
||||
var maxSpeed: Int = -1//最大速度
|
||||
var strategyType: Int //策略类型:城市、热门区域、非上报区域等
|
||||
|
||||
constructor(
|
||||
strategyId: String,
|
||||
reportType: Int,
|
||||
reportTimeInterval: Int,
|
||||
infoTimeout: Int,
|
||||
minSpeed: Int,
|
||||
maxSpeed: Int,
|
||||
strategyType: Int
|
||||
) {
|
||||
this.strategyId = strategyId
|
||||
this.reportType = reportType
|
||||
this.reportTimeInterval = reportTimeInterval
|
||||
this.infoTimeout = infoTimeout
|
||||
this.minSpeed = minSpeed
|
||||
this.maxSpeed = maxSpeed
|
||||
this.strategyType = strategyType
|
||||
}
|
||||
}
|
||||
|
||||
fun Pic.getMaxSpeed(): Int {
|
||||
return if (maxSpeed == 0) {
|
||||
-1
|
||||
} else {
|
||||
maxSpeed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Pic {
|
||||
var strategyId: String //策略ID
|
||||
var reportType: Int //一次性、周期性
|
||||
var reportTimeInterval: Int //上传时间间隔 单位:分钟
|
||||
var infoTimeout: Int //情报失效时间 单位:分钟
|
||||
var minSpeed: Int = -1 //最小速度
|
||||
var maxSpeed: Int = -1 //最大速度
|
||||
var strategyType: Int //策略类型:城市、热门区域、非上报区域等
|
||||
|
||||
constructor(
|
||||
strategyId: String,
|
||||
reportType: Int,
|
||||
reportTimeInterval: Int,
|
||||
infoTimeout: Int,
|
||||
minSpeed: Int,
|
||||
maxSpeed: Int,
|
||||
strategyType: Int
|
||||
) {
|
||||
this.strategyId = strategyId
|
||||
this.reportType = reportType
|
||||
this.reportTimeInterval = reportTimeInterval
|
||||
this.infoTimeout = infoTimeout
|
||||
this.minSpeed = minSpeed
|
||||
this.maxSpeed = maxSpeed
|
||||
this.strategyType = strategyType
|
||||
}
|
||||
}
|
||||
|
||||
class StrategyRequest {
|
||||
var lon: Double
|
||||
var lat: Double
|
||||
var cityCode: String
|
||||
|
||||
constructor(lon: Double, lat: Double, cityCode: String) {
|
||||
this.lon = lon
|
||||
this.lat = lat
|
||||
this.cityCode = cityCode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
data class InformationBody(
|
||||
val data: String,
|
||||
val addr: String,
|
||||
val areaCode: String,
|
||||
val areaName: String,
|
||||
val cityCode: String,
|
||||
val cityName: String,
|
||||
val generateTime: Long,
|
||||
val lat: Double,
|
||||
val lon: Double,
|
||||
val provinceName: String,
|
||||
val sn: String,
|
||||
val street: String,
|
||||
val type: Int,
|
||||
val uid: Int,
|
||||
val infoType: Int,
|
||||
val infoTimeout:Int,
|
||||
val trafficInfoType:String, // 上报情报类型
|
||||
val isShare: Boolean, // 是否分享给附近车机
|
||||
val direction: Float,
|
||||
val poiType: String, //类型分类
|
||||
val mainInfoId: Long, //事件id
|
||||
val speed: Float, //车速
|
||||
val fromType: String //上报触发来源
|
||||
)
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng
|
||||
|
||||
fun LocationInfo.toLatLngPoint(): com.mogo.eagle.core.data.map.MogoLatLng {
|
||||
return com.mogo.eagle.core.data.map.MogoLatLng(latitude, longitude)
|
||||
}
|
||||
|
||||
class LocationInfo {
|
||||
var provinceName: String = "" //省的名称
|
||||
var cityName: String = "" //城市的名称
|
||||
var cityCode :String = "" //城市编码
|
||||
var areaName :String = "" //区县名称
|
||||
var areaCode :String = "" //区县编码
|
||||
var street :String = "" //街道名称
|
||||
var longitude: Double = 0.0
|
||||
var latitude: Double = 0.0
|
||||
var address: String = ""
|
||||
var time: Long = 0L
|
||||
var direction: Float = 0.0f
|
||||
constructor()
|
||||
|
||||
constructor(longitude: Double, latitude: Double, address: String, time: Long) {
|
||||
this.longitude = longitude
|
||||
this.latitude = latitude
|
||||
this.address = address
|
||||
this.time = time
|
||||
}
|
||||
|
||||
constructor(
|
||||
provinceName: String,
|
||||
cityName: String,
|
||||
cityCode: String,
|
||||
areaName: String,
|
||||
areaCode: String,
|
||||
street: String,
|
||||
longitude: Double,
|
||||
latitude: Double,
|
||||
address: String,
|
||||
time: Long,
|
||||
direction: Float = 0.0f
|
||||
) {
|
||||
this.provinceName = provinceName
|
||||
this.cityName = cityName
|
||||
this.cityCode = cityCode
|
||||
this.areaName = areaName
|
||||
this.areaCode = areaCode
|
||||
this.street = street
|
||||
this.longitude = longitude
|
||||
this.latitude = latitude
|
||||
this.address = address
|
||||
this.time = time
|
||||
this.direction = direction
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
class Results(var cityStrategy: CityStrategy)
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
|
||||
import com.mogo.module.common.constants.HostConst
|
||||
import com.mogo.module.share.net.HttpClient
|
||||
import com.mogo.module.share.utils.LocationUtil
|
||||
|
||||
class StrategyServiceModel : BaseRepository() {
|
||||
|
||||
suspend fun getCityStrategy(): BaseResponse<Results> {
|
||||
return apiCall {
|
||||
val map = hashMapOf<String, String>()
|
||||
map["sn"] = MoGoAiCloudClientConfig.getInstance().getSn()
|
||||
val locInfo = LocationUtil.getInstance().getLocationInfo()
|
||||
map["data"] = Gson().toJson(
|
||||
StrategyRequest(
|
||||
locInfo.longitude,
|
||||
locInfo.latitude,
|
||||
locInfo.cityCode
|
||||
)
|
||||
)
|
||||
HttpClient.getInstance(HostConst.GEOFENCE_HOST).getHttpApi().getCityStrategy(map)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
import com.mogo.module.share.constant.*
|
||||
import com.mogo.module.share.constant.ShareConstants.*
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.mogo.module.share.bean.event
|
||||
|
||||
|
||||
/**
|
||||
* @description
|
||||
*
|
||||
* @author lixiaopeng
|
||||
* @since 2019-10-13
|
||||
*/
|
||||
class GetImageSuccessEvent {
|
||||
private var imageUrl: String? = null
|
||||
private var type: String? = null
|
||||
|
||||
constructor(imageUrl: String?, type: String?) {
|
||||
this.imageUrl = imageUrl
|
||||
this.type = type
|
||||
}
|
||||
|
||||
fun getImageUrl(): String? {
|
||||
return imageUrl
|
||||
}
|
||||
|
||||
fun getType(): String? {
|
||||
return type
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mogo.module.share.bean.event
|
||||
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class LatLngStickyEventBus {
|
||||
|
||||
companion object {
|
||||
private var mEventBus = EventBus.builder()
|
||||
.logNoSubscriberMessages(false)
|
||||
.sendNoSubscriberEvent(false)
|
||||
.build()
|
||||
|
||||
fun getInstance(): EventBus {
|
||||
return mEventBus
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,4 +5,44 @@ const val S_TAG = "StrategyShare"
|
||||
/**
|
||||
* 目前两个策略上报(事故,拥堵)都是走的这个push
|
||||
*/
|
||||
const val ACCIDENT_STRATEGY_SHARE_PUSH_TYPE = 401013
|
||||
const val ACCIDENT_STRATEGY_SHARE_PUSH_TYPE = 401013
|
||||
|
||||
const val TANLU_ROAD_CURRENT = "10015" //实时路况
|
||||
|
||||
/**
|
||||
* 默认视频抓取时长,单位是秒
|
||||
*/
|
||||
const val DEFAULT_VIDEO_DURATION = 10
|
||||
|
||||
/**
|
||||
* 数据策略:交通事故上报
|
||||
*/
|
||||
const val UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO = "5"
|
||||
|
||||
/**
|
||||
* 数据策略:已有事件云端校验
|
||||
*/
|
||||
const val UPLOAD_FROM_STRATEGY_CLOUD_CHECK = "4"
|
||||
|
||||
/**
|
||||
* 数据策略:拥堵自动上报
|
||||
*/
|
||||
const val UPLOAD_FROM_STRATEGY_BLOCK_AUTO = "3"
|
||||
|
||||
/**
|
||||
* 策略上报集合
|
||||
*/
|
||||
val STRATEGY_UPLOAD_TYPE_ARRAY = arrayOf(UPLOAD_FROM_STRATEGY_BLOCK_AUTO,
|
||||
UPLOAD_FROM_STRATEGY_CLOUD_CHECK, UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO)
|
||||
|
||||
val AlarmTypePic: Int = 1 //定时任务类型 1照片
|
||||
val AlarmTypeVideo: Int = 2 //定时任务类型 2视频
|
||||
|
||||
val alarmBroadAction: String = "com.zhidao.roadCondition.AlarmBroadCast" //定时广播
|
||||
val sendInformationAction: String = "com.zhidao.roadCondition.SendInformation" //主动上报广播
|
||||
val customResultAction: String = "com.zhidao.roadCondition.CustomResult" //主动上报结果广播
|
||||
|
||||
const val INFO_TYPE_IMG = 0 //图片
|
||||
const val INFO_TYPE_VIDEO = 1
|
||||
const val INFO_TYPE_VOICE = 2
|
||||
const val INFO_TYPE_WORD = 3
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mogo.module.share.net
|
||||
|
||||
import com.mogo.module.share.bean.BaseResponse
|
||||
import com.mogo.module.share.bean.Results
|
||||
import retrofit2.http.*
|
||||
|
||||
/**
|
||||
* 接口声明
|
||||
*/
|
||||
interface HttpApi {
|
||||
//获取城市策略
|
||||
@FormUrlEncoded
|
||||
@POST("yycp-geo-fence-carService/car/carStrategy/no/getCityStrategy/v1")
|
||||
suspend fun getCityStrategy(@FieldMap cityStrategy: Map<String, String>): BaseResponse<Results>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.mogo.module.share.net
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.eagle.core.network.NetConfig
|
||||
import com.mogo.module.share.constant.HttpConstant
|
||||
import okhttp3.Cache
|
||||
import okhttp3.Dns
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
class HttpClient private constructor(baseUrl: String) {
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_CONNECT_TIME = 30L
|
||||
const val DEFAULT_WRITE_TIMEOUT = 30L
|
||||
const val DEFAULT_READ_TIMEOUT = 30L
|
||||
|
||||
private var baseUrlClientMap = HashMap<String, HttpClient>()
|
||||
|
||||
fun getInstance(): HttpClient {
|
||||
val baseUrl = HttpConstant.getNetHost()
|
||||
var httpClient = baseUrlClientMap[baseUrl]
|
||||
if (httpClient == null) {
|
||||
synchronized(HttpClient::class.java) {
|
||||
if (httpClient == null) {
|
||||
httpClient = HttpClient(baseUrl)
|
||||
baseUrlClientMap[baseUrl] = httpClient!!
|
||||
}
|
||||
}
|
||||
}
|
||||
return httpClient!!
|
||||
}
|
||||
|
||||
fun getInstance(baseUrl: String): HttpClient {
|
||||
var httpClient = baseUrlClientMap[baseUrl]
|
||||
if (httpClient == null) {
|
||||
synchronized(HttpClient::class.java) {
|
||||
if (httpClient == null) {
|
||||
httpClient = HttpClient(baseUrl)
|
||||
baseUrlClientMap[baseUrl] = httpClient!!
|
||||
}
|
||||
}
|
||||
}
|
||||
return httpClient!!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private var retrofit: Retrofit
|
||||
private var httpApi: HttpApi
|
||||
|
||||
init {
|
||||
retrofit = Retrofit.Builder()
|
||||
.client(getOkHttpClient())
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.baseUrl(baseUrl)
|
||||
.build()
|
||||
httpApi = retrofit.create(HttpApi::class.java)
|
||||
}
|
||||
|
||||
fun getHttpApi(): HttpApi {
|
||||
return httpApi
|
||||
}
|
||||
|
||||
private fun getOkHttpClient(): OkHttpClient {
|
||||
val builder = OkHttpClient.Builder()
|
||||
val httpLoggingInterceptor = HttpLoggingInterceptor()
|
||||
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
|
||||
val cacheFile = File(AbsMogoApplication.getApp().applicationContext.cacheDir, "cache")
|
||||
val cache = Cache(cacheFile, 1024 * 1024 * 50)
|
||||
|
||||
val httpDns = NetConfig.instance().httpDns
|
||||
if (httpDns != null) {
|
||||
builder.dns(Dns { hostname: String? ->
|
||||
val addresses = httpDns.lookup(hostname)
|
||||
if (addresses != null && !addresses.isEmpty()) {
|
||||
return@Dns addresses
|
||||
}
|
||||
Dns.SYSTEM.lookup(hostname)
|
||||
})
|
||||
}
|
||||
|
||||
return builder
|
||||
.addInterceptor(httpLoggingInterceptor)
|
||||
.cache(cache)
|
||||
.connectTimeout(DEFAULT_CONNECT_TIME, TimeUnit.SECONDS)
|
||||
.readTimeout(DEFAULT_READ_TIMEOUT, TimeUnit.SECONDS)
|
||||
.writeTimeout(DEFAULT_WRITE_TIMEOUT, TimeUnit.SECONDS)
|
||||
.retryOnConnectionFailure(true)
|
||||
.build()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,417 @@
|
||||
package com.mogo.module.share.service
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import com.hw.videoprocessor.VideoProcessor
|
||||
import com.mogo.cloud.network.BaseData
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
|
||||
import com.mogo.cloud.tanlu.api.ITanluUploadCallback
|
||||
import com.mogo.cloud.tanlu.api.MogoUploadManager
|
||||
import com.mogo.cloud.tanlu.bean.UploadInfo
|
||||
import com.mogo.cloud.tanlu.bean.UploadResult
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.module.share.bean.event.GetImageSuccessEvent
|
||||
import com.mogo.module.share.bean.event.LatLngStickyEventBus
|
||||
import com.mogo.module.share.constant.STRATEGY_UPLOAD_TYPE_ARRAY
|
||||
import com.mogo.module.share.utils.*
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyMaxSpeed
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyMinSpeed
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType
|
||||
import com.mogo.utils.NetworkUtils
|
||||
import com.zhidao.auto.carcorder.callback.TakePhotoCallback
|
||||
import com.zhidao.auto.carcorder.callback.TakeVideoCallback
|
||||
import com.zhidao.auto.carcorder.controller.ZdCarCoderController
|
||||
import java.io.File
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* @description 记录仪相关操作
|
||||
*
|
||||
* @author lixiaopeng
|
||||
* @since 2019-10-30
|
||||
*/
|
||||
object CarCorderController : TakePhotoCallback, TakeVideoCallback {
|
||||
const val TAG: String = "CarCorderController"
|
||||
private lateinit var zdCarCoderController: ZdCarCoderController
|
||||
private var outputVideoPath: String = ""
|
||||
private var mType: String = "" //1 上报拥堵, 2 封路和查车
|
||||
private var mainInfoId: Long = 0
|
||||
private var mFromType: String = ""
|
||||
private var mLongitude: Double = 0.0
|
||||
private var mLatitude: Double = 0.0
|
||||
private var mSpeed: Float = 0f
|
||||
|
||||
private var mAddress: String = ""
|
||||
private var mDirection: Float = 0f
|
||||
private var mAreaCode: String = ""
|
||||
private var mCityCode: String = ""
|
||||
|
||||
|
||||
private var getVideoFailed: (() -> Unit)? = null
|
||||
|
||||
fun getVideoFailed(getVideoFailed: (() -> Unit)) {
|
||||
this.getVideoFailed = getVideoFailed
|
||||
}
|
||||
|
||||
fun initCarCorderController() {
|
||||
try {
|
||||
zdCarCoderController =
|
||||
ZdCarCoderController.getInstance(AbsMogoApplication.getApp().applicationContext)
|
||||
zdCarCoderController.addCallback(this)
|
||||
zdCarCoderController.addVideoCallback(this)
|
||||
zdCarCoderController.init()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun takePhoto(
|
||||
photoType: Int,
|
||||
cameraId: Int,
|
||||
haveVoice: Boolean,
|
||||
isCustom: Boolean = false,
|
||||
type: String,
|
||||
mainInfoId: Long,
|
||||
fromType: String,
|
||||
longitude: Double,
|
||||
latitude: Double,
|
||||
speed: Float,
|
||||
address: String,
|
||||
direction: Float,
|
||||
areaCode: String,
|
||||
cityCode: String
|
||||
) {
|
||||
Log.d(TAG, "takePhoto ---------- type = $type --- mType = $mType ---fromType = $fromType")
|
||||
this.mType = type
|
||||
this.mainInfoId = mainInfoId
|
||||
this.mFromType = fromType
|
||||
this.mLongitude = longitude
|
||||
this.mLatitude = latitude
|
||||
this.mSpeed = speed
|
||||
this.mAddress = address
|
||||
this.mDirection = direction
|
||||
this.mAreaCode = areaCode
|
||||
this.mCityCode = cityCode
|
||||
|
||||
CustomStatusHandler.offerPhotoStatus(isCustom)
|
||||
zdCarCoderController.takePhoto(photoType, cameraId, haveVoice)
|
||||
trackGetPhoto(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isCustom: 是否手动上传
|
||||
* @param id: 标志是哪一个上传
|
||||
*/
|
||||
fun takeVideo(
|
||||
cameraId: Int,
|
||||
duration: Int,
|
||||
isCustom: Boolean = false,
|
||||
id: Long = 0L,
|
||||
type: String,
|
||||
mainInfoId: Long,
|
||||
fromType: String,
|
||||
longitude: Double,
|
||||
latitude: Double,
|
||||
speed: Float,
|
||||
address: String,
|
||||
direction: Float,
|
||||
areaCode: String,
|
||||
cityCode: String
|
||||
) {
|
||||
Log.d(TAG, "takeVideo -------- isCustom = $isCustom ---mFromType = $mFromType ---type = $type ---speed = $speed")
|
||||
this.mType = type
|
||||
this.mainInfoId = mainInfoId
|
||||
this.mFromType = fromType
|
||||
this.mLongitude = longitude
|
||||
this.mLatitude = latitude
|
||||
this.mSpeed = speed
|
||||
this.mAddress = address
|
||||
this.mDirection = direction
|
||||
this.mAreaCode = areaCode
|
||||
this.mCityCode = cityCode
|
||||
|
||||
if (DebugConfig.getCarMachineType() == 0) { //自研车机
|
||||
outputVideoPath = getCompressVideoPath()
|
||||
CustomStatusHandler.offerVideoStatus(TakeEntity(isCustom, id, fromType))
|
||||
zdCarCoderController.takeVideo(cameraId, duration)
|
||||
trackGetVideo(1)
|
||||
} else { //比亚迪
|
||||
Log.d(TAG, "takeVideo ------ isnet = " + NetworkUtils.isConnected(AbsMogoApplication.getApp().applicationContext))
|
||||
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) }
|
||||
|
||||
//地图上打点
|
||||
taskAsync(3_000) {
|
||||
try {
|
||||
// LatLngStickyEventBus.getInstance()
|
||||
// .postSticky(GetImageSuccessEvent("", mType))
|
||||
} catch (e: java.lang.Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
fun release() {
|
||||
zdCarCoderController.release()
|
||||
}
|
||||
|
||||
//拍照失败回调
|
||||
override fun onTakePhotoFail(photoType: Int, camera: Int) {
|
||||
trackGetPhoto(3)
|
||||
val isCustom = CustomStatusHandler.pollPhotoStatus()
|
||||
Log.e(TAG, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom")
|
||||
//获取图片失败也上报,图片不打点
|
||||
if (isCustom) {
|
||||
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//拍照成功回调返回图片本地路径
|
||||
override fun onTakePhotoSuccess(photoType: Int, camera: Int, photoPath: String?) {
|
||||
trackGetPhoto(2)
|
||||
Log.d(TAG, "onTakePhotoSuccess -----mType = $mType --- mainInfoId = $mainInfoId")
|
||||
val isCustom = CustomStatusHandler.pollPhotoStatus()
|
||||
|
||||
if (!isCustom) {
|
||||
trackNormalEvent(CarNet_auto_upload, null)
|
||||
}
|
||||
|
||||
var interceptor = false
|
||||
if (interceptor) {
|
||||
return
|
||||
}
|
||||
|
||||
val minSpeedPic =
|
||||
getStrategyMinSpeed(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
"pic",
|
||||
getStrategyType("pic")
|
||||
)
|
||||
val maxSpeedPic =
|
||||
getStrategyMaxSpeed(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
"pic",
|
||||
getStrategyType("pic")
|
||||
)
|
||||
val speed = LocationUtil.getInstance().getSpeed()
|
||||
|
||||
if (!TextUtils.isEmpty(mType)) {
|
||||
Log.d(TAG, "onTakePhotoSuccess mType != null")
|
||||
if (photoPath != null) {
|
||||
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.d(TAG, "onTakePhotoSuccess mType == null")
|
||||
Log.d(
|
||||
TAG,
|
||||
"onTakePhotoSuccess maxSpeedPic = $maxSpeedPic ---> speed = $speed ---->minSpeedPic= $minSpeedPic"
|
||||
)
|
||||
if (maxSpeedPic == -1) {
|
||||
if (speed >= (abs(minSpeedPic) / 3.6f)) {
|
||||
Log.d(TAG, "onTakePhotoSuccess abs =" + (abs(minSpeedPic) / 3.6f))
|
||||
if (photoPath != null) {
|
||||
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (minSpeedPic > 0 && maxSpeedPic > 0) {
|
||||
Log.d(TAG, "onTakePhotoSuccess minSpeedPic > 0 -- speed = $speed")
|
||||
if ((speed >= (minSpeedPic / 3.6f)) && speed <= (maxSpeedPic / 3.6f)) {
|
||||
if (photoPath != null) {
|
||||
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取视频成功
|
||||
override fun onTakeVideoSuccess(camera: Int, videoPath: String?) {
|
||||
val thumbnailPath =
|
||||
AbsMogoApplication.getApp().applicationContext.filesDir.parent + File.separator + "Thumbnail${System.currentTimeMillis()}.jpg"
|
||||
val isSuccess = getVideoThumbnail(videoPath!!, thumbnailPath)
|
||||
Log.d(
|
||||
TAG,
|
||||
"getVideo onTakeVideoSuccess===$videoPath -----> isSuccess= $isSuccess ----> mType = $mType --- mainInfoId = $mainInfoId"
|
||||
)
|
||||
|
||||
val entity = CustomStatusHandler.pollVideoStatus()
|
||||
|
||||
entity?.let {
|
||||
if (!entity.isCustom) {
|
||||
trackNormalEvent(CarNet_auto_upload_video, null)
|
||||
}
|
||||
}
|
||||
|
||||
if (isSuccess) {
|
||||
val minSpeedVideo = getStrategyMinSpeed(
|
||||
AbsMogoApplication.getApp().applicationContext, "video",
|
||||
getStrategyType("video")
|
||||
)
|
||||
val maxSpeedVideo = getStrategyMaxSpeed(
|
||||
AbsMogoApplication.getApp().applicationContext, "video",
|
||||
getStrategyType("video")
|
||||
)
|
||||
val speed = LocationUtil.getInstance().getSpeed()
|
||||
|
||||
entity?.let {
|
||||
if (it.isCustom) {
|
||||
compressVideo(videoPath, thumbnailPath, it)
|
||||
|
||||
} else if (entity.fromType in STRATEGY_UPLOAD_TYPE_ARRAY) {
|
||||
// 属于策略上报
|
||||
compressVideo(videoPath, thumbnailPath, it)
|
||||
|
||||
} else {
|
||||
Log.d(
|
||||
TAG,
|
||||
"onTakeVideoSuccess maxSpeedVideo = $maxSpeedVideo --->speed= $speed + minSpeedVideo = $minSpeedVideo"
|
||||
)
|
||||
if (maxSpeedVideo == -1) {
|
||||
Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f))
|
||||
if (speed >= (abs(minSpeedVideo) / 3.6f)) {
|
||||
//获取视频以及缩略图成功,开始上报
|
||||
compressVideo(videoPath, thumbnailPath, it)
|
||||
}
|
||||
}
|
||||
|
||||
if (minSpeedVideo > 0 && maxSpeedVideo > 0) {
|
||||
Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed")
|
||||
if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) {
|
||||
compressVideo(videoPath, thumbnailPath, it)
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
trackGetVideo(2)
|
||||
}
|
||||
}
|
||||
|
||||
private var videoAndThumbMap: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
//获取视频失败
|
||||
override fun onTakeVideoFail(camera: Int) {
|
||||
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
|
||||
|
||||
//地图上打点
|
||||
taskAsync(3_000) {
|
||||
try {
|
||||
LatLngStickyEventBus.getInstance().postSticky(GetImageSuccessEvent("", mType))
|
||||
} catch (e: java.lang.Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩视频并且上传
|
||||
*/
|
||||
private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}"
|
||||
)
|
||||
val startTime = System.currentTimeMillis()
|
||||
Thread(Runnable {
|
||||
try {
|
||||
VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext)
|
||||
.input(videoPath)
|
||||
.output(outputVideoPath)
|
||||
.removeAudio(true)
|
||||
.outWidth(1920)
|
||||
.outHeight(1080)
|
||||
.bitrate(2000 * 1024)
|
||||
.frameRate(25)
|
||||
.process()
|
||||
Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime))
|
||||
getInfo(outputVideoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
|
||||
//删除压缩前的视频
|
||||
deletePicFile(videoPath)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "compressVideo e = $e")
|
||||
//删除压缩前的视频
|
||||
deletePicFile(videoPath)
|
||||
e.printStackTrace()
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报路况的视频和图片
|
||||
*/
|
||||
private fun uploadRoadInfo(info: UploadInfo) {
|
||||
MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback {
|
||||
override fun onSuccess(result: BaseData<UploadResult>) {
|
||||
if (result.result != null) {
|
||||
Log.d(TAG, "result =" + result.result);
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(code: Int) {
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun getInfo(filePath: String, addr: String, lon: Double, lat: Double, poiType: String,
|
||||
direction: Float, areaCode: String, cityCode: String, type: Int, fromType: String
|
||||
, mainInfoId: Long): UploadInfo? {
|
||||
val info = UploadInfo()
|
||||
info.filePath = filePath
|
||||
info.addr = addr
|
||||
info.longitude = lon
|
||||
info.latitude = lat
|
||||
info.poiType = poiType
|
||||
info.direction = direction
|
||||
info.areaCode = areaCode
|
||||
info.cityCode = cityCode
|
||||
info.sn = MoGoAiCloudClientConfig.getInstance().getSn()
|
||||
info.type = type //0为图片, 1为视频
|
||||
info.fromType = fromType
|
||||
info.mainInfoId = mainInfoId
|
||||
info.infoType = 1
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
override fun onTakePhotoCancel(photoType: Int, camera: Int) {
|
||||
Log.d(TAG, "onTakePhotoCancel -----photoType = $photoType")
|
||||
}
|
||||
|
||||
override fun onTakeVideoCancel(camera: Int) {
|
||||
Log.d(TAG, "onTakeVideoCancel -----camera = $camera")
|
||||
//失败了,传空地址,发起请求
|
||||
videoAndThumbMap["video"] = ""
|
||||
videoAndThumbMap["thumb"] = ""
|
||||
|
||||
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
|
||||
}
|
||||
|
||||
//获取图片
|
||||
private fun trackGetPhoto(type: Int) {
|
||||
trackNormalEvent(
|
||||
CarNet_Get_Picture, mutableMapOf("type" to type),
|
||||
AbsMogoApplication.getApp().applicationContext
|
||||
)
|
||||
}
|
||||
|
||||
//获取视频
|
||||
private fun trackGetVideo(type: Int) {
|
||||
trackNormalEvent(
|
||||
CarNet_Get_Video, mutableMapOf("type" to type),
|
||||
AbsMogoApplication.getApp().applicationContext
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.mogo.module.share.service
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @since 2019-11-25
|
||||
*
|
||||
* 拍照、拍视频手动、被动状态队列
|
||||
*/
|
||||
object CustomStatusHandler {
|
||||
|
||||
private val takePhotoStatusQueue: Queue<Boolean> = ArrayDeque(5)
|
||||
private val takeVideoStatusQueue: Queue<TakeEntity> = ArrayDeque(5)
|
||||
|
||||
fun offerPhotoStatus(status: Boolean) {
|
||||
takePhotoStatusQueue.offer(status)
|
||||
}
|
||||
|
||||
fun pollPhotoStatus() = takePhotoStatusQueue.poll() ?: false
|
||||
|
||||
fun offerVideoStatus(entity: TakeEntity) {
|
||||
takeVideoStatusQueue.offer(entity)
|
||||
}
|
||||
|
||||
fun pollVideoStatus(): TakeEntity? = takeVideoStatusQueue.poll()
|
||||
}
|
||||
|
||||
class TakeEntity(
|
||||
var isCustom: Boolean, var id: Long, var fromType: String = "0"
|
||||
)
|
||||
@@ -0,0 +1,360 @@
|
||||
package com.mogo.module.share.service
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.elegant.analytics.Analytics
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.module.common.MogoApisHandler
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths
|
||||
import com.mogo.module.share.bean.event.GetImageSuccessEvent
|
||||
import com.mogo.module.share.bean.event.LatLngStickyEventBus
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.mogo.utils.storage.SharedPrefsMgr
|
||||
import com.zhidao.cosupload.manager.CosUploadManagerImpl
|
||||
import com.mogo.module.share.BuildConfig
|
||||
import com.mogo.module.share.constant.*
|
||||
import com.mogo.module.share.utils.*
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.clearStrategyType
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyFrequency
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyInterval
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
/**
|
||||
* 上报流程服务
|
||||
*/
|
||||
class MainService : Service() {
|
||||
|
||||
companion object {
|
||||
fun launchService(context: Context, params: UploadParams?) {
|
||||
val intent = Intent(context, MainService::class.java).apply {
|
||||
Log.e("MainService", "launch type = $params")
|
||||
putExtra("params", params)
|
||||
}
|
||||
context.startService(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var mainServiceHttpModel: MainServiceController
|
||||
private var mAlarmManager: AlarmManager =
|
||||
AbsMogoApplication.getApp().applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
|
||||
//是否已经获取过策略
|
||||
var isGetStrategies: Boolean = false
|
||||
private val TAG: String = this.javaClass.simpleName
|
||||
|
||||
//1是一次性,2是周期性
|
||||
private var picType: Int = 0
|
||||
private var videoType: Int = 0
|
||||
private var shareType: String = "type"
|
||||
private var fromType: String = ""
|
||||
private var isCustom: Boolean = false
|
||||
private var speed: Float = 0f
|
||||
|
||||
private var params: UploadParams? = null
|
||||
private var mainInfoId: Long = 0
|
||||
private var mLongitude: Double = 0.0
|
||||
private var mLatitude: Double = 0.0
|
||||
private lateinit var serviceApis: IMogoServiceApis
|
||||
private var mAddress: String = ""
|
||||
private var mDirection: Float = 0f
|
||||
private var mAreaCode: String = ""
|
||||
private var mCityCode: String = ""
|
||||
private var id: Long = System.currentTimeMillis()
|
||||
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
//清理多媒体资源和sp策略数据
|
||||
clearStrategyType(this)
|
||||
//初始化埋点
|
||||
Analytics.getInstance().start(this)
|
||||
//参数说明:appKey: app唯一标识(比如:包名)
|
||||
CosUploadManagerImpl.getInstance(AbsMogoApplication.getApp().applicationContext)
|
||||
.init(BuildConfig.APPLICATION_ID, 0)
|
||||
serviceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(this) as IMogoServiceApis
|
||||
if (serviceApis.mapServiceApi.getSingletonLocationClient(this) != null &&
|
||||
serviceApis.mapServiceApi.getSingletonLocationClient(this).lastKnowLocation != null) {
|
||||
speed = serviceApis.mapServiceApi.getSingletonLocationClient(this).lastKnowLocation.speed
|
||||
Log.d(TAG, "onStartCommand speed = $speed")
|
||||
}
|
||||
|
||||
if (intent != null) {
|
||||
params = intent.getParcelableExtra("params")
|
||||
params?.let {
|
||||
shareType = it.eventType
|
||||
fromType = it.fromType
|
||||
mainInfoId = it.parentId
|
||||
mLongitude = it.lon
|
||||
mLatitude = it.lat
|
||||
mAddress = it.addr
|
||||
mDirection = it.direction
|
||||
mAreaCode = it.areaCode
|
||||
mCityCode = it.cityCode
|
||||
|
||||
Log.d(TAG, "onStartCommand shareType = $shareType --fromType = $fromType --mainInfoId = $mainInfoId -- mLongitude = $mLongitude --mLatitude = $mLatitude --it.duration = ${it.duration} ")
|
||||
if (fromType == UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO || fromType == UPLOAD_FROM_STRATEGY_BLOCK_AUTO) {
|
||||
// 如果是策略上报,isCustom = false
|
||||
takeVideo(it.duration)
|
||||
} else {
|
||||
takeVideo(it.duration, isCustom = true, id = id)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "intent == null ")
|
||||
}
|
||||
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
//定时任务回调广播
|
||||
private var mAlarmBroadCast: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(p0: Context?, p1: Intent) {
|
||||
Log.d(TAG, "receive alarm!!!!!!!!!!AlarmType===${p1.getIntExtra("AlarmType", 1)}")
|
||||
if (p1.action == alarmBroadAction) {
|
||||
if (p1.getIntExtra("AlarmType", 1) == AlarmTypePic) {
|
||||
//拍照
|
||||
takePhoto(true)
|
||||
} else {
|
||||
//录像
|
||||
val duration = p1.getIntExtra("duration", 3)
|
||||
takeVideo(duration, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//主动上报图片情报广播
|
||||
var mCustomSendBroadCast: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(p0: Context?, p1: Intent) {
|
||||
val id = p1.getLongExtra("id", 0L)
|
||||
if (p1.action == sendInformationAction) {
|
||||
takeVideo(DEFAULT_VIDEO_DURATION, isCustom = true, id = id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
init()
|
||||
//初始化定位
|
||||
LocationUtil.getInstance().initLocation()
|
||||
|
||||
initLocationListener()
|
||||
LatLngStickyEventBus.getInstance().register(this)
|
||||
trackNormalEvent(CarNet_MainService_Start, null)
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
//初始化拍照sdk
|
||||
CarCorderController.initCarCorderController()
|
||||
mainServiceHttpModel = MainServiceController()
|
||||
registReceiver()
|
||||
// CosCallbackMapController.init(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片成功
|
||||
*/
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true, priority = 98)
|
||||
fun getImageEvent(getImageSuccessEvent: GetImageSuccessEvent) {
|
||||
val info = LocationUtil.getInstance().getLocationInfo()
|
||||
Log.d("MainService", "getImageEvent long = ${info.longitude} ----> lat= ${info.latitude}")
|
||||
Log.d(
|
||||
"MainService",
|
||||
"getImageEvent url = " + getImageSuccessEvent.getImageUrl() + ">>>>type =" + getImageSuccessEvent.getType()
|
||||
)
|
||||
|
||||
if (!DebugConfig.isMapBased()) {
|
||||
MogoApisHandler.getInstance().apis.statusManagerApi.setUploadingStatus("CARD_TYPE_ROAD_CONDITION", false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化定位监听
|
||||
*/
|
||||
private fun initLocationListener() {
|
||||
val isOpen = SharedPrefsMgr.getInstance(AbsMogoApplication.getApp().applicationContext).getBoolean("KEY_SERVER_REPORTSTRATEGY_SWITCH", false)
|
||||
Logger.d("EntrancePresenter", " initLocationListener ---- isOpen = $isOpen")
|
||||
//开始开始监听速度,只要超过一次5公里每小时则即开始获取策略进行本地上报 只有release才加此判断,qa环境方便测试
|
||||
LocationUtil.getInstance().setonSpeedlistenner(object : LocationUtil.SpeedListener {
|
||||
override fun onSpeedGet(speed: Float) {
|
||||
if (isOpen) {
|
||||
if (speed > (5 / 3.6f) && !isGetStrategies) {
|
||||
mainServiceHttpModel.initStrategies {
|
||||
handleReportStrategy()
|
||||
}
|
||||
Log.d("MainService", "initLocationListener more than 5 start upload speed = $speed")
|
||||
isGetStrategies = true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报策略判断
|
||||
*/
|
||||
private fun handleReportStrategy() {
|
||||
//1是一次性,2是周期性
|
||||
picType = getStrategyFrequency(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
"pic",
|
||||
getStrategyType("pic")
|
||||
)
|
||||
videoType = getStrategyFrequency(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
"video",
|
||||
getStrategyType("video")
|
||||
)
|
||||
Log.d("MainService", "handleReportStrategy picType = $picType ---videoType = $videoType")
|
||||
shareType = TANLU_ROAD_CURRENT
|
||||
if (picType == 1) {
|
||||
takePhoto()
|
||||
} else if (picType == 2) {
|
||||
postPhotoAlarmTask(true)
|
||||
}
|
||||
|
||||
if (videoType == 1) {
|
||||
takeVideo(DEFAULT_VIDEO_DURATION)
|
||||
} else if (videoType == 2) {
|
||||
postVideoAlarmTask(true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun registReceiver() {
|
||||
//注册定时任务回调
|
||||
val intentFilter = IntentFilter(alarmBroadAction)
|
||||
intentFilter.addAction("com.zhidao.sendmessage.test")
|
||||
intentFilter.addAction("com.zhidao.takevideo.test")
|
||||
intentFilter.addAction("com.zhidao.takepic.test")
|
||||
registerReceiver(mAlarmBroadCast, intentFilter)
|
||||
}
|
||||
|
||||
//获取图片
|
||||
private fun takePhoto(isInterval: Boolean = false, isCustom: Boolean = false) {
|
||||
Log.d("MainService", "takePhoto -----1----->")
|
||||
//判断是否授权
|
||||
// if (isAuthorization(BaseApplication.getAppContext())) {
|
||||
//目前不支持连拍,只能定时2秒拍一张 第一期每次只拍一张
|
||||
Observable.intervalRange(0, 1, 0, 2_000, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
CarCorderController.takePhoto(1, 1, false, isCustom, TANLU_ROAD_CURRENT, mainInfoId, fromType, mLongitude, mLatitude, speed, mAddress, mDirection, mAreaCode, mCityCode)
|
||||
}
|
||||
// }
|
||||
|
||||
postPhotoAlarmTask(isInterval)
|
||||
|
||||
this@MainService.isCustom = isCustom
|
||||
}
|
||||
|
||||
//获取录像
|
||||
private fun takeVideo(
|
||||
duration: Int,
|
||||
isInterval: Boolean = false,
|
||||
isCustom: Boolean = false,
|
||||
id: Long = 0
|
||||
) {
|
||||
Log.d("MainService", "takeVideo --------1----> fromType = $fromType --isCustom = $isCustom")
|
||||
// if (isAuthorization(BaseApplication.getAppContext())) {
|
||||
CarCorderController.takeVideo(1, duration, isCustom, id, shareType, mainInfoId, fromType, mLongitude, mLatitude, speed, mAddress, mDirection, mAreaCode, mCityCode)
|
||||
// }
|
||||
postVideoAlarmTask(isInterval)
|
||||
|
||||
this@MainService.isCustom = isCustom
|
||||
}
|
||||
|
||||
private fun postPhotoAlarmTask(isInterval: Boolean = false) {
|
||||
if (isInterval) {
|
||||
trackNormalEvent(CarNet_Create_Task, null)
|
||||
val intent = Intent()
|
||||
intent.action = alarmBroadAction
|
||||
intent.putExtra("number", getLong(PIC_NUMBER, PIC_NUMBER_DEFAULT))
|
||||
intent.putExtra("AlarmType", AlarmTypePic)
|
||||
val pendingIntent = PendingIntent.getBroadcast(this, AlarmTypePic, intent, 0)
|
||||
Log.d(
|
||||
"MainService",
|
||||
"postPhotoAlarmTask time =" + getStrategyInterval(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
"pic",
|
||||
getStrategyType("pic")
|
||||
)
|
||||
)
|
||||
|
||||
mAlarmManager.setExact(
|
||||
AlarmManager.RTC, System.currentTimeMillis() +
|
||||
getStrategyInterval(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
"pic",
|
||||
getStrategyType("pic")
|
||||
)
|
||||
, pendingIntent
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
//开始倒计时任务
|
||||
private fun postVideoAlarmTask(isInterval: Boolean = false) {
|
||||
if (isInterval) {
|
||||
trackNormalEvent(CarNet_Create_Task, null)
|
||||
val videoIntent = Intent()
|
||||
videoIntent.action = alarmBroadAction
|
||||
videoIntent.putExtra(
|
||||
"duration", (VIDEO_DURATION_DEFAULT / 1000).toInt()
|
||||
)
|
||||
videoIntent.putExtra("AlarmType", AlarmTypeVideo)
|
||||
val videoPendingIntent =
|
||||
PendingIntent.getBroadcast(this, AlarmTypeVideo, videoIntent, 0)
|
||||
Log.d(
|
||||
"MainService",
|
||||
"postVideoAlarmTask time =" + getStrategyInterval(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
"video",
|
||||
getStrategyType("video")
|
||||
)
|
||||
)
|
||||
|
||||
mAlarmManager.setExact(
|
||||
AlarmManager.RTC, System.currentTimeMillis() +
|
||||
getStrategyInterval(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
"video",
|
||||
getStrategyType("video")
|
||||
)
|
||||
, videoPendingIntent
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
unregisterReceiver(mAlarmBroadCast)
|
||||
// unregisterReceiver(mCustomSendBroadCast)
|
||||
CarCorderController.release()
|
||||
// CosCallbackMapController.release()
|
||||
LatLngStickyEventBus.getInstance().unregister(this)
|
||||
LatLngStickyEventBus.getInstance().removeAllStickyEvents()
|
||||
trackNormalEvent(CarNet_MainService_Destory, null)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
package com.mogo.module.share.service
|
||||
|
||||
import android.util.Log
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.eagle.core.network.request
|
||||
import com.mogo.module.share.bean.*
|
||||
import com.mogo.module.share.utils.CarNet_Get_Strategy
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyFrequency
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyInterval
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyMaxSpeed
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyMinSpeed
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyType
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyValidity
|
||||
import com.mogo.module.share.utils.trackNormalEvent
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class MainServiceController {
|
||||
|
||||
companion object {
|
||||
const val TAG = "MainServiceController"
|
||||
}
|
||||
|
||||
//逆地理编码是否重试
|
||||
private var geoRetry = false
|
||||
private var mFromType: String = ""
|
||||
private var mPoiType: String = ""
|
||||
|
||||
private val strategyModel by lazy { StrategyServiceModel() }
|
||||
|
||||
fun initStrategies(initFinish: (() -> Unit)? = null) {
|
||||
request<BaseResponse<Results>> {
|
||||
loader {
|
||||
strategyModel.getCityStrategy()
|
||||
}
|
||||
onSuccess {
|
||||
it.result.let { strategy ->
|
||||
trackNormalEvent(CarNet_Get_Strategy, null)
|
||||
Log.d(TAG, "pic =" + strategy.cityStrategy.pic)
|
||||
Log.d(TAG, "video =" + strategy.cityStrategy.video)
|
||||
syncStrategiesData(strategy.cityStrategy)
|
||||
initFinish?.invoke()
|
||||
}
|
||||
}
|
||||
onError {
|
||||
reInitStrategies()
|
||||
Log.e(TAG, "initStrategies onError ${it.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun reInitStrategies() = runBlocking {
|
||||
launch {
|
||||
initStrategies()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据同步到sharePreference中
|
||||
*/
|
||||
private fun syncStrategiesData(strategy: CityStrategy) {
|
||||
if (strategy.pic != null && strategy.video!=null) {
|
||||
setStrategyType(AbsMogoApplication.getApp().applicationContext, strategy.pic!!.strategyType, "pic")
|
||||
setStrategyType(AbsMogoApplication.getApp().applicationContext, strategy.video!!.strategyType, "video")
|
||||
setStrategyFrequency(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.pic!!.strategyType,
|
||||
"pic",
|
||||
strategy.pic!!.reportType
|
||||
)
|
||||
setStrategyFrequency(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.video!!.strategyType,
|
||||
"video",
|
||||
strategy.video!!.reportType
|
||||
)
|
||||
setStrategyInterval(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.pic!!.strategyType,
|
||||
"pic",
|
||||
strategy.pic!!.reportTimeInterval * 60 * 1000L
|
||||
)
|
||||
setStrategyInterval(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.video!!.strategyType,
|
||||
"video",
|
||||
strategy.video!!.reportTimeInterval * 60 * 1000L
|
||||
)
|
||||
setStrategyValidity(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.pic!!.strategyType,
|
||||
"pic",
|
||||
strategy.pic!!.infoTimeout
|
||||
)
|
||||
setStrategyValidity(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.video!!.strategyType,
|
||||
"video",
|
||||
strategy.video!!.infoTimeout
|
||||
)
|
||||
setStrategyMaxSpeed(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.pic!!.strategyType,
|
||||
"pic",
|
||||
strategy.pic!!.getMaxSpeed()
|
||||
)
|
||||
setStrategyMaxSpeed(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.video!!.strategyType,
|
||||
"video",
|
||||
strategy.video!!.getMaxSpeed()
|
||||
)
|
||||
setStrategyMinSpeed(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.pic!!.strategyType,
|
||||
"pic",
|
||||
strategy.pic!!.minSpeed
|
||||
)
|
||||
setStrategyMinSpeed(
|
||||
AbsMogoApplication.getApp().applicationContext,
|
||||
strategy.video!!.strategyType,
|
||||
"video",
|
||||
strategy.video!!.minSpeed
|
||||
)
|
||||
} else {
|
||||
Log.d(TAG, "strategy Data is null")
|
||||
}
|
||||
}
|
||||
|
||||
//上传情报数据
|
||||
// fun sendInformationMessage(
|
||||
// fromType: String,
|
||||
// type: Int,
|
||||
// url: Map<String, String>,
|
||||
// isCustom: Boolean = false,
|
||||
// trafficInfoType:String = "",
|
||||
// isShare:Boolean = false,
|
||||
// poiType:String,
|
||||
// mainInfoId:Long,
|
||||
// speed: Float,
|
||||
// longitude: Double,
|
||||
// latitude: Double,
|
||||
// customSend: ((Boolean) -> Unit)? = null
|
||||
// ) {
|
||||
// Log.d(TAG, " sendInformationMessage poiType = $poiType -- fromType = $fromType")
|
||||
// mFromType = fromType
|
||||
// mPoiType = poiType
|
||||
//
|
||||
// val locationInfo = LocationUtil.getInstance().getLocationInfo()
|
||||
// if (locationInfo.address.isEmpty()) {
|
||||
// Log.d(TAG, " sendInformationMessage locationInfo.address = $locationInfo.address")
|
||||
// trackUploadGeo(1)
|
||||
// geoLocation(type, url, locationInfo, isCustom,trafficInfoType, isShare, customSend,poiType,mainInfoId,speed, longitude,latitude)
|
||||
// } else {
|
||||
// postInformationMessage(
|
||||
// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare,poiType,mainInfoId,longitude,latitude, speed, mFromType),
|
||||
// customSend
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
//如果address为空则逆地理编码
|
||||
// private fun geoLocation(
|
||||
// type: Int,
|
||||
// url: Map<String, String>,
|
||||
// locationInfo: LocationInfo,
|
||||
// isCustom: Boolean,
|
||||
// trafficInfoType:String,
|
||||
// isShare: Boolean,
|
||||
// customSend: ((Boolean) -> Unit)? = null,
|
||||
// poiType: String,
|
||||
// mainInfoId: Long,
|
||||
// speed: Float,
|
||||
// longitude: Double,
|
||||
// latitude: Double
|
||||
// ) {
|
||||
// Log.d(TAG, " geoLocation -- poiType = $poiType")
|
||||
// LocationUtil.getInstance()
|
||||
// .geoCodeLocation(locationInfo.toLatLngPoint(), {
|
||||
// Log.d(TAG, "geoLocation -------start -->")
|
||||
// postInformationMessage(
|
||||
// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude, speed, mFromType),
|
||||
// customSend
|
||||
// )
|
||||
// }, {
|
||||
// //转换失败的情况下再重试一次
|
||||
// Log.d(TAG, "geoLocation -------true-->")
|
||||
// geoRetry = if (!geoRetry) {
|
||||
// geoLocation(type, url, locationInfo, isCustom, trafficInfoType, isShare, customSend, poiType,mainInfoId,speed, longitude,latitude)
|
||||
// true
|
||||
// } else {
|
||||
// //如果两次都失败,直接上报服务端
|
||||
// Log.d(TAG, "geoLocation ---- postInformationMessage ---false-->")
|
||||
// postInformationMessage(
|
||||
// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude,speed, mFromType),
|
||||
// customSend
|
||||
// )
|
||||
// false
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
|
||||
// private fun postInformationMessage(
|
||||
// informationBody: InformationBody,
|
||||
// customSend: ((Boolean) -> Unit)? = null
|
||||
// ) {
|
||||
// trackUploadServer(3)
|
||||
// request<BaseResponse<UploadResult>> {
|
||||
// loader {
|
||||
// strategyModel.uploadInformation(informationBody)
|
||||
// }
|
||||
// onSuccess {
|
||||
// Log.i(TAG, "upload success id = " + it.result.id)
|
||||
// if (mFromType == "6") {
|
||||
// sendUgcStatusReceiver(it.result.id, mPoiType, mFromType)
|
||||
// }
|
||||
// trackUploadServer(1)
|
||||
// customSend?.invoke(true)
|
||||
// }
|
||||
// onError {
|
||||
// Log.i(TAG, "$it upload message ${it.message}")
|
||||
// trackUploadServer(2)
|
||||
// if (mFromType == "6") {
|
||||
// sendUgcStatusReceiver(0, mPoiType, mFromType)
|
||||
// }
|
||||
// customSend?.invoke(false)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// private fun sendUgcStatusReceiver(id: Long, type: String?, fromType: String?) {
|
||||
// Log.d(TAG, "sendUgcStatusReceiver id = $id ---type = $type --fromType = $fromType ")
|
||||
// val intent = Intent()
|
||||
// intent.action = "com.v2x.ugc.upload.status"
|
||||
// intent.putExtra("id", id)
|
||||
// intent.putExtra("type", type)
|
||||
// intent.putExtra("fromType", fromType)
|
||||
// AbsMogoApplication.getApp().applicationContext.sendBroadcast(intent)
|
||||
// }
|
||||
//
|
||||
// //上传服务器
|
||||
// private fun trackUploadServer(type: Int) {
|
||||
// trackNormalEvent(
|
||||
// CarNet_Servers_Upload, mutableMapOf("type" to type)
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// //上传
|
||||
// private fun trackUploadGeo(type: Int) {
|
||||
// trackNormalEvent(
|
||||
// CarNet_Geo, mutableMapOf("type" to type)
|
||||
// )
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.mogo.module.share.service
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
/**
|
||||
* 上报参数
|
||||
*/
|
||||
class UploadParams(val eventType: String, val fromType: String, val duration: Int, val parentId: Long, val lat: Double, val lon: Double,val addr:String,val direction:Float,val areaCode:String,val cityCode:String) : Parcelable {
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readString()!!,
|
||||
parcel.readString()!!,
|
||||
parcel.readInt(),
|
||||
parcel.readLong(),
|
||||
parcel.readDouble(),
|
||||
parcel.readDouble(),
|
||||
parcel.readString()!!,
|
||||
parcel.readFloat(),
|
||||
parcel.readString()!!,
|
||||
parcel.readString()!!
|
||||
)
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(eventType)
|
||||
parcel.writeString(fromType)
|
||||
parcel.writeInt(duration)
|
||||
parcel.writeLong(parentId)
|
||||
parcel.writeDouble(lat)
|
||||
parcel.writeDouble(lon)
|
||||
parcel.writeString(addr)
|
||||
parcel.writeFloat(direction)
|
||||
parcel.writeString(areaCode)
|
||||
parcel.writeString(cityCode)
|
||||
}
|
||||
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "UploadParams(eventType='$eventType', fromType='$fromType', duration=$duration, parentId=$parentId, lat=$lat, lon=$lon, addr='$addr', direction=$direction, areaCode='$areaCode', cityCode='$cityCode')"
|
||||
}
|
||||
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<UploadParams> {
|
||||
override fun createFromParcel(parcel: Parcel): UploadParams {
|
||||
return UploadParams(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<UploadParams?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.mogo.module.share.utils
|
||||
|
||||
import android.content.Context
|
||||
import com.elegant.analytics.Analytics
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.network.Utils.getFotaVersion
|
||||
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 开始, type=4 成功返回视频和缩略图,type=5 成功但没有返回全视频和缩略图
|
||||
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_Geo:String = "CarNet_Geo_Location" //上传服务端, type=1开始 ,type=2 成功, type=3 失败
|
||||
|
||||
|
||||
const val CarNet_live_broadcast = "CarNet_live_broadcast" // 地图页面点击直播(在线可直播车机)
|
||||
//自定义埋点
|
||||
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"] = getFotaVersion()
|
||||
localParams["sn"] = MoGoAiCloudClientConfig.getInstance().getSn()
|
||||
|
||||
Analytics.getInstance().track(event, data)
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.mogo.module.share.utils
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.os.Environment
|
||||
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? {
|
||||
val file = File(fileUrl)
|
||||
if (file.exists()) {
|
||||
val requestBody = RequestBody.create(MediaType.parse("image/jpg"), file)
|
||||
return MultipartBody.Part.createFormData("file", file.name, requestBody)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun deletePicFile(filePath: String?): Boolean {
|
||||
val file = File(filePath)
|
||||
if (file.exists()) {
|
||||
//如果图片地址包含此路径则是C上面的拍照,需要再删除后摄图片
|
||||
if (filePath!!.contains("usbotg-1-1.1")) {
|
||||
//将地址替换成后摄图片地址
|
||||
val 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()) {
|
||||
return
|
||||
}
|
||||
//取得这个目录下的所有子文件对象
|
||||
val files: Array<File> = file.listFiles()
|
||||
//遍历该目录下的文件对象
|
||||
for (f in files) {
|
||||
//判断子目录是否存在子目录,如果是文件则删除
|
||||
if (f.isDirectory) {
|
||||
deleteAllFile(f)
|
||||
} else {
|
||||
f.delete()
|
||||
}
|
||||
}
|
||||
//删除空文件夹 for循环已经把上一层节点的目录清空。
|
||||
// file.delete()
|
||||
}
|
||||
|
||||
|
||||
//根据本地视频文件生成缩略图文件
|
||||
fun getVideoThumbnail(filePath: String, picPath: String): Boolean {
|
||||
var b: Bitmap? = null
|
||||
val 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)
|
||||
val 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 deleteCompressVideoFile(path: String?) {
|
||||
val file = File(path)
|
||||
val files = file.listFiles()
|
||||
for (f in files) {
|
||||
// /storage/emulated/0/Movies/compress_video_20210202121826.mp4
|
||||
if (f.toString().contains("compress_video")) {
|
||||
f.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//获取压缩后的视频路径
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.mogo.module.share.utils
|
||||
|
||||
import android.util.Log
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.eagle.core.data.map.MogoLocation
|
||||
import com.mogo.map.search.geo.IMogoGeoSearchListener
|
||||
import com.mogo.map.search.geo.MogoRegeocodeAddress
|
||||
import com.mogo.map.search.geo.MogoRegeocodeResult
|
||||
import com.mogo.map.search.geo.query.MogoRegeocodeQuery
|
||||
import com.mogo.module.common.MogoApisHandler
|
||||
import com.mogo.module.share.bean.LocationInfo
|
||||
|
||||
|
||||
private fun toLocInfo(
|
||||
address: MogoRegeocodeAddress,
|
||||
latlngPoint: com.mogo.eagle.core.data.map.MogoLatLng
|
||||
): LocationInfo {
|
||||
return LocationInfo(
|
||||
address.province,
|
||||
address.city,
|
||||
address.cityCode,
|
||||
address.district,
|
||||
address.adCode,
|
||||
address.roads[0].name,
|
||||
latlngPoint.lon,
|
||||
latlngPoint.lat,
|
||||
address.formatAddress,
|
||||
System.currentTimeMillis()
|
||||
)
|
||||
}
|
||||
|
||||
private fun toLocInfo(location: MogoLocation): LocationInfo {
|
||||
return LocationInfo(
|
||||
location.province,
|
||||
location.cityName,
|
||||
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 speedListener: SpeedListener? = null
|
||||
private var locationInfo: LocationInfo? = null
|
||||
private var speed: Float = 0.0f
|
||||
|
||||
fun initLocation() {
|
||||
//初始化client
|
||||
init = true
|
||||
MogoApisHandler.getInstance().apis.mapServiceApi.getSingletonLocationClient(mContext).addLocationListener {location->
|
||||
if (null != location) {
|
||||
locationInfo = LocationInfo()
|
||||
locationInfo!!.longitude = location.longitude
|
||||
locationInfo!!.latitude = location.latitude
|
||||
locationInfo!!.address = location.address
|
||||
locationInfo!!.time = location.time
|
||||
locationInfo!!.provinceName = location.province
|
||||
locationInfo!!.cityName = location.cityName
|
||||
locationInfo!!.cityCode = location.cityCode
|
||||
locationInfo!!.areaName = location.district
|
||||
locationInfo!!.areaCode = location.adCode
|
||||
locationInfo!!.street = location.street
|
||||
locationInfo!!.direction = location.bearing
|
||||
listener?.onChanged(locationInfo!!)
|
||||
speed = location.speed
|
||||
speedListener?.onSpeedGet(location.speed)
|
||||
} else {
|
||||
Log.d(TAG, "定位失败 -> location is null")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getLocationInfo(): LocationInfo {
|
||||
return if (null != locationInfo) {
|
||||
locationInfo!!
|
||||
} else {
|
||||
val location = MogoApisHandler.getInstance().apis.mapServiceApi.getSingletonLocationClient(mContext).lastKnowLocation
|
||||
toLocInfo(location)
|
||||
}
|
||||
}
|
||||
|
||||
//如果获取到的location address为空可以通过高德逆地理编码获得
|
||||
fun geoCodeLocation(
|
||||
latlngPoint: com.mogo.eagle.core.data.map.MogoLatLng,
|
||||
locGeoCode: (((locInfo: LocationInfo) -> Unit)),
|
||||
onError: ((msg: String) -> Unit)
|
||||
) {
|
||||
val geocoderSearch = MogoApisHandler.getInstance().apis.mapServiceApi.getGeoSearch(AbsMogoApplication.getApp().applicationContext)
|
||||
val regeocodeQuery = MogoRegeocodeQuery()
|
||||
regeocodeQuery.latlngType = ""
|
||||
regeocodeQuery.point = latlngPoint
|
||||
regeocodeQuery.radius = 200
|
||||
geocoderSearch.getFromLocationAsyn(regeocodeQuery)
|
||||
geocoderSearch.setGeoSearchListener(object : IMogoGeoSearchListener {
|
||||
override fun onRegeocodeSearched(regeocodeResult: MogoRegeocodeResult?) {
|
||||
// super.onRegeocodeSearched(regeocodeResult)
|
||||
if( regeocodeResult == null ){
|
||||
trackUploadGeo(3)
|
||||
onError.invoke("geoCode")
|
||||
} else {
|
||||
trackUploadGeo(2)
|
||||
val regeocodeAddress = regeocodeResult.regeocodeAddress
|
||||
regeocodeAddress?.let {
|
||||
val locInfo = toLocInfo(regeocodeAddress, latlngPoint)
|
||||
locGeoCode.invoke(locInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//上传
|
||||
private fun trackUploadGeo(type: Int) {
|
||||
trackNormalEvent(
|
||||
CarNet_Geo, mutableMapOf("type" to type)
|
||||
)
|
||||
}
|
||||
|
||||
fun getSpeed():Float{
|
||||
return speed
|
||||
}
|
||||
|
||||
fun setonSpeedlistenner(speedListener: SpeedListener) {
|
||||
this.speedListener = speedListener
|
||||
}
|
||||
|
||||
interface SpeedListener {
|
||||
fun onSpeedGet(speed: Float)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.mogo.module.share.utils
|
||||
|
||||
import android.util.Log
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.module.share.bean.InformationBody
|
||||
import com.mogo.module.share.bean.LocationInfo
|
||||
import com.mogo.module.share.constant.INFO_TYPE_IMG
|
||||
import com.mogo.module.share.constant.INFO_TYPE_VIDEO
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType
|
||||
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyValidity
|
||||
|
||||
|
||||
fun getInformationBody(
|
||||
types: Int,
|
||||
urls: Map<String, String>,
|
||||
locationInfo: LocationInfo,
|
||||
isCustom: Boolean,
|
||||
trafficInfoType:String = "",
|
||||
isShare:Boolean,
|
||||
poiType: String,
|
||||
mainInfoId: Long,
|
||||
longitude: Double,
|
||||
latitude: Double,
|
||||
speed: Float,
|
||||
fromType: String
|
||||
): InformationBody {
|
||||
val jsonArray = JsonArray()
|
||||
val type: Int
|
||||
type = if (types == INFO_TYPE_VIDEO) {
|
||||
val videoObject = JsonObject()
|
||||
videoObject.addProperty("thumbnail", urls["thumb"])
|
||||
videoObject.addProperty("url", urls["video"])
|
||||
jsonArray.add(videoObject)
|
||||
INFO_TYPE_VIDEO
|
||||
} else {
|
||||
val urlObject = JsonObject()
|
||||
urlObject.addProperty("url", urls["pic"])
|
||||
jsonArray.add(urlObject)
|
||||
INFO_TYPE_IMG
|
||||
}
|
||||
val infoType = if (isCustom) 1 else 0
|
||||
Log.d("MainServiceController", "isCustom = $isCustom ---- infoType = $infoType")
|
||||
return InformationBody(
|
||||
jsonArray.toString(),
|
||||
locationInfo.address,
|
||||
locationInfo.areaCode,
|
||||
locationInfo.areaName,
|
||||
locationInfo.cityCode,
|
||||
locationInfo.cityName,
|
||||
System.currentTimeMillis(),
|
||||
if (latitude == 0.0) locationInfo.latitude else latitude,
|
||||
if (longitude == 0.0) locationInfo.longitude else longitude,
|
||||
locationInfo.provinceName,
|
||||
MoGoAiCloudClientConfig.getInstance().getSn(),
|
||||
locationInfo.street,
|
||||
type,
|
||||
0,
|
||||
infoType,
|
||||
getStrategyValidity(AbsMogoApplication.getApp().applicationContext, convertUploadTypeOfSP(type), getStrategyType(convertUploadTypeOfSP(type))),
|
||||
trafficInfoType,
|
||||
isShare,
|
||||
locationInfo.direction,
|
||||
poiType,
|
||||
mainInfoId,
|
||||
speed,
|
||||
fromType
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertUploadTypeOfSP(type: Int): String {
|
||||
return when (type) {
|
||||
INFO_TYPE_IMG -> "pic"
|
||||
INFO_TYPE_VIDEO -> "video"
|
||||
else -> "pic"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.mogo.module.share.utils
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.edit
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
|
||||
const val FILE_NAME = "settings_data"
|
||||
|
||||
const val PIC_NUMBER = "PIC_NUMBER" //图片拍摄张数
|
||||
const val VIDEO_DURATION_DEFAULT = 10_000L //视频拍摄时长
|
||||
const val PIC_NUMBER_DEFAULT = 1L //图片拍摄张数
|
||||
|
||||
fun putLong(key: String, value: Long) {
|
||||
val 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) {
|
||||
val 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) {
|
||||
val sharedPreferences =
|
||||
AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit {
|
||||
putString(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.mogo.module.share.utils
|
||||
|
||||
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) {
|
||||
val 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) {
|
||||
val 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
|
||||
) {
|
||||
val 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
|
||||
) {
|
||||
val 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
|
||||
) {
|
||||
val 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
|
||||
) {
|
||||
val 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
|
||||
) {
|
||||
val 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,20 @@
|
||||
package com.mogo.module.share.utils
|
||||
|
||||
import bolts.Task.delay
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
@ObsoleteCoroutinesApi
|
||||
@PublishedApi
|
||||
internal var ThreadPool =
|
||||
newFixedThreadPoolContext(Runtime.getRuntime().availableProcessors() * 2, "ThreadPool")
|
||||
|
||||
|
||||
/**
|
||||
* 并发执行,常用于最外层
|
||||
* 特点带返回值
|
||||
*/
|
||||
@ObsoleteCoroutinesApi
|
||||
fun <T> taskAsync(delayTime: Long = 0, job: suspend () -> T) = GlobalScope.async(ThreadPool) {
|
||||
delay(delayTime)
|
||||
job()
|
||||
}
|
||||
@@ -10,8 +10,6 @@ import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.service.share.IMogoTanluProvider;
|
||||
import com.mogo.service.share.TanluUploadParams;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.roadcondition.service.MainService;
|
||||
import com.zhidao.roadcondition.service.UploadParams;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.io.File
|
||||
*
|
||||
* @author lixiaopeng
|
||||
* @since 2019-10-30
|
||||
*
|
||||
*
|
||||
*/
|
||||
class CosStatusController : CosStatusCallback {
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class MainService : Service() {
|
||||
fun launchService(context: Context, params: UploadParams?) {
|
||||
|
||||
val intent = Intent(context, MainService::class.java).apply {
|
||||
Log.e("MainService", "launchService type = $params")
|
||||
Log.e("MainService", "launch type = $params")
|
||||
putExtra("params", params)
|
||||
}
|
||||
context.startService(intent)
|
||||
|
||||
@@ -54,7 +54,7 @@ include ':libraries:map-autonavi'
|
||||
include ':libraries:mogo-map'
|
||||
|
||||
// OLD业务模块
|
||||
include ':modules:tanlulib'
|
||||
//include ':modules:tanlulib'
|
||||
include ':modules:mogo-module-monitor'
|
||||
include ':modules:mogo-module-adas'
|
||||
include ':modules:mogo-module-map'
|
||||
|
||||
Reference in New Issue
Block a user