diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/MoGoAutopilotProvider.kt b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/MoGoAutopilotProvider.kt index 13547d9ade..1c714d13ec 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/MoGoAutopilotProvider.kt +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/MoGoAutopilotProvider.kt @@ -5,17 +5,21 @@ import android.content.Context import androidx.annotation.RequiresPermission import com.alibaba.android.arouter.facade.annotation.Route import com.mogo.cloud.passport.MoGoAiCloudClientConfig -import com.mogo.eagle.core.data.autopilot.AutopilotControlCmdParameter import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters +import com.mogo.eagle.core.data.autopilot.toRouteInfo import com.mogo.eagle.core.data.config.FunctionBuildConfig import com.mogo.eagle.core.data.constants.MoGoConfig import com.mogo.eagle.core.data.constants.MogoServicePaths +import com.mogo.eagle.core.data.deva.scene.SceneConstant.Companion.M_ADAS_IMPL +import com.mogo.eagle.core.data.trafficlight.TrafficLightResult +import com.mogo.eagle.core.data.trafficlight.toTrafficLightDetail import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotProvider import com.mogo.eagle.core.function.api.map.collect.IMoGoMapDataCollectProvider import com.mogo.eagle.core.function.autopilot.adapter.MoGoAdasListenerImpl import com.mogo.eagle.core.function.autopilot.adapter.MoGoAdasMsgConnectStatusListenerImpl import com.mogo.eagle.core.function.autopilot.adapter.MoGoHandAdasMsgManager import com.mogo.eagle.core.function.autopilot.server.AsyncDataToAutopilotServer +import com.mogo.eagle.core.function.call.logger.CallerLogger import com.mogo.eagle.core.function.call.map.CallerMapDataCollectorManager import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils import com.mogo.eagle.core.utilcode.mogo.logger.Logger @@ -52,8 +56,8 @@ class MoGoAutopilotProvider : get() = TAG override fun init(context: Context) { - MoGoHandAdasMsgManager.getInstance(); - Logger.d(TAG, "初始化工控机连接……") + MoGoHandAdasMsgManager.getInstance() + CallerLogger.i("$M_ADAS_IMPL$TAG", "初始化工控机连接……") mContext = context // 初始化ADAS 域控制器 CupidLogUtils.setEnableLog(false) @@ -72,26 +76,24 @@ class MoGoAutopilotProvider : NSDNettyManager.getInstance().startNSDNettyServerWithSN(context, object : NettyServerListener { override fun onMessageResponseServer(msg: MogoProtocolMsg?, channel: Channel?) { - Logger.d(TAG, "Receive client data is:${msg?.toString()}") + CallerLogger.d("$M_ADAS_IMPL$TAG", "Receive client data is:${msg?.toString()}") } override fun onStartServer() { ToastUtils.showShort("司机端服务启动成功!") - Logger.d(TAG, "onStartServer") } override fun onStopServer() { ToastUtils.showLong("司机端服务停止!") - Logger.d(TAG, "onStopServer") } override fun onChannelConnect(channel: Channel?) { val socketAddress = channel?.remoteAddress().toString() - Logger.d(TAG, "Client ip is:${socketAddress}") + CallerLogger.d("$M_ADAS_IMPL$TAG", "Client ip is:${socketAddress}") } override fun onChannelDisConnect(channel: Channel?) { - Logger.d(TAG, "onChannelDisConnect") + CallerLogger.d("$M_ADAS_IMPL$TAG", "onChannelDisConnect") } }, MoGoAiCloudClientConfig.getInstance().sn) } else { @@ -108,22 +110,23 @@ class MoGoAutopilotProvider : .searchAndConnectServer(context, MoGoAiCloudClientConfig.getInstance().sn, object : NettyClientListener { override fun onMessageResponseClient(msg: MogoProtocolMsg?, sign: String?) { - Logger.d(TAG, "收到司机端的数据!") // 乘客端收到adas数据直接解析,后续分发解析后的数据流程同司机端 msg?.let { AdasManager.getInstance().parseIPCData(it.body) - Logger.d(TAG, "解析司机端数据完毕!") } } override fun onClientStatusConnectChanged(statusCode: Int, sign: String?) { when (statusCode) { ConnectState.STATUS_CONNECT_SUCCESS -> { - Logger.d(TAG, "乘客端连接司机端服务成功! sign is:${sign}") + CallerLogger.d("$M_ADAS_IMPL$TAG", "乘客端连接司机端服务成功! sign is:${sign}") } else -> { ToastUtils.showLong("和司机端连接异常!") - Logger.d(TAG, "client statusCode is:${statusCode}") + CallerLogger.d( + "$M_ADAS_IMPL$TAG", + "client statusCode is:${statusCode}" + ) } } } @@ -138,17 +141,15 @@ class MoGoAutopilotProvider : AdasManager.getInstance().setOnMultiDeviceListener { bytes -> // 发送数据给乘客端 if (NSDNettyManager.getInstance().isServerStart) { - Logger.d( - TAG, - "司机端透传数据给乘客端!" - ) NSDNettyManager.getInstance() .sendMsgToAllClients(MogoProtocolMsg(NORMAL_DATA, bytes.size, bytes)) } else { - Logger.d(TAG, "司机端Server未启动!") + CallerLogger.d("$M_ADAS_IMPL$TAG", "司机端Server未启动!") } } } + + CallerLogger.i("$M_ADAS_IMPL$TAG", "initServer……") // 同步数据给工控机的服务 AsyncDataToAutopilotServer.INSTANCE.initServer() // 同步是否开启美化模式 @@ -188,32 +189,45 @@ class MoGoAutopilotProvider : override fun onMapCollectStart(cmdId: Int, cmdTime: Long) { val result = recordPackage(2, cmdId) - Logger.d(TAG, "开始记录包: [$cmdId, $result]") + CallerLogger.d("$M_ADAS_IMPL$TAG", "开始记录包: [$cmdId, $result]") } override fun onMapCollectEnd(cmdId: Int, cmdTime: Long) { val result = stopRecord(2, cmdId) - Logger.d(TAG, "结束记录包: [$cmdId, $result]") + CallerLogger.d("$M_ADAS_IMPL$TAG", "结束记录包: [$cmdId, $result]") } - override fun startAutoPilot(result: AutopilotControlParameters) { + override fun startAutoPilot(controlParameters: AutopilotControlParameters) { if (AdasManager.getInstance().ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED) { - val parameter = AutopilotControlCmdParameter("aiCloudToStartAutopilot", result) -// AdasManager.getInstance().aiCloudToAdasData(GsonUtils.toJson(parameter)) //todo pb : 需要指定来源 + AdasManager.getInstance().sendAutoPilotModeReq(1, 1, controlParameters.toRouteInfo()) } else { - Logger.e(TAG, "车机与工控机链接失败,无法开启自动驾驶") + CallerLogger.e("$M_ADAS_IMPL$TAG", "车机与工控机链接失败,无法开启自动驾驶") } } + override fun sendTrafficLightData(trafficLightResult: TrafficLightResult) { + AdasManager.getInstance().sendTrafficLightData( + trafficLightResult.crossId, + trafficLightResult.lat, + trafficLightResult.lon, + trafficLightResult.heading, + trafficLightResult.direction, + trafficLightResult.lightId, + trafficLightResult.laneNo, + trafficLightResult.arrowNo, + trafficLightResult.flashYellow, + trafficLightResult.toTrafficLightDetail() + ) + } + override fun sendMessageToAutopilot(jsonString: String) { -// AdasManager.getInstance().sendMessage(jsonString) //todo pb : 红绿灯 } override fun cancelAutoPilot() { if (AdasManager.getInstance().ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED) { -// AdasManager.getInstance().controlAutopilotCarHead() //todo pb : 需要指定来源 + AdasManager.getInstance().sendAutoPilotModeReq(0, 1, null) } else { - Logger.e(TAG, "车机与工控机链接失败,无法断开自动驾驶") + CallerLogger.e("$M_ADAS_IMPL$TAG", "车机与工控机链接失败,无法断开自动驾驶") } } @@ -295,9 +309,23 @@ class MoGoAutopilotProvider : */ override fun setControlAutopilotCarAuto(isEnable: Boolean) { if (isEnable) { -// AdasManager.getInstance().sendAutoPilotModeReq() //todo pb : 需要指定来源 + AdasManager.getInstance().sendAutoPilotModeReq(1, 0, null) } else { -// AdasManager.getInstance().sendAutoPilotModeReq() //todo pb : 需要指定来源 + AdasManager.getInstance().sendAutoPilotModeReq(0, 0, null) } } + + /** + * 请求工控机基础配置信息 + */ + override fun getCarConfig() { + AdasManager.getInstance().sendCarConfigReq() + } + + /** + * 获取全局路径 + */ + override fun getGlobalPath() { + AdasManager.getInstance().sendGlobalPathReq() + } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/adapter/MoGoAdasListenerImpl.kt b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/adapter/MoGoAdasListenerImpl.kt index 0883ebd287..13b928d2fe 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/adapter/MoGoAdasListenerImpl.kt +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/adapter/MoGoAdasListenerImpl.kt @@ -15,6 +15,7 @@ import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_C import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_ADAS_MESSAGE_RECT_DATA import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_ADAS import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_WEB_SOCKET_DATA +import com.mogo.eagle.core.data.deva.scene.SceneConstant.Companion.M_ADAS import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.invokeArriveAtStation import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.invokeAutoPilotStatus @@ -28,10 +29,9 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListen import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager.invokeAutopilotRotting import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager.invokeAutopilotTrajectory import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotVehicleStateListenerManager -import com.mogo.eagle.core.function.call.hmi.CallerHmiManager import com.mogo.eagle.core.function.call.hmi.CallerHmiManager.showAdUpgradeStatus import com.mogo.eagle.core.function.call.hmi.CallerHmiManager.showDockerRebootResult -import com.mogo.eagle.core.utilcode.mogo.logger.Logger +import com.mogo.eagle.core.function.call.logger.CallerLogger import com.mogo.module.common.MogoApisHandler import com.mogo.module.common.datacenter.SnapshotLocationDataCenter import com.mogo.module.service.MarkerServiceHandler @@ -49,7 +49,7 @@ import record_cache.RecordPanelOuterClass import java.util.* /** - * @author emarrow + * @author emArrow * @since 2022/3/11 * * @@ -172,8 +172,9 @@ class MoGoAdasListenerImpl : OnAdasListener { autopilotStatusInfo.connectIP = AdasManager.getInstance().ipcConnectedIp } if (autopilotStatusInfo.dockVersion == null) { -// autopilotStatusInfo.dockVersion = -// AdasManager.getInstance() //todo pb : get docker + AdasManager.getInstance().carConfig?.let { + autopilotStatusInfo.dockVersion = it.dockVersion + } } invokeAutoPilotStatus() } @@ -278,8 +279,8 @@ class MoGoAdasListenerImpl : OnAdasListener { override fun onUpgradeStateInfo(info: IPCUpgradeStateInfo) { if (info != null) { - Logger.d( - TAG, "onUpgradeStateInfo " + + CallerLogger.d( + "$M_ADAS$TAG", "onUpgradeStateInfo " + " upgrade mode=" + info.upgradeMode + " download status=" + info.downloadStatus + " download progress current=" + info.progress.current + @@ -292,7 +293,7 @@ class MoGoAdasListenerImpl : OnAdasListener { info.progress.total, info.images, info.upgradeStatus ) } else { - Logger.d(TAG, "onUpgradeStateInfo : upgrade state info is null") + CallerLogger.w("$M_ADAS$TAG", "onUpgradeStateInfo : upgrade state info is null") } } @@ -300,7 +301,7 @@ class MoGoAdasListenerImpl : OnAdasListener { if (info != null && "docker restart autocar_default_1" == info.cmd) { showDockerRebootResult(info.code, info.msg) } else { - Logger.d(TAG, "onSSHResult : result info is null") + CallerLogger.w("$M_ADAS$TAG", "onSSHResult : result info is null") } } diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/adapter/MoGoAdasMsgConnectStatusListenerImpl.kt b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/adapter/MoGoAdasMsgConnectStatusListenerImpl.kt index 38d86dbb23..c6eceb27d3 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/adapter/MoGoAdasMsgConnectStatusListenerImpl.kt +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/adapter/MoGoAdasMsgConnectStatusListenerImpl.kt @@ -3,10 +3,11 @@ package com.mogo.eagle.core.function.autopilot.adapter import com.mogo.cloud.passport.MoGoAiCloudClientConfig import com.mogo.commons.debug.DebugConfig import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo +import com.mogo.eagle.core.data.deva.scene.SceneConstant.Companion.M_ADAS_IMPL import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener import com.mogo.eagle.core.function.autopilot.network.AdasServiceModel import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager -import com.mogo.eagle.core.utilcode.mogo.logger.Logger +import com.mogo.eagle.core.function.call.logger.CallerLogger import com.zhidao.support.adas.high.AdasManager import com.zhidao.support.adas.high.OnAdasConnectStatusListener import com.zhidao.support.adas.high.common.Constants @@ -18,12 +19,10 @@ import java.util.concurrent.TimeUnit /** * ADAS-SDK与工控机连接状态回调 - * - * @author donghongyu */ class MoGoAdasMsgConnectStatusListenerImpl : OnAdasConnectStatusListener, IMoGoAutopilotStatusListener { - private val TAG = "MoGoAdasMsgConnectStatusListenerImpl" + private val TAG = "ConnectStatus" //自动驾驶状态 private var mCurrentAutopilotStatus = -1 @@ -34,7 +33,7 @@ class MoGoAdasMsgConnectStatusListenerImpl : OnAdasConnectStatusListener, override fun onConnectionIPCStatus(ipcConnectionStatus: Int, reason: String?) { if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED) { - Logger.d(TAG, "webSocket 连接成功") + CallerLogger.d("$M_ADAS_IMPL$TAG", "webSocket 连接成功") // 初始化自动驾驶状态信息 CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectIP = AdasManager.getInstance().ipcConnectedIp @@ -47,17 +46,17 @@ class MoGoAdasMsgConnectStatusListenerImpl : OnAdasConnectStatusListener, // 开启轮训上传自动驾驶状态 updateDriveStatusTask() } else if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.DISCONNECTED) { - Logger.d(TAG, "webSocket 连接失败 reason:$reason") + CallerLogger.d("$M_ADAS_IMPL$TAG", "webSocket 连接失败 reason:$reason") CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectIP = AdasManager.getInstance().ipcConnectedIp CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectStatus = false CallerAutoPilotStatusListenerManager.invokeAutoPilotStatus() } else if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTING) { - Logger.d(TAG, "webSocket 正在连接") + CallerLogger.d("$M_ADAS_IMPL$TAG", "webSocket 正在连接") } else if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.SEARCH_ADDRESS) { - Logger.d(TAG, "webSocket 正在搜索工控机IP") + CallerLogger.d("$M_ADAS_IMPL$TAG", "webSocket 正在搜索工控机IP") } else if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.NOT_FOUND_ADDRESS) { - Logger.d(TAG, "webSocket 找不到可用IP 传入的IP不可用或固定IP列表中所有IP不可用") + CallerLogger.d("$M_ADAS_IMPL$TAG", "webSocket 找不到可用IP 传入的IP不可用或固定IP列表中所有IP不可用") } } @@ -88,7 +87,7 @@ class MoGoAdasMsgConnectStatusListenerImpl : OnAdasConnectStatusListener, * 同步SN信息给工控机 */ private fun syncBasicInfoToAutopilot() { - Logger.d(TAG, "同步PAD的SN给工控机……") + CallerLogger.d("$M_ADAS_IMPL$TAG", "同步PAD的SN给工控机……") // 设置PAD-SN给工控,网络环境 AdasManager.getInstance() .sendBasicInfoResp(MoGoAiCloudClientConfig.getInstance().sn, DebugConfig.getNetMode()) @@ -98,7 +97,7 @@ class MoGoAdasMsgConnectStatusListenerImpl : OnAdasConnectStatusListener, * 上传自动驾驶状态任务 */ private fun updateDriveStatusTask() { - Logger.d(TAG, "updateDriveStatusTask") + CallerLogger.d("$M_ADAS_IMPL$TAG", "updateDriveStatusTask") Flowable.interval(0, 5, TimeUnit.SECONDS) .subscribeOn(Schedulers.io()) .unsubscribeOn(Schedulers.io()) diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/entity/AutonomousDriveStatusBean.java b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/entity/AutonomousDriveStatusBean.java index 2557f03e5e..ffbd292b4c 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/entity/AutonomousDriveStatusBean.java +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/entity/AutonomousDriveStatusBean.java @@ -1,7 +1,7 @@ package com.mogo.eagle.core.function.autopilot.entity; /** - * Created by XuYong on 2021/5/28 16:12 + * Created by SuYong on 2021/5/28 16:12 */ public class AutonomousDriveStatusBean { diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/entity/ReportSiteBean.java b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/entity/ReportSiteBean.java index 9b1f9f4328..1d12392d24 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/entity/ReportSiteBean.java +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/entity/ReportSiteBean.java @@ -1,7 +1,7 @@ package com.mogo.eagle.core.function.autopilot.entity; /** - * Created by XuYong on 2021/5/31 16:24 + * Created by SuYong on 2021/5/31 16:24 */ public class ReportSiteBean { private String sn; diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/network/AdasServiceModel.java b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/network/AdasServiceModel.java index 23b0a1677f..b19f01eb39 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/network/AdasServiceModel.java +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/network/AdasServiceModel.java @@ -8,7 +8,6 @@ import com.mogo.eagle.core.function.autopilot.entity.ReportSiteBean; import com.mogo.eagle.core.network.RequestOptions; import com.mogo.eagle.core.network.SubscribeImpl; import com.mogo.eagle.core.network.utils.GsonUtil; -import com.mogo.eagle.core.utilcode.mogo.logger.Logger; import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.constants.HostConst; @@ -89,7 +88,6 @@ public class AdasServiceModel { @Override public void onSuccess(BaseData o) { super.onSuccess(o); - Logger.d(TAG, "autopilotArrive success"); } }); } diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/server/AsyncDataToAutopilotServer.kt b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/server/AsyncDataToAutopilotServer.kt index 24aa7c7ad1..f67f021802 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/server/AsyncDataToAutopilotServer.kt +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/server/AsyncDataToAutopilotServer.kt @@ -1,12 +1,9 @@ package com.mogo.eagle.core.function.autopilot.server -import com.mogo.eagle.core.data.autopilot.AutopilotControlCmdParameter import com.mogo.eagle.core.data.trafficlight.TrafficLightResult import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotManager import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager -import com.mogo.eagle.core.utilcode.mogo.logger.Logger -import com.mogo.eagle.core.utilcode.util.GsonUtils /** * @author xiaoyuzhou @@ -25,12 +22,10 @@ class AsyncDataToAutopilotServer private constructor() : IMoGoTrafficLightListen } fun initServer() { - Logger.d(TAG, "initServer……") CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this) } override fun onTrafficLightStatus(trafficLightResult: TrafficLightResult) { - val autopilotControlCmdParameter = AutopilotControlCmdParameter("light", trafficLightResult) - CallerAutoPilotManager.sendDataToAutopilot(GsonUtils.toJson(autopilotControlCmdParameter)) + CallerAutoPilotManager.sendTrafficLightData(trafficLightResult) } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-chat/src/main/java/com/mogo/eagle/core/function/chat/facade/aop/BaseAspectj.kt b/core/function-impl/mogo-core-function-chat/src/main/java/com/mogo/eagle/core/function/chat/facade/aop/BaseAspectj.kt index 032eefd2eb..9b7ea9196d 100644 --- a/core/function-impl/mogo-core-function-chat/src/main/java/com/mogo/eagle/core/function/chat/facade/aop/BaseAspectj.kt +++ b/core/function-impl/mogo-core-function-chat/src/main/java/com/mogo/eagle/core/function/chat/facade/aop/BaseAspectj.kt @@ -1,8 +1,9 @@ package com.mogo.eagle.core.function.chat.facade.aop import android.os.Looper -import android.util.Log import com.mogo.commons.debug.DebugConfig +import com.mogo.eagle.core.data.deva.scene.SceneConstant.Companion.M_CHAT +import com.mogo.eagle.core.function.call.logger.CallerLogger import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.reflect.CodeSignature import org.aspectj.lang.reflect.MethodSignature @@ -37,7 +38,7 @@ open class BaseAspectj { if (Looper.myLooper() != Looper.getMainLooper()) { builder.append("[Thread:\"").append(Thread.currentThread().name).append("\"]") } - Log.i(asTag(cls), builder.toString()) + CallerLogger.d(M_CHAT + asTag(cls), builder.toString()) } fun exitMethod(joinPoint: ProceedingJoinPoint, result: Any?, lengthMill: Long) { @@ -50,10 +51,10 @@ open class BaseAspectj { && signature.returnType != Void.TYPE val builder = StringBuilder("\u21E0 ") - .append(methodName) - .append("[") - .append(lengthMill) - .append("ms]") + .append(methodName) + .append("[") + .append(lengthMill) + .append("ms]") if (hasReturnType) { builder.append(" = ") @@ -61,7 +62,7 @@ open class BaseAspectj { result.toString() }) } - Log.i(asTag(cls), builder.toString()) + CallerLogger.d(M_CHAT + asTag(cls), builder.toString()) } private fun asTag(cls: Class<*>): String { diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/VehicleMonitoringManager.kt b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/VehicleMonitoringManager.kt index 7b375408f3..306f3f0c7e 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/VehicleMonitoringManager.kt +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/VehicleMonitoringManager.kt @@ -33,7 +33,6 @@ class VehicleMonitoringManager : ICheckProvider, IMogoStatusChangedListener { private var hasTipShow = false //是否已经弹框提示 var dialog: CheckDialog? = null override fun init(context: Context) { - LogUtils.dTag(TAG, "初始化 CheckProvider 模块") mContext = context MogoApisHandler.getInstance().apis.statusManagerApi.registerStatusChangedListener( TAG, diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckActivity.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckActivity.java index e02fbd27c8..da6dfe3b32 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckActivity.java +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckActivity.java @@ -7,7 +7,6 @@ import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.graphics.Rect; import android.os.Bundle; -import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.ProgressBar; @@ -91,20 +90,15 @@ public class CheckActivity extends AppCompatActivity { mRecyclerView.setAdapter(mCheckAdapter); } - private void checkAction() { CheckNetWork.INSTANCE.checkNetWork(this.getApplicationContext(), new ICheckResultCallBack() { @Override public void callBackWithCheckData(CheckResultData data) { - Log.d("CheckActivity", "车辆自检结果是:" + data.toString()); - ThreadUtils.runOnUiThread(new Runnable() { - @Override - public void run() { - if (data != null && mCheckAdapter != null) { - mCheckAdapter.errorMsg = null; - mCheckAdapter.mCheckResultData = data; - mCheckAdapter.notifyDataSetChanged(); - } + ThreadUtils.runOnUiThread(() -> { + if (data != null && mCheckAdapter != null) { + mCheckAdapter.errorMsg = null; + mCheckAdapter.mCheckResultData = data; + mCheckAdapter.notifyDataSetChanged(); } }); } @@ -121,7 +115,6 @@ public class CheckActivity extends AppCompatActivity { } - /** * **************************************************************************************检测动画 */ @@ -180,16 +173,12 @@ public class CheckActivity extends AppCompatActivity { public void animatorScanCarBorder(boolean show, int weight) { if (show) { mValueAnimator = ValueAnimator.ofInt(0, weight); - } else { } - mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - Rect rect = new Rect(0, 0, (int) mValueAnimator.getAnimatedValue(), scanTopImageView.getHeight()); - setProgressBarRefresh((int) mValueAnimator.getAnimatedValue()); - scanTopImageView.setClip(rect); - tipsImageView.setClip(rect); - } + mValueAnimator.addUpdateListener(animation -> { + Rect rect = new Rect(0, 0, (int) mValueAnimator.getAnimatedValue(), scanTopImageView.getHeight()); + setProgressBarRefresh((int) mValueAnimator.getAnimatedValue()); + scanTopImageView.setClip(rect); + tipsImageView.setClip(rect); }); mValueAnimator.setDuration(DURATION_TIME); mValueAnimator.start(); @@ -200,7 +189,7 @@ public class CheckActivity extends AppCompatActivity { */ public void setProgressBarRefresh(int animateValue) { if (mProgressBar != null) { - double scale = new BigDecimal((float) animateValue / scanBottomCarImage.getWidth()) + double scale = BigDecimal.valueOf((float) animateValue / scanBottomCarImage.getWidth()) .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100; if (mProgressBar.getProgress() < 100) { mProgressBar.setProgress((int) scale); @@ -231,7 +220,7 @@ public class CheckActivity extends AppCompatActivity { @Override protected void onDestroy() { super.onDestroy(); - mCheckAdapter.ondestry(); + mCheckAdapter.onDestroy(); } } diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckAdapter.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckAdapter.java index cfbde3bc19..039409810a 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckAdapter.java +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckAdapter.java @@ -1,7 +1,6 @@ package com.mogo.eagle.core.function.check.view; import android.content.Context; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -23,7 +22,6 @@ import com.mogo.eagle.core.function.check.net.CheckResultData; */ public class CheckAdapter extends RecyclerView.Adapter { - private static final String TAG = "CheckActivity"; LayoutInflater mLayoutInflater; CheckResultData mCheckResultData; private Context mContext; @@ -51,13 +49,11 @@ public class CheckAdapter extends RecyclerView.Adapter if (viewType == CheckItemInfo.CheckAdapterStyleEnum.ITEM_TYPE_CHECK_TITLE) { View v = mLayoutInflater.inflate(R.layout.check_titel, parent, false); - CheckTitleViewHolder holder = new CheckTitleViewHolder(v); - return holder; + return new CheckTitleViewHolder(v); } View v = mLayoutInflater.inflate(R.layout.check_list, parent, false); - CheckListViewHolder holder = new CheckListViewHolder(v); - return holder; + return new CheckListViewHolder(v); } public void dismissDialog() { @@ -66,7 +62,7 @@ public class CheckAdapter extends RecyclerView.Adapter } } - public void ondestry() { + public void onDestroy() { mContext = null; mCheckInfoListDialog = null; } @@ -74,9 +70,9 @@ public class CheckAdapter extends RecyclerView.Adapter /** * 顶部view列表 */ - class CheckTitleViewHolder extends RecyclerView.ViewHolder { - private ImageView errorImage; - private TextView mTextView; + private static class CheckTitleViewHolder extends RecyclerView.ViewHolder { + private final ImageView errorImage; + private final TextView mTextView; public CheckTitleViewHolder(@NonNull View itemView) { super(itemView); @@ -88,11 +84,11 @@ public class CheckAdapter extends RecyclerView.Adapter /** * 版本->软件检测 */ - class CheckListViewHolder extends RecyclerView.ViewHolder { - private TextView viewTitle; + private static class CheckListViewHolder extends RecyclerView.ViewHolder { + private final TextView viewTitle; private TextView iconAutoTitle; - private TextView autoRiskState; - private ImageView iconAuto; + private final TextView autoRiskState; + private final ImageView iconAuto; public CheckListViewHolder(@NonNull View itemView) { super(itemView); @@ -135,7 +131,6 @@ public class CheckAdapter extends RecyclerView.Adapter ((CheckListViewHolder) holder).autoRiskState.setText("存在异常项"); } ((CheckListViewHolder) holder).iconAuto.setOnClickListener(v -> { - Log.d(TAG, "硬件检测结果:"); if (mCheckInfoListDialog != null) { mCheckInfoListDialog.dismiss(); } @@ -155,7 +150,6 @@ public class CheckAdapter extends RecyclerView.Adapter ((CheckListViewHolder) holder).autoRiskState.setText("存在异常项"); } ((CheckListViewHolder) holder).iconAuto.setOnClickListener(v -> { - Log.d(TAG, "系统检测结果:"); if (mCheckInfoListDialog != null) { mCheckInfoListDialog.dismiss(); } diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckDialog.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckDialog.java index a80c0111ba..aa31c60104 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckDialog.java +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckDialog.java @@ -19,9 +19,7 @@ import com.mogo.module.common.dialog.BaseFloatDialog; */ public class CheckDialog extends BaseFloatDialog { - private ImageView cancel; private boolean showWarning; - private TextView checkDetail; private Context mContext; public CheckDialog(@NonNull Context context, boolean hasError) { @@ -37,11 +35,11 @@ public class CheckDialog extends BaseFloatDialog { public void initView() { setContentView(R.layout.check_dialog); - cancel = findViewById(R.id.cancel_button); + ImageView cancel = findViewById(R.id.cancel_button); cancel.setOnClickListener(v -> { dismiss(); }); - checkDetail = findViewById(R.id.check_detail); + TextView checkDetail = findViewById(R.id.check_detail); checkDetail.setOnClickListener(v -> { dismiss(); if (mContext != null) { @@ -50,17 +48,15 @@ public class CheckDialog extends BaseFloatDialog { }); //根据条件显示体检页面/风险提示 - if (showWarning == true) { + if (showWarning) { findViewById(R.id.error_view).setVisibility(View.VISIBLE); findViewById(R.id.check_view).setVisibility(View.INVISIBLE); - } else { findViewById(R.id.error_view).setVisibility(View.INVISIBLE); findViewById(R.id.check_view).setVisibility(View.VISIBLE); } } - public void cancel() { } diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoAdapter.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoAdapter.java index 48dd8a96fe..3e04633765 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoAdapter.java +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoAdapter.java @@ -5,7 +5,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.ScrollView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -25,14 +24,14 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { LayoutInflater mLayoutInflater; private Context mContext; private String mStyle; - private List showData; + private final List showData; //item类型 public static final int ITEM_TYPE_CONTENT = 0;//内容 public static final int ITEM_TYPE_BOTTOM = 1;//footer类型 //适配UI的空白表格 private int mBottomCount = 0; - public CheckInfoAdapter(Context context, String style, List checkResultData) { + public CheckInfoAdapter(Context context, String style, List checkResultData) { mContext = context; mStyle = style; showData = checkResultData; @@ -50,7 +49,7 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { } View v = mLayoutInflater.inflate(R.layout.check_info_adapter, parent, false); - CheckInfoAdapter.CheckInfoViewHolder holder = new CheckInfoAdapter.CheckInfoViewHolder(v); + CheckInfoAdapter.CheckInfoViewHolder holder = new CheckInfoViewHolder(v); return holder; } @@ -62,7 +61,7 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { if (position < showData.size() * 2) { int index = position / 2; CheckResultData.CheckListItem positionItem = showData.get(index); - if (isEven(position) == true) {//偶数隐藏图片显示检测指标 + if (isEven(position)) {//偶数隐藏图片显示检测指标 ((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.GONE); ((CheckInfoViewHolder) holder).mTextView.setText(positionItem.getName()); } else {//奇数显示图片和检测指标结果 @@ -105,9 +104,9 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { return showData.size() * 2 + mBottomCount; } - public class CheckInfoViewHolder extends RecyclerView.ViewHolder { - private ImageView checkIcon; - private TextView mTextView; + private static class CheckInfoViewHolder extends RecyclerView.ViewHolder { + private final ImageView checkIcon; + private final TextView mTextView; public CheckInfoViewHolder(View v) { super(v); @@ -116,7 +115,7 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { } } - public class CheckInfoFooter extends RecyclerView.ViewHolder { + private static class CheckInfoFooter extends RecyclerView.ViewHolder { public CheckInfoFooter(View v) { super(v); } diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoGridItemDivider.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoGridItemDivider.java index 8b678c7963..863ed6c3c0 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoGridItemDivider.java +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoGridItemDivider.java @@ -6,7 +6,6 @@ import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; -import android.util.Log; import android.view.View; import androidx.recyclerview.widget.GridLayoutManager; @@ -19,9 +18,8 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager; * @since: 9/22/21 */ public class CheckInfoGridItemDivider extends RecyclerView.ItemDecoration { - private String TAG = getClass().getSimpleName(); private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; - private Drawable divider; + private final Drawable divider; public CheckInfoGridItemDivider(Context context) { final TypedArray a = context.obtainStyledAttributes(ATTRS); @@ -44,7 +42,6 @@ public class CheckInfoGridItemDivider extends RecyclerView.ItemDecoration { @Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { - drawHorizontal(c, parent); drawVertical(c, parent); @@ -138,10 +135,7 @@ public class CheckInfoGridItemDivider extends RecyclerView.ItemDecoration { //是否为第一行 private boolean isFirstRaw(int pos, int spanCount) { - if (pos < spanCount) { - return true; - } - return false; + return pos < spanCount; } @Override diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoListDialog.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoListDialog.java index 1a170692dc..e61b7f2541 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoListDialog.java +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoListDialog.java @@ -63,7 +63,7 @@ public class CheckInfoListDialog extends BaseFloatDialog { } catch (Exception e) { e.printStackTrace(); } - List resultData = showInfoResult(); + List resultData = showInfoResult(); CheckInfoAdapter adapter = new CheckInfoAdapter(mContext, mStyle, resultData); mRecyclerView.setAdapter(adapter); //关闭按钮 @@ -72,13 +72,13 @@ public class CheckInfoListDialog extends BaseFloatDialog { }); } - public List showInfoResult() { + public List showInfoResult() { if (result.size() > 0) { result.clear(); } try { - List checkListResult = new ArrayList(); + List checkListResult = new ArrayList(); try { if (mStyle.equals(CheckItemInfo.CheckInfoStyle.CHECK_INFO_STYLE_DEVICES)) { checkListResult = mCheckResultData.getData().getDevices(); diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoRecyclerView.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoRecyclerView.java index 53b44b14bc..eea15f59ca 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoRecyclerView.java +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoRecyclerView.java @@ -15,8 +15,8 @@ import com.mogo.eagle.core.function.check.R; * @since: 9/29/21 */ public class CheckInfoRecyclerView extends RecyclerView { - private int maxHeight = (int) getContext().getResources().getDimension(R.dimen.check_height); - private int maxWeight = (int) getContext().getResources().getDimension(R.dimen.check_width); + private final int maxHeight = (int) getContext().getResources().getDimension(R.dimen.check_height); + private final int maxWeight = (int) getContext().getResources().getDimension(R.dimen.check_width); public CheckInfoRecyclerView(@NonNull Context context) { super(context); diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt index 01f0f0e0d5..3aa35ed140 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt @@ -51,6 +51,7 @@ import com.mogo.map.uicontroller.VisualAngleMode.* import com.mogo.module.common.MogoApisHandler import kotlinx.android.synthetic.main.view_debug_setting.view.* import mogo.telematics.pad.MessagePad +import mogo_msg.MogoReportMsg import java.util.* /** @@ -581,6 +582,10 @@ class DebugSettingView @JvmOverloads constructor( } + override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) { + //todo pb : 工控机异常信息回调 + + } override fun onLocationChanged(location: MogoLocation?) { diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlCmdParameter.java b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlCmdParameter.java deleted file mode 100644 index 09a900acef..0000000000 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlCmdParameter.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.mogo.eagle.core.data.autopilot; - - -/** - * @author congtaowang - * @since 2020/10/22 - * - * 域控制器 控制指令发送 - * - */ -public class AutopilotControlCmdParameter { - - public String action; - public Object result; - - public AutopilotControlCmdParameter(String action, Object result) { - this.action = action; - this.result = result; - } - - @Override - public String toString() { - return "AutoPilotControlCmdParameter{" + - "action='" + action + '\'' + - ", result=" + result + - '}'; - } -} diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlParameters.java b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlParameters.java deleted file mode 100644 index da97f3fe04..0000000000 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlParameters.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.mogo.eagle.core.data.autopilot; - -import java.util.List; - -/** - * @author donghongyu - * @since 2021/09/22 - *

- * 启动自动驾驶参数 - *

- * { - * "action": "aiCloudToStartAutopilot", - * "result": { - * "endLatLon": { - * "lat": 40.2023065, - * "lon": 116.7328583 - * }, - * "isSpeakVoice": false, - * "speedLimit": 0.0, - * "startLatLon": { - * "lat": 40.20070823669507, - * "lon": 116.73264342448671 - * }, - * "startName": "HYKXC", - * "endName": "HYJC", - * "vehicleType": 10, - * "wayLatLons": null - * } - * } - */ -public class AutopilotControlParameters { - - public String startName=""; - public String endName=""; - public AutoPilotLonLat startLatLon; - public List wayLatLons; - public AutoPilotLonLat endLatLon; - public float speedLimit; - public int vehicleType;// 运营类型 - /** - * 是否播放adas的 开始自动驾驶 语音 - */ - public boolean isSpeakVoice = true; - - public static class AutoPilotLonLat { - public double lat; - public double lon; - - public AutoPilotLonLat() { - } - - public AutoPilotLonLat(double lat, double lon) { - this.lat = lat; - this.lon = lon; - } - - @Override - public String toString() { - return "AutoPilotLonLat{" + - "lat=" + lat + - ", lon=" + lon + - '}'; - } - } - - @Override - public String toString() { - return "AutopilotControlParameters{" + - "startName='" + startName + '\'' + - ", endName='" + endName + '\'' + - ", startLatLon=" + startLatLon + - ", wayLatLons=" + wayLatLons + - ", endLatLon=" + endLatLon + - ", speedLimit=" + speedLimit + - ", vehicleType=" + vehicleType + - ", isSpeakVoice=" + isSpeakVoice + - '}'; - } -} diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlParameters.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlParameters.kt new file mode 100644 index 0000000000..8fda6801ab --- /dev/null +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/autopilot/AutopilotControlParameters.kt @@ -0,0 +1,116 @@ +package com.mogo.eagle.core.data.autopilot + +import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLonLat +import mogo.telematics.pad.MessagePad + +/** + * @author donghongyu + * @since 2021/09/22 + * + * + * 启动自动驾驶参数 + * + * + * { + * "action": "aiCloudToStartAutopilot", + * "result": { + * "endLatLon": { + * "lat": 40.2023065, + * "lon": 116.7328583 + * }, + * "isSpeakVoice": false, + * "speedLimit": 0.0, + * "startLatLon": { + * "lat": 40.20070823669507, + * "lon": 116.73264342448671 + * }, + * "startName": "HYKXC", + * "endName": "HYJC", + * "vehicleType": 10, + * "wayLatLons": null + * } + * } + */ + +fun AutopilotControlParameters.toRouteInfo(): MessagePad.RouteInfo{ + val routeInfo = MessagePad.RouteInfo.newBuilder() + val startLoc = routeInfo.startLocationBuilder + val endLoc = routeInfo.endLocationBuilder + this.startLatLon?.let { + startLoc.latitude = it.lat + startLoc.longitude = it.lon + } + this.endLatLon?.let { + endLoc.latitude = it.lat + endLoc.longitude = it.lon + } + this.wayLatLons?.forEach { + val locBuilder = MessagePad.Location.newBuilder() + locBuilder.latitude = it.lat + locBuilder.longitude = it.lon + routeInfo.addWayPoints(locBuilder.build()) + } + routeInfo.startName = this.startName + routeInfo.endName = this.endName + routeInfo.vehicleType = this.vehicleType + routeInfo.isSpeakVoice = this.isSpeakVoice + routeInfo.speedLimit = this.speedLimit.toDouble() + routeInfo.startLocation = startLoc.build() + routeInfo.endLocation = endLoc.build() + return routeInfo.build() +} + + +class AutopilotControlParameters { + @JvmField + var startName = "" + @JvmField + var endName = "" + @JvmField + var startLatLon: AutoPilotLonLat? = null + @JvmField + var wayLatLons: List? = null + @JvmField + var endLatLon: AutoPilotLonLat? = null + var speedLimit = 0f + @JvmField + var vehicleType // 运营类型 + = 0 + + /** + * 是否播放adas的 开始自动驾驶 语音 + */ + @JvmField + var isSpeakVoice = true + + class AutoPilotLonLat { + var lat = 0.0 + var lon = 0.0 + + constructor() {} + constructor(lat: Double, lon: Double) { + this.lat = lat + this.lon = lon + } + + override fun toString(): String { + return "AutoPilotLonLat{" + + "lat=" + lat + + ", lon=" + lon + + '}' + } + } + + override fun toString(): String { + return "AutopilotControlParameters{" + + "startName='" + startName + '\'' + + ", endName='" + endName + '\'' + + ", startLatLon=" + startLatLon + + ", wayLatLons=" + wayLatLons + + ", endLatLon=" + endLatLon + + ", speedLimit=" + speedLimit + + ", vehicleType=" + vehicleType + + ", isSpeakVoice=" + isSpeakVoice + + '}' + } +} \ No newline at end of file diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/deva/scene/SceneConstant.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/deva/scene/SceneConstant.kt index c97d1db6cb..b8cef5423a 100644 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/deva/scene/SceneConstant.kt +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/deva/scene/SceneConstant.kt @@ -4,20 +4,22 @@ class SceneConstant { companion object { //lib包 - const val M_ADAS = "lib-mogo-adas_" + const val M_ADAS = "LIB-ADAS_" //核心module - const val M_NETWORK = "core-network_" + const val M_NETWORK = "CORE-NETWORK_" //core业务module - const val M_DEVA = "core-impl-deva_" - const val M_OBU = "core-impl-obu_" - const val M_DISPATCH = "core-impl-dispatch_" - const val M_V2X = "core-impl-v2x_" - const val M_HMI = "core-impl-hmi_" + const val M_ADAS_IMPL = "CORE-ADAS_" + const val M_CHAT = "CORE-CHAT_" + const val M_DEVA = "CORE-DEVA_" + const val M_DISPATCH = "CORE-DISPATCH_" + const val M_HMI = "CORE-HMI_" + const val M_OBU = "CORE-OBU_" + const val M_V2X = "CORE-V2X_" //旧module - const val M_ROUTE = "old-module-service_" - const val M_OTHER = "all-modules_" + const val M_ROUTE = "OLD-MODULE-SERVICE_" + const val M_OTHER = "ALL-MODULES_" } } \ No newline at end of file diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/trafficlight/TrafficLightResult.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/trafficlight/TrafficLightResult.kt index 78d6158db9..376379889b 100644 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/trafficlight/TrafficLightResult.kt +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/trafficlight/TrafficLightResult.kt @@ -1,5 +1,7 @@ package com.mogo.eagle.core.data.trafficlight +import mogo.telematics.pad.MessagePad + fun TrafficLightResult.currentRoadTrafficLight(): TrafficLightStatus? { return TrafficLightStatusHelper.getCurrentRoadTrafficLight(this) } @@ -8,6 +10,23 @@ fun TrafficLightResult.currentRoadIsRight():Boolean{ return TrafficLightStatusHelper.currentRoadIsRight(this) } +fun TrafficLightResult.toTrafficLightDetail():MessagePad.TrafficLightDetail{ + val trafficLightBuilder = MessagePad.TrafficLightDetail.newBuilder() + val left = trafficLightBuilder.leftBuilder + val mid = trafficLightBuilder.midBuilder + val right = trafficLightBuilder.rightBuilder + left.phaseNo = this.laneList.left.phaseNo + left.color = this.laneList.left.color + left.remain = this.laneList.left.remain + mid.phaseNo = this.laneList.mid.phaseNo + mid.color = this.laneList.mid.color + mid.remain = this.laneList.mid.remain + right.phaseNo = this.laneList.right.phaseNo + right.color = this.laneList.right.color + right.remain = this.laneList.right.remain + return trafficLightBuilder.build() +} + /** * 路口红绿灯请求返回数据 */ diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoAutopilotProvider.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoAutopilotProvider.kt index a3fef27670..7a018a380b 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoAutopilotProvider.kt +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoAutopilotProvider.kt @@ -1,6 +1,7 @@ package com.mogo.eagle.core.function.api.autopilot import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters +import com.mogo.eagle.core.data.trafficlight.TrafficLightResult import com.mogo.eagle.core.function.api.base.IMoGoFunctionServerProvider /** @@ -23,6 +24,11 @@ interface IMoGoAutopilotProvider : IMoGoFunctionServerProvider { */ fun startAutoPilot(controlParameters: AutopilotControlParameters) + /** + * 给工控机透出路口红绿灯信息 + */ + fun sendTrafficLightData(trafficLightResult: TrafficLightResult) + /** * 发送json数据给 Autopilot 自动驾驶控制器 * 具体的json格式需要与@宋克难 进行沟通 @@ -118,4 +124,16 @@ interface IMoGoAutopilotProvider : IMoGoFunctionServerProvider { * isEnable = false 关闭 */ fun setControlAutopilotCarAuto(isEnable: Boolean) + + /** + * 查询工控机基础配置信息 + */ + fun getCarConfig() + + /** + * 获取全局路径 + */ + fun getGlobalPath() + + } \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotManager.kt index 12eb5ca96d..69de58bf2a 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotManager.kt @@ -3,6 +3,7 @@ package com.mogo.eagle.core.function.call.autopilot import android.os.SystemClock import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters import com.mogo.eagle.core.data.constants.MogoServicePaths +import com.mogo.eagle.core.data.trafficlight.TrafficLightResult import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotProvider import com.mogo.eagle.core.function.call.base.CallerBase import kotlin.random.Random @@ -17,8 +18,8 @@ object CallerAutoPilotManager { private val providerApi: IMoGoAutopilotProvider? get() = CallerBase.getApiInstance( - IMoGoAutopilotProvider::class.java, - MogoServicePaths.PATH_AUTO_PILOT + IMoGoAutopilotProvider::class.java, + MogoServicePaths.PATH_AUTO_PILOT ) /** @@ -44,11 +45,10 @@ object CallerAutoPilotManager { } /** - * 发送json数据给 Autopilot 自动驾驶控制器 - * 具体的json格式需要与@宋克难 进行沟通 + * 发送红绿灯数据至工控机 */ - fun sendDataToAutopilot(jsonString: String) { - providerApi?.sendMessageToAutopilot(jsonString) + fun sendTrafficLightData(trafficLightResult: TrafficLightResult) { + providerApi?.sendTrafficLightData(trafficLightResult) } /** diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/logger/CallerLogger.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/logger/CallerLogger.kt index 85f4cb6c61..ab9ad07236 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/logger/CallerLogger.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/logger/CallerLogger.kt @@ -5,25 +5,25 @@ import com.mogo.eagle.core.utilcode.mogo.logger.Logger object CallerLogger { - fun i(tag: String, message: String, any: Any) { + fun i(tag: String, message: String, any: Any? = null) { if (scene.check(tag)) { Logger.i(tag, message, any) } } - fun d(tag: String, message: String, any: Any) { + fun d(tag: String, message: String, any: Any? = null) { if (scene.check(tag)) { Logger.d(tag, message, any) } } - fun w(tag: String, message: String, any: Any) { + fun w(tag: String, message: String, any: Any? = null) { if (scene.check(tag)) { Logger.w(tag, message, any) } } - fun e(tag: String, message: String, any: Any) { + fun e(tag: String, message: String, any: Any? = null) { if (scene.check(tag)) { Logger.e(tag, message, any) } diff --git a/libraries/mogo-adas-data/consumer-rules.pro b/libraries/mogo-adas-data/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libraries/mogo-adas-data/proguard-rules.pro b/libraries/mogo-adas-data/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/libraries/mogo-adas-data/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/AdasManager.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/AdasManager.java index d3eadb9fd4..5beee029da 100644 --- a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/AdasManager.java +++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/AdasManager.java @@ -50,7 +50,6 @@ public class AdasManager implements IAdasNetCommApi { } - public void setCarConfig(MessagePad.CarConfigResp carConfig) { this.carConfig = carConfig; } @@ -127,7 +126,6 @@ public class AdasManager implements IAdasNetCommApi { } } - /** * 连接工控机 */ diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/CupidLogUtils.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/CupidLogUtils.java index a238fdba15..b63454a790 100644 --- a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/CupidLogUtils.java +++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/CupidLogUtils.java @@ -25,34 +25,34 @@ public class CupidLogUtils { if (!mIsEnableLog) { return; } - Log.i(tag, msg); + Log.i("[tag=" + tag + "]", "[data=" + msg + "]"); } public static void w(String tag, String msg) { if (!mIsEnableLog) { return; } - Log.w(tag, msg); + Log.w("[tag=" + tag + "]", "[data=" + msg + "]"); } public static void e(String tag, String msg) { if (!mIsEnableLog) { return; } - Log.e(tag, msg); + Log.e("[tag=" + tag + "]", "[data=" + msg + "]"); } public static void e(String msg) { if (!mIsEnableLog) { return; } - Log.e("elita_lib", msg); + Log.e("[tag=elita_lib]", "[data=" + msg + "]"); } public static void w(String msg) { if (!mIsEnableLog) { return; } - Log.e("elita_lib", msg); + Log.e("[tag=elita_lib]", "[data=" + msg + "]"); } } diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/FileUtils.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/FileUtils.java deleted file mode 100644 index 4376c74e9a..0000000000 --- a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/FileUtils.java +++ /dev/null @@ -1,1543 +0,0 @@ -package com.zhidao.support.adas.high.common; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.RandomAccessFile; -import java.net.URL; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; -import java.security.DigestInputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import javax.net.ssl.HttpsURLConnection; - -/** - *

- *     author: Blankj
- *     blog  : http://blankj.com
- *     time  : 2016/05/03
- *     desc  : utils about file
- * 
- */ -public final class FileUtils { - - private static final String LINE_SEP = System.getProperty("line.separator"); - - private FileUtils() { - throw new UnsupportedOperationException("u can't instantiate me..."); - } - - /** - * Return the file by path. - * - * @param filePath The path of file. - * @return the file - */ - public static File getFileByPath(final String filePath) { - return isSpace(filePath) ? null : new File(filePath); - } - - /** - * Return whether the file exists. - * - * @param filePath The path of file. - * @return {@code true}: yes
{@code false}: no - */ - public static boolean isFileExists(final String filePath) { - return isFileExists(getFileByPath(filePath)); - } - - /** - * Return whether the file exists. - * - * @param file The file. - * @return {@code true}: yes
{@code false}: no - */ - public static boolean isFileExists(final File file) { - return file != null && file.exists(); - } - - /** - * Rename the file. - * - * @param filePath The path of file. - * @param newName The new name of file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean rename(final String filePath, final String newName) { - return rename(getFileByPath(filePath), newName); - } - - /** - * Rename the file. - * - * @param file The file. - * @param newName The new name of file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean rename(final File file, final String newName) { - // file is null then return false - if (file == null) return false; - // file doesn't exist then return false - if (!file.exists()) return false; - // the new name is space then return false - if (isSpace(newName)) return false; - // the new name equals old name then return true - if (newName.equals(file.getName())) return true; - File newFile = new File(file.getParent() + File.separator + newName); - // the new name of file exists then return false - return !newFile.exists() - && file.renameTo(newFile); - } - - /** - * Return whether it is a directory. - * - * @param dirPath The path of directory. - * @return {@code true}: yes
{@code false}: no - */ - public static boolean isDir(final String dirPath) { - return isDir(getFileByPath(dirPath)); - } - - /** - * Return whether it is a directory. - * - * @param file The file. - * @return {@code true}: yes
{@code false}: no - */ - public static boolean isDir(final File file) { - return file != null && file.exists() && file.isDirectory(); - } - - /** - * Return whether it is a file. - * - * @param filePath The path of file. - * @return {@code true}: yes
{@code false}: no - */ - public static boolean isFile(final String filePath) { - return isFile(getFileByPath(filePath)); - } - - /** - * Return whether it is a file. - * - * @param file The file. - * @return {@code true}: yes
{@code false}: no - */ - public static boolean isFile(final File file) { - return file != null && file.exists() && file.isFile(); - } - - /** - * Create a directory if it doesn't exist, otherwise do nothing. - * - * @param dirPath The path of directory. - * @return {@code true}: exists or creates successfully
{@code false}: otherwise - */ - public static boolean createOrExistsDir(final String dirPath) { - return createOrExistsDir(getFileByPath(dirPath)); - } - - /** - * Create a directory if it doesn't exist, otherwise do nothing. - * - * @param file The file. - * @return {@code true}: exists or creates successfully
{@code false}: otherwise - */ - public static boolean createOrExistsDir(final File file) { - return file != null && (file.exists() ? file.isDirectory() : file.mkdirs()); - } - - /** - * Create a file if it doesn't exist, otherwise do nothing. - * - * @param filePath The path of file. - * @return {@code true}: exists or creates successfully
{@code false}: otherwise - */ - public static boolean createOrExistsFile(final String filePath) { - return createOrExistsFile(getFileByPath(filePath)); - } - - /** - * Create a file if it doesn't exist, otherwise do nothing. - * - * @param file The file. - * @return {@code true}: exists or creates successfully
{@code false}: otherwise - */ - public static boolean createOrExistsFile(final File file) { - if (file == null) return false; - if (file.exists()) return file.isFile(); - if (!createOrExistsDir(file.getParentFile())) return false; - try { - return file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } - } - - /** - * Create a file if it doesn't exist, otherwise delete old file before creating. - * - * @param filePath The path of file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean createFileByDeleteOldFile(final String filePath) { - return createFileByDeleteOldFile(getFileByPath(filePath)); - } - - /** - * Create a file if it doesn't exist, otherwise delete old file before creating. - * - * @param file The file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean createFileByDeleteOldFile(final File file) { - if (file == null) return false; - // file exists and unsuccessfully delete then return false - if (file.exists() && !file.delete()) return false; - if (!createOrExistsDir(file.getParentFile())) return false; - try { - return file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } - } - - /** - * Copy the directory. - * - * @param srcDirPath The path of source directory. - * @param destDirPath The path of destination directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean copyDir(final String srcDirPath, - final String destDirPath) { - return copyDir(getFileByPath(srcDirPath), getFileByPath(destDirPath)); - } - - /** - * Copy the directory. - * - * @param srcDirPath The path of source directory. - * @param destDirPath The path of destination directory. - * @param listener The replace listener. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean copyDir(final String srcDirPath, - final String destDirPath, - final OnReplaceListener listener) { - return copyDir(getFileByPath(srcDirPath), getFileByPath(destDirPath), listener); - } - - /** - * Copy the directory. - * - * @param srcDir The source directory. - * @param destDir The destination directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean copyDir(final File srcDir, - final File destDir) { - return copyOrMoveDir(srcDir, destDir, false); - } - - /** - * Copy the directory. - * - * @param srcDir The source directory. - * @param destDir The destination directory. - * @param listener The replace listener. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean copyDir(final File srcDir, - final File destDir, - final OnReplaceListener listener) { - return copyOrMoveDir(srcDir, destDir, listener, false); - } - - /** - * Copy the file. - * - * @param srcFilePath The path of source file. - * @param destFilePath The path of destination file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean copyFile(final String srcFilePath, - final String destFilePath) { - return copyFile(getFileByPath(srcFilePath), getFileByPath(destFilePath)); - } - - /** - * Copy the file. - * - * @param srcFilePath The path of source file. - * @param destFilePath The path of destination file. - * @param listener The replace listener. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean copyFile(final String srcFilePath, - final String destFilePath, - final OnReplaceListener listener) { - return copyFile(getFileByPath(srcFilePath), getFileByPath(destFilePath), listener); - } - - /** - * Copy the file. - * - * @param srcFile The source file. - * @param destFile The destination file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean copyFile(final File srcFile, - final File destFile) { - return copyOrMoveFile(srcFile, destFile, false); - } - - /** - * Copy the file. - * - * @param srcFile The source file. - * @param destFile The destination file. - * @param listener The replace listener. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean copyFile(final File srcFile, - final File destFile, - final OnReplaceListener listener) { - return copyOrMoveFile(srcFile, destFile, listener, false); - } - - /** - * Move the directory. - * - * @param srcDirPath The path of source directory. - * @param destDirPath The path of destination directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean moveDir(final String srcDirPath, - final String destDirPath) { - return moveDir(getFileByPath(srcDirPath), getFileByPath(destDirPath)); - } - - /** - * Move the directory. - * - * @param srcDirPath The path of source directory. - * @param destDirPath The path of destination directory. - * @param listener The replace listener. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean moveDir(final String srcDirPath, - final String destDirPath, - final OnReplaceListener listener) { - return moveDir(getFileByPath(srcDirPath), getFileByPath(destDirPath), listener); - } - - /** - * Move the directory. - * - * @param srcDir The source directory. - * @param destDir The destination directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean moveDir(final File srcDir, - final File destDir) { - return copyOrMoveDir(srcDir, destDir, true); - } - - /** - * Move the directory. - * - * @param srcDir The source directory. - * @param destDir The destination directory. - * @param listener The replace listener. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean moveDir(final File srcDir, - final File destDir, - final OnReplaceListener listener) { - return copyOrMoveDir(srcDir, destDir, listener, true); - } - - /** - * Move the file. - * - * @param srcFilePath The path of source file. - * @param destFilePath The path of destination file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean moveFile(final String srcFilePath, - final String destFilePath) { - return moveFile(getFileByPath(srcFilePath), getFileByPath(destFilePath)); - } - - /** - * Move the file. - * - * @param srcFilePath The path of source file. - * @param destFilePath The path of destination file. - * @param listener The replace listener. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean moveFile(final String srcFilePath, - final String destFilePath, - final OnReplaceListener listener) { - return moveFile(getFileByPath(srcFilePath), getFileByPath(destFilePath), listener); - } - - /** - * Move the file. - * - * @param srcFile The source file. - * @param destFile The destination file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean moveFile(final File srcFile, - final File destFile) { - return copyOrMoveFile(srcFile, destFile, true); - } - - /** - * Move the file. - * - * @param srcFile The source file. - * @param destFile The destination file. - * @param listener The replace listener. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean moveFile(final File srcFile, - final File destFile, - final OnReplaceListener listener) { - return copyOrMoveFile(srcFile, destFile, listener, true); - } - - private static boolean copyOrMoveDir(final File srcDir, - final File destDir, - final boolean isMove) { - return copyOrMoveDir(srcDir, destDir, new OnReplaceListener() { - @Override - public boolean onReplace() { - return true; - } - }, isMove); - } - - private static boolean copyOrMoveDir(final File srcDir, - final File destDir, - final OnReplaceListener listener, - final boolean isMove) { - if (srcDir == null || destDir == null) return false; - // destDir's path locate in srcDir's path then return false - String srcPath = srcDir.getPath() + File.separator; - String destPath = destDir.getPath() + File.separator; - if (destPath.contains(srcPath)) return false; - if (!srcDir.exists() || !srcDir.isDirectory()) return false; - if (destDir.exists()) { - if (listener == null || listener.onReplace()) {// require delete the old directory - if (!deleteAllInDir(destDir)) {// unsuccessfully delete then return false - return false; - } - } else { - return true; - } - } - if (!createOrExistsDir(destDir)) return false; - File[] files = srcDir.listFiles(); - for (File file : files) { - File oneDestFile = new File(destPath + file.getName()); - if (file.isFile()) { - if (!copyOrMoveFile(file, oneDestFile, listener, isMove)) return false; - } else if (file.isDirectory()) { - if (!copyOrMoveDir(file, oneDestFile, listener, isMove)) return false; - } - } - return !isMove || deleteDir(srcDir); - } - - private static boolean copyOrMoveFile(final File srcFile, - final File destFile, - final boolean isMove) { - return copyOrMoveFile(srcFile, destFile, new OnReplaceListener() { - @Override - public boolean onReplace() { - return true; - } - }, isMove); - } - - private static boolean copyOrMoveFile(final File srcFile, - final File destFile, - final OnReplaceListener listener, - final boolean isMove) { - if (srcFile == null || destFile == null) return false; - // srcFile equals destFile then return false - if (srcFile.equals(destFile)) return false; - // srcFile doesn't exist or isn't a file then return false - if (!srcFile.exists() || !srcFile.isFile()) return false; - if (destFile.exists()) { - if (listener == null || listener.onReplace()) {// require delete the old file - if (!destFile.delete()) {// unsuccessfully delete then return false - return false; - } - } else { - return true; - } - } - if (!createOrExistsDir(destFile.getParentFile())) return false; - try { - return writeFileFromIS(destFile, new FileInputStream(srcFile)) - && !(isMove && !deleteFile(srcFile)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return false; - } - } - - /** - * Delete the directory. - * - * @param filePath The path of file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean delete(final String filePath) { - return delete(getFileByPath(filePath)); - } - - /** - * Delete the directory. - * - * @param file The file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean delete(final File file) { - if (file == null) return false; - if (file.isDirectory()) { - return deleteDir(file); - } - return deleteFile(file); - } - - /** - * Delete the directory. - * - * @param dirPath The path of directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteDir(final String dirPath) { - return deleteDir(getFileByPath(dirPath)); - } - - /** - * Delete the directory. - * - * @param dir The directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteDir(final File dir) { - if (dir == null) return false; - // dir doesn't exist then return true - if (!dir.exists()) return true; - // dir isn't a directory then return false - if (!dir.isDirectory()) return false; - File[] files = dir.listFiles(); - if (files != null && files.length != 0) { - for (File file : files) { - if (file.isFile()) { - if (!file.delete()) return false; - } else if (file.isDirectory()) { - if (!deleteDir(file)) return false; - } - } - } - return dir.delete(); - } - - /** - * Delete the file. - * - * @param srcFilePath The path of source file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteFile(final String srcFilePath) { - return deleteFile(getFileByPath(srcFilePath)); - } - - /** - * Delete the file. - * - * @param file The file. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteFile(final File file) { - return file != null && (!file.exists() || file.isFile() && file.delete()); - } - - /** - * Delete the all in directory. - * - * @param dirPath The path of directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteAllInDir(final String dirPath) { - return deleteAllInDir(getFileByPath(dirPath)); - } - - /** - * Delete the all in directory. - * - * @param dir The directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteAllInDir(final File dir) { - return deleteFilesInDirWithFilter(dir, new FileFilter() { - @Override - public boolean accept(File pathname) { - return true; - } - }); - } - - /** - * Delete all files in directory. - * - * @param dirPath The path of directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteFilesInDir(final String dirPath) { - return deleteFilesInDir(getFileByPath(dirPath)); - } - - /** - * Delete all files in directory. - * - * @param dir The directory. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteFilesInDir(final File dir) { - return deleteFilesInDirWithFilter(dir, new FileFilter() { - @Override - public boolean accept(File pathname) { - return pathname.isFile(); - } - }); - } - - /** - * Delete all files that satisfy the filter in directory. - * - * @param dirPath The path of directory. - * @param filter The filter. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteFilesInDirWithFilter(final String dirPath, - final FileFilter filter) { - return deleteFilesInDirWithFilter(getFileByPath(dirPath), filter); - } - - /** - * Delete all files that satisfy the filter in directory. - * - * @param dir The directory. - * @param filter The filter. - * @return {@code true}: success
{@code false}: fail - */ - public static boolean deleteFilesInDirWithFilter(final File dir, final FileFilter filter) { - if (dir == null) return false; - // dir doesn't exist then return true - if (!dir.exists()) return true; - // dir isn't a directory then return false - if (!dir.isDirectory()) return false; - File[] files = dir.listFiles(); - if (files != null && files.length != 0) { - for (File file : files) { - if (filter.accept(file)) { - if (file.isFile()) { - if (!file.delete()) return false; - } else if (file.isDirectory()) { - if (!deleteDir(file)) return false; - } - } - } - } - return true; - } - - /** - * Return the files in directory. - *

Doesn't traverse subdirectories

- * - * @param dirPath The path of directory. - * @return the files in directory - */ - public static List listFilesInDir(final String dirPath) { - return listFilesInDir(dirPath, false); - } - - /** - * Return the files in directory. - *

Doesn't traverse subdirectories

- * - * @param dir The directory. - * @return the files in directory - */ - public static List listFilesInDir(final File dir) { - return listFilesInDir(dir, false); - } - - /** - * Return the files in directory. - * - * @param dirPath The path of directory. - * @param isRecursive True to traverse subdirectories, false otherwise. - * @return the files in directory - */ - public static List listFilesInDir(final String dirPath, final boolean isRecursive) { - return listFilesInDir(getFileByPath(dirPath), isRecursive); - } - - /** - * Return the files in directory. - * - * @param dir The directory. - * @param isRecursive True to traverse subdirectories, false otherwise. - * @return the files in directory - */ - public static List listFilesInDir(final File dir, final boolean isRecursive) { - return listFilesInDirWithFilter(dir, new FileFilter() { - @Override - public boolean accept(File pathname) { - return true; - } - }, isRecursive); - } - - /** - * Return the files that satisfy the filter in directory. - *

Doesn't traverse subdirectories

- * - * @param dirPath The path of directory. - * @param filter The filter. - * @return the files that satisfy the filter in directory - */ - public static List listFilesInDirWithFilter(final String dirPath, - final FileFilter filter) { - return listFilesInDirWithFilter(getFileByPath(dirPath), filter, false); - } - - /** - * Return the files that satisfy the filter in directory. - *

Doesn't traverse subdirectories

- * - * @param dir The directory. - * @param filter The filter. - * @return the files that satisfy the filter in directory - */ - public static List listFilesInDirWithFilter(final File dir, - final FileFilter filter) { - return listFilesInDirWithFilter(dir, filter, false); - } - - /** - * Return the files that satisfy the filter in directory. - * - * @param dirPath The path of directory. - * @param filter The filter. - * @param isRecursive True to traverse subdirectories, false otherwise. - * @return the files that satisfy the filter in directory - */ - public static List listFilesInDirWithFilter(final String dirPath, - final FileFilter filter, - final boolean isRecursive) { - return listFilesInDirWithFilter(getFileByPath(dirPath), filter, isRecursive); - } - - /** - * Return the files that satisfy the filter in directory. - * - * @param dir The directory. - * @param filter The filter. - * @param isRecursive True to traverse subdirectories, false otherwise. - * @return the files that satisfy the filter in directory - */ - public static List listFilesInDirWithFilter(final File dir, - final FileFilter filter, - final boolean isRecursive) { - if (!isDir(dir)) return null; - List list = new ArrayList<>(); - File[] files = dir.listFiles(); - if (files != null && files.length != 0) { - for (File file : files) { - if (filter.accept(file)) { - list.add(file); - } - if (isRecursive && file.isDirectory()) { - //noinspection ConstantConditions - list.addAll(listFilesInDirWithFilter(file, filter, true)); - } - } - } - return list; - } - - /** - * Return the time that the file was last modified. - * - * @param filePath The path of file. - * @return the time that the file was last modified - */ - - public static long getFileLastModified(final String filePath) { - return getFileLastModified(getFileByPath(filePath)); - } - - /** - * Return the time that the file was last modified. - * - * @param file The file. - * @return the time that the file was last modified - */ - public static long getFileLastModified(final File file) { - if (file == null) return -1; - return file.lastModified(); - } - - /** - * Return the charset of file simply. - * - * @param filePath The path of file. - * @return the charset of file simply - */ - public static String getFileCharsetSimple(final String filePath) { - return getFileCharsetSimple(getFileByPath(filePath)); - } - - /** - * Return the charset of file simply. - * - * @param file The file. - * @return the charset of file simply - */ - public static String getFileCharsetSimple(final File file) { - int p = 0; - InputStream is = null; - try { - is = new BufferedInputStream(new FileInputStream(file)); - p = (is.read() << 8) + is.read(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - switch (p) { - case 0xefbb: - return "UTF-8"; - case 0xfffe: - return "Unicode"; - case 0xfeff: - return "UTF-16BE"; - default: - return "GBK"; - } - } - - /** - * Return the number of lines of file. - * - * @param filePath The path of file. - * @return the number of lines of file - */ - public static int getFileLines(final String filePath) { - return getFileLines(getFileByPath(filePath)); - } - - /** - * Return the number of lines of file. - * - * @param file The file. - * @return the number of lines of file - */ - public static int getFileLines(final File file) { - int count = 1; - InputStream is = null; - try { - is = new BufferedInputStream(new FileInputStream(file)); - byte[] buffer = new byte[1024]; - int readChars; - if (LINE_SEP.endsWith("\n")) { - while ((readChars = is.read(buffer, 0, 1024)) != -1) { - for (int i = 0; i < readChars; ++i) { - if (buffer[i] == '\n') ++count; - } - } - } else { - while ((readChars = is.read(buffer, 0, 1024)) != -1) { - for (int i = 0; i < readChars; ++i) { - if (buffer[i] == '\r') ++count; - } - } - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - return count; - } - - /** - * Return the size of directory. - * - * @param dirPath The path of directory. - * @return the size of directory - */ - public static String getDirSize(final String dirPath) { - return getDirSize(getFileByPath(dirPath)); - } - - /** - * Return the size of directory. - * - * @param dir The directory. - * @return the size of directory - */ - public static String getDirSize(final File dir) { - long len = getDirLength(dir); - return len == -1 ? "" : byte2FitMemorySize(len); - } - - /** - * Return the length of file. - * - * @param filePath The path of file. - * @return the length of file - */ - public static String getFileSize(final String filePath) { - long len = getFileLength(filePath); - return len == -1 ? "" : byte2FitMemorySize(len); - } - - /** - * Return the length of file. - * - * @param file The file. - * @return the length of file - */ - public static String getFileSize(final File file) { - long len = getFileLength(file); - return len == -1 ? "" : byte2FitMemorySize(len); - } - - /** - * Return the length of directory. - * - * @param dirPath The path of directory. - * @return the length of directory - */ - public static long getDirLength(final String dirPath) { - return getDirLength(getFileByPath(dirPath)); - } - - /** - * Return the length of directory. - * - * @param dir The directory. - * @return the length of directory - */ - public static long getDirLength(final File dir) { - if (!isDir(dir)) return -1; - long len = 0; - File[] files = dir.listFiles(); - if (files != null && files.length != 0) { - for (File file : files) { - if (file.isDirectory()) { - len += getDirLength(file); - } else { - len += file.length(); - } - } - } - return len; - } - - /** - * Return the length of file. - * - * @param filePath The path of file. - * @return the length of file - */ - public static long getFileLength(final String filePath) { - boolean isURL = filePath.matches("[a-zA-z]+://[^\\s]*"); - if (isURL) { - try { - HttpsURLConnection conn = (HttpsURLConnection) new URL(filePath).openConnection(); - conn.setRequestProperty("Accept-Encoding", "identity"); - conn.connect(); - if (conn.getResponseCode() == 200) { - return conn.getContentLength(); - } - return -1; - } catch (IOException e) { - e.printStackTrace(); - } - } - return getFileLength(getFileByPath(filePath)); - } - - /** - * Return the length of file. - * - * @param file The file. - * @return the length of file - */ - public static long getFileLength(final File file) { - if (!isFile(file)) return -1; - return file.length(); - } - - /** - * 获取指定文件大小 - * @return - * @throws Exception - */ - public static long getFileSizeLong(File file) throws Exception - { - long size = 0; - if (file.exists()){ - FileInputStream fis = null; - fis = new FileInputStream(file); - size = fis.available(); - } - else{ - CupidLogUtils.e("获取文件大小","文件不存在!"); - } - return size; - } - - /** - * Return the MD5 of file. - * - * @param filePath The path of file. - * @return the md5 of file - */ - public static String getFileMD5ToString(final String filePath) { - File file = isSpace(filePath) ? null : new File(filePath); - return getFileMD5ToString(file); - } - - /** - * Return the MD5 of file. - * - * @param file The file. - * @return the md5 of file - */ - public static String getFileMD5ToString(final File file) { - return bytes2HexString(getFileMD5(file)); - } - - /** - * Return the MD5 of file. - * - * @param filePath The path of file. - * @return the md5 of file - */ - public static byte[] getFileMD5(final String filePath) { - return getFileMD5(getFileByPath(filePath)); - } - - /** - * Return the MD5 of file. - * - * @param file The file. - * @return the md5 of file - */ - public static byte[] getFileMD5(final File file) { - if (file == null) return null; - DigestInputStream dis = null; - try { - FileInputStream fis = new FileInputStream(file); - MessageDigest md = MessageDigest.getInstance("MD5"); - dis = new DigestInputStream(fis, md); - byte[] buffer = new byte[1024 * 256]; - while (true) { - if (!(dis.read(buffer) > 0)) break; - } - md = dis.getMessageDigest(); - return md.digest(); - } catch (NoSuchAlgorithmException | IOException e) { - e.printStackTrace(); - } finally { - try { - if (dis != null) { - dis.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - return null; - } - - /** - * Return the file's path of directory. - * - * @param file The file. - * @return the file's path of directory - */ - public static String getDirName(final File file) { - if (file == null) return ""; - return getDirName(file.getAbsolutePath()); - } - - /** - * Return the file's path of directory. - * - * @param filePath The path of file. - * @return the file's path of directory - */ - public static String getDirName(final String filePath) { - if (isSpace(filePath)) return ""; - int lastSep = filePath.lastIndexOf(File.separator); - return lastSep == -1 ? "" : filePath.substring(0, lastSep + 1); - } - - /** - * Return the name of file. - * - * @param file The file. - * @return the name of file - */ - public static String getFileName(final File file) { - if (file == null) return ""; - return getFileName(file.getAbsolutePath()); - } - - /** - * Return the name of file. - * - * @param filePath The path of file. - * @return the name of file - */ - public static String getFileName(final String filePath) { - if (isSpace(filePath)) return ""; - int lastSep = filePath.lastIndexOf(File.separator); - return lastSep == -1 ? filePath : filePath.substring(lastSep + 1); - } - - /** - * Return the name of file without extension. - * - * @param file The file. - * @return the name of file without extension - */ - public static String getFileNameNoExtension(final File file) { - if (file == null) return ""; - return getFileNameNoExtension(file.getPath()); - } - - /** - * Return the name of file without extension. - * - * @param filePath The path of file. - * @return the name of file without extension - */ - public static String getFileNameNoExtension(final String filePath) { - if (isSpace(filePath)) return ""; - int lastPoi = filePath.lastIndexOf('.'); - int lastSep = filePath.lastIndexOf(File.separator); - if (lastSep == -1) { - return (lastPoi == -1 ? filePath : filePath.substring(0, lastPoi)); - } - if (lastPoi == -1 || lastSep > lastPoi) { - return filePath.substring(lastSep + 1); - } - return filePath.substring(lastSep + 1, lastPoi); - } - - /** - * Return the extension of file. - * - * @param file The file. - * @return the extension of file - */ - public static String getFileExtension(final File file) { - if (file == null) return ""; - return getFileExtension(file.getPath()); - } - - /** - * Return the extension of file. - * - * @param filePath The path of file. - * @return the extension of file - */ - public static String getFileExtension(final String filePath) { - if (isSpace(filePath)) return ""; - int lastPoi = filePath.lastIndexOf('.'); - int lastSep = filePath.lastIndexOf(File.separator); - if (lastPoi == -1 || lastSep >= lastPoi) return ""; - return filePath.substring(lastPoi + 1); - } - - /** - * Notify system to scan the file. - * - * @param file The file. - */ - public static void notifySystemToScan(Context context, final File file) { - if (file == null || !file.exists()) return; - Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - Uri uri = Uri.fromFile(file); - intent.setData(uri); - context.sendBroadcast(intent); - } - - /** - * Notify system to scan the file. - * - * @param filePath The path of file. - */ - public static void notifySystemToScan(final Context context, final String filePath) { - notifySystemToScan(context, getFileByPath(filePath)); - } - - /////////////////////////////////////////////////////////////////////////// - // interface - /////////////////////////////////////////////////////////////////////////// - - public interface OnReplaceListener { - boolean onReplace(); - } - - /////////////////////////////////////////////////////////////////////////// - // other utils methods - /////////////////////////////////////////////////////////////////////////// - - private static final char[] HEX_DIGITS = - {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - - private static String bytes2HexString(final byte[] bytes) { - if (bytes == null) return ""; - int len = bytes.length; - if (len <= 0) return ""; - char[] ret = new char[len << 1]; - for (int i = 0, j = 0; i < len; i++) { - ret[j++] = HEX_DIGITS[bytes[i] >> 4 & 0x0f]; - ret[j++] = HEX_DIGITS[bytes[i] & 0x0f]; - } - return new String(ret); - } - - private static String byte2FitMemorySize(final long byteNum) { - if (byteNum < 0) { - return "shouldn't be less than zero!"; - } else if (byteNum < 1024) { - return String.format(Locale.getDefault(), "%.3fB", (double) byteNum); - } else if (byteNum < 1048576) { - return String.format(Locale.getDefault(), "%.3fKB", (double) byteNum / 1024); - } else if (byteNum < 1073741824) { - return String.format(Locale.getDefault(), "%.3fMB", (double) byteNum / 1048576); - } else { - return String.format(Locale.getDefault(), "%.3fGB", (double) byteNum / 1073741824); - } - } - - private static boolean isSpace(final String s) { - if (s == null) return true; - for (int i = 0, len = s.length(); i < len; ++i) { - if (!Character.isWhitespace(s.charAt(i))) { - return false; - } - } - return true; - } - - private static boolean writeFileFromIS(final File file, - final InputStream is) { - OutputStream os = null; - try { - os = new BufferedOutputStream(new FileOutputStream(file)); - byte data[] = new byte[8192]; - int len; - while ((len = is.read(data, 0, 8192)) != -1) { - os.write(data, 0, len); - } - return true; - } catch (IOException e) { - e.printStackTrace(); - return false; - } finally { - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - try { - if (os != null) { - os.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * 写文件 string - * - * @param fullFileName - * @param logContent - * @param isAppend - */ - public static void writeFile(String fullFileName, String logContent, boolean isAppend) { - FileWriter fileWriter = null; - try { - fileWriter = new FileWriter(new File(fullFileName), isAppend); - fileWriter.write(logContent); - fileWriter.write("\n"); - fileWriter.flush(); - fileWriter.close(); - } catch (Exception e) { - } finally { - BaseIoUtils.closeSilently(fileWriter); - } - } - - /** - * 获取文件路径 - * - * @param baseDir - * @param fileName - * @return - */ - public static String getFilePath(Context context, String baseDir, String fileName) { - String basePath = saveVideoBasePathDir(context, baseDir); - File file = new File(basePath + File.separator + fileName); - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - - if (!file.exists()) { - try { - file.createNewFile(); - return file.getAbsolutePath(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return file.getAbsolutePath(); - } - - /** - * 保存图片的路径 - * - * @return - */ - public static String saveVideoBasePathDir(Context context, String dirName) { - String basePath = null; - //有SD卡 - if (BaseSDCardHelper.isSDCardMounted()) { - basePath = BaseSDCardHelper.getSDCardBaseDir(); - } else { - basePath = context.getCacheDir().getAbsolutePath(); - } - - return basePath + File.separator + dirName; - - } - - /** - * 删除文件夹 - * - * @param context - * @param baseDir - */ - public static void removeAllFileDir(Context context, String baseDir) { - String basePath = saveVideoBasePathDir(context, baseDir); - File file = new File(basePath); - if (file.exists()) { - delAllFile(file.getAbsolutePath()); - } - } - - - public static boolean delAllFile(String path) { - boolean flag = false; - try { - File file = new File(path); - if (!file.exists()) { - return flag; - } - if (!file.isDirectory()) { - return flag; - } - String[] tempList = file.list(); - File temp = null; - for (int i = 0; i < tempList.length; i++) { - if (path.endsWith(File.separator)) { - temp = new File(path + tempList[i]); - } else { - temp = new File(path + File.separator + tempList[i]); - } - if (temp.isFile()) { - temp.delete(); - } - if (temp.isDirectory()) { - delAllFile(path + "/" + tempList[i]);// 先删除文件夹里面的文件 - delFolder(path + "/" + tempList[i]);// 再删除空文件夹 - flag = true; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return flag; - } - - private static void delFolder(String folderPath) { - try { - delAllFile(folderPath); // 删除完里面所有内容 - String filePath = folderPath; - filePath = filePath.toString(); - File myFilePath = new File(filePath); - myFilePath.delete(); // 删除空文件夹 - } catch (Exception e) { - e.printStackTrace(); - } - } - - - /** - * 根据byte数组生成文件 - * - * @param bytes 生成文件用到的byte数组 - */ - public static void createFileWithByte(byte[] bytes, String filePath) { - /** - * 创建File对象,其中包含文件所在的目录以及文件的命名 - */ - File file = new File(filePath); - // 创建FileOutputStream对象 - FileOutputStream outputStream = null; - // 创建BufferedOutputStream对象 - BufferedOutputStream bufferedOutputStream = null; - try { - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - if (!file.exists()) { - // 在文件系统中根据路径创建一个新的空文件 - file.createNewFile(); - } - // 获取FileOutputStream对象 - outputStream = new FileOutputStream(file); - // 获取BufferedOutputStream对象 - bufferedOutputStream = new BufferedOutputStream(outputStream); - // 往文件所在的缓冲输出流中写byte数据 - bufferedOutputStream.write(bytes); - // 刷出缓冲输出流,该步很关键,要是不执行flush()方法,那么文件的内容是空的。 - bufferedOutputStream.flush(); - } catch (Exception e) { - // 打印异常信息 - e.printStackTrace(); - } finally { - // 关闭创建的流对象 - if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (bufferedOutputStream != null) { - try { - bufferedOutputStream.close(); - } catch (Exception e2) { - e2.printStackTrace(); - } - } - } - } - - /** - * Mapped File way MappedByteBuffer 可以在处理大文件时,提升性能 - * - * @param filename - * @return - * @throws IOException - */ - public static byte[] file2ByteArray(String filename) throws IOException { - - FileChannel fc = null; - try { - fc = new RandomAccessFile(filename, "r").getChannel(); - MappedByteBuffer byteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, - fc.size()).load(); - System.out.println(byteBuffer.isLoaded()); - byte[] result = new byte[(int) fc.size()]; - if (byteBuffer.remaining() > 0) { - // System.out.println("remain"); - byteBuffer.get(result, 0, byteBuffer.remaining()); - } - return result; - } catch (IOException e) { - e.printStackTrace(); - throw e; - } finally { - try { - fc.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public static String getNowString(final java.text.DateFormat format) { - return millis2String(System.currentTimeMillis(), format); - } - - /** - * Milliseconds to the formatted time string. - * - * @param millis The milliseconds. - * @param format The format. - * @return the formatted time string - */ - public static String millis2String(final long millis, final java.text.DateFormat format) { - return format.format(new Date(millis)); - } - -} \ No newline at end of file diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/HandlerThreadManager.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/HandlerThreadManager.java deleted file mode 100644 index 94cfee8328..0000000000 --- a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/HandlerThreadManager.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.zhidao.support.adas.high.common; - -import android.os.Handler; -import android.os.HandlerThread; -import android.os.Looper; - -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -public class HandlerThreadManager { - private volatile static HandlerThread sBackgroundHandlerThread; - private volatile static HandlerThread sIOHandlerThread; - private volatile static Handler sBackgroundHandler; - private volatile static Handler sMainHandler; - - public static Handler getBackgroundHandler() { - if (sBackgroundHandler == null) { - sBackgroundHandler = new Handler(getBackgroundHandlerThread().getLooper()); - } - return sBackgroundHandler; - } - - public static HandlerThread getBackgroundHandlerThread() { - synchronized (HandlerThreadManager.class) { - if (sBackgroundHandlerThread == null) { - sBackgroundHandlerThread = new HandlerThread("autopilot_bgd_thread"); - sBackgroundHandlerThread.start(); - } - } - return sBackgroundHandlerThread; - } - - private static HandlerThread getVideoHandlerThread() { - synchronized (HandlerThreadManager.class) { - if (sIOHandlerThread == null) { - sIOHandlerThread = new HandlerThread("autopilot_video_thread"); - sIOHandlerThread.start(); - } - } - return sIOHandlerThread; - } - - - public static Handler getMainHandler() { - if (sMainHandler == null) { - sMainHandler = new Handler(Looper.getMainLooper()); - } - return sMainHandler; - } - - public static final Executor EXECUTOR = new ThreadPoolExecutor(2, 5, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue(30), - new ThreadFactory() { - private final AtomicInteger mCount = new AtomicInteger(1); - - public Thread newThread(Runnable r) { - return new Thread(r, "autopilot-thread-pool" + mCount.getAndIncrement()); - } - }); -} diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/ReportMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/ReportMessage.java index 3e2d18f928..a0635df079 100644 --- a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/ReportMessage.java +++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/ReportMessage.java @@ -22,7 +22,6 @@ public class ReportMessage extends MyAbstractMessageHandler { if (adasListener != null) { adasListener.onReportMessage(header, mogoReportMessage); } -// CupidLogUtils.e("监控事件报告--->" + mogoReportMessage.toString()); }