[DebugView]添加切换环境入口
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package com.zhjt.mogo_core_function_devatools.env
|
||||
|
||||
import android.content.Context.MODE_PRIVATE
|
||||
import android.os.Process
|
||||
import com.mogo.commons.constants.*
|
||||
import com.mogo.commons.debug.*
|
||||
import com.mogo.eagle.core.function.call.map.*
|
||||
import com.mogo.eagle.core.utilcode.mogo.storage.*
|
||||
import com.mogo.eagle.core.utilcode.util.*
|
||||
|
||||
|
||||
object EnvChangeManager {
|
||||
|
||||
private val sp = Utils.getApp().getSharedPreferences("env_change", MODE_PRIVATE)
|
||||
|
||||
private fun updateCityCode(cityCode: String?) {
|
||||
sp.edit().putString("city_code", cityCode).commit()
|
||||
}
|
||||
|
||||
private fun updateNetMode(netMode: Int) {
|
||||
sp.edit().putInt("net_mode", netMode).commit()
|
||||
}
|
||||
|
||||
private fun getConfig() : Pair<String, Int>? {
|
||||
val cityCode = sp.getString("city_code", null)
|
||||
val severType = sp.getInt("net_mode", -1)
|
||||
if (cityCode == null || severType == -1) {
|
||||
return null
|
||||
}
|
||||
return Pair(cityCode, severType)
|
||||
}
|
||||
|
||||
fun getCityName(): String {
|
||||
val cache = getConfig()
|
||||
return if (cache == null) {
|
||||
val cityCode = CallerMapLocationListenerManager.getCurrentLocation()?.cityCode ?: SharedPrefsMgr.getInstance(Utils.getApp()).getString(SharedPrefsConstants.LOCATION_CITY_CODE) ?: "010"
|
||||
updateCityCode(cityCode)
|
||||
when(cityCode) {
|
||||
"010" -> "北京"
|
||||
"0734" -> "衡阳"
|
||||
else -> "未知"
|
||||
}
|
||||
} else {
|
||||
when(cache.first) {
|
||||
"010" -> "北京"
|
||||
"0734" -> "衡阳"
|
||||
else -> "未知"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getNetMode(): String {
|
||||
val cache = getConfig()
|
||||
if (cache == null) {
|
||||
val mode = DebugConfig.getNetMode()
|
||||
updateNetMode(mode)
|
||||
return when(mode) {
|
||||
DebugConfig.NET_MODE_RELEASE -> "生产"
|
||||
DebugConfig.NET_MODE_QA -> "测试"
|
||||
DebugConfig.NET_MODE_DEMO -> "演示"
|
||||
else -> "未知"
|
||||
}
|
||||
} else {
|
||||
return when(cache.second) {
|
||||
DebugConfig.NET_MODE_RELEASE -> "生产"
|
||||
DebugConfig.NET_MODE_QA -> "测试"
|
||||
DebugConfig.NET_MODE_DEMO -> "演示"
|
||||
else -> "未知"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun changeTo(cityCode: String, netMode: Int) {
|
||||
updateCityCode(cityCode)
|
||||
updateNetMode(netMode)
|
||||
restartApp()
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
updateCityCode(null)
|
||||
updateNetMode(-1)
|
||||
restartApp()
|
||||
}
|
||||
|
||||
private fun restartApp() {
|
||||
Utils.getApp().startActivity(Utils.getApp().packageManager.getLaunchIntentForPackage(Utils.getApp().packageName))
|
||||
Process.killProcess(Process.myPid())
|
||||
}
|
||||
|
||||
fun getEnvConfig(): EnvConfig? = getConfig()?.let {
|
||||
EnvConfig(it.first, it.second,
|
||||
if (it.first == "010") 116.397446 else 112.582654,
|
||||
if (it.first == "010") 39.909004 else 26.816478)
|
||||
}
|
||||
|
||||
data class EnvConfig(val cityCode: String, val netMode: Int, val lat: Double, val lon: Double)
|
||||
}
|
||||
@@ -11,9 +11,12 @@ import android.text.Html
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.*
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import chassis.Chassis
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient
|
||||
@@ -52,6 +55,7 @@ import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.function.hmi.ui.logcatch.ILogViewListener
|
||||
import com.mogo.eagle.core.function.hmi.ui.logcatch.LogInfoView
|
||||
import com.mogo.eagle.core.function.hmi.ui.upgrade.UpgradeListAdapter
|
||||
import com.mogo.eagle.core.network.*
|
||||
import com.mogo.eagle.core.utilcode.kotlin.onClick
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.LogLevel
|
||||
@@ -66,6 +70,7 @@ import com.mogo.map.uicontroller.VisualAngleMode.*
|
||||
import com.mogo.module.service.routeoverlay.*
|
||||
import com.zhidao.easysocket.utils.L
|
||||
import com.zhidao.support.adas.high.other.permission.BackgrounderPermission
|
||||
import com.zhjt.mogo_core_function_devatools.env.*
|
||||
import kotlinx.android.synthetic.main.view_debug_setting.view.*
|
||||
import mogo.telematics.pad.MessagePad
|
||||
import mogo_msg.MogoReportMsg
|
||||
@@ -765,7 +770,7 @@ class DebugSettingView @JvmOverloads constructor(
|
||||
/**
|
||||
* 设置鹰眼本地参数配置监听
|
||||
*/
|
||||
private fun setEagleEyeConfigListener() {
|
||||
@SuppressLint("SetTextI18n") private fun setEagleEyeConfigListener() {
|
||||
//初始化刹车加速度阈值信息
|
||||
val brakeThreshold = SharedPrefsMgr.getInstance(context)
|
||||
.getFloat(MoGoConfig.BRAKE_ACCELERATION_THRESHOLD, -2.5F)
|
||||
@@ -810,6 +815,41 @@ class DebugSettingView @JvmOverloads constructor(
|
||||
tbReportWarning.visibility = GONE
|
||||
}
|
||||
|
||||
//切换环境
|
||||
tvCurEnv.text = "当前环境:${EnvChangeManager.getCityName()}${EnvChangeManager.getNetMode()}"
|
||||
btChangeEnv.onClick {
|
||||
PopupMenu(context, btChangeEnv).also { p ->
|
||||
p.menuInflater.inflate(R.menu.menu_env_pop, p.menu)
|
||||
MenuCompat.setGroupDividerEnabled(p.menu, true)
|
||||
p.setOnMenuItemClickListener { item ->
|
||||
when(item.itemId) {
|
||||
R.id.group_hy -> {
|
||||
return@setOnMenuItemClickListener false
|
||||
}
|
||||
R.id.group_bj -> {
|
||||
return@setOnMenuItemClickListener false
|
||||
}
|
||||
R.id.env_reset ->
|
||||
EnvChangeManager.reset()
|
||||
R.id.hy_product ->
|
||||
EnvChangeManager.changeTo("0734", DebugConfig.NET_MODE_RELEASE)
|
||||
R.id.hy_qa ->
|
||||
EnvChangeManager.changeTo("0734", DebugConfig.NET_MODE_QA)
|
||||
R.id.hy_demo ->
|
||||
EnvChangeManager.changeTo("0734", DebugConfig.NET_MODE_DEMO)
|
||||
R.id.bj_product ->
|
||||
EnvChangeManager.changeTo("010", DebugConfig.NET_MODE_RELEASE)
|
||||
R.id.bj_qa ->
|
||||
EnvChangeManager.changeTo("010", DebugConfig.NET_MODE_QA)
|
||||
R.id.bj_demo ->
|
||||
EnvChangeManager.changeTo("010", DebugConfig.NET_MODE_DEMO)
|
||||
else ->
|
||||
throw AssertionError("invalid item: $item")
|
||||
}
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1036,6 +1036,38 @@
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:id="@+id/llChangeEnv"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/dp_10"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCurEnv"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#1A1A1A"
|
||||
android:gravity="start"
|
||||
android:textSize="@dimen/dp_24"
|
||||
android:layout_weight="1"
|
||||
tools:text="当前环境:"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btChangeEnv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/dp_8"
|
||||
android:layout_marginStart="20px"
|
||||
android:text="切换环境"
|
||||
android:textSize="@dimen/dp_24"
|
||||
android:textColor="#1A1A1A"/>
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnBrakeThreshold"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -1046,8 +1078,8 @@
|
||||
android:paddingEnd="@dimen/dp_20"
|
||||
android:text="设置刹车加速度阈值"
|
||||
android:textSize="@dimen/dp_24"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@id/llChangeEnv"
|
||||
app:layout_constraintLeft_toLeftOf="parent" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="0dp"
|
||||
@@ -1132,12 +1164,9 @@
|
||||
android:textOff="开启异常上报提示"
|
||||
android:textOn="关闭异常上报提示"
|
||||
android:textSize="@dimen/dp_24"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnConnectServerIp"
|
||||
/>
|
||||
|
||||
app:layout_constraintTop_toBottomOf="@id/btnConnectServerIp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/tbHmiController"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2016 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:id="@+id/group_hy"
|
||||
android:title="衡阳">
|
||||
<menu>
|
||||
<item android:id="@+id/hy_product" android:title="生产环境"/>
|
||||
<item android:id="@+id/hy_qa" android:title="测试环境"/>
|
||||
<item android:id="@+id/hy_demo" android:title="演示环境"/>
|
||||
</menu>
|
||||
</item>
|
||||
<item android:id="@+id/group_bj"
|
||||
android:title="北京">
|
||||
<menu>
|
||||
<item android:id="@+id/bj_product" android:title="生产环境"/>
|
||||
<item android:id="@+id/bj_qa" android:title="测试环境"/>
|
||||
<item android:id="@+id/bj_demo" android:title="演示环境"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item android:id="@+id/env_reset" android:title="重置" />
|
||||
</menu>
|
||||
Reference in New Issue
Block a user