Merge branch 'dev_minibus-d_230425_3.2.0' of gitlab.zhidaoauto.com:SCA/L4HA/AndroidApp/MoGoEagleEye into dev_minibus-d_230425_3.2.0
This commit is contained in:
1
app_ipc_monitoring/.gitignore
vendored
1
app_ipc_monitoring/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1 +0,0 @@
|
||||
# 工控机测试程序
|
||||
@@ -1,245 +0,0 @@
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
// 定义当前gradle文件的全局变量
|
||||
ext {
|
||||
//主版本号
|
||||
MAJOR_VERSION = 1
|
||||
//次版本号
|
||||
MINOR_VERSION = 0
|
||||
createFile()
|
||||
buildTimes = getBuildTime()
|
||||
isRelease = checkRelease()
|
||||
gitBranchName = getWorkingBranchName()
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
defaultConfig {
|
||||
applicationId "com.zhidao.adas.client"
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
targetSdkVersion 25
|
||||
multiDexEnabled true
|
||||
versionCode increasedVersionCode()
|
||||
versionName increasedVersionName()
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
flavorDimensions "multi_device"
|
||||
|
||||
packagingOptions {
|
||||
//解决编译时com.android.builder.merge.DuplicateRelativeFileException: More than one file was found with OS independent path 'META-INF/rxjava.properties'这个错误
|
||||
exclude 'META-INF/rxjava.properties'
|
||||
}
|
||||
externalNativeBuild {
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
keyAlias 'CarLauncher'
|
||||
keyPassword 'ZDauto123456'
|
||||
storeFile file(getProjectDir().getParent() + '/keystore/car_launcher.jks')
|
||||
storePassword 'ZDauto123456'
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
debug {
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
signingConfig signingConfigs.release
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
//配置自定义打包名称
|
||||
applicationVariants.all { variant ->
|
||||
def buildTypeName = variant.buildType.name
|
||||
//println("buildTypeName-------->" + buildTypeName)
|
||||
variant.outputs.all {
|
||||
StringBuffer buffer = new StringBuffer()
|
||||
buffer.append(getProject().name)
|
||||
buffer.append("_")
|
||||
buffer.append(defaultConfig.versionName)
|
||||
buffer.append(".")
|
||||
buffer.append(buildTimes)
|
||||
buffer.append("_")
|
||||
buffer.append(gitBranchName)
|
||||
buffer.append("_")
|
||||
//获取渠道编号
|
||||
String flavor = variant.flavorName
|
||||
if (flavor != null && flavor != "") {
|
||||
buffer.append(flavor)
|
||||
buffer.append("_")
|
||||
}
|
||||
//获取打包时间
|
||||
def fileName = "${buffer.toString()}${buildTypeName}.apk"
|
||||
//测试文件名称
|
||||
buildConfigField 'String', 'APK_NAME', "\"${fileName}\""
|
||||
//println("fileName-------->" + fileName)
|
||||
//这里修改apk文件名
|
||||
outputFileName = fileName
|
||||
}
|
||||
}
|
||||
|
||||
//插入构建时间
|
||||
buildTypes.each {
|
||||
it.buildConfigField 'String', 'BUILD_TIME', "\"${buildTimes}\""
|
||||
it.buildConfigField 'String', 'GIT_BRANCH_NAME', "\"${gitBranchName}\""
|
||||
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_TAXI', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_P);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
||||
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_BUS', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_N);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
||||
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_M1', 'null'
|
||||
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_M2', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_N);add(chassis.Chassis.GearPosition.GEAR_P);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
||||
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_SWEEPER', 'null'
|
||||
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_VAN', 'null'
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
productFlavors {
|
||||
passenger {
|
||||
dimension "multi_device"
|
||||
buildConfigField 'boolean', 'IS_CLIENT', 'true'
|
||||
}
|
||||
driver {
|
||||
dimension "multi_device"
|
||||
buildConfigField 'boolean', 'IS_CLIENT', 'false'
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
lintOptions {
|
||||
checkReleaseBuilds false
|
||||
// Or, if you prefer, you can continue to check for errors in release builds,
|
||||
// but continue the build even when errors are found:
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation rootProject.ext.dependencies.material
|
||||
implementation rootProject.ext.dependencies.androidxconstraintlayout
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
implementation "androidx.recyclerview:recyclerview:1.2.0"
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
implementation rootProject.ext.dependencies.gson
|
||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||
implementation project(':libraries:mogo-adas')
|
||||
implementation project(':libraries:mogo-adas-data')
|
||||
implementation project(':libraries:mogo-obu')
|
||||
// implementation 'com.zhidao.support.adas:high:2.8.0.0'
|
||||
// implementation 'com.zhjt.mogo.adas.data:adas-data:2.6.6.0'
|
||||
// compileOnly project(':core:mogo-core-data')
|
||||
// implementation project(':core:mogo-core-utils')
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'com.android.support:multidex:1.0.3'
|
||||
// implementation 'com.mogo.cloud:telematic:1.3.59'//注释掉司机端 乘客端
|
||||
implementation 'com.jcraft:jsch:0.1.55'
|
||||
}
|
||||
|
||||
// 删除老的APK
|
||||
def checkRelease() {
|
||||
def runTasks = gradle.startParameter.taskNames
|
||||
for (String task : runTasks) {
|
||||
// 我这里认为执行“assembleRelease”和非“debug”的任务就是执行“release”的任务
|
||||
if (task.contains("assembleRelease") || task.contains("Release")) {
|
||||
deleteOldAPK("release")
|
||||
return true
|
||||
} else if (task.contains("Debug")) {
|
||||
deleteOldAPK("debug")
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
//在Moudle 根目录中创建gradle.properties文件存储VersionCode
|
||||
def createFile() {
|
||||
def propFile = file('./gradle.properties')
|
||||
Properties props = new Properties()
|
||||
if (!propFile.exists()) {
|
||||
propFile.createNewFile()
|
||||
props.load(new FileInputStream(propFile))
|
||||
props['VERSION_CODE'] = '1'
|
||||
props.store(propFile.newWriter(), null)
|
||||
} else {
|
||||
props.load(new FileInputStream(propFile))
|
||||
def code = props['VERSION_CODE']
|
||||
if (code == null || code == "0") {
|
||||
props['VERSION_CODE'] = '1'
|
||||
props.store(propFile.newWriter(), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
//读取VersionCode
|
||||
def readVersionCode() {
|
||||
def propFile = file('./gradle.properties')
|
||||
Properties props = new Properties()
|
||||
props.load(new FileInputStream(propFile))
|
||||
// 读取gradle.properties文件中定义的VERSION_CODE属性
|
||||
def code = props['VERSION_CODE'].toInteger()
|
||||
//def code = props.getProperty('VERSION_CODE').toInteger()
|
||||
return code
|
||||
}
|
||||
//当打包的是Release版本时自动更新VersionCode
|
||||
def increasedVersionCode() {
|
||||
def code = readVersionCode()
|
||||
//println("isRelease====" + isRelease)
|
||||
if (isRelease) {
|
||||
code++
|
||||
def propFile = file('./gradle.properties')
|
||||
Properties props = new Properties()
|
||||
props.load(new FileInputStream(propFile))
|
||||
props['VERSION_CODE'] = code.toString()
|
||||
// 将最新的versionCode写入gradle.properties文件中
|
||||
props.store(propFile.newWriter(), null)
|
||||
}
|
||||
return code
|
||||
}
|
||||
|
||||
//删除无用apk
|
||||
def deleteOldAPK(String buildTypeName) {
|
||||
|
||||
// 使用map创建一个树
|
||||
def tree = fileTree(dir: './build/outputs/apk', include: "${buildTypeName}/*.apk")
|
||||
//println("文件个数:" + tree.size())
|
||||
// 遍历文件树
|
||||
tree.each { File file ->
|
||||
//println("删除文件名称:" + file)
|
||||
file.delete()
|
||||
}
|
||||
}
|
||||
|
||||
def increasedVersionName() {
|
||||
def versionName = "${MAJOR_VERSION}.${MINOR_VERSION}.${readVersionCode()}"
|
||||
return versionName
|
||||
}
|
||||
|
||||
def getBuildTime() {
|
||||
//设置时间格式
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd.HHmmss", Locale.getDefault())
|
||||
//获取当前时间
|
||||
Date curDate = new Date(System.currentTimeMillis())
|
||||
return formatter.format(curDate)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 获取当前分支名称
|
||||
*/
|
||||
def getWorkingBranchName() {
|
||||
def workingBranchName = ""
|
||||
def proc = "git rev-parse --abbrev-ref HEAD".execute()
|
||||
proc.in.eachLine { line -> workingBranchName = line }
|
||||
proc.err.eachLine { line -> println line }
|
||||
proc.waitFor()
|
||||
workingBranchName = "${workingBranchName}"
|
||||
println "Working branch name: " + workingBranchName
|
||||
return workingBranchName
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
#Fri Mar 31 13:39:14 CST 2023
|
||||
VERSION_CODE=4
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
26
app_ipc_monitoring/proguard-rules.pro
vendored
26
app_ipc_monitoring/proguard-rules.pro
vendored
@@ -1,26 +0,0 @@
|
||||
# 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
|
||||
|
||||
#-----MogoMap-----
|
||||
-keep class com.mogo.map.MogoNavi{
|
||||
private <init>();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.zhidao.adas.client;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("com.zhidao.adas.client", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.zhidao.adas.client">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.DEVICE_POWER"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
|
||||
<uses-permission android:name="android.permission.READ_CALL_LOG" />
|
||||
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
|
||||
<uses-permission android:name="com.android.voicemail.permission.ADD_VOICEMAIL" />
|
||||
<uses-permission android:name="android.permission.USE_SIP" />
|
||||
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 用于进行网络定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 用于访问GPS定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.AutopilotConfigActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.HelpActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".other.permission.PermissionLongBackgroundRunningDialog"
|
||||
android:theme="@style/PermissionLongBackgroundRunningDialogStyle" />
|
||||
<activity
|
||||
android:name=".other.router.RouterActivity"
|
||||
android:theme="@style/NoActionBar" />
|
||||
<!-- 开机启动 -->
|
||||
<receiver
|
||||
android:name="BootCompletedReceive"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
|
||||
android:process=":daemon">
|
||||
<intent-filter android:priority="1000">
|
||||
<action
|
||||
android:name="android.net.conn.CONNECTIVITY_CHANGE"
|
||||
tools:ignore="BatteryLife" />
|
||||
<action android:name="android.net.ethernet.ETH_STATE_CHANGED" />
|
||||
<action android:name="mitv.network.ethernet.action.ETHERNET_STATE_CHANGED" />
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.USER_PRESENT" />
|
||||
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
|
||||
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
|
||||
<action android:name="com.duokan.duokanplayer.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.LETV_SCREENON" />
|
||||
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.android.server.action.NETWORK_STATS_UPDATED" />
|
||||
<action android:name="android.intent.action.MEDIA_MOUNTED" />
|
||||
<action android:name="android.intent.action.MEDIA_UNMOUNTED" />
|
||||
<action android:name="android.intent.action.MEDIA_EJECT" />
|
||||
|
||||
<data android:scheme="file" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.zhidao.adas.client;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.zhidao.adas.client.utils.CrashHandler;
|
||||
|
||||
import chassis.Chassis;
|
||||
|
||||
public class App extends Application {
|
||||
public static App INSTANCE;
|
||||
|
||||
public Chassis.GearPosition gear;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
INSTANCE = this;
|
||||
CrashHandler.getInstance().init(this);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.zhidao.adas.client;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class BootCompletedReceive extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.i("开机", "启动");
|
||||
}
|
||||
}
|
||||
@@ -1,705 +0,0 @@
|
||||
package com.zhidao.adas.client;
|
||||
|
||||
import android.util.Pair;
|
||||
|
||||
import com.zhidao.adas.client.bean.BaseInfo;
|
||||
import com.zhidao.adas.client.bean.DataShow;
|
||||
import com.zhidao.adas.client.bean.ErrorData;
|
||||
import com.zhidao.adas.client.bean.ObuMap;
|
||||
import com.zhidao.adas.client.bean.ObuRsi;
|
||||
import com.zhidao.adas.client.bean.ObuRsm;
|
||||
import com.zhidao.adas.client.bean.ObuSpat;
|
||||
import com.zhidao.adas.client.bean.PerceptionTrafficLight;
|
||||
import com.zhidao.adas.client.bean.PlanningDecisionState;
|
||||
import com.zhidao.adas.client.bean.PlanningObjects;
|
||||
import com.zhidao.adas.client.bean.PredictionObstacleTrajectory;
|
||||
import com.zhidao.adas.client.bean.RecordDataConfig;
|
||||
import com.zhidao.adas.client.bean.RecordPanel;
|
||||
import com.zhidao.adas.client.bean.RoboSweeperTaskIndex;
|
||||
import com.zhidao.adas.client.bean.StatusInfo;
|
||||
import com.zhidao.adas.client.bean.TrackedObjects;
|
||||
import com.zhidao.adas.client.bean.Trajectory;
|
||||
import com.zhidao.adas.client.bean.Warn;
|
||||
import com.zhidao.adas.client.log.LogSave;
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
import com.zhidao.support.adas.high.common.ThreadPoolManager;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* 数据分发
|
||||
*/
|
||||
public class DataDistribution {
|
||||
private static final String TAG = DataDistribution.class.getSimpleName();
|
||||
private volatile static DataDistribution INSTANCE;
|
||||
private final LinkedBlockingQueue<BaseInfo> queue;
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS ", Locale.getDefault());
|
||||
private Future future;
|
||||
private Pair<String, OnAdasClientListener> listener;
|
||||
private volatile boolean isCutDown = true;//是否缩短日志显示
|
||||
private int resId = R.id.rb_analysis;
|
||||
|
||||
private DataDistribution() {
|
||||
queue = new LinkedBlockingQueue<>();
|
||||
start();
|
||||
}
|
||||
|
||||
public static DataDistribution getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (DataDistribution.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new DataDistribution();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void setResId(int resId) {
|
||||
this.resId = resId;
|
||||
}
|
||||
|
||||
public void registerAdasClientListener(Pair<String, OnAdasClientListener> listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void unregisterAdasClientListener(Pair<String, OnAdasClientListener> listener) {
|
||||
if (this.listener != null && listener != null)
|
||||
if (listener.second.hashCode() == this.listener.second.hashCode()) {
|
||||
this.listener = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addData(BaseInfo info) {
|
||||
queue.add(info);
|
||||
}
|
||||
|
||||
|
||||
public void start() {
|
||||
if (future == null) {
|
||||
future = ThreadPoolManager.getsInstance().submit(new WriteThread());
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
queue.clear();
|
||||
if (future != null && !future.isCancelled()) {
|
||||
future.cancel(true);
|
||||
}
|
||||
future = null;
|
||||
}
|
||||
|
||||
public void setCutDown(boolean cutDown) {
|
||||
this.isCutDown = cutDown;
|
||||
}
|
||||
|
||||
private static final int LIST_SIZE = 30;//默认list最大数据量
|
||||
public final List<DataShow> listTrajectory = new ArrayList<>();
|
||||
public final List<DataShow> listTrackedObjects = new ArrayList<>();
|
||||
public final List<DataShow> listGnssInfo = new ArrayList<>();
|
||||
public final List<DataShow> listVehicleState = new ArrayList<>();
|
||||
public final List<DataShow> listAutopilotState = new ArrayList<>();
|
||||
public final List<DataShow> listMogoReportMessage = new ArrayList<>();
|
||||
public final List<DataShow> listPerceptionTrafficLight = new ArrayList<>();
|
||||
public final List<DataShow> listPredictionObstacleTrajectory = new ArrayList<>();
|
||||
public final List<DataShow> listRecordPanel = new ArrayList<>();
|
||||
public final List<DataShow> listGlobalPathResp = new ArrayList<>();
|
||||
public final List<DataShow> listWarn = new ArrayList<>();
|
||||
public final List<DataShow> listArrivalNotification = new ArrayList<>();
|
||||
public final List<DataShow> listStatusInfo = new ArrayList<>();
|
||||
public final List<DataShow> listRecordDataConfig = new ArrayList<>();
|
||||
public final List<DataShow> listErrorData = new ArrayList<>();
|
||||
public final List<DataShow> listOriginalPointCloud = new ArrayList<>();
|
||||
public final List<DataShow> listPlanningObjects = new ArrayList<>();
|
||||
public final List<DataShow> listPlanningDecisionState = new ArrayList<>();
|
||||
public final List<DataShow> listChassisStates = new ArrayList<>();
|
||||
public final List<DataShow> listFSMFunctionStates = new ArrayList<>();
|
||||
public final List<DataShow> listBackCameraVideo = new ArrayList<>();
|
||||
public final List<DataShow> listRoboSweeperTaskIndex = new ArrayList<>();
|
||||
public final List<DataShow> listBagManagerCmd = new ArrayList<>();
|
||||
public final List<DataShow> listObuSpat = new ArrayList<>();
|
||||
public final List<DataShow> listObuRsi = new ArrayList<>();
|
||||
public final List<DataShow> listObuRsm = new ArrayList<>();
|
||||
public final List<DataShow> listObuMap = new ArrayList<>();
|
||||
public final List<DataShow> listV2nCongestionEvent = new ArrayList<>();
|
||||
public final List<DataShow> listV2nGlobalPathEvents = new ArrayList<>();
|
||||
public final List<DataShow> listGetParamResp = new ArrayList<>();
|
||||
|
||||
private long listTrajectorySize = 0;
|
||||
private long listTrackedObjectsSize = 0;
|
||||
private long listGnssInfoSize = 0;
|
||||
private long listVehicleStateSize = 0;
|
||||
private long listAutopilotStateSize = 0;
|
||||
private long listMogoReportMessageSize = 0;
|
||||
private long listPerceptionTrafficLightSize = 0;
|
||||
private long listPredictionObstacleTrajectorySize = 0;
|
||||
private long listRecordPanelSize = 0;
|
||||
private long listGlobalPathRespSize = 0;
|
||||
private long listWarnSize = 0;
|
||||
private long listArrivalNotificationSize = 0;
|
||||
private long listStatusInfoSize = 0;
|
||||
private long listRecordDataConfigSize = 0;
|
||||
private long listErrorDataSize = 0;
|
||||
private long listOriginalPointCloudSize = 0;
|
||||
private long listPlanningObjectsSize = 0;
|
||||
private long listPlanningDecisionStateSize = 0;
|
||||
private long listChassisStatesSize = 0;
|
||||
private long listFSMFunctionStatesSize = 0;
|
||||
private long listBackCameraVideoSize = 0;
|
||||
private long listRoboSweeperTaskIndexSize = 0;
|
||||
private long listBagManagerCmdSize = 0;
|
||||
private long listObuSpatSize = 0;
|
||||
private long listObuRsiSize = 0;
|
||||
private long listObuRsmSize = 0;
|
||||
private long listObuMapSize = 0;
|
||||
private long listV2nCongestionEventSize = 0;
|
||||
private long listV2nGlobalPathEventsSize = 0;
|
||||
private long listGetParamRespSize = 0;
|
||||
|
||||
public void clearCount() {
|
||||
listTrajectorySize = 1;
|
||||
listTrackedObjectsSize = 1;
|
||||
listGnssInfoSize = 1;
|
||||
listVehicleStateSize = 1;
|
||||
listAutopilotStateSize = 1;
|
||||
listMogoReportMessageSize = 1;
|
||||
listPerceptionTrafficLightSize = 1;
|
||||
listPredictionObstacleTrajectorySize = 1;
|
||||
listRecordPanelSize = 1;
|
||||
listGlobalPathRespSize = 1;
|
||||
listWarnSize = 1;
|
||||
listArrivalNotificationSize = 1;
|
||||
listStatusInfoSize = 1;
|
||||
listRecordDataConfigSize = 1;
|
||||
listErrorDataSize = 1;
|
||||
listOriginalPointCloudSize = 1;
|
||||
listPlanningObjectsSize = 1;
|
||||
listPlanningDecisionStateSize = 1;
|
||||
listChassisStatesSize = 1;
|
||||
listFSMFunctionStatesSize = 1;
|
||||
listBackCameraVideoSize = 1;
|
||||
listRoboSweeperTaskIndexSize = 1;
|
||||
listBagManagerCmdSize = 1;
|
||||
listObuSpatSize = 1;
|
||||
listObuRsiSize = 1;
|
||||
listObuRsmSize = 1;
|
||||
listObuMapSize = 1;
|
||||
listV2nCongestionEventSize = 1;
|
||||
listV2nGlobalPathEventsSize = 1;
|
||||
listGetParamRespSize = 1;
|
||||
}
|
||||
|
||||
public String cutDown(String str) {
|
||||
if (isCutDown && str.length() > 850) {
|
||||
str = str.substring(0, 850) + "\n(已缩短。如需查看完整数据,请勾选日志缩短复选框)";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
private String onTransmit(String time, BaseInfo data) {
|
||||
String temp = data.toString(resId);
|
||||
String str = cutDown(temp);
|
||||
if (data instanceof Trajectory) {
|
||||
listTrajectory.add(0, new DataShow(listTrajectorySize++, time + str));
|
||||
if (listTrajectory.size() > LIST_SIZE) {
|
||||
listTrajectory.remove(listTrajectory.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_TRAJECTORY.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof TrackedObjects) {
|
||||
listTrackedObjects.add(0, new DataShow(listTrackedObjectsSize++, time + str));
|
||||
if (listTrackedObjects.size() > LIST_SIZE) {
|
||||
listTrackedObjects.remove(listTrackedObjects.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_TRACKED_OBJECTS.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof OriginalPointCloudData) {
|
||||
listOriginalPointCloud.add(0, new DataShow(listOriginalPointCloudSize++, time + str));
|
||||
if (listOriginalPointCloud.size() > LIST_SIZE) {
|
||||
listOriginalPointCloud.remove(listOriginalPointCloud.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_POINT_CLOUD_ORIGINAL.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof PlanningObjects) {
|
||||
listPlanningObjects.add(0, new DataShow(listPlanningObjectsSize++, time + str));
|
||||
if (listPlanningObjects.size() > LIST_SIZE) {
|
||||
listPlanningObjects.remove(listPlanningObjects.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_PLANNING_OBJECTS.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof PlanningDecisionState) {
|
||||
listPlanningDecisionState.add(0, new DataShow(listPlanningDecisionStateSize++, time + str));
|
||||
if (listPlanningDecisionState.size() > LIST_SIZE) {
|
||||
listPlanningDecisionState.remove(listPlanningDecisionState.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_PLANNING_DECISION_STATE.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ObuSpat) {
|
||||
listObuSpat.add(0, new DataShow(listObuSpatSize++, time + str));
|
||||
if (listObuSpat.size() > LIST_SIZE) {
|
||||
listObuSpat.remove(listObuSpat.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_OBU_SPAT.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ObuRsi) {
|
||||
listObuRsi.add(0, new DataShow(listObuRsiSize++, time + str));
|
||||
if (listObuRsi.size() > LIST_SIZE) {
|
||||
listObuRsi.remove(listObuRsi.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_OBU_RSI.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ObuRsm) {
|
||||
listObuRsm.add(0, new DataShow(listObuRsmSize++, time + str));
|
||||
if (listObuRsm.size() > LIST_SIZE) {
|
||||
listObuRsm.remove(listObuRsm.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_OBU_RSM.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ObuMap) {
|
||||
listObuMap.add(0, new DataShow(listObuMapSize++, time + str));
|
||||
if (listObuMap.size() > LIST_SIZE) {
|
||||
listObuMap.remove(listObuMap.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_OBU_MAP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof GnssInfo) {
|
||||
listGnssInfo.add(0, new DataShow(listGnssInfoSize++, time + str));
|
||||
if (listGnssInfo.size() > LIST_SIZE) {
|
||||
listGnssInfo.remove(listGnssInfo.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_GNSS_INFO.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof VehicleState) {
|
||||
listVehicleState.add(0, new DataShow(listVehicleStateSize++, time + str));
|
||||
if (listVehicleState.size() > LIST_SIZE) {
|
||||
listVehicleState.remove(listVehicleState.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_VEHICLE_STATE.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ChassisStates) {
|
||||
listChassisStates.add(0, new DataShow(listChassisStatesSize++, time + str));
|
||||
if (listChassisStates.size() > LIST_SIZE) {
|
||||
listChassisStates.remove(listChassisStates.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_CHASSIS_STATES.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof AutopilotState) {
|
||||
listAutopilotState.add(0, new DataShow(listAutopilotStateSize++, time + str));
|
||||
if (listAutopilotState.size() > LIST_SIZE) {
|
||||
listAutopilotState.remove(listAutopilotState.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_AUTOPILOT_STATE.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof MogoReportMessage) {
|
||||
listMogoReportMessage.add(0, new DataShow(listMogoReportMessageSize++, time + str));
|
||||
if (listMogoReportMessage.size() > LIST_SIZE) {
|
||||
listMogoReportMessage.remove(listMogoReportMessage.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_REPORT_MESSAGE.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof PerceptionTrafficLight) {
|
||||
listPerceptionTrafficLight.add(0, new DataShow(listPerceptionTrafficLightSize++, time + str));
|
||||
if (listPerceptionTrafficLight.size() > LIST_SIZE) {
|
||||
listPerceptionTrafficLight.remove(listPerceptionTrafficLight.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_PERCEPTION_TRAFFIC_LIGHT.equals(listener.first)) {
|
||||
listener.second.onPerceptionTrafficLight((PerceptionTrafficLight) data);
|
||||
}
|
||||
} else if (data instanceof PredictionObstacleTrajectory) {
|
||||
listPredictionObstacleTrajectory.add(0, new DataShow(listPredictionObstacleTrajectorySize++, time + str));
|
||||
if (listPredictionObstacleTrajectory.size() > LIST_SIZE) {
|
||||
listPredictionObstacleTrajectory.remove(listPredictionObstacleTrajectory.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof BasicInfoReq) {
|
||||
|
||||
} else if (data instanceof CarConfigResp) {
|
||||
if (listener != null && Constants.TITLE.TITLE_CAR_CONFIG_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof RecordPanel) {
|
||||
listRecordPanel.add(0, new DataShow(listRecordPanelSize++, time + str));
|
||||
if (listRecordPanel.size() > LIST_SIZE) {
|
||||
listRecordPanel.remove(listRecordPanel.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_RECORD_RESULT.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof BagManagerCmd) {
|
||||
listBagManagerCmd.add(0, new DataShow(listBagManagerCmdSize++, time + str));
|
||||
if (listBagManagerCmd.size() > LIST_SIZE) {
|
||||
listBagManagerCmd.remove(listBagManagerCmd.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_BAG_MANAGER_CMD.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof GlobalPathResp) {
|
||||
listGlobalPathResp.add(0, new DataShow(listGlobalPathRespSize++, time + str));
|
||||
if (listGlobalPathResp.size() > LIST_SIZE) {
|
||||
listGlobalPathResp.remove(listGlobalPathResp.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_GLOBAL_PATH_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof Warn) {
|
||||
listWarn.add(0, new DataShow(listWarnSize++, time + str));
|
||||
if (listWarn.size() > LIST_SIZE) {
|
||||
listWarn.remove(listWarn.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_WARN.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ArrivalNotification) {
|
||||
listArrivalNotification.add(0, new DataShow(listArrivalNotificationSize++, time + str));
|
||||
if (listArrivalNotification.size() > LIST_SIZE) {
|
||||
listArrivalNotification.remove(listArrivalNotification.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_ARRIVAL_NOTIFICATION.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof StatusInfo) {
|
||||
listStatusInfo.add(0, new DataShow(listStatusInfoSize++, time + str));
|
||||
if (listStatusInfo.size() > LIST_SIZE) {
|
||||
listStatusInfo.remove(listStatusInfo.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_STATUS_QUERY_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof RecordDataConfig) {
|
||||
listRecordDataConfig.add(0, new DataShow(listRecordDataConfigSize++, time + str));
|
||||
if (listRecordDataConfig.size() > LIST_SIZE) {
|
||||
listRecordDataConfig.remove(listRecordDataConfig.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_RECORD_DATA_CONFIG_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof RoboSweeperTaskIndex) {
|
||||
listRoboSweeperTaskIndex.add(0, time + str);
|
||||
if (listRoboSweeperTaskIndex.size() > LIST_SIZE) {
|
||||
listRoboSweeperTaskIndex.remove(listRoboSweeperTaskIndex.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_SWEEPER_TASK_INDEX_DATA.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof RoboSweeperTaskIndex) {
|
||||
listRoboSweeperTaskIndex.add(0, new DataShow(listRoboSweeperTaskIndexSize++, time + str));
|
||||
if (listRoboSweeperTaskIndex.size() > LIST_SIZE) {
|
||||
listRoboSweeperTaskIndex.remove(listRoboSweeperTaskIndex.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_SWEEPER_TASK_INDEX_DATA.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof FSMFunctionStates) {
|
||||
listFSMFunctionStates.add(0, new DataShow(listFSMFunctionStatesSize++, time + str));
|
||||
if (listFSMFunctionStates.size() > LIST_SIZE) {
|
||||
listFSMFunctionStates.remove(listFSMFunctionStates.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_FUNCTION_STATES.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ErrorData) {
|
||||
listErrorData.add(0, new DataShow(listErrorDataSize++, time + str));
|
||||
if (listErrorData.size() > 100) {
|
||||
listErrorData.remove(listErrorData.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_ERROR.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
if (data.header == null) {
|
||||
if (data instanceof ErrorData) {
|
||||
listErrorData.add(0, new DataShow(listErrorDataSize++, time + str));
|
||||
if (listErrorData.size() > 100) {
|
||||
listErrorData.remove(listErrorData.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_ERROR.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MessagePad.MessageType messageType = data.header.getMsgType();
|
||||
if (messageType == MessagePad.MessageType.MsgTypeTrajectory) {
|
||||
listTrajectory.add(0, new DataShow(listTrajectorySize++, time + str));
|
||||
if (listTrajectory.size() > LIST_SIZE) {
|
||||
listTrajectory.remove(listTrajectory.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_TRAJECTORY.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeTrackedObjects) {
|
||||
listTrackedObjects.add(0, new DataShow(listTrackedObjectsSize++, time + str));
|
||||
if (listTrackedObjects.size() > LIST_SIZE) {
|
||||
listTrackedObjects.remove(listTrackedObjects.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_TRACKED_OBJECTS.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypePlanningObjects) {
|
||||
listPlanningObjects.add(0, new DataShow(listPlanningObjectsSize++, time + str));
|
||||
if (listPlanningObjects.size() > LIST_SIZE) {
|
||||
listPlanningObjects.remove(listPlanningObjects.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_PLANNING_OBJECTS.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypePlanningDecisionState) {
|
||||
listPlanningDecisionState.add(0, new DataShow(listPlanningDecisionStateSize++, time + str));
|
||||
if (listPlanningDecisionState.size() > LIST_SIZE) {
|
||||
listPlanningDecisionState.remove(listPlanningDecisionState.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_PLANNING_DECISION_STATE.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeGnssInfo) {
|
||||
listGnssInfo.add(0, new DataShow(listGnssInfoSize++, time + str));
|
||||
if (listGnssInfo.size() > LIST_SIZE) {
|
||||
listGnssInfo.remove(listGnssInfo.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_GNSS_INFO.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeVehicleState) {
|
||||
listVehicleState.add(0, new DataShow(listVehicleStateSize++, time + str));
|
||||
if (listVehicleState.size() > LIST_SIZE) {
|
||||
listVehicleState.remove(listVehicleState.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_VEHICLE_STATE.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeChassisStates) {
|
||||
listChassisStates.add(0, new DataShow(listChassisStatesSize++, time + str));
|
||||
if (listChassisStates.size() > LIST_SIZE) {
|
||||
listChassisStates.remove(listChassisStates.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_CHASSIS_STATES.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeAutopilotState) {
|
||||
listAutopilotState.add(0, new DataShow(listAutopilotStateSize++, time + str));
|
||||
if (listAutopilotState.size() > LIST_SIZE) {
|
||||
listAutopilotState.remove(listAutopilotState.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_AUTOPILOT_STATE.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeReportMessage) {
|
||||
listMogoReportMessage.add(0, new DataShow(listMogoReportMessageSize++, time + str));
|
||||
if (listMogoReportMessage.size() > LIST_SIZE) {
|
||||
listMogoReportMessage.remove(listMogoReportMessage.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_REPORT_MESSAGE.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypePredictionObstacleTrajectory) {
|
||||
listPredictionObstacleTrajectory.add(0, new DataShow(listPredictionObstacleTrajectorySize++, time + str));
|
||||
if (listPredictionObstacleTrajectory.size() > LIST_SIZE) {
|
||||
listPredictionObstacleTrajectory.remove(listPredictionObstacleTrajectory.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeCarConfigResp) {
|
||||
if (listener != null && Constants.TITLE.TITLE_CAR_CONFIG_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeRecordResult) {
|
||||
listRecordPanel.add(0, new DataShow(listRecordPanelSize++, time + str));
|
||||
if (listRecordPanel.size() > LIST_SIZE) {
|
||||
listRecordPanel.remove(listRecordPanel.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_RECORD_RESULT.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeBagManagerCmd) {
|
||||
listBagManagerCmd.add(0, new DataShow(listBagManagerCmdSize++, time + str));
|
||||
if (listBagManagerCmd.size() > LIST_SIZE) {
|
||||
listBagManagerCmd.remove(listBagManagerCmd.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_BAG_MANAGER_CMD.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeGlobalPathResp) {
|
||||
listGlobalPathResp.add(0, new DataShow(listGlobalPathRespSize++, time + str));
|
||||
if (listGlobalPathResp.size() > LIST_SIZE) {
|
||||
listGlobalPathResp.remove(listGlobalPathResp.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_GLOBAL_PATH_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeWarn) {
|
||||
listWarn.add(0, new DataShow(listWarnSize++, time + str));
|
||||
if (listWarn.size() > LIST_SIZE) {
|
||||
listWarn.remove(listWarn.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_WARN.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeArrivalNotification) {
|
||||
listArrivalNotification.add(0, new DataShow(listArrivalNotificationSize++, time + str));
|
||||
if (listArrivalNotification.size() > LIST_SIZE) {
|
||||
listArrivalNotification.remove(listArrivalNotification.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_ARRIVAL_NOTIFICATION.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeStatusQueryResp) {
|
||||
listStatusInfo.add(0, new DataShow(listStatusInfoSize++, time + str));
|
||||
if (listStatusInfo.size() > LIST_SIZE) {
|
||||
listStatusInfo.remove(listStatusInfo.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_STATUS_QUERY_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeRecordDataConfigResp) {
|
||||
listRecordDataConfig.add(0, new DataShow(listRecordDataConfigSize++, time + str));
|
||||
if (listRecordDataConfig.size() > LIST_SIZE) {
|
||||
listRecordDataConfig.remove(listRecordDataConfig.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_RECORD_DATA_CONFIG_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeSweeperTaskIndexData) {
|
||||
listRoboSweeperTaskIndex.add(0, new DataShow(listRoboSweeperTaskIndexSize++, time + str));
|
||||
if (listRoboSweeperTaskIndex.size() > LIST_SIZE) {
|
||||
listRoboSweeperTaskIndex.remove(listRoboSweeperTaskIndex.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_SWEEPER_TASK_INDEX_DATA.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeFunctionStates) {
|
||||
listFSMFunctionStates.add(0, new DataShow(listFSMFunctionStatesSize++, time + str));
|
||||
if (listFSMFunctionStates.size() > LIST_SIZE) {
|
||||
listFSMFunctionStates.remove(listFSMFunctionStates.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_FUNCTION_STATES.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypePointCloud) {
|
||||
listOriginalPointCloud.add(0, new DataShow(listOriginalPointCloudSize++, time + str));
|
||||
if (listOriginalPointCloud.size() > LIST_SIZE) {
|
||||
listOriginalPointCloud.remove(listOriginalPointCloud.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_POINT_CLOUD_ORIGINAL.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeBackCameraVideo) {
|
||||
listBackCameraVideo.add(0, new DataShow(listBackCameraVideoSize++, time + str));
|
||||
if (listBackCameraVideo.size() > LIST_SIZE) {
|
||||
listBackCameraVideo.remove(listBackCameraVideo.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_BACK_CAMERA_VIDEO.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeV2nCongestionEvent) {
|
||||
listV2nCongestionEvent.add(0, new DataShow(listV2nCongestionEventSize++, time + str));
|
||||
if (listV2nCongestionEvent.size() > LIST_SIZE) {
|
||||
listV2nCongestionEvent.remove(listV2nCongestionEvent.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_V2N_CONGESTION_EVENT.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeV2nGlobalPathEvents) {
|
||||
listV2nGlobalPathEvents.add(0, new DataShow(listV2nGlobalPathEventsSize++, time + str));
|
||||
if (listV2nGlobalPathEvents.size() > LIST_SIZE) {
|
||||
listV2nGlobalPathEvents.remove(listV2nGlobalPathEvents.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_V2N_GLOBAL_PATH_EVENTS.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (messageType == MessagePad.MessageType.MsgTypeGetParamResp) {
|
||||
listGetParamResp.add(0, new DataShow(listGetParamRespSize++, time + str));
|
||||
if (listGetParamResp.size() > LIST_SIZE) {
|
||||
listGetParamResp.remove(listGetParamResp.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_GET_PARAM_RESP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof PerceptionTrafficLight) {
|
||||
listPerceptionTrafficLight.add(0, new DataShow(listPerceptionTrafficLightSize++, time + str));
|
||||
if (listPerceptionTrafficLight.size() > LIST_SIZE) {
|
||||
listPerceptionTrafficLight.remove(listPerceptionTrafficLight.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_PERCEPTION_TRAFFIC_LIGHT.equals(listener.first)) {
|
||||
listener.second.onPerceptionTrafficLight((PerceptionTrafficLight) data);
|
||||
}
|
||||
} else if (data instanceof ObuSpat) {
|
||||
listObuSpat.add(0, new DataShow(listObuSpatSize++, time + str));
|
||||
if (listObuSpat.size() > LIST_SIZE) {
|
||||
listObuSpat.remove(listObuSpat.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_OBU_SPAT.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ObuRsi) {
|
||||
listObuRsi.add(0, new DataShow(listObuRsiSize++, time + str));
|
||||
if (listObuRsi.size() > LIST_SIZE) {
|
||||
listObuRsi.remove(listObuRsi.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_OBU_RSI.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ObuRsm) {
|
||||
listObuRsm.add(0, new DataShow(listObuRsmSize++, time + str));
|
||||
if (listObuRsm.size() > LIST_SIZE) {
|
||||
listObuRsm.remove(listObuRsm.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_OBU_RSM.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
} else if (data instanceof ObuMap) {
|
||||
listObuMap.add(0, new DataShow(listObuMapSize++, time + str));
|
||||
if (listObuMap.size() > LIST_SIZE) {
|
||||
listObuMap.remove(listObuMap.size() - 1);
|
||||
}
|
||||
if (listener != null && Constants.TITLE.RECEIVE_OBU_MAP.equals(listener.first)) {
|
||||
listener.second.onRefresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
private class WriteThread implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (this) {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
BaseInfo data = queue.take();
|
||||
String time = sdf.format(new Date(data.nowTime));
|
||||
String temp = onTransmit(time, data);
|
||||
String builder = time + "[action]:" + data.action + " [data]:" + temp;
|
||||
LogSave.getInstance().saveLog(builder);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,338 +0,0 @@
|
||||
package com.zhidao.adas.client;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.mogo.support.obu.MogoObuManager;
|
||||
import com.mogo.support.obu.ObuScene;
|
||||
import com.mogo.support.obu.constants.MogoObuConstants;
|
||||
import com.mogo.support.obu.constants.MogoObuTopicId;
|
||||
import com.mogo.support.obu.model.MogoObuHvBasicsData;
|
||||
import com.mogo.support.obu.model.MogoObuMapMathData;
|
||||
import com.mogo.support.obu.model.MogoObuRsiWarningData;
|
||||
import com.mogo.support.obu.model.MogoObuRsmWarningData;
|
||||
import com.mogo.support.obu.model.MogoObuRvWarningData;
|
||||
import com.mogo.support.obu.model.MogoObuSpatWarningData;
|
||||
import com.mogo.support.obu.model.MogoObuSystemStatusData;
|
||||
import com.mogo.support.obu.model.advance.AccFourAxes;
|
||||
import com.mogo.support.obu.model.advance.DateTime;
|
||||
import com.mogo.support.obu.model.advance.NodeId;
|
||||
import com.mogo.support.obu.model.advance.Participant;
|
||||
import com.mogo.support.obu.model.advance.PositionLLV;
|
||||
import com.mogo.support.obu.model.advance.RsiWarning;
|
||||
import com.mogo.support.obu.model.advance.SpatLight;
|
||||
import com.mogo.support.obu.model.advance.V2xWarning;
|
||||
import com.mogo.support.obu.model.advance.VehBasics;
|
||||
import com.mogo.support.obu.model.advance.VehControl;
|
||||
import com.mogo.support.obu.model.advance.VehSize;
|
||||
import com.mogo.support.obu.model.advance.VerticalLLV;
|
||||
import com.mogo.support.obu.model.advance.WarningData;
|
||||
import com.mogo.support.obu.model.result.BaseResult;
|
||||
import com.zhidao.support.adas.high.common.ThreadPoolManager;
|
||||
import com.zhidao.support.obu.ObuManager;
|
||||
import com.zhidao.support.obu.OnObuListener;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* OBU SDK Java对象转PB对象测试
|
||||
*/
|
||||
public class ObuTest {
|
||||
|
||||
|
||||
public static void start() {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ObuManager.getInstance().registerObuListener(listener);
|
||||
Class clazz = MogoObuManager.class;
|
||||
MogoObuManager mogoObuManager = MogoObuManager.getInstance();
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
for (Method m : methods) {
|
||||
String name = m.getName();
|
||||
if ("onObuCallback".equals(name)) {
|
||||
m.setAccessible(true);
|
||||
try {
|
||||
m.invoke(mogoObuManager, MogoObuTopicId.HV_BASIC.id, buildMogoObuHvBasicsData());
|
||||
m.invoke(mogoObuManager, MogoObuTopicId.RV_WARNING.id, buildMogoObuRvWarningData());
|
||||
m.invoke(mogoObuManager, MogoObuTopicId.SPAT_WARNING.id, buildMogoObuSpatWarningData());
|
||||
m.invoke(mogoObuManager, MogoObuTopicId.RSI_WARNING.id, buildMogoObuRsiWarningData());
|
||||
m.invoke(mogoObuManager, MogoObuTopicId.RSM_WARNING.id, buildMogoObuRsmWarningData());
|
||||
m.invoke(mogoObuManager, MogoObuTopicId.MAP_MATCH.id, buildMogoObuMapMathData());
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
ThreadPoolManager.getsInstance().execute(runnable);
|
||||
}
|
||||
|
||||
private static int have(int unitMask, int mask) {
|
||||
unitMask += mask;
|
||||
return unitMask;
|
||||
}
|
||||
|
||||
private static MogoObuHvBasicsData buildMogoObuHvBasicsData() {
|
||||
int vehBasicsUnitMask = 0;
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.ID);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.SEC_MARK);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.LATITUDE);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.LONGITUDE);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.ELEVATION);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.SPEED);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.HEADING);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.ACC_FOUR_AXES);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.VEH_SIZE);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.VEH_CLASS);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.VEH_CONTROL_MSG);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.TARGET_POSITION);
|
||||
VehBasics vehBasics = new VehBasics(vehBasicsUnitMask);
|
||||
vehBasics.setId("aaa");
|
||||
vehBasics.setLatitude(10000000);
|
||||
vehBasics.setLongitude(20000000);
|
||||
vehBasics.setElevation(2000);
|
||||
vehBasics.setSpeed(3000);
|
||||
vehBasics.setHeading(4000);
|
||||
vehBasics.setAccFourAxes(new AccFourAxes(200, 201, 202, 203));
|
||||
vehBasics.setVehSize(new VehSize(300, 301, 302));
|
||||
vehBasics.setVehClass(303);
|
||||
|
||||
int vehControlUnitMask = 0;
|
||||
vehControlUnitMask = have(vehControlUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_CONTROL.BRAKE_PEDAL_STATUS);
|
||||
vehControlUnitMask = have(vehControlUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_CONTROL.TRANSMISSION_STATUS);
|
||||
vehControlUnitMask = have(vehControlUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_CONTROL.EXTERIOR_LIGHTS);
|
||||
VehControl vehControl = new VehControl(vehControlUnitMask);
|
||||
vehControl.setBrakePedalStatus(401);
|
||||
vehControl.setTransmissionStatus(402);
|
||||
vehControl.setExteriorLights(403);
|
||||
vehBasics.setVehControlMsg(vehControl);
|
||||
vehBasics.setTargetPosition(8);
|
||||
MogoObuHvBasicsData data = new MogoObuHvBasicsData(1, vehBasics);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static MogoObuRvWarningData buildMogoObuRvWarningData() {
|
||||
int vehBasicsUnitMask = 0;
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.ID);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.SEC_MARK);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.LATITUDE);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.LONGITUDE);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.ELEVATION);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.SPEED);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.HEADING);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.ACC_FOUR_AXES);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.VEH_SIZE);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.VEH_CLASS);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.VEH_CONTROL_MSG);
|
||||
vehBasicsUnitMask = have(vehBasicsUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_BASICS.TARGET_POSITION);
|
||||
VehBasics vehBasics = new VehBasics(vehBasicsUnitMask);
|
||||
vehBasics.setId("aaa");
|
||||
vehBasics.setLatitude(20000000);
|
||||
vehBasics.setLongitude(30000000);
|
||||
vehBasics.setElevation(4000);
|
||||
vehBasics.setSpeed(5000);
|
||||
vehBasics.setHeading(6000);
|
||||
vehBasics.setAccFourAxes(new AccFourAxes(700, 801, 902, 1003));
|
||||
vehBasics.setVehSize(new VehSize(1100, 1201, 1302));
|
||||
vehBasics.setVehClass(1403);
|
||||
|
||||
int vehControlUnitMask = 0;
|
||||
vehControlUnitMask = have(vehControlUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_CONTROL.BRAKE_PEDAL_STATUS);
|
||||
vehControlUnitMask = have(vehControlUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_CONTROL.TRANSMISSION_STATUS);
|
||||
vehControlUnitMask = have(vehControlUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_VEH_CONTROL.EXTERIOR_LIGHTS);
|
||||
VehControl vehControl = new VehControl(vehControlUnitMask);
|
||||
vehControl.setBrakePedalStatus(1501);
|
||||
vehControl.setTransmissionStatus(1602);
|
||||
vehControl.setExteriorLights(1703);
|
||||
vehBasics.setVehControlMsg(vehControl);
|
||||
vehBasics.setTargetPosition(18);
|
||||
|
||||
int v2xWarningUnitMask = 0;
|
||||
v2xWarningUnitMask = have(v2xWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING.WARNING_NUM);
|
||||
v2xWarningUnitMask = have(v2xWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING.WARNING_DATA);
|
||||
v2xWarningUnitMask = have(v2xWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING.WARNING_TIME);
|
||||
v2xWarningUnitMask = have(v2xWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING.DISTANCE);
|
||||
V2xWarning v2xWarning = new V2xWarning(v2xWarningUnitMask);
|
||||
|
||||
DateTime dateTime = new DateTime(19, 20, 21, 22, 23, 24, 25);
|
||||
List<WarningData> warningDatas = new ArrayList<>();
|
||||
int warningDataMask = 0;
|
||||
warningDataMask = have(warningDataMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING_DATA.STATUS);
|
||||
warningDataMask = have(warningDataMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING_DATA.WARNING_TYPE);
|
||||
warningDataMask = have(warningDataMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING_DATA.WARNING_LEVEL);
|
||||
warningDataMask = have(warningDataMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING_DATA.WARNING_PRIORITY);
|
||||
WarningData warningData1 = new WarningData(warningDataMask, 3);
|
||||
warningData1.setWarningType(26);
|
||||
warningData1.setWarningLevel(27);
|
||||
warningData1.setWarningPriority(28);
|
||||
warningDatas.add(warningData1);
|
||||
WarningData warningData2 = new WarningData(warningDataMask, 4);
|
||||
warningData2.setWarningType(29);
|
||||
warningData2.setWarningLevel(30);
|
||||
warningData2.setWarningPriority(31);
|
||||
warningDatas.add(warningData2);
|
||||
v2xWarning.setWarningNum(2);
|
||||
v2xWarning.setWarningData(warningDatas);
|
||||
v2xWarning.setWarningTime(dateTime);
|
||||
v2xWarning.setDistance(32);
|
||||
MogoObuRvWarningData data = new MogoObuRvWarningData(2, vehBasics, v2xWarning);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private static MogoObuSpatWarningData buildMogoObuSpatWarningData() {
|
||||
List<SpatLight> lights = new ArrayList<>();
|
||||
lights.add(new SpatLight(35, 36, 37, 38, 39, 40));
|
||||
lights.add(new SpatLight(41, 42, 43, 44, 45, 46));
|
||||
lights.add(new SpatLight(47, 48, 49, 50, 51, 52));
|
||||
MogoObuSpatWarningData data = new MogoObuSpatWarningData(33, 34, 3, lights);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static MogoObuRsiWarningData buildMogoObuRsiWarningData() {
|
||||
List<RsiWarning> list = new ArrayList<>();
|
||||
int rsiWarningUnitMask = 0;
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.SCENE_TYPE);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.POSITION);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.SIGN_SERIAL_NUM);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.EVENT_SERIAL_NUM);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.SPEED_MAX_LIMIT);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.SPEED_MIN_LIMIT);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.EVENT_RADIUS);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.WARNING_LEVEL);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.TARGET_POSITION);
|
||||
rsiWarningUnitMask = have(rsiWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_RSI_WARNING.DISTANCE);
|
||||
RsiWarning rsiWarning1 = new RsiWarning(rsiWarningUnitMask);
|
||||
rsiWarning1.setSceneType(53);
|
||||
rsiWarning1.setPosition(new PositionLLV(7, 54, 55, new VerticalLLV(7, 56)));
|
||||
rsiWarning1.setSignSerialNum(57);
|
||||
rsiWarning1.setEventSerialNum(58);
|
||||
rsiWarning1.setSpeedMinLimit(59);
|
||||
rsiWarning1.setSpeedMaxLimit(60);
|
||||
rsiWarning1.setEventRadius(61);
|
||||
rsiWarning1.setWarningLevel(62);
|
||||
rsiWarning1.setTargetPosition(63);
|
||||
rsiWarning1.setDistance(64);
|
||||
list.add(rsiWarning1);
|
||||
|
||||
RsiWarning rsiWarning2 = new RsiWarning(rsiWarningUnitMask);
|
||||
rsiWarning2.setSceneType(65);
|
||||
rsiWarning2.setPosition(new PositionLLV(7, 66, 67, new VerticalLLV(7, 68)));
|
||||
rsiWarning2.setSignSerialNum(69);
|
||||
rsiWarning2.setEventSerialNum(70);
|
||||
rsiWarning2.setSpeedMinLimit(71);
|
||||
rsiWarning2.setSpeedMaxLimit(72);
|
||||
rsiWarning2.setEventRadius(73);
|
||||
rsiWarning2.setWarningLevel(74);
|
||||
rsiWarning2.setTargetPosition(75);
|
||||
rsiWarning2.setDistance(76);
|
||||
list.add(rsiWarning2);
|
||||
MogoObuRsiWarningData data = new MogoObuRsiWarningData(53, 2, list);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static MogoObuRsmWarningData buildMogoObuRsmWarningData() {
|
||||
Participant participant = new Participant(78, 79, 80, 81, 82, 83, 84, 85, 86, new AccFourAxes(87, 88, 89, 90), new VehSize(91, 92, 93), 94, 95);
|
||||
int v2xWarningUnitMask = 0;
|
||||
v2xWarningUnitMask = have(v2xWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING.WARNING_NUM);
|
||||
v2xWarningUnitMask = have(v2xWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING.WARNING_DATA);
|
||||
v2xWarningUnitMask = have(v2xWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING.WARNING_TIME);
|
||||
v2xWarningUnitMask = have(v2xWarningUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING.DISTANCE);
|
||||
V2xWarning v2xWarning = new V2xWarning(v2xWarningUnitMask);
|
||||
|
||||
DateTime dateTime = new DateTime(96, 97, 98, 99, 100, 101, 102);
|
||||
List<WarningData> warningDatas = new ArrayList<>();
|
||||
int warningDataMask = 0;
|
||||
warningDataMask = have(warningDataMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING_DATA.STATUS);
|
||||
warningDataMask = have(warningDataMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING_DATA.WARNING_TYPE);
|
||||
warningDataMask = have(warningDataMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING_DATA.WARNING_LEVEL);
|
||||
warningDataMask = have(warningDataMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_V2X_WARNING_DATA.WARNING_PRIORITY);
|
||||
WarningData warningData1 = new WarningData(warningDataMask, 3);
|
||||
warningData1.setWarningType(103);
|
||||
warningData1.setWarningLevel(104);
|
||||
warningData1.setWarningPriority(105);
|
||||
warningDatas.add(warningData1);
|
||||
WarningData warningData2 = new WarningData(warningDataMask, 4);
|
||||
warningData2.setWarningType(106);
|
||||
warningData2.setWarningLevel(107);
|
||||
warningData2.setWarningPriority(108);
|
||||
warningDatas.add(warningData2);
|
||||
v2xWarning.setWarningNum(2);
|
||||
v2xWarning.setWarningData(warningDatas);
|
||||
v2xWarning.setWarningTime(dateTime);
|
||||
v2xWarning.setDistance(109);
|
||||
MogoObuRsmWarningData data = new MogoObuRsmWarningData(77, participant, v2xWarning);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static MogoObuMapMathData buildMogoObuMapMathData() {
|
||||
int mogoObuMapMathDataUnitMask = 0;
|
||||
mogoObuMapMathDataUnitMask = have(mogoObuMapMathDataUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_MAP_MATH.CURRENT_NODE_ID);
|
||||
mogoObuMapMathDataUnitMask = have(mogoObuMapMathDataUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_MAP_MATH.UPSTREAM_NODE_ID);
|
||||
mogoObuMapMathDataUnitMask = have(mogoObuMapMathDataUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_MAP_MATH.MATCHING_LANE_ID);
|
||||
mogoObuMapMathDataUnitMask = have(mogoObuMapMathDataUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_MAP_MATH.SPEED_MAX_LIMIT);
|
||||
mogoObuMapMathDataUnitMask = have(mogoObuMapMathDataUnitMask, MogoObuConstants.UNIT_MASK.MOGO_OBU_MAP_MATH.SPEED_MIN_LIMIT);
|
||||
MogoObuMapMathData data = new MogoObuMapMathData(mogoObuMapMathDataUnitMask, 110);
|
||||
data.setCurrentNodeId(new NodeId(111,112));
|
||||
data.setUpstreamNodeId(new NodeId(113,114));
|
||||
data.setMatchingLaneId(115);
|
||||
data.setSpeedMaxLimit(116);
|
||||
data.setSpeedMinLimit(117);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static OnObuListener listener = new OnObuListener() {
|
||||
@Override
|
||||
public void onConnectStatus(int connectStatus) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObuCallResult(BaseResult result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObuSystemStatus(MogoObuSystemStatusData data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGnssInfo(MessagePad.GnssInfo gnssInfo) {
|
||||
Log.i("ddddd", "onGnssInfo=\n" + TextFormat.printer().escapingNonAscii(false).printToString(gnssInfo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObuRvWarning(ObuScene.RvWarningData rvWarningData) {
|
||||
Log.i("ddddd", "onObuRvWarning=\n" + TextFormat.printer().escapingNonAscii(false).printToString(rvWarningData));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObuSpatWarning(ObuScene.SpatWarningData spatWarningData) {
|
||||
Log.i("ddddd", "onObuSpatWarning=\n" + TextFormat.printer().escapingNonAscii(false).printToString(spatWarningData));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObuRsiWarning(ObuScene.RsiWarningData rsiWarningData) {
|
||||
Log.i("ddddd", "onObuRsiWarning=\n" + TextFormat.printer().escapingNonAscii(false).printToString(rsiWarningData));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObuRsmWarning(ObuScene.RsmWarningData rsmWarningData) {
|
||||
Log.i("ddddd", "onObuRsmWarning=\n" + TextFormat.printer().escapingNonAscii(false).printToString(rsmWarningData));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObuMapMath(ObuScene.MapMatchData mapMatchData) {
|
||||
Log.i("ddddd", "onObuMapMath=\n" + TextFormat.printer().escapingNonAscii(false).printToString(mapMatchData));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package com.zhidao.adas.client;
|
||||
|
||||
import com.zhidao.adas.client.bean.PerceptionTrafficLight;
|
||||
|
||||
public abstract class OnAdasClientListener {
|
||||
|
||||
public abstract void onRefresh();
|
||||
|
||||
// /**
|
||||
// * 自动驾驶局部轨迹 车前引导线
|
||||
// *
|
||||
// * @param isAdd 是否是添加数据回调
|
||||
// */
|
||||
// public void onTrajectory() {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 障碍物 他车数据
|
||||
// *
|
||||
// * @param trackedObjects 数据
|
||||
// */
|
||||
// public void onTrackedObjects(TrackedObjects trackedObjects) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 惯导信息
|
||||
// *
|
||||
// * @param isAdd 是否是添加数据回调
|
||||
// */
|
||||
// public void onGnssInfo() {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 底盘信息, 透传底盘状态,pb参考底盘
|
||||
// *
|
||||
// * @param vehicleState 数据
|
||||
// */
|
||||
// public void onVehicleState(VehicleState vehicleState) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 自动驾驶状态
|
||||
// *
|
||||
// * @param autopilotState 数据
|
||||
// */
|
||||
// public void onAutopilotState(AutopilotState autopilotState) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 监控事件报告
|
||||
// *
|
||||
// * @param mogoReportMessage 数据
|
||||
// */
|
||||
// public void onReportMessage(MogoReportMessage mogoReportMessage) {
|
||||
// }
|
||||
//
|
||||
/**
|
||||
* 感知红绿灯
|
||||
*
|
||||
* @param trafficLights 感知红绿灯
|
||||
*/
|
||||
public void onPerceptionTrafficLight(PerceptionTrafficLight trafficLights) {
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * 自动驾驶设备基础信息请求
|
||||
// *
|
||||
// * @param basicInfoReq 数据 目前没有任何参数
|
||||
// */
|
||||
// public void onBasicInfoReq(BasicInfoReq basicInfoReq) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 车机基础信息应答
|
||||
// *
|
||||
// * @param carConfigResp 数据
|
||||
// */
|
||||
// public void onCarConfigResp(CarConfigResp carConfigResp) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 数据采集结果
|
||||
// *
|
||||
// * @param recordPanel 数据
|
||||
// */
|
||||
// public void onRecordResult(RecordPanel recordPanel) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 自动驾驶路径应答
|
||||
// *
|
||||
// * @param globalPathResp 数据
|
||||
// */
|
||||
// public void onGlobalPathResp(GlobalPathResp globalPathResp) {
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 报警信息
|
||||
// * 暂时保留,目前没有使用
|
||||
// *
|
||||
// * @param warn 数据
|
||||
// */
|
||||
// @Deprecated
|
||||
// public void onWarn(Warn warn) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 到站提醒 自动驾驶站点
|
||||
// *
|
||||
// * @param arrivalNotification 数据
|
||||
// */
|
||||
// public void onArrivalNotification(ArrivalNotification arrivalNotification) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 升级状态
|
||||
// *
|
||||
// * @param info
|
||||
// */
|
||||
// @Deprecated
|
||||
// public void onUpgradeStateInfo(IPCUpgradeStateInfo info) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 向IPC发送命令返回结果
|
||||
// *
|
||||
// * @param info
|
||||
// */
|
||||
// public void onSSHResult(SSHResult info) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 数据错误
|
||||
// *
|
||||
// * @param status 错误原因
|
||||
// * @param bytes 原始数据
|
||||
// */
|
||||
// public void onError(ProtocolStatus status, byte[] bytes) {
|
||||
//
|
||||
// }
|
||||
}
|
||||
@@ -1,480 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.bean.AutoPilotMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AutopilotConfigAdapter extends RecyclerView.Adapter<AutopilotConfigAdapter.MyViewHolder> {
|
||||
|
||||
private List<AutoPilotMode> datas;
|
||||
private Context mContext;
|
||||
private OnHaveDataListener onHaveDataListener;
|
||||
private boolean isShowDel = false;
|
||||
|
||||
public AutopilotConfigAdapter(List<AutoPilotMode> datas) {
|
||||
this.datas = datas;
|
||||
if (datas == null) {
|
||||
this.datas = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public void setShowDel(boolean showDel) {
|
||||
isShowDel = showDel;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public List<AutoPilotMode> getDatas() {
|
||||
return datas;
|
||||
}
|
||||
|
||||
public interface OnHaveDataListener {
|
||||
void onHaveData(boolean isHave);
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnHaveDataListener l) {
|
||||
this.onHaveDataListener = l;
|
||||
}
|
||||
|
||||
public void add() {
|
||||
datas.add(new AutoPilotMode());
|
||||
notifyItemInserted(datas.size() - 1);
|
||||
if (onHaveDataListener != null && datas.size() == 1)
|
||||
onHaveDataListener.onHaveData(true);
|
||||
}
|
||||
|
||||
public void minus(int position) {
|
||||
AutoPilotMode bean = datas.get(position);
|
||||
bean.wayLatLons = null;
|
||||
bean = null;
|
||||
datas.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
notifyItemRangeChanged(position, getItemCount());
|
||||
if (onHaveDataListener != null && datas.size() == 0)
|
||||
onHaveDataListener.onHaveData(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
//创建ViewHolder
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
//实例化得到Item布局文件的View对象
|
||||
mContext = parent.getContext();
|
||||
View v = LayoutInflater.from(mContext).inflate(R.layout.item_autopilot_config, parent, false);
|
||||
//返回MyViewHolder的对象
|
||||
return new MyViewHolder(v);
|
||||
}
|
||||
|
||||
//绑定数据
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
AutoPilotMode mode = datas.get(position);
|
||||
if (!TextUtils.isEmpty(mode.name))
|
||||
holder.path_name.setText(mode.name);
|
||||
if (mode.speedLimit != 0.0)
|
||||
holder.speed.setText(String.valueOf(mode.speedLimit));
|
||||
if (!TextUtils.isEmpty(mode.startName))
|
||||
holder.start_name.setText(mode.startName);
|
||||
if (!TextUtils.isEmpty(mode.endName))
|
||||
holder.end_name.setText(mode.endName);
|
||||
if (mode.startLatLon != null) {
|
||||
if (mode.startLatLon.longitude != 0.0)
|
||||
holder.start_lon.setText(String.valueOf(mode.startLatLon.longitude));
|
||||
if (mode.startLatLon.latitude != 0.0)
|
||||
holder.start_lat.setText(String.valueOf(mode.startLatLon.latitude));
|
||||
}
|
||||
if (mode.endLatLon != null) {
|
||||
if (mode.endLatLon.longitude != 0.0)
|
||||
holder.end_lon.setText(String.valueOf(mode.endLatLon.longitude));
|
||||
if (mode.endLatLon.latitude != 0.0)
|
||||
holder.end_lat.setText(String.valueOf(mode.endLatLon.latitude));
|
||||
}
|
||||
holder.setViaData();
|
||||
holder.del.setVisibility(isShowDel ? View.VISIBLE : View.GONE);
|
||||
if (mode.isBus) {
|
||||
holder.bus.setChecked(true);
|
||||
} else {
|
||||
holder.taxi.setChecked(true);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mode.routeName)) {
|
||||
holder.route_name.setText(mode.routeName);
|
||||
}
|
||||
if (mode.routeID != -1)
|
||||
holder.route_id.setText(String.valueOf(mode.routeID));
|
||||
}
|
||||
|
||||
//返回Item的数量
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return datas == null ? 0 : datas.size();
|
||||
}
|
||||
|
||||
//继承RecyclerView.ViewHolder抽象类的自定义ViewHolder
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
RecyclerView recyclerView;
|
||||
EditText path_name;
|
||||
EditText speed;
|
||||
EditText start_name;
|
||||
EditText end_name;
|
||||
EditText start_lon;
|
||||
EditText start_lat;
|
||||
EditText end_lon;
|
||||
EditText end_lat;
|
||||
EditText route_id;
|
||||
EditText route_name;
|
||||
TextView num;
|
||||
TextView del;
|
||||
ImageView add;
|
||||
ImageView minus;
|
||||
ViaPositionAdapter adapter;
|
||||
RadioGroup car_type;
|
||||
RadioButton taxi;
|
||||
RadioButton bus;
|
||||
|
||||
MyViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
route_id = itemView.findViewById(R.id.route_id);
|
||||
route_name = itemView.findViewById(R.id.route_name);
|
||||
car_type = itemView.findViewById(R.id.car_type);
|
||||
taxi = itemView.findViewById(R.id.taxi);
|
||||
bus = itemView.findViewById(R.id.bus);
|
||||
recyclerView = itemView.findViewById(R.id.RecyclerView);
|
||||
path_name = itemView.findViewById(R.id.path_name);
|
||||
speed = itemView.findViewById(R.id.speed);
|
||||
start_name = itemView.findViewById(R.id.start_name);
|
||||
end_name = itemView.findViewById(R.id.end_name);
|
||||
start_lon = itemView.findViewById(R.id.start_lon);
|
||||
start_lat = itemView.findViewById(R.id.start_lat);
|
||||
end_lon = itemView.findViewById(R.id.end_lon);
|
||||
end_lat = itemView.findViewById(R.id.end_lat);
|
||||
num = itemView.findViewById(R.id.num);
|
||||
del = itemView.findViewById(R.id.del);
|
||||
add = itemView.findViewById(R.id.add);
|
||||
minus = itemView.findViewById(R.id.minus);
|
||||
initRecyclerView();
|
||||
car_type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
datas.get(getBindingAdapterPosition()).isBus = checkedId == R.id.bus;
|
||||
}
|
||||
});
|
||||
minus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
minus();
|
||||
}
|
||||
});
|
||||
add.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
add();
|
||||
}
|
||||
});
|
||||
del.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AutopilotConfigAdapter.this.minus(getBindingAdapterPosition());
|
||||
}
|
||||
});
|
||||
path_name.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
datas.get(getBindingAdapterPosition()).name = s.toString().trim();
|
||||
}
|
||||
});
|
||||
speed.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
try {
|
||||
datas.get(getBindingAdapterPosition()).speedLimit = Double.parseDouble(s.toString().trim());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
speed.setText("");
|
||||
Toast.makeText(mContext, "输入不合法", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
datas.get(getBindingAdapterPosition()).speedLimit = 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
start_name.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
datas.get(getBindingAdapterPosition()).startName = s.toString().trim();
|
||||
}
|
||||
});
|
||||
end_name.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
datas.get(getBindingAdapterPosition()).endName = s.toString().trim();
|
||||
}
|
||||
});
|
||||
start_lon.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
try {
|
||||
if (datas.get(getBindingAdapterPosition()).startLatLon == null)
|
||||
datas.get(getBindingAdapterPosition()).startLatLon = new AutoPilotMode.Location();
|
||||
datas.get(getBindingAdapterPosition()).startLatLon.longitude = Double.parseDouble(s.toString().trim());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
start_lon.setText("");
|
||||
Toast.makeText(mContext, "输入不合法", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (datas.get(getBindingAdapterPosition()).startLatLon != null) {
|
||||
datas.get(getBindingAdapterPosition()).startLatLon.longitude = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
start_lat.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
try {
|
||||
if (datas.get(getBindingAdapterPosition()).startLatLon == null)
|
||||
datas.get(getBindingAdapterPosition()).startLatLon = new AutoPilotMode.Location();
|
||||
datas.get(getBindingAdapterPosition()).startLatLon.latitude = Double.parseDouble(s.toString().trim());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
start_lat.setText("");
|
||||
Toast.makeText(mContext, "输入不合法", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (datas.get(getBindingAdapterPosition()).startLatLon != null)
|
||||
datas.get(getBindingAdapterPosition()).startLatLon.latitude = 0.0;
|
||||
}
|
||||
}
|
||||
});
|
||||
end_lon.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
try {
|
||||
if (datas.get(getBindingAdapterPosition()).endLatLon == null)
|
||||
datas.get(getBindingAdapterPosition()).endLatLon = new AutoPilotMode.Location();
|
||||
datas.get(getBindingAdapterPosition()).endLatLon.longitude = Double.parseDouble(s.toString().trim());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
end_lon.setText("");
|
||||
Toast.makeText(mContext, "输入不合法", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (datas.get(getBindingAdapterPosition()).endLatLon != null)
|
||||
datas.get(getBindingAdapterPosition()).endLatLon.longitude = 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
end_lat.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
try {
|
||||
if (datas.get(getBindingAdapterPosition()).endLatLon == null)
|
||||
datas.get(getBindingAdapterPosition()).endLatLon = new AutoPilotMode.Location();
|
||||
datas.get(getBindingAdapterPosition()).endLatLon.latitude = Double.parseDouble(s.toString().trim());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
end_lat.setText("");
|
||||
Toast.makeText(mContext, "输入不合法", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (datas.get(getBindingAdapterPosition()).endLatLon != null)
|
||||
datas.get(getBindingAdapterPosition()).endLatLon.latitude = 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
route_name.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
datas.get(getBindingAdapterPosition()).routeName = s.toString().trim();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
route_id.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
try {
|
||||
datas.get(getBindingAdapterPosition()).routeID = Integer.parseInt(s.toString().trim());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
speed.setText("");
|
||||
Toast.makeText(mContext, "输入不合法", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
datas.get(getBindingAdapterPosition()).routeID = -1;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initRecyclerView() {
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
adapter = new ViaPositionAdapter();
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
}
|
||||
|
||||
private void minus() {
|
||||
if (adapter.getItemCount() > 0) {
|
||||
adapter.minus();
|
||||
num.setText(String.valueOf(adapter.getItemCount()));
|
||||
}
|
||||
}
|
||||
|
||||
public void add() {
|
||||
adapter.addHint();
|
||||
recyclerView.scrollToPosition(adapter.getItemCount() - 1);
|
||||
num.setText(String.valueOf(adapter.getItemCount()));
|
||||
}
|
||||
|
||||
public void setViaData() {
|
||||
if (adapter.getDatas() == null) {
|
||||
List<AutoPilotMode.Location> list = datas.get(getBindingAdapterPosition()).wayLatLons;
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
datas.get(getBindingAdapterPosition()).wayLatLons = list;
|
||||
}
|
||||
adapter.setDatas(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.base.BaseAdapter;
|
||||
import com.zhidao.adas.client.base.BaseViewHolder;
|
||||
import com.zhidao.adas.client.bean.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des
|
||||
* @date 2021/8/13
|
||||
*/
|
||||
public class ConfigAdapter extends BaseAdapter<Config, ConfigAdapter.ViewHolder> {
|
||||
|
||||
|
||||
public ConfigAdapter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(List<Config> mDatas) {
|
||||
super.setData(mDatas);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDataToItem(ViewHolder viewHolder, Config data, int position) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
viewHolder.name.setText(data.name);
|
||||
viewHolder.value.setText(data.value);
|
||||
if (data.color == -1) {
|
||||
data.color = R.color.colorSlateGray;
|
||||
}
|
||||
viewHolder.value.setTextColor(mContext.getResources().getColor(data.color));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getItemViewResource(ViewGroup viewGroup) {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.item_config, viewGroup, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewHolder getViewHolder(View view) {
|
||||
return new ViewHolder(view, this);
|
||||
}
|
||||
|
||||
class ViewHolder extends BaseViewHolder<ConfigAdapter> {
|
||||
TextView name;
|
||||
TextView value;
|
||||
|
||||
public ViewHolder(View itemView, ConfigAdapter adapter) {
|
||||
super(itemView, adapter);
|
||||
name = itemView.findViewById(R.id.name);
|
||||
value = itemView.findViewById(R.id.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.base.BaseAdapter;
|
||||
import com.zhidao.adas.client.base.BaseViewHolder;
|
||||
import com.zhidao.adas.client.bean.IPCConnectState;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
* 连接状态
|
||||
*/
|
||||
public class ConnectStatusAdapter extends BaseAdapter<IPCConnectState, ConnectStatusAdapter.ViewHolder> {
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS ", Locale.getDefault());
|
||||
private static final String POS = "%03d. ";
|
||||
|
||||
public void refreshView() {
|
||||
// notifyItemChanged(mDatas.size()-1,0);
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
protected void onBindDataToItem(ViewHolder viewHolder, IPCConnectState data, int position) {
|
||||
viewHolder.id.setText(String.format(Locale.getDefault(), POS, getItemCount() - position));
|
||||
String str = "<font color='#999999'>" + sdf.format(new Date(data.time)) + "\n</font> <br />" + data.status;
|
||||
viewHolder.editText.setText(Html.fromHtml(str));
|
||||
viewHolder.editText.setTextColor(mContext.getResources().getColor(data.color));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getItemViewResource(ViewGroup viewGroup) {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.item_status, viewGroup, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ViewHolder getViewHolder(View view) {
|
||||
return new ViewHolder(view, this);
|
||||
}
|
||||
|
||||
|
||||
class ViewHolder extends BaseViewHolder<ConnectStatusAdapter> {
|
||||
EditText editText;
|
||||
TextView id;
|
||||
|
||||
public ViewHolder(View itemView, ConnectStatusAdapter adapter) {
|
||||
super(itemView, adapter);
|
||||
editText = itemView.findViewById(R.id.log);
|
||||
id = itemView.findViewById(R.id.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.base.BaseAdapter;
|
||||
import com.zhidao.adas.client.base.BaseViewHolder;
|
||||
import com.zhidao.adas.client.bean.DataShow;
|
||||
|
||||
|
||||
//log所用
|
||||
public class DataShowAdapter extends BaseAdapter<DataShow, DataShowAdapter.ViewHolder> {
|
||||
|
||||
|
||||
public void refreshView() {
|
||||
// notifyItemChanged(mDatas.size()-1,0);
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
protected void onBindDataToItem(ViewHolder viewHolder, DataShow data, int position) {
|
||||
viewHolder.id.setText(data.position + ". ");
|
||||
viewHolder.editText.setText(data.data);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getItemViewResource(ViewGroup viewGroup) {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.item_log_info, viewGroup, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ViewHolder getViewHolder(View view) {
|
||||
return new ViewHolder(view, this);
|
||||
}
|
||||
|
||||
|
||||
class ViewHolder extends BaseViewHolder<DataShowAdapter> {
|
||||
EditText editText;
|
||||
TextView id;
|
||||
|
||||
public ViewHolder(View itemView, DataShowAdapter adapter) {
|
||||
super(itemView, adapter);
|
||||
editText = itemView.findViewById(R.id.log);
|
||||
id = itemView.findViewById(R.id.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.base.BaseAdapter;
|
||||
import com.zhidao.adas.client.base.BaseViewHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des
|
||||
* @date 2021/8/13
|
||||
*/
|
||||
public class InfoTitleAdapter extends BaseAdapter<String, InfoTitleAdapter.ViewHolder> {
|
||||
private int selectedPosition = 0;//当前选中的下标
|
||||
private boolean isFragment = false;
|
||||
|
||||
public void setSelectedPosition(int position) {
|
||||
if (position != selectedPosition) {
|
||||
notifyItemChanged(position);
|
||||
notifyItemChanged(selectedPosition);
|
||||
selectedPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public InfoTitleAdapter(List<String> data, boolean isFragment) {
|
||||
super(data);
|
||||
this.isFragment = isFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDataToItem(ViewHolder viewHolder, String data, int position) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
if (isFragment) {
|
||||
viewHolder.itemView.setSelected(selectedPosition == position);
|
||||
}
|
||||
viewHolder.title.setText(data);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getItemViewResource(ViewGroup viewGroup) {
|
||||
View view;
|
||||
if (isFragment) {
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.item_info, viewGroup, false);
|
||||
} else {
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.item_info1, viewGroup, false);
|
||||
}
|
||||
// if (!isFragment) {
|
||||
// int h = viewGroup.getHeight() - DensityUtil.dip2px(mContext, 16);
|
||||
// ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
|
||||
// if (layoutParams != null) {
|
||||
// layoutParams.width = DensityUtil.dip2px(mContext, 150);
|
||||
//// layoutParams.height = DensityUtil.dip2px(mContext, 50);
|
||||
// layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
//// layoutParams.height = h / 2;
|
||||
// }
|
||||
// }
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewHolder getViewHolder(View view) {
|
||||
return new ViewHolder(view, this);
|
||||
}
|
||||
|
||||
class ViewHolder extends BaseViewHolder<InfoTitleAdapter> {
|
||||
TextView title;
|
||||
|
||||
public ViewHolder(View itemView, InfoTitleAdapter adapter) {
|
||||
super(itemView, adapter);
|
||||
title = itemView.findViewById(R.id.tv_info_title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.bean.InterfaceModel;
|
||||
import com.zhidao.support.adas.high.common.MessageType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class InterfaceAdapter extends RecyclerView.Adapter<InterfaceAdapter.MyViewHolder> {
|
||||
|
||||
private List<InterfaceModel> mDatas;
|
||||
private boolean isEnabled = true;//是否可操作
|
||||
private boolean oldIsEnabled = isEnabled;
|
||||
private int isCheckAll = 2;//0:全选 1:全不选 2:任意选
|
||||
private int checkNum;
|
||||
private boolean oldIsCheckAll = false;
|
||||
|
||||
private OnInterfaceAdapterListener listener;
|
||||
|
||||
public void setListener(OnInterfaceAdapterListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public interface OnInterfaceAdapterListener {
|
||||
void onCheckAll(boolean isCheckAll);
|
||||
|
||||
void onCheckNum(int checkNum);
|
||||
}
|
||||
|
||||
public int getCheckNum() {
|
||||
return checkNum;
|
||||
}
|
||||
|
||||
//获取已选中的
|
||||
public Set<MessageType> getCheckedModel() {
|
||||
Set<MessageType> messageTypes = new HashSet<>();
|
||||
if (mDatas != null) {
|
||||
for (InterfaceModel model : mDatas) {
|
||||
if (model.isSelected()) {
|
||||
messageTypes.add(model.getMessageType());
|
||||
}
|
||||
}
|
||||
}
|
||||
return messageTypes;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
isEnabled = true;
|
||||
oldIsEnabled = true;
|
||||
isCheckAll = 2;
|
||||
checkNum = 0;
|
||||
}
|
||||
|
||||
public void setData(List<InterfaceModel> mDatas, int checkNum) {
|
||||
init();
|
||||
this.mDatas = mDatas;
|
||||
if (mDatas != null && !mDatas.isEmpty()) {
|
||||
this.checkNum = checkNum;
|
||||
updateCheckAllStatus(true);
|
||||
}
|
||||
}
|
||||
|
||||
//全选 全不选
|
||||
public void setCheckAll(boolean checkAll) {
|
||||
isCheckAll = checkAll ? 0 : 1;
|
||||
checkNum = checkAll ? getItemCount() : 0;
|
||||
notifyDataSetChanged();
|
||||
updateCheckNumStatusCall();
|
||||
updateCheckAllStatus(false);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled) {
|
||||
if (oldIsEnabled != isEnabled) {
|
||||
oldIsEnabled = isEnabled;
|
||||
this.isEnabled = isEnabled;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//创建ViewHolder
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
//实例化得到Item布局文件的View对象
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_interface, parent, false);
|
||||
//返回MyViewHolder的对象
|
||||
return new MyViewHolder(v);
|
||||
}
|
||||
|
||||
//绑定数据
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
holder.index.setEnabled(isEnabled);
|
||||
holder.name.setEnabled(isEnabled);
|
||||
holder.itemView.setEnabled(isEnabled);
|
||||
holder.itemCheck.setEnabled(isEnabled);
|
||||
InterfaceModel model = mDatas.get(position);
|
||||
holder.name.setText(model.getMessageType().desc);
|
||||
holder.index.setText((position + 1) + ".");
|
||||
if (isCheckAll == 0) {
|
||||
model.setSelected(true);
|
||||
} else if (isCheckAll == 1) {
|
||||
model.setSelected(false);
|
||||
}
|
||||
holder.itemCheck.setChecked(model.isSelected());
|
||||
|
||||
}
|
||||
|
||||
//返回Item的数量
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDatas == null ? 0 : mDatas.size();
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取制定 位置的Data
|
||||
* @param position 下标
|
||||
* @return Data
|
||||
*/
|
||||
public InterfaceModel getItem(int position) {
|
||||
return mDatas == null ? null : mDatas.get(position);
|
||||
}
|
||||
|
||||
//继承RecyclerView.ViewHolder抽象类的自定义ViewHolder
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView name;
|
||||
TextView index;
|
||||
CheckBox itemCheck;
|
||||
|
||||
MyViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
index = itemView.findViewById(R.id.index);
|
||||
name = itemView.findViewById(R.id.name);
|
||||
name.setSelected(true);
|
||||
itemCheck = itemView.findViewById(R.id.item_check);
|
||||
init();
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
InterfaceModel model = getItem(getBindingAdapterPosition());
|
||||
model.setSelected(!model.isSelected());
|
||||
updateCheckNum(model.isSelected());
|
||||
itemCheck.setChecked(model.isSelected());
|
||||
}
|
||||
});
|
||||
itemCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (buttonView.isPressed()) {
|
||||
updateCheckNum(isChecked);
|
||||
InterfaceModel model = getItem(getBindingAdapterPosition());
|
||||
model.setSelected(isChecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//更新选中个数
|
||||
private void updateCheckNum(boolean isChecked) {
|
||||
if (isChecked) {
|
||||
checkNum++;
|
||||
} else {
|
||||
checkNum--;
|
||||
}
|
||||
updateCheckNumStatusCall();
|
||||
updateCheckAllStatus(true);
|
||||
}
|
||||
|
||||
private void updateCheckNumStatusCall() {
|
||||
if (listener != null)
|
||||
listener.onCheckNum(checkNum);
|
||||
}
|
||||
|
||||
//更新全选状态
|
||||
private void updateCheckAllStatus(boolean isNotice) {
|
||||
if (getItemCount() == checkNum) {
|
||||
isCheckAll = 0;
|
||||
updateCheckAllStatusCall(isNotice, true);
|
||||
} else if (0 == checkNum) {
|
||||
isCheckAll = 1;
|
||||
updateCheckAllStatusCall(isNotice, false);
|
||||
} else {
|
||||
isCheckAll = 2;
|
||||
updateCheckAllStatusCall(isNotice, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateCheckAllStatusCall(boolean isNotice, boolean isCheckAll) {
|
||||
if (isNotice)
|
||||
if (oldIsCheckAll != isCheckAll) {
|
||||
oldIsCheckAll = isCheckAll;
|
||||
if (listener != null)
|
||||
listener.onCheckAll(isCheckAll);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.base.BaseAdapter;
|
||||
import com.zhidao.adas.client.base.BaseViewHolder;
|
||||
import com.zhidao.adas.client.bean.AutoPilotMode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des 线路
|
||||
* @date 2021/8/13
|
||||
*/
|
||||
public class LineAdapter extends BaseAdapter<AutoPilotMode, LineAdapter.ViewHolder> {
|
||||
|
||||
|
||||
public LineAdapter(List<AutoPilotMode> data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(List<AutoPilotMode> mDatas) {
|
||||
super.setData(mDatas);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDataToItem(ViewHolder viewHolder, AutoPilotMode data, int position) {
|
||||
viewHolder.title.setText("(" + (data.isBus ? "Bus" : "Taxi") + ")" + data.name + " " + data.startName + "->" + data.endName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getItemViewResource(ViewGroup viewGroup) {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.item_info, viewGroup, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewHolder getViewHolder(View view) {
|
||||
return new ViewHolder(view, this);
|
||||
}
|
||||
|
||||
class ViewHolder extends BaseViewHolder<LineAdapter> {
|
||||
TextView title;
|
||||
|
||||
public ViewHolder(View itemView, LineAdapter adapter) {
|
||||
super(itemView, adapter);
|
||||
// ViewGroup.LayoutParams layoutParams = itemView.getLayoutParams();
|
||||
// if (layoutParams != null) {
|
||||
// layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
//
|
||||
// }
|
||||
title = itemView.findViewById(R.id.tv_info_title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.bean.SendCmdOption;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des
|
||||
* @date 2021/8/13
|
||||
*/
|
||||
public class SendCmdAdapter extends RecyclerView.Adapter<SendCmdAdapter.ViewHolder> {
|
||||
private final List<? extends SendCmdOption<?>> data;
|
||||
private final OnItemClickListener listener;
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(SendCmdOption<?> data);
|
||||
}
|
||||
|
||||
public SendCmdAdapter(List<? extends SendCmdOption<?>> data, OnItemClickListener listener) {
|
||||
this.data = data;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_info, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
SendCmdOption<?> option = data.get(position);
|
||||
holder.title.setText(option.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return data == null ? 0 : data.size();
|
||||
}
|
||||
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView title;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
title = itemView.findViewById(R.id.tv_info_title);
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
listener.onItemClick(data.get(getBindingAdapterPosition()));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.base.BaseAdapter;
|
||||
import com.zhidao.adas.client.base.BaseViewHolder;
|
||||
import com.zhidao.adas.client.bean.SpecialVehicleBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des 线路
|
||||
* @date 2021/8/13
|
||||
*/
|
||||
public class SpecialVehicleAdapter extends BaseAdapter<SpecialVehicleBean, SpecialVehicleAdapter.ViewHolder> {
|
||||
|
||||
|
||||
public SpecialVehicleAdapter(List<SpecialVehicleBean> data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(List<SpecialVehicleBean> mDatas) {
|
||||
super.setData(mDatas);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDataToItem(ViewHolder viewHolder, SpecialVehicleBean data, int position) {
|
||||
viewHolder.title.setText(data.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getItemViewResource(ViewGroup viewGroup) {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.item_info, viewGroup, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewHolder getViewHolder(View view) {
|
||||
return new ViewHolder(view, this);
|
||||
}
|
||||
|
||||
class ViewHolder extends BaseViewHolder<SpecialVehicleAdapter> {
|
||||
TextView title;
|
||||
|
||||
public ViewHolder(View itemView, SpecialVehicleAdapter adapter) {
|
||||
super(itemView, adapter);
|
||||
// ViewGroup.LayoutParams layoutParams = itemView.getLayoutParams();
|
||||
// if (layoutParams != null) {
|
||||
// layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
//
|
||||
// }
|
||||
title = itemView.findViewById(R.id.tv_info_title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
package com.zhidao.adas.client.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.bean.AutoPilotMode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ViaPositionAdapter extends RecyclerView.Adapter<ViaPositionAdapter.MyViewHolder> {
|
||||
|
||||
private List<AutoPilotMode.Location> datas;
|
||||
private Context mContext;
|
||||
|
||||
public void setDatas(List<AutoPilotMode.Location> datas) {
|
||||
this.datas = datas;
|
||||
if (!this.datas.isEmpty()) {
|
||||
for (int i = 0; i < this.datas.size(); i++) {
|
||||
this.datas.get(i).name = "点" + (i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<AutoPilotMode.Location> getDatas() {
|
||||
return datas;
|
||||
}
|
||||
|
||||
public void addHint() {
|
||||
datas.add(new AutoPilotMode.Location("点" + (datas.size() + 1)));
|
||||
notifyItemInserted(datas.size() - 1);
|
||||
}
|
||||
|
||||
public void minus() {
|
||||
datas.remove(datas.size() - 1);
|
||||
notifyItemRemoved(datas.size() - 1);
|
||||
notifyItemRangeChanged(datas.size() - 1, getItemCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
//创建ViewHolder
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
//实例化得到Item布局文件的View对象
|
||||
mContext = parent.getContext();
|
||||
View v = LayoutInflater.from(mContext).inflate(R.layout.item_via, parent, false);
|
||||
//返回MyViewHolder的对象
|
||||
return new MyViewHolder(v);
|
||||
}
|
||||
|
||||
//绑定数据
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
AutoPilotMode.Location location = datas.get(position);
|
||||
holder.title.setText(location.name);
|
||||
if (location.longitude != 0.0)
|
||||
holder.lon.setText(String.valueOf(location.longitude));
|
||||
if (location.latitude != 0.0)
|
||||
holder.lat.setText(String.valueOf(location.latitude));
|
||||
// holder.input.setFocusable(true);
|
||||
// holder.input.setFocusableInTouchMode(true);
|
||||
// holder.input.requestFocus();
|
||||
|
||||
}
|
||||
|
||||
//返回Item的数量
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return datas == null ? 0 : datas.size();
|
||||
}
|
||||
|
||||
|
||||
//继承RecyclerView.ViewHolder抽象类的自定义ViewHolder
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView title;
|
||||
EditText lon;
|
||||
EditText lat;
|
||||
|
||||
MyViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
title = itemView.findViewById(R.id.title);
|
||||
lon = itemView.findViewById(R.id.lon);
|
||||
lat = itemView.findViewById(R.id.lat);
|
||||
lon.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
try {
|
||||
datas.get(getBindingAdapterPosition()).longitude = Double.parseDouble(s.toString().trim());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
lon.setText("");
|
||||
Toast.makeText(mContext, "输入不合法", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
datas.get(getBindingAdapterPosition()).longitude = 0.0;
|
||||
}
|
||||
}
|
||||
});
|
||||
lat.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
try {
|
||||
datas.get(getBindingAdapterPosition()).latitude = Double.parseDouble(s.toString().trim());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
lat.setText("");
|
||||
Toast.makeText(mContext, "输入不合法", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
datas.get(getBindingAdapterPosition()).latitude = 0.0;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
package com.zhidao.adas.client.base;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.Gravity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.zhidao.adas.client.ui.MainActivity;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
private BaseHandler mBaseHandler;
|
||||
private Toast toast;
|
||||
|
||||
protected void showToastCenter(String msg) {
|
||||
showToastCenter(msg, Toast.LENGTH_SHORT);
|
||||
}
|
||||
|
||||
protected void showToastCenter(String msg, int duration) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (toast != null) {
|
||||
toast.cancel();
|
||||
toast = null;
|
||||
}
|
||||
toast = Toast.makeText(BaseActivity.this, "", duration); //如果有居中显示需求
|
||||
toast.setGravity(Gravity.CENTER, 0, 0);
|
||||
toast.setText(msg);
|
||||
toast.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (getHandler() != null)
|
||||
getHandler().removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化一个Handler,如果需要使用Handler,先调用此方法,
|
||||
* 然后可以使用postRunnable(Runnable runnable),
|
||||
* sendMessage在handleMessage(Message msg)中接收msg
|
||||
*/
|
||||
public void initHandler() {
|
||||
mBaseHandler = new BaseHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回Handler,在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @return Handler
|
||||
*/
|
||||
public Handler getHandler() {
|
||||
return mBaseHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同Handler 的 handleMessage,
|
||||
* getHandler.sendMessage,发送的Message在此接收
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
protected void handleMessage(Message msg) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 同Handler的postRunnable
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*/
|
||||
protected void postRunnable(Runnable runnable) {
|
||||
postRunnableDelayed(runnable, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同Handler的postRunnableDelayed
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*/
|
||||
protected void postRunnableDelayed(Runnable runnable, long delayMillis) {
|
||||
if (mBaseHandler == null) initHandler();
|
||||
mBaseHandler.postDelayed(runnable, delayMillis);
|
||||
}
|
||||
|
||||
|
||||
protected static class BaseHandler extends Handler {
|
||||
private final WeakReference<BaseActivity> mObjects;
|
||||
|
||||
public BaseHandler(BaseActivity mPresenter) {
|
||||
mObjects = new WeakReference<BaseActivity>(mPresenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
BaseActivity mPresenter = mObjects.get();
|
||||
if (mPresenter != null)
|
||||
mPresenter.handleMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package com.zhidao.adas.client.base;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* RecycleView Adapter
|
||||
* Created by renfeicui on 2018/10/12.
|
||||
*/
|
||||
public abstract class BaseAdapter<D, VH extends BaseViewHolder> extends RecyclerView.Adapter<VH> {
|
||||
protected String TAG = this.getClass().getSimpleName();
|
||||
protected List<D> mDatas;
|
||||
protected Context mContext;
|
||||
private OnItemClickListener<D> mItemClick;
|
||||
|
||||
public interface OnItemClickListener<D> {
|
||||
void onItemClick(int position, D data);
|
||||
}
|
||||
|
||||
|
||||
public BaseAdapter() {
|
||||
}
|
||||
|
||||
public BaseAdapter(List<D> mDatas) {
|
||||
this.mDatas = mDatas;
|
||||
}
|
||||
|
||||
public BaseAdapter(OnItemClickListener<D> listener) {
|
||||
mItemClick = listener;
|
||||
}
|
||||
|
||||
public BaseAdapter(List<D> mDatas, OnItemClickListener<D> listener) {
|
||||
this.mDatas = mDatas;
|
||||
mItemClick = listener;
|
||||
}
|
||||
|
||||
public void setData(List<D> mDatas) {
|
||||
this.mDatas = mDatas;
|
||||
if (!mDatas.isEmpty())
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public List<D> getData() {
|
||||
return mDatas;
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener<D> listener) {
|
||||
mItemClick = listener;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取制定 位置的Data
|
||||
* @param position 下标
|
||||
* @return Data
|
||||
*/
|
||||
public D getItem(int position) {
|
||||
return mDatas == null ? null : mDatas.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDatas == null ? 0 : mDatas.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull VH viewHolder, int position) {
|
||||
D bean = getItem(position);
|
||||
onBindDataToItem(viewHolder, bean, position);
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public VH onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||
mContext = viewGroup.getContext();
|
||||
return getViewHolder(getItemViewResource(viewGroup));
|
||||
}
|
||||
|
||||
/***
|
||||
* 同onBindViewHolder()
|
||||
* @param viewHolder viewHolder
|
||||
* @param data 数据
|
||||
* @param position 下标
|
||||
*/
|
||||
protected abstract void onBindDataToItem(VH viewHolder, D data, int position);
|
||||
|
||||
/***
|
||||
* 获取Item布局
|
||||
* @return id
|
||||
*/
|
||||
protected abstract View getItemViewResource(ViewGroup viewGroup);
|
||||
|
||||
/**
|
||||
* 获取ViewHolder
|
||||
*
|
||||
* @param view
|
||||
* @return
|
||||
*/
|
||||
protected abstract VH getViewHolder(View view);
|
||||
|
||||
public void onClick(BaseViewHolder viewHolder) {
|
||||
if (mItemClick != null) {
|
||||
mItemClick.onItemClick(viewHolder.getAdapterPosition(), getItem(viewHolder.getAdapterPosition()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
package com.zhidao.adas.client.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.zhidao.adas.client.DataDistribution;
|
||||
import com.zhidao.adas.client.OnAdasClientListener;
|
||||
import com.zhidao.adas.client.bean.PerceptionTrafficLight;
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import perception.TrafficLightOuterClass;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des
|
||||
* @date 2021/8/16
|
||||
*/
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
protected final String TAG = this.getClass().getSimpleName();
|
||||
private static final int WHAT_REFRESH = 0x01;
|
||||
private static final int WHAT_UPDATE_CONNECT_STATUS = 0x02;
|
||||
protected static final int WHAT_REFRESH_TRAFFIC_LIGHTS = 0x02;
|
||||
protected String title;
|
||||
|
||||
public BaseFragment() {
|
||||
}
|
||||
|
||||
public BaseFragment(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
initHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (!isHidden())
|
||||
DataDistribution.getInstance().registerAdasClientListener(new Pair<>(title, adasClientListener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
DataDistribution.getInstance().unregisterAdasClientListener(new Pair<>(title, adasClientListener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
if (!hidden) {
|
||||
DataDistribution.getInstance().registerAdasClientListener(new Pair<>(title, adasClientListener));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConnectStatus(int ipcConnectionStatus) {
|
||||
if (getHandler() != null) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = WHAT_UPDATE_CONNECT_STATUS;
|
||||
msg.arg1 = ipcConnectionStatus;
|
||||
getHandler().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onConnectionIPCStatus(int ipcConnectionStatus) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (getHandler() != null)
|
||||
getHandler().removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
protected abstract void onRefreshView();
|
||||
|
||||
|
||||
private final OnAdasClientListener adasClientListener = new OnAdasClientListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
getHandler().sendEmptyMessage(WHAT_REFRESH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPerceptionTrafficLight(PerceptionTrafficLight trafficLights) {
|
||||
super.onPerceptionTrafficLight(trafficLights);
|
||||
if (Constants.TITLE.RECEIVE_PERCEPTION_TRAFFIC_LIGHT.equals(title)) {
|
||||
TrafficLightOuterClass.TrafficLights bean = trafficLights.bean;
|
||||
TrafficLightOuterClass.TrafficLight light = null;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (bean.hasStraight()) {
|
||||
light = bean.getStraight();
|
||||
builder.append("当前:").append("直行灯");
|
||||
} else if (bean.hasLeft()) {
|
||||
light = bean.getLeft();
|
||||
builder.append("当前:").append("左转灯");
|
||||
} else if (bean.hasRight()) {
|
||||
light = bean.getRight();
|
||||
builder.append("当前:").append("右转灯");
|
||||
} else if (bean.hasUTurn()) {
|
||||
light = bean.getUTurn();
|
||||
builder.append("当前:").append("掉头灯");
|
||||
}
|
||||
Message msg = Message.obtain();
|
||||
msg.what = WHAT_REFRESH_TRAFFIC_LIGHTS;
|
||||
if (light != null) {
|
||||
builder.append(" 灯态:").append(getLightState(light.getState()));
|
||||
builder.append(" 车道类型:").append(getLightType(light.getType()));
|
||||
float d = light.getDuration();
|
||||
builder.append(" 读秒:").append(d < 0 ? "未知" : d);
|
||||
msg.obj = builder.toString();
|
||||
}
|
||||
getHandler().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取车道
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
protected String getLightType(TrafficLightOuterClass.LightType type) {
|
||||
String str = null;
|
||||
if (type == TrafficLightOuterClass.LightType.TYPE_VEHICLE) {
|
||||
str = "机动车道";
|
||||
} else if (type == TrafficLightOuterClass.LightType.TYPE_BICYLE) {
|
||||
str = "自行车道";
|
||||
} else if (type == TrafficLightOuterClass.LightType.TYPE_PEDSTRIAN) {
|
||||
str = "行人道";
|
||||
} else if (type == TrafficLightOuterClass.LightType.TYPE_LANE) {
|
||||
str = "车道";
|
||||
} else {//TrafficLightOuterClass.LightState.TYPE_DEFAULT
|
||||
str = "未知";
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取灯态
|
||||
*
|
||||
* @param state
|
||||
* @return
|
||||
*/
|
||||
protected String getLightState(TrafficLightOuterClass.LightState state) {
|
||||
String light = null;
|
||||
if (state == TrafficLightOuterClass.LightState.STATE_RED) {
|
||||
light = "红";
|
||||
} else if (state == TrafficLightOuterClass.LightState.STATE_YELLOW) {
|
||||
light = "黄";
|
||||
} else if (state == TrafficLightOuterClass.LightState.STATE_GREEN) {
|
||||
light = "绿";
|
||||
} else if (state == TrafficLightOuterClass.LightState.STATE_FLASH) {
|
||||
light = "闪";
|
||||
} else {//TrafficLightOuterClass.LightState.STATE_OFF
|
||||
light = "没";
|
||||
}
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
|
||||
private BaseHandler mBaseHandler;
|
||||
|
||||
|
||||
/**
|
||||
* 初始化一个Handler,如果需要使用Handler,先调用此方法,
|
||||
* 然后可以使用postRunnable(Runnable runnable),
|
||||
* sendMessage在handleMessage(Message msg)中接收msg
|
||||
*/
|
||||
public void initHandler() {
|
||||
mBaseHandler = new BaseHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回Handler,在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @return Handler
|
||||
*/
|
||||
public Handler getHandler() {
|
||||
return mBaseHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同Handler 的 handleMessage,
|
||||
* getHandler.sendMessage,发送的Message在此接收
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
protected void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case WHAT_REFRESH:
|
||||
if (isVisible())
|
||||
onRefreshView();
|
||||
break;
|
||||
|
||||
case WHAT_UPDATE_CONNECT_STATUS:
|
||||
if (isVisible())
|
||||
onConnectionIPCStatus(msg.arg1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同Handler的postRunnable
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*/
|
||||
protected void postRunnable(Runnable runnable) {
|
||||
postRunnableDelayed(runnable, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同Handler的postRunnableDelayed
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*/
|
||||
protected void postRunnableDelayed(Runnable runnable, long delayMillis) {
|
||||
if (mBaseHandler == null) initHandler();
|
||||
mBaseHandler.postDelayed(runnable, delayMillis);
|
||||
}
|
||||
|
||||
|
||||
protected static class BaseHandler extends Handler {
|
||||
private final WeakReference<BaseFragment> mObjects;
|
||||
|
||||
public BaseHandler(BaseFragment mPresenter) {
|
||||
mObjects = new WeakReference<BaseFragment>(mPresenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
BaseFragment mPresenter = mObjects.get();
|
||||
if (mPresenter != null)
|
||||
mPresenter.handleMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.zhidao.adas.client.base;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
||||
public abstract class BaseViewHolder<T extends BaseAdapter> extends RecyclerView.ViewHolder {
|
||||
private T adapter;
|
||||
public View itemView;
|
||||
|
||||
public BaseViewHolder(View itemView, final T adapter) {
|
||||
super(itemView);
|
||||
this.itemView = itemView;
|
||||
this.adapter = adapter;
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
adapter.onClick(BaseViewHolder.this);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.GeneratedMessageV3;
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.support.adas.high.bean.AdasParam;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public class AdasParamReceiveData extends BaseInfo {
|
||||
public final GeneratedMessageV3 bean;
|
||||
private final AdasParam adasParam;
|
||||
|
||||
public AdasParamReceiveData(MessagePad.Header header, GeneratedMessageV3 bean, AdasParam adasParam, SimpleDateFormat sdf) {
|
||||
super("接收", bean.getSerializedSize(), header, sdf);
|
||||
this.bean = bean;
|
||||
this.adasParam = adasParam;
|
||||
}
|
||||
|
||||
public String toString(int resId) {
|
||||
String srt = "";
|
||||
if (resId == R.id.rb_analysis) {
|
||||
srt = TextFormat.printer().shortDebugString(bean);
|
||||
} else if (resId == R.id.rb_original) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray());
|
||||
} else if (resId == R.id.rb_all) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray()) + '\n' + TextFormat.printer().shortDebugString(bean);
|
||||
}
|
||||
return super.toString(resId) + srt + "\n原始数据翻译:\n" + adasParam.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public class AutoPilotMode {
|
||||
public String name;
|
||||
public String startName;
|
||||
public Location startLatLon;
|
||||
public String endName;
|
||||
public Location endLatLon;
|
||||
public double speedLimit;
|
||||
public List<Location> wayLatLons;
|
||||
public int routeID = -1;//道路ID
|
||||
public String routeName;//道路名称
|
||||
public boolean isBus = false;//true:bus false:taxi
|
||||
|
||||
public List<MessagePad.Location> getWayLatLons() {
|
||||
if (wayLatLons == null || wayLatLons.isEmpty()) return null;
|
||||
List<MessagePad.Location> list = new ArrayList<>();
|
||||
for (int i = 0; i < wayLatLons.size(); i++) {
|
||||
MessagePad.Location.Builder builder = MessagePad.Location.newBuilder();
|
||||
builder.setLatitude(wayLatLons.get(i).latitude).setLongitude(wayLatLons.get(i).longitude);
|
||||
list.add(builder.build());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static class Location {
|
||||
public String name;
|
||||
public double longitude;
|
||||
public double latitude;
|
||||
|
||||
public Location() {
|
||||
}
|
||||
|
||||
public Location(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isNull() {
|
||||
return longitude == 0.0 || latitude == 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNull() {
|
||||
if (wayLatLons != null && !wayLatLons.isEmpty()) {
|
||||
for (int i = 0; i < wayLatLons.size(); i++) {
|
||||
if (wayLatLons.get(i).isNull()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isBus) {
|
||||
return TextUtils.isEmpty(name) || TextUtils.isEmpty(startName) || TextUtils.isEmpty(endName) ||
|
||||
startLatLon == null || startLatLon.isNull() || endLatLon == null || endLatLon.isNull() ||
|
||||
speedLimit == 0.0 || routeID == -1 || TextUtils.isEmpty(routeName);
|
||||
} else
|
||||
return TextUtils.isEmpty(name) || TextUtils.isEmpty(startName) || TextUtils.isEmpty(endName) ||
|
||||
startLatLon == null || startLatLon.isNull() || endLatLon == null || endLatLon.isNull() ||
|
||||
speedLimit == 0.0;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public abstract class BaseInfo {
|
||||
public final String action;
|
||||
public final long nowTime;
|
||||
public final MessagePad.Header header;
|
||||
public final int len;
|
||||
public final int payloadLen;
|
||||
private SimpleDateFormat sdf;
|
||||
|
||||
public BaseInfo(String action, int len, MessagePad.Header header, SimpleDateFormat sdf) {
|
||||
this.action = action;
|
||||
this.payloadLen = len;
|
||||
nowTime = System.currentTimeMillis();
|
||||
int headerSize = 0;
|
||||
if (header != null) {
|
||||
headerSize = header.getSerializedSize();
|
||||
}
|
||||
this.len = 8 + headerSize + len;
|
||||
this.header = header;
|
||||
this.sdf = sdf;
|
||||
}
|
||||
|
||||
public BaseInfo(String action, int len) {
|
||||
this.action = action;
|
||||
nowTime = System.currentTimeMillis();
|
||||
this.len = len;
|
||||
this.payloadLen = len;
|
||||
this.header = null;
|
||||
}
|
||||
|
||||
public String toString(int resId) {
|
||||
String str = "原始数据长度:" + len + "\tPayload数据长度:" + payloadLen + '\n';
|
||||
if (header != null) {
|
||||
str += "Header:[" + "MessageID:" + header.getMsgID() +
|
||||
" MessageType:" + header.getMsgType() + " 发送时间:" + sdf.format(new Date((long) (header.getTimestamp() * 1000)))
|
||||
+ " 数据源时间:" + sdf.format(new Date((long) (header.getSourceTimestamp() * 1000))) + "]\n";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Config {
|
||||
public final String name;
|
||||
public String value;
|
||||
public int color = -1;
|
||||
|
||||
public Config(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Config config = (Config) o;
|
||||
return Objects.equals(name, config.name);
|
||||
}
|
||||
|
||||
public void cover(Config config) {
|
||||
this.value = config.value;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
public class DataShow {
|
||||
public final long position;
|
||||
public final String data;
|
||||
|
||||
public DataShow(long position, String data) {
|
||||
this.position = position;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
import com.zhidao.support.adas.high.common.ProtocolStatus;
|
||||
|
||||
public class ErrorData extends BaseInfo {
|
||||
private final ProtocolStatus status;
|
||||
private final byte[] bytes;
|
||||
|
||||
public ErrorData(ProtocolStatus status, byte[] bytes) {
|
||||
super("接收", bytes.length);
|
||||
this.status = status;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(int resId) {
|
||||
return super.toString(resId) + status + "\n原始数据:" + ByteUtil.byteArrToHex(bytes);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import androidx.annotation.ColorRes;
|
||||
|
||||
public class IPCConnectState {
|
||||
public final long time;
|
||||
public final String status;
|
||||
@ColorRes
|
||||
public final int color;
|
||||
|
||||
public IPCConnectState(String status, @ColorRes int color) {
|
||||
this.status = status;
|
||||
this.color = color;
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.zhidao.support.adas.high.common.MessageType;
|
||||
|
||||
|
||||
public class InterfaceModel {
|
||||
private boolean isSelected = false;//是否选择
|
||||
private final MessageType messageType;
|
||||
|
||||
public InterfaceModel(MessageType messageType) {
|
||||
this.messageType = messageType;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return isSelected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
isSelected = selected;
|
||||
}
|
||||
|
||||
public MessageType getMessageType() {
|
||||
return messageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
InterfaceModel that = (InterfaceModel) o;
|
||||
return messageType == that.messageType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
public class MySSHResult extends BaseInfo {
|
||||
public final String info;
|
||||
|
||||
public MySSHResult(String info, int len) {
|
||||
super("接收", len);
|
||||
this.info = info;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.mogo.support.obu.ObuScene;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public class ObuMap extends BaseInfo {
|
||||
public final ObuScene.MapMatchData bean;
|
||||
|
||||
|
||||
public ObuMap(MessagePad.Header header, ObuScene.MapMatchData bean, SimpleDateFormat sdf) {
|
||||
super("接收", bean.getSerializedSize(), header, sdf);
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(int resId) {
|
||||
String srt = "";
|
||||
if (resId == R.id.rb_analysis) {
|
||||
srt = TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
} else if (resId == R.id.rb_original) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray());
|
||||
} else if (resId == R.id.rb_all) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray()) + '\n' + TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
}
|
||||
return super.toString(resId) + srt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.mogo.support.obu.ObuScene;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public class ObuRsi extends BaseInfo {
|
||||
public final ObuScene.RsiWarningData bean;
|
||||
|
||||
|
||||
public ObuRsi(MessagePad.Header header, ObuScene.RsiWarningData bean, SimpleDateFormat sdf) {
|
||||
super("接收", bean.getSerializedSize(), header, sdf);
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(int resId) {
|
||||
String srt = "";
|
||||
if (resId == R.id.rb_analysis) {
|
||||
srt = TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
} else if (resId == R.id.rb_original) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray());
|
||||
} else if (resId == R.id.rb_all) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray()) + '\n' + TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
}
|
||||
return super.toString(resId) + srt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.mogo.support.obu.ObuScene;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public class ObuRsm extends BaseInfo {
|
||||
public final ObuScene.RsmWarningData bean;
|
||||
|
||||
|
||||
public ObuRsm(MessagePad.Header header, ObuScene.RsmWarningData bean, SimpleDateFormat sdf) {
|
||||
super("接收", bean.getSerializedSize(), header, sdf);
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(int resId) {
|
||||
String srt = "";
|
||||
if (resId == R.id.rb_analysis) {
|
||||
srt = TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
} else if (resId == R.id.rb_original) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray());
|
||||
} else if (resId == R.id.rb_all) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray()) + '\n' + TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
}
|
||||
return super.toString(resId) + srt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.mogo.support.obu.ObuScene;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public class ObuSpat extends BaseInfo {
|
||||
public final ObuScene.SpatWarningData bean;
|
||||
|
||||
|
||||
public ObuSpat(MessagePad.Header header, ObuScene.SpatWarningData bean, SimpleDateFormat sdf) {
|
||||
super("接收", bean.getSerializedSize(), header, sdf);
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(int resId) {
|
||||
String srt = "";
|
||||
if (resId == R.id.rb_analysis) {
|
||||
srt = TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
} else if (resId == R.id.rb_original) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray());
|
||||
} else if (resId == R.id.rb_all) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray()) + '\n' + TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
}
|
||||
return super.toString(resId) + srt;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
import mogo.v2x.ObuWarningEvent;
|
||||
|
||||
public class ObuWarningData extends BaseInfo {
|
||||
public final ObuWarningEvent.ObuWarningData bean;
|
||||
|
||||
public ObuWarningData(MessagePad.Header header, ObuWarningEvent.ObuWarningData bean, SimpleDateFormat sdf) {
|
||||
super("接收", bean.getSerializedSize(), header, sdf);
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
import perception.TrafficLightOuterClass;
|
||||
|
||||
public class PerceptionTrafficLight extends BaseInfo {
|
||||
public final TrafficLightOuterClass.TrafficLights bean;
|
||||
|
||||
public PerceptionTrafficLight(MessagePad.Header header, TrafficLightOuterClass.TrafficLights bean, SimpleDateFormat sdf) {
|
||||
super("接收", bean.getSerializedSize(), header, sdf);
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(int resId) {
|
||||
String srt = "";
|
||||
if (resId == R.id.rb_analysis) {
|
||||
srt = TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
} else if (resId == R.id.rb_original) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray());
|
||||
} else if (resId == R.id.rb_all) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray()) + '\n' + TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
}
|
||||
return super.toString(resId) + srt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public class ReceiveBytesData extends BaseInfo {
|
||||
public final byte[] data;
|
||||
|
||||
public ReceiveBytesData(MessagePad.Header header, byte[] data, SimpleDateFormat sdf) {
|
||||
super("接收", data.length, header, sdf);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(int resId) {
|
||||
return super.toString(resId) + "Payload原始数据:" + ByteUtil.byteArrToHex(data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.GeneratedMessageV3;
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
public class ReceiveData extends BaseInfo {
|
||||
public final GeneratedMessageV3 bean;
|
||||
|
||||
public ReceiveData(MessagePad.Header header, GeneratedMessageV3 bean, SimpleDateFormat sdf) {
|
||||
super("接收", bean.getSerializedSize(), header, sdf);
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
|
||||
public String toString(int resId) {
|
||||
String srt = "";
|
||||
if (resId == R.id.rb_analysis) {
|
||||
srt = TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
} else if (resId == R.id.rb_original) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray());
|
||||
} else if (resId == R.id.rb_all) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(bean.toByteArray()) + '\n' + TextFormat.printer().escapingNonAscii(false).printToString(bean);
|
||||
}
|
||||
return super.toString(resId) + srt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SendCmd<T> {
|
||||
|
||||
public final String name;
|
||||
public final List<SendCmdOption<T>> value;
|
||||
|
||||
public SendCmd(String name, List<SendCmdOption<T>> value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
//Planning命令
|
||||
public static SendCmd<Integer> getSendToPlanning() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("靠边停车", SendCmdOption.TAG.PULL_OVER, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("重新起步", SendCmdOption.TAG.PULL_OVER, 2));
|
||||
cmds.add(new SendCmdOption<Integer>("紧急停车", SendCmdOption.TAG.PULL_OVER, 3));
|
||||
cmds.add(new SendCmdOption<Integer>("左变道", SendCmdOption.TAG.LANE_CHANGE, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("右变道", SendCmdOption.TAG.LANE_CHANGE, 2));
|
||||
cmds.add(new SendCmdOption<Integer>("超车", SendCmdOption.TAG.LANE_CHANGE, 3));
|
||||
cmds.add(new SendCmdOption<Integer>("恢复自动决策", SendCmdOption.TAG.LANE_CHANGE, 4));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_PLANNING_CMD, cmds);
|
||||
}
|
||||
|
||||
//演示模式开关
|
||||
public static SendCmd<Integer> getSendDemoMode() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("打开", SendCmdOption.TAG.DEMO_MODE, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("关闭", SendCmdOption.TAG.DEMO_MODE, 0));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_SET_DEMO_MODE_REQ, cmds);
|
||||
}
|
||||
|
||||
//盲区开关
|
||||
public static SendCmd<Boolean> getSendBlindArea() {
|
||||
List<SendCmdOption<Boolean>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Boolean>("开启", SendCmdOption.TAG.BLIND_AREA, true));
|
||||
cmds.add(new SendCmdOption<Boolean>("关闭", SendCmdOption.TAG.BLIND_AREA, false));
|
||||
return new SendCmd<Boolean>(Constants.TITLE.SEND_BLIND_AREA, cmds);
|
||||
}
|
||||
|
||||
//V2N数据到PnC
|
||||
public static SendCmd<Boolean> getSendV2nToPnc() {
|
||||
List<SendCmdOption<Boolean>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Boolean>("发送", SendCmdOption.TAG.V2N_TO_PNC, true));
|
||||
cmds.add(new SendCmdOption<Boolean>("关闭", SendCmdOption.TAG.V2N_TO_PNC, false));
|
||||
return new SendCmd<Boolean>(Constants.TITLE.SEND_V2N_TO_PNC, cmds);
|
||||
}
|
||||
|
||||
//雨天模式开关
|
||||
public static SendCmd<Integer> getSendRainMode() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("打开", SendCmdOption.TAG.RAIN_MODE, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("关闭", SendCmdOption.TAG.RAIN_MODE, 0));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_SET_RAIN_MODE_REQ, cmds);
|
||||
}
|
||||
|
||||
//绕障类功能开关
|
||||
public static SendCmd<Integer> getSendDetouring() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("开", SendCmdOption.TAG.DETOURING, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("关", SendCmdOption.TAG.DETOURING, 0));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_DETOURING, cmds);
|
||||
}
|
||||
|
||||
//AEB
|
||||
public static SendCmd<Integer> getSendAeb() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("开", SendCmdOption.TAG.AEB, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("关", SendCmdOption.TAG.AEB, 0));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_AEB, cmds);
|
||||
}
|
||||
|
||||
//限制绕障开关
|
||||
public static SendCmd<Integer> getSendLaneChangeRestrainVaild() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("限制绕障", SendCmdOption.TAG.LANE_CHANGE_RESTRAIN_VALID, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("正常绕障", SendCmdOption.TAG.LANE_CHANGE_RESTRAIN_VALID, 0));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_LANE_CHANGE_RESTRAIN_VALID, cmds);
|
||||
}
|
||||
|
||||
//停车让行线前避让等待开关
|
||||
public static SendCmd<Integer> getSendStopYieldVaild() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("停车让行线前需要避让等待", SendCmdOption.TAG.STOP_YIELD_VALID, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("停车让行线前无需避让等待", SendCmdOption.TAG.STOP_YIELD_VALID, 0));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_STOP_YIELD_VALID, cmds);
|
||||
}
|
||||
|
||||
//地图限速功能开关
|
||||
public static SendCmd<Integer> getSendHadmapSpeedLimitVaild() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("使用地图限速功能", SendCmdOption.TAG.HADMAP_SPEED_LIMIT_VALID, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("不使用地图限速功能", SendCmdOption.TAG.HADMAP_SPEED_LIMIT_VALID, 0));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_HADMAP_SPEED_LIMIT_VALID, cmds);
|
||||
}
|
||||
|
||||
//环岛模式开关
|
||||
public static SendCmd<Integer> getSendRampThetaValid() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("环岛模式", SendCmdOption.TAG.RAMP_THETA_VALID, 1));
|
||||
cmds.add(new SendCmdOption<Integer>("普通模式", SendCmdOption.TAG.RAMP_THETA_VALID, 0));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_RAMP_THETA_VALID, cmds);
|
||||
}
|
||||
|
||||
//参数获取请求
|
||||
public static SendCmd<Integer> getSendGetParamReq() {
|
||||
List<SendCmdOption<Integer>> cmds = new ArrayList<>();
|
||||
cmds.add(new SendCmdOption<Integer>("获取全部", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.UNKNOWN, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.UNKNOWN));
|
||||
cmds.add(new SendCmdOption<Integer>("绕障类功能开关", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.DETOURING, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.DETOURING));
|
||||
cmds.add(new SendCmdOption<Integer>("变道绕障的目标障碍物速度阈值", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.DETOURING_SPEED, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.DETOURING_SPEED));
|
||||
cmds.add(new SendCmdOption<Integer>("AEB开关", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.AEB, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.AEB));
|
||||
cmds.add(new SendCmdOption<Integer>("限制绕障开关", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.LANE_CHANGE_RESTRAIN_VALID, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.LANE_CHANGE_RESTRAIN_VALID));
|
||||
cmds.add(new SendCmdOption<Integer>("停车让行线前避让等待开关", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.STOP_YIELD_VALID, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.STOP_YIELD_VALID));
|
||||
cmds.add(new SendCmdOption<Integer>("地图限速功能开关", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.HADMAP_SPEED_LIMIT_VALID, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.HADMAP_SPEED_LIMIT_VALID));
|
||||
cmds.add(new SendCmdOption<Integer>("环岛模式开关", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.RAMP_THETA_VALID, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.RAMP_THETA_VALID));
|
||||
cmds.add(new SendCmdOption<Integer>("弱网减速停车策略开关", com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.WEAK_NET_SLOW_DOWN, com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.WEAK_NET_SLOW_DOWN));
|
||||
return new SendCmd<Integer>(Constants.TITLE.SEND_GET_PARAM_REQ, cmds);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
public class SendCmdOption<T> {
|
||||
public interface TAG {
|
||||
int PULL_OVER = 0;//Planning指令 靠边停车
|
||||
int LANE_CHANGE = 1;//Planning指令 变道
|
||||
int DEMO_MODE = 2;//演示模式
|
||||
int BLIND_AREA = 3;//盲区数据开关
|
||||
int RAIN_MODE = 4;//雨天模式
|
||||
int DETOURING = 5;//绕障类功能
|
||||
int V2N_TO_PNC = 6;//V2N数据到PnC
|
||||
int AEB = 7;//AEB开关
|
||||
int LANE_CHANGE_RESTRAIN_VALID = 8;//限制绕障开关
|
||||
int STOP_YIELD_VALID = 9;//停车让行线前避让等待开关
|
||||
int HADMAP_SPEED_LIMIT_VALID = 10;//地图限速功能开关
|
||||
int RAMP_THETA_VALID = 11;//环岛模式开关
|
||||
}
|
||||
|
||||
public final String name;
|
||||
public final int tag;
|
||||
public final T value;
|
||||
|
||||
public SendCmdOption(String name, int tag, T value) {
|
||||
this.name = name;
|
||||
this.tag = tag;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -1,347 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.zhidao.adas.client.ui.special.SpecialVehicleFloatWindowManager;
|
||||
import com.zhidao.adas.client.utils.PreferencesUtils;
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import chassis.SpecialVehicleTaskCmdOuterClass;
|
||||
|
||||
public class SpecialVehicleBean {
|
||||
public interface TAG {
|
||||
String FTQSC = "ftqsc";//福田清扫车
|
||||
String KWXB = "kwxb";//开沃小巴
|
||||
String JLM1 = "jlm1";//金旅M1
|
||||
}
|
||||
|
||||
public interface SEND_TYPE {
|
||||
int ONE = 0;//单次发送
|
||||
int MORE = 1;//多次发送
|
||||
int ALL = 2;//两种方式都支持
|
||||
}
|
||||
|
||||
public final String name;
|
||||
public final String simpleName;//简单名字 两个字
|
||||
public final List<SpecialVehicleOption> options;
|
||||
public final String tag;//用于存储
|
||||
public int sendType = SEND_TYPE.ONE;//发送类型
|
||||
private SpecialVehicleFloatWindowManager manager;
|
||||
|
||||
public static final int SCREEN_MARGIN = 20;
|
||||
|
||||
private final String FLOAT_WINDOW_LOCATION_MIN_X;
|
||||
private final String FLOAT_WINDOW_LOCATION_MIN_Y;
|
||||
private final String FLOAT_WINDOW_LOCATION_MAX_X;
|
||||
private final String FLOAT_WINDOW_LOCATION_MAX_Y;
|
||||
|
||||
private SpecialVehicleBean(@NonNull String name, @NonNull String simpleName, String tag, List<SpecialVehicleOption> options) {
|
||||
this.name = name;
|
||||
this.simpleName = simpleName;
|
||||
this.tag = tag;
|
||||
this.options = options;
|
||||
FLOAT_WINDOW_LOCATION_MIN_X = tag + "_float_window_location_min_x";
|
||||
FLOAT_WINDOW_LOCATION_MIN_Y = tag + "_float_window_location_min_y";
|
||||
FLOAT_WINDOW_LOCATION_MAX_X = tag + "_float_window_location_max_X";
|
||||
FLOAT_WINDOW_LOCATION_MAX_Y = tag + "_float_window_location_max_y";
|
||||
|
||||
}
|
||||
|
||||
public void showFloat(Context context) {
|
||||
if (manager == null)
|
||||
manager = new SpecialVehicleFloatWindowManager(context, this);
|
||||
manager.show();
|
||||
}
|
||||
|
||||
public void dismissFloat() {
|
||||
if (manager != null) {
|
||||
manager.onBack();
|
||||
manager = null;
|
||||
}
|
||||
}
|
||||
|
||||
/************************悬浮窗位置******************/
|
||||
|
||||
|
||||
public void setFloatWindowLocationMinX(Context context, int x) {
|
||||
PreferencesUtils.putInt(context, FLOAT_WINDOW_LOCATION_MIN_X, x);
|
||||
}
|
||||
|
||||
public int getFloatWindowLocationMinX(Context context) {
|
||||
return PreferencesUtils.getInt(context, FLOAT_WINDOW_LOCATION_MIN_X, SCREEN_MARGIN);
|
||||
}
|
||||
|
||||
public void setFloatWindowLocationMinY(Context context, int y) {
|
||||
PreferencesUtils.putInt(context, FLOAT_WINDOW_LOCATION_MIN_Y, y);
|
||||
}
|
||||
|
||||
public int getFloatWindowLocationMinY(Context context) {
|
||||
return PreferencesUtils.getInt(context, FLOAT_WINDOW_LOCATION_MIN_Y, SCREEN_MARGIN);
|
||||
}
|
||||
|
||||
|
||||
/************************悬浮窗位置******************/
|
||||
|
||||
public void setFloatWindowLocationMaxX(Context context, int x) {
|
||||
PreferencesUtils.putInt(context, FLOAT_WINDOW_LOCATION_MAX_X, x);
|
||||
}
|
||||
|
||||
public int getFloatWindowLocationMaxX(Context context) {
|
||||
return PreferencesUtils.getInt(context, FLOAT_WINDOW_LOCATION_MAX_X, SCREEN_MARGIN);
|
||||
}
|
||||
|
||||
public void setFloatWindowLocationMaxY(Context context, int y) {
|
||||
PreferencesUtils.putInt(context, FLOAT_WINDOW_LOCATION_MAX_Y, y);
|
||||
}
|
||||
|
||||
public int getFloatWindowLocationMaxY(Context context) {
|
||||
return PreferencesUtils.getInt(context, FLOAT_WINDOW_LOCATION_MAX_Y, SCREEN_MARGIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* 命令下发
|
||||
*
|
||||
* @param index -1一次性发送所有命令 其他 单个命令发送
|
||||
* @return
|
||||
*/
|
||||
public String sendCmd(int index) {
|
||||
String str = "";
|
||||
if (TextUtils.equals(this.tag, TAG.FTQSC)) { //福田清扫车
|
||||
SpecialVehicleTaskCmdOuterClass.RoboSweeperFuTianCleanCmd.Builder builder = SpecialVehicleTaskCmdOuterClass.RoboSweeperFuTianCleanCmd.newBuilder();
|
||||
if (index < 0) {
|
||||
for (index = 0; index < options.size(); index++) {
|
||||
SpecialVehicleOption option = options.get(index);
|
||||
if (option.moreCheckPos != -1) {
|
||||
option.checkPos = option.moreCheckPos;
|
||||
option.moreCheckPos = -1;
|
||||
}
|
||||
setFuTianCleanValue(builder, index, option.checkPos);
|
||||
}
|
||||
} else {
|
||||
int checkPos = options.get(index).checkPos;
|
||||
setFuTianCleanValue(builder, index, checkPos);
|
||||
}
|
||||
SpecialVehicleTaskCmdOuterClass.RoboSweeperFuTianCleanCmd fuTianCleanCmd = builder.build();
|
||||
SpecialVehicleTaskCmdOuterClass.RoboSweeperFuTianTaskCmd fuTianTaskCmd = SpecialVehicleTaskCmdOuterClass.RoboSweeperFuTianTaskCmd.newBuilder()
|
||||
.setRoboSweeperFutianCleanCmd(fuTianCleanCmd).build();
|
||||
AdasManager.getInstance().sendRoboSweeperFuTianTaskCmd(fuTianTaskCmd);
|
||||
str = TextFormat.printer().escapingNonAscii(false).shortDebugString(fuTianTaskCmd);
|
||||
} else if (TextUtils.equals(this.tag, TAG.KWXB)) { //开沃小巴
|
||||
SpecialVehicleTaskCmdOuterClass.RoboVanSkywellTaskCmd vanSkywellTaskCmd = SpecialVehicleTaskCmdOuterClass.RoboVanSkywellTaskCmd.newBuilder()
|
||||
.build();
|
||||
AdasManager.getInstance().sendRoboVanSkywellTaskCmd(vanSkywellTaskCmd);
|
||||
} else if (TextUtils.equals(this.tag, TAG.JLM1)) { //金旅M1
|
||||
SpecialVehicleTaskCmdOuterClass.RoboBusJinlvM1Cmd.Builder builder = SpecialVehicleTaskCmdOuterClass.RoboBusJinlvM1Cmd.newBuilder();
|
||||
if (index < 0) {
|
||||
for (index = 0; index < options.size(); index++) {
|
||||
SpecialVehicleOption option = options.get(index);
|
||||
if (option.moreCheckPos != -1) {
|
||||
option.checkPos = option.moreCheckPos;
|
||||
option.moreCheckPos = -1;
|
||||
}
|
||||
setJinlvM1Value(builder, index, option.checkPos);
|
||||
}
|
||||
} else {
|
||||
int checkPos = options.get(index).checkPos;
|
||||
setJinlvM1Value(builder, index, checkPos);
|
||||
}
|
||||
SpecialVehicleTaskCmdOuterClass.RoboBusJinlvM1Cmd roboBusJinlvM1Cmd = builder.build();
|
||||
AdasManager.getInstance().sendRoboBusJinlvM1TaskCmd(roboBusJinlvM1Cmd);
|
||||
str = TextFormat.printer().escapingNonAscii(false).shortDebugString(roboBusJinlvM1Cmd);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
private void setJinlvM1Value(SpecialVehicleTaskCmdOuterClass.RoboBusJinlvM1Cmd.Builder builder, int index, int checkPos) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
builder.setAirConditionerCmd(checkPos);
|
||||
break;
|
||||
case 1:
|
||||
builder.setAirConditionerModeCmd(checkPos);
|
||||
break;
|
||||
case 2:
|
||||
builder.setAirConditionerWindSpeedCmd(checkPos);
|
||||
break;
|
||||
case 3:
|
||||
if (checkPos == 1) {
|
||||
checkPos = 16;
|
||||
} else if (checkPos == 2) {
|
||||
checkPos = 20;
|
||||
} else if (checkPos == 3) {
|
||||
checkPos = 26;
|
||||
}
|
||||
builder.setAirConditionerTemperatureCmd(checkPos);
|
||||
break;
|
||||
case 4:
|
||||
builder.setHeaderCmd(checkPos);
|
||||
break;
|
||||
case 5:
|
||||
builder.setHeaderWindSpeedCmd(checkPos);
|
||||
break;
|
||||
case 6:
|
||||
builder.setMainLamp1Cmd(checkPos);
|
||||
break;
|
||||
case 7:
|
||||
builder.setMainLamp2Cmd(checkPos);
|
||||
break;
|
||||
case 8:
|
||||
builder.setSmallLampCmd(checkPos);
|
||||
break;
|
||||
case 9:
|
||||
builder.setFrontDoorCmd(checkPos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setFuTianCleanValue(SpecialVehicleTaskCmdOuterClass.RoboSweeperFuTianCleanCmd.Builder builder, int index, int checkPos) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
builder.setCleanOpenRequirement(checkPos);
|
||||
break;
|
||||
case 1:
|
||||
builder.setCleanModeRequirement(checkPos);
|
||||
break;
|
||||
case 2:
|
||||
builder.setCleanDirectionRequirement(checkPos);
|
||||
break;
|
||||
case 3:
|
||||
builder.setCleanIntensityRequirement(checkPos);
|
||||
break;
|
||||
case 4:
|
||||
builder.setDuskCloseRequirement(checkPos);
|
||||
break;
|
||||
case 5:
|
||||
builder.setSuctionNozzlefleOpenRequirement(checkPos);
|
||||
break;
|
||||
case 6:
|
||||
builder.setSprayGunOpenRequirement(checkPos);
|
||||
break;
|
||||
case 7:
|
||||
builder.setSweepdiskSpeedRequirement(checkPos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static List<SpecialVehicleBean> init() {
|
||||
List<SpecialVehicleBean> list = new ArrayList<>();
|
||||
List<SpecialVehicleOption> optionsF = new ArrayList<>();
|
||||
int tag = 0;
|
||||
String[] value = new String[3];
|
||||
value[0] = "0-No Req";
|
||||
value[1] = "1-Start";
|
||||
value[2] = "2-Stop";
|
||||
optionsF.add(new SpecialVehicleOption("清扫作业", tag++, value, 0));
|
||||
value = new String[6];
|
||||
value[0] = "0-No Req";
|
||||
value[1] = "1-Sweeping";
|
||||
value[2] = "2-Wash Sweeper";
|
||||
value[3] = "3-Pure Wash";
|
||||
value[4] = "4-Pure Draw";
|
||||
value[5] = "5-Close Clean";
|
||||
optionsF.add(new SpecialVehicleOption("清扫模式", tag++, value, 0));
|
||||
value = new String[5];
|
||||
value[0] = "0-No Req";
|
||||
value[1] = "1-Both";
|
||||
value[2] = "2-Left";
|
||||
value[3] = "3-Right";
|
||||
value[4] = "4-Close Side";
|
||||
optionsF.add(new SpecialVehicleOption("清扫方向", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-No Req";
|
||||
value[1] = "1-Stand";
|
||||
value[2] = "2-Strong";
|
||||
optionsF.add(new SpecialVehicleOption("作业强度", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-No Req";
|
||||
value[1] = "1-Close";
|
||||
value[2] = "2-Open";
|
||||
optionsF.add(new SpecialVehicleOption("降尘", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-No Req";
|
||||
value[1] = "1-Open";
|
||||
value[2] = "2-Close";
|
||||
optionsF.add(new SpecialVehicleOption("吸嘴挡板", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-No Req";
|
||||
value[1] = "1-Open";
|
||||
value[2] = "2-Close";
|
||||
optionsF.add(new SpecialVehicleOption("喷雾枪", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-No Req";
|
||||
value[1] = "1-Decelerate";
|
||||
value[2] = "2-Accelerate";
|
||||
optionsF.add(new SpecialVehicleOption("扫盘加速", tag, value, 0));
|
||||
SpecialVehicleBean beanF = new SpecialVehicleBean("福田清扫车", "福清", TAG.FTQSC, optionsF);
|
||||
SpecialVehicleBean beanK = new SpecialVehicleBean("开沃小巴", "开巴", TAG.KWXB, null);
|
||||
List<SpecialVehicleOption> optionsM1 = new ArrayList<>();
|
||||
tag = 0;
|
||||
value = new String[3];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-开启空调";
|
||||
value[2] = "2-关闭空调";
|
||||
optionsM1.add(new SpecialVehicleOption("空调", tag++, value, 0));
|
||||
value = new String[4];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-自动模式";
|
||||
value[2] = "2-制冷模式";
|
||||
value[3] = "3-通风模式";
|
||||
optionsM1.add(new SpecialVehicleOption("空调模式", tag++, value, 0));
|
||||
value = new String[4];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-1档";
|
||||
value[2] = "2-2档";
|
||||
value[3] = "3-3档";
|
||||
optionsM1.add(new SpecialVehicleOption("空调档位", tag++, value, 0));
|
||||
value = new String[4];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "16-16度";
|
||||
value[2] = "20-20度";
|
||||
value[3] = "26-26度";
|
||||
optionsM1.add(new SpecialVehicleOption("空调温度", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-开启暖风";
|
||||
value[2] = "2-关闭暖风";
|
||||
optionsM1.add(new SpecialVehicleOption("暖风机", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-1档";
|
||||
value[2] = "2-2档";
|
||||
optionsM1.add(new SpecialVehicleOption("暖风机档位", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-开启";
|
||||
value[2] = "2-关闭";
|
||||
optionsM1.add(new SpecialVehicleOption("顶灯1", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-开启";
|
||||
value[2] = "2-关闭";
|
||||
optionsM1.add(new SpecialVehicleOption("顶灯2", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-开启";
|
||||
value[2] = "2-关闭";
|
||||
optionsM1.add(new SpecialVehicleOption("氛围灯", tag++, value, 0));
|
||||
value = new String[3];
|
||||
value[0] = "0-DEFAULT";
|
||||
value[1] = "1-打开";
|
||||
value[2] = "2-关闭";
|
||||
optionsM1.add(new SpecialVehicleOption("车门", tag++, value, 0));
|
||||
SpecialVehicleBean beanM1 = new SpecialVehicleBean("金旅M1", "M1", TAG.JLM1, optionsM1);
|
||||
list.add(beanF);
|
||||
list.add(beanK);
|
||||
list.add(beanM1);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
public class SpecialVehicleOption {
|
||||
public final String name;
|
||||
public final int tag;
|
||||
public final String[] value;
|
||||
public int checkPos = 0;//选中的下标
|
||||
public int moreCheckPos = -1;//发送模式下多条模式时选中的下标
|
||||
|
||||
public SpecialVehicleOption(String name, int tag, String[] value, int checkPos) {
|
||||
this.name = name;
|
||||
this.tag = tag;
|
||||
this.value = value;
|
||||
this.checkPos = checkPos;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
public class UpdateDataEvent {
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.zhidao.adas.client.bean;
|
||||
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
import mogo.v2x.MogoV2X;
|
||||
import mogo.v2x.RoadOverviewEvents;
|
||||
|
||||
public class V2nGlobalPathEventsReceiveData extends BaseInfo {
|
||||
public final RoadOverviewEvents.RoadOverviewData roadOverview;
|
||||
public final MogoV2X.RSI_PB construct;
|
||||
public final MogoV2X.RSI_PB triangle;
|
||||
public final MogoV2X.RSI_PB congestion;
|
||||
public final MogoV2X.RSM_PB parkingViolation;
|
||||
|
||||
public V2nGlobalPathEventsReceiveData(MessagePad.Header header, RoadOverviewEvents.RoadOverviewData roadOverview, MogoV2X.RSI_PB construct, MogoV2X.RSI_PB triangle, MogoV2X.RSI_PB congestion, MogoV2X.RSM_PB parkingViolation, SimpleDateFormat sdf) {
|
||||
super("接收", roadOverview.getSerializedSize(), header, sdf);
|
||||
this.roadOverview = roadOverview;
|
||||
this.construct = construct;
|
||||
this.triangle = triangle;
|
||||
this.congestion = congestion;
|
||||
this.parkingViolation = parkingViolation;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(int resId) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('\n').append("施工:");
|
||||
if (construct != null) {
|
||||
builder.append(TextFormat.printer().escapingNonAscii(false).printToString(construct));
|
||||
} else {
|
||||
builder.append("null");
|
||||
}
|
||||
builder.append('\n').append("三角牌:");
|
||||
if (triangle != null) {
|
||||
builder.append(TextFormat.printer().escapingNonAscii(false).printToString(triangle));
|
||||
} else {
|
||||
builder.append("null");
|
||||
}
|
||||
builder.append('\n').append("拥堵:");
|
||||
if (congestion != null) {
|
||||
builder.append(TextFormat.printer().escapingNonAscii(false).printToString(congestion));
|
||||
} else {
|
||||
builder.append("null");
|
||||
}
|
||||
builder.append('\n').append("违停:");
|
||||
if (parkingViolation != null) {
|
||||
builder.append(TextFormat.printer().escapingNonAscii(false).printToString(parkingViolation));
|
||||
} else {
|
||||
builder.append("null");
|
||||
}
|
||||
String srt = "";
|
||||
if (resId == R.id.rb_analysis) {
|
||||
srt = builder.toString();
|
||||
} else if (resId == R.id.rb_original) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(roadOverview.toByteArray());
|
||||
} else if (resId == R.id.rb_all) {
|
||||
srt = "Payload原始数据:" + ByteUtil.byteArrToHex(roadOverview.toByteArray()) + builder.toString();
|
||||
}
|
||||
return super.toString(resId) + srt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package com.zhidao.adas.client.log;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
import com.zhidao.support.adas.high.common.ThreadPoolManager;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* 与服务器交互日志管理任务
|
||||
*/
|
||||
public class ConnectStatusSave {
|
||||
private static final String TAG = ConnectStatusSave.class.getSimpleName();
|
||||
private static final String LOG_FILE_NAME = "ConnectStatus-%s.log";//文件名称
|
||||
private volatile static ConnectStatusSave INSTANCE;
|
||||
private static final long MAX_CAPACITY = 20 * 1024 * 1024L;//单文件最大存储容量 kb
|
||||
private final LinkedBlockingQueue<String> queue;
|
||||
private BufferedWriter buff = null;
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS", Locale.getDefault());
|
||||
private File file;
|
||||
private volatile long capacity = MAX_CAPACITY;
|
||||
private Future future;
|
||||
|
||||
private ConnectStatusSave() {
|
||||
queue = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
public static ConnectStatusSave getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (ConnectStatusSave.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ConnectStatusSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSdcardUse() {
|
||||
boolean bl = false;
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
bl = true;
|
||||
}
|
||||
return bl;
|
||||
}
|
||||
|
||||
private synchronized void getFile() throws IOException {
|
||||
if (isSdcardUse()) {
|
||||
String time = sdf.format(new Date());
|
||||
String childPath = time.split("_")[0] + File.separator;
|
||||
file = new File(Constants.ROOT_PATH + childPath + String.format(LOG_FILE_NAME, time));
|
||||
if (!file.exists()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
file.createNewFile();
|
||||
}
|
||||
FileWriter fw = new FileWriter(file, true);
|
||||
buff = new BufferedWriter(fw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void saveLog(String info) {
|
||||
if (isStart()) {
|
||||
queue.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isStart() {
|
||||
return future != null;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (future == null) {
|
||||
future = ThreadPoolManager.getsInstance().submit(new WriteThread());
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (future != null) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
queue.clear();
|
||||
if (!future.isCancelled()) {
|
||||
future.cancel(true);
|
||||
}
|
||||
future = null;
|
||||
closeBufferedWriter();
|
||||
}
|
||||
};
|
||||
ThreadPoolManager.getsInstance().execute(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
private void closeBufferedWriter() {
|
||||
if (buff != null) {
|
||||
try {
|
||||
buff.flush();
|
||||
buff.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buff = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class WriteThread implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (this) {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
long size = 0;
|
||||
if (file != null) {
|
||||
size = file.length();
|
||||
}
|
||||
if (size > capacity || file == null || !file.exists() || buff == null) {
|
||||
closeBufferedWriter();
|
||||
getFile();
|
||||
}
|
||||
String data = queue.take();
|
||||
if (buff != null && !TextUtils.isEmpty(data)) {
|
||||
buff.write(data);
|
||||
buff.newLine();
|
||||
buff.flush();
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package com.zhidao.adas.client.log;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
import com.zhidao.support.adas.high.common.ThreadPoolManager;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* 与服务器交互日志管理任务
|
||||
*/
|
||||
public class LogSave {
|
||||
private static final String TAG = LogSave.class.getSimpleName();
|
||||
private static final String LOG_FILE_NAME = "%s.log";//文件名称
|
||||
private volatile static LogSave INSTANCE;
|
||||
private static final long MAX_CAPACITY = 20 * 1024 * 1024L;//单文件最大存储容量 kb
|
||||
private final LinkedBlockingQueue<String> queue;
|
||||
private BufferedWriter buff = null;
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS", Locale.getDefault());
|
||||
private File file;
|
||||
private volatile long capacity = MAX_CAPACITY;
|
||||
private Future future;
|
||||
|
||||
private LogSave() {
|
||||
queue = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
public static LogSave getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (LogSave.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new LogSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSdcardUse() {
|
||||
boolean bl = false;
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
bl = true;
|
||||
}
|
||||
return bl;
|
||||
}
|
||||
|
||||
private synchronized void getFile() throws IOException {
|
||||
if (isSdcardUse()) {
|
||||
String time = sdf.format(new Date());
|
||||
String childPath = time.split("_")[0] + File.separator;
|
||||
file = new File(Constants.ROOT_PATH + childPath + String.format(LOG_FILE_NAME, time));
|
||||
if (!file.exists()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
file.createNewFile();
|
||||
}
|
||||
FileWriter fw = new FileWriter(file, true);
|
||||
buff = new BufferedWriter(fw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void saveLog(String info) {
|
||||
if (isStart()) {
|
||||
queue.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isStart() {
|
||||
return future != null;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (future == null) {
|
||||
future = ThreadPoolManager.getsInstance().submit(new WriteThread());
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (future != null) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
queue.clear();
|
||||
if (!future.isCancelled()) {
|
||||
future.cancel(true);
|
||||
}
|
||||
future = null;
|
||||
closeBufferedWriter();
|
||||
}
|
||||
};
|
||||
ThreadPoolManager.getsInstance().execute(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
private void closeBufferedWriter() {
|
||||
if (buff != null) {
|
||||
try {
|
||||
buff.flush();
|
||||
buff.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buff = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class WriteThread implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (this) {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
long size = 0;
|
||||
if (file != null) {
|
||||
size = file.length();
|
||||
}
|
||||
if (size > capacity || file == null || !file.exists() || buff == null) {
|
||||
closeBufferedWriter();
|
||||
getFile();
|
||||
}
|
||||
String data = queue.take();
|
||||
if (buff != null && !TextUtils.isEmpty(data)) {
|
||||
buff.write(data);
|
||||
buff.newLine();
|
||||
buff.flush();
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
package com.zhidao.adas.client.other.permission;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 长时间后台运行权限检查
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
public class BackgrounderPermission {
|
||||
private static volatile BackgrounderPermission INSTANCE;
|
||||
private OnAdasPermissionListener listener;
|
||||
|
||||
private BackgrounderPermission() {
|
||||
}
|
||||
|
||||
public static BackgrounderPermission getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (BackgrounderPermission.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new BackgrounderPermission();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void setListener(OnAdasPermissionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void showPermissionLongBackgroundRunningDialog(Context context) {
|
||||
Intent intent = new Intent(context, PermissionLongBackgroundRunningDialog.class);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
void onBackgrounderPermission(boolean isBackgrounderPermission) {
|
||||
if (listener != null) {
|
||||
listener.onBackgrounderPermission(isBackgrounderPermission);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前是否开启电池优化
|
||||
*
|
||||
* @param context 上下文
|
||||
* @return 否在设备的电源白名单上 true 表示未优化
|
||||
*/
|
||||
boolean isIgnoringBatteryOptimizations(Context context) {
|
||||
boolean isIgnoring = false;
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
if (powerManager != null) {
|
||||
isIgnoring = powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
|
||||
}
|
||||
return isIgnoring;
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请 关闭电池优化权限
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
|
||||
void requestIgnoreBatteryOptimizations(Activity context) {
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||
context.startActivityForResult(intent, PermissionLongBackgroundRunningDialog.REQUEST_CODE_BATTERY_OPTIMIZATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否忽略计费网络限制
|
||||
* 后台运行时网络限制
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
|
||||
private boolean isIgnoringMeteredNetworkRestrictions(Context context) {
|
||||
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
// 检查设备是否在计费网络
|
||||
// if (connMgr.isActiveNetworkMetered()) {
|
||||
// Checks user’s Data Saver settings.
|
||||
switch (connMgr.getRestrictBackgroundStatus()) {
|
||||
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED:
|
||||
// 用户已为此应用启用流量节省程序。应用应努力限制前台流量消耗,并妥善处理后台流量消耗限制。
|
||||
Log.i("Permission", "用户已为此应用启用流量节省程序。应用应努力限制前台流量消耗,并妥善处理后台流量消耗限制。");
|
||||
return false;
|
||||
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELISTED:
|
||||
// 用户已启用流量节省程序,但应用在白名单中。应用应努力限制前台和后台流量消耗。
|
||||
Log.i("Permission", "用户已启用流量节省程序,但应用在白名单中。应用应努力限制前台和后台流量消耗。");
|
||||
return false;
|
||||
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED:
|
||||
// 流量节省程序已停用。
|
||||
Log.i("Permission", "流量节省程序已停用。");
|
||||
return true;
|
||||
}
|
||||
// } else {
|
||||
// // 设备不在计费网络,为所欲为
|
||||
// Log.i("Permission","设备不在计费网络,为所欲为");
|
||||
// return true;
|
||||
// }
|
||||
Log.i("dddd", "其他");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 除非应用的核心功能受到不利影响,否则 Google Play 政策禁止应用请求直接豁免 Android 6.0+ 中的电源管理功能(低电耗模式和应用待机模式)
|
||||
*/
|
||||
private static void requestAddDataSaverWhite(Context context) {
|
||||
// ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
// if (connMgr != null && connMgr.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED) {
|
||||
Intent intent = new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS);
|
||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||
context.startActivity(intent);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许长时间后台运行
|
||||
* 目前测试得出:电池优化会影响后台运行
|
||||
*
|
||||
* @param context 上下文
|
||||
* @return
|
||||
*/
|
||||
public boolean isPermissionLongBackgroundRunning(Context context) {
|
||||
// return isIgnoringBatteryOptimizations(context) && isIgnoringMeteredNetworkRestrictions(context);
|
||||
return isIgnoringBatteryOptimizations(context);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.zhidao.adas.client.other.permission;
|
||||
|
||||
public interface OnAdasPermissionListener {
|
||||
/**
|
||||
* 是否允许后台运行
|
||||
* 目前只检查了是否关闭电池优化
|
||||
* @param isAllow 是否允许后台运行
|
||||
*/
|
||||
void onBackgrounderPermission(boolean isAllow);
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package com.zhidao.adas.client.other.permission;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
|
||||
|
||||
/**
|
||||
* 数据用量及电池优化 权限申请
|
||||
* 高版本Android系统会针对熄屏、休眠或后台 对电池WiFi等进行优化,长时间网络可能会断开连接
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
public class PermissionLongBackgroundRunningDialog extends AppCompatActivity {
|
||||
public static final int REQUEST_CODE_BATTERY_OPTIMIZATIONS = 0x01;
|
||||
private TextView hint_battery;
|
||||
private Button btn_close_battery_optimizations;
|
||||
private BackgrounderPermission listener;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_adas_permission_long_background_running);
|
||||
initView();
|
||||
setBatteryHint();
|
||||
// //设置弹出窗口与屏幕对齐
|
||||
// Window win = this.getWindow();
|
||||
// int density = (int) (getResources().getDisplayMetrics().density + 0.5f);
|
||||
////设置内边距,这里设置为10dp
|
||||
// win.getDecorView().setPadding(10 * density, 10 * density, 10 * density, 10 * density);
|
||||
// WindowManager.LayoutParams lp = win.getAttributes();
|
||||
////设置窗口宽度
|
||||
// lp.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
////设置窗口高度
|
||||
// lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
////设置Dialog位置
|
||||
// lp.gravity = Gravity.TOP;
|
||||
// win.setAttributes(lp);
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
hint_battery = findViewById(R.id.hint_battery);
|
||||
btn_close_battery_optimizations = findViewById(R.id.btn_close_battery_optimizations);
|
||||
btn_close_battery_optimizations.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BackgrounderPermission.getInstance().requestIgnoreBatteryOptimizations(PermissionLongBackgroundRunningDialog.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private boolean setBatteryHint() {
|
||||
boolean isIgnoringBatteryOptimizations = BackgrounderPermission.getInstance().isIgnoringBatteryOptimizations(this);
|
||||
btn_close_battery_optimizations.setVisibility(isIgnoringBatteryOptimizations ? View.INVISIBLE : View.VISIBLE);
|
||||
String str = "电池优化:" + (isIgnoringBatteryOptimizations ? "<font color='green'>不优化</font>" : "<font color='red'>优化</font>");
|
||||
hint_battery.setText(Html.fromHtml(str, Html.FROM_HTML_MODE_LEGACY));
|
||||
return isIgnoringBatteryOptimizations;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == REQUEST_CODE_BATTERY_OPTIMIZATIONS) {
|
||||
BackgrounderPermission.getInstance().onBackgrounderPermission(setBatteryHint());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
package com.zhidao.adas.client.other.router;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.JsResult;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public class PlaceholderFragment extends Fragment {
|
||||
private static final String TAG = PlaceholderFragment.class.getSimpleName();
|
||||
private static final String ROUTER_URL = "router_url";
|
||||
private static final String ROUTER_COOKIE = "router_cookie";
|
||||
private String url;
|
||||
private ProgressBar progressBar;
|
||||
private WebView webView;
|
||||
private CookieManager cookieManager;
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
public static PlaceholderFragment newInstance(String url) {
|
||||
PlaceholderFragment fragment = new PlaceholderFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(ROUTER_URL, url);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
url = getArguments().getString(ROUTER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_router, container, false);
|
||||
webView = view.findViewById(R.id.web_view);
|
||||
progressBar = view.findViewById(R.id.progressbar);//进度条
|
||||
if (getActivity() != null)
|
||||
sharedPreferences = getActivity().getSharedPreferences("adas_config", Context.MODE_PRIVATE);
|
||||
cookieManager = CookieManager.getInstance();
|
||||
cookieManager.setAcceptCookie(true);
|
||||
initWebView();
|
||||
return view;
|
||||
}
|
||||
|
||||
public void onRefresh() {
|
||||
webView.reload();
|
||||
}
|
||||
|
||||
private void initWebView() {
|
||||
String cokkie = null;
|
||||
if (sharedPreferences != null)
|
||||
cokkie = sharedPreferences.getString(ROUTER_COOKIE, null);
|
||||
if (cokkie != null && cokkie.length() > 0 && cokkie.contains(url)) {
|
||||
int index = cokkie.indexOf("##");
|
||||
cookieManager.setCookie(this.url, cokkie.substring(index));
|
||||
}
|
||||
webView.loadUrl(url);//加载url
|
||||
webView.addJavascriptInterface(this, "android");//添加js监听 这样html就能调用客户端
|
||||
webView.setWebChromeClient(webChromeClient);
|
||||
webView.setWebViewClient(webViewClient);
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
webSettings.setJavaScriptEnabled(true);//允许使用js
|
||||
|
||||
/**
|
||||
* LOAD_CACHE_ONLY: 不使用网络,只读取本地缓存数据
|
||||
* LOAD_DEFAULT: (默认)根据cache-control决定是否从网络上取数据。
|
||||
* LOAD_NO_CACHE: 不使用缓存,只从网络获取数据.
|
||||
* LOAD_CACHE_ELSE_NETWORK,只要本地有,无论是否过期,或者no-cache,都使用缓存中的数据。
|
||||
*/
|
||||
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);//不使用缓存,只从网络获取数据.
|
||||
//支持屏幕缩放
|
||||
webSettings.setSupportZoom(true);
|
||||
webSettings.setBuiltInZoomControls(true);
|
||||
//不显示webview缩放按钮
|
||||
webSettings.setDisplayZoomControls(false);
|
||||
// webSettings.setUseWideViewPort(true);//自适应屏幕
|
||||
webSettings.setLoadWithOverviewMode(true);
|
||||
webSettings.setAllowFileAccess(true);
|
||||
webSettings.setAppCacheEnabled(true);
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
webSettings.setDatabaseEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
//WebViewClient主要帮助WebView处理各种通知、请求事件
|
||||
private final WebViewClient webViewClient = new WebViewClient() {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {//页面加载完成
|
||||
progressBar.setVisibility(View.GONE);
|
||||
String oldCookie = cookieManager.getCookie(url);
|
||||
if (!TextUtils.isEmpty(oldCookie)) {
|
||||
String cokkie = null;
|
||||
if (sharedPreferences != null)
|
||||
cokkie = sharedPreferences.getString(ROUTER_COOKIE, null);
|
||||
if (!TextUtils.equals(cokkie, oldCookie)) {
|
||||
sharedPreferences.edit().putString(url + "##" + ROUTER_COOKIE, oldCookie).apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {//页面开始加载
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
//返回true 拦截
|
||||
return super.shouldOverrideUrlLoading(view, url);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//WebChromeClient主要辅助WebView处理Javascript的对话框、网站图标、网站title、加载进度等
|
||||
private final WebChromeClient webChromeClient = new WebChromeClient() {
|
||||
//不支持js的alert弹窗,需要自己监听然后通过dialog弹窗
|
||||
@Override
|
||||
public boolean onJsAlert(WebView webView, String url, String message, JsResult result) {
|
||||
AlertDialog.Builder localBuilder = new AlertDialog.Builder(webView.getContext());
|
||||
localBuilder.setMessage(message).setPositiveButton("确定", null);
|
||||
localBuilder.setCancelable(false);
|
||||
localBuilder.create().show();
|
||||
|
||||
//注意:
|
||||
//必须要这一句代码:result.confirm()表示:
|
||||
//处理结果为确定状态同时唤醒WebCore线程
|
||||
//否则不能继续点击按钮
|
||||
result.confirm();
|
||||
return true;
|
||||
}
|
||||
|
||||
//获取网页标题
|
||||
@Override
|
||||
public void onReceivedTitle(WebView view, String title) {
|
||||
super.onReceivedTitle(view, title);
|
||||
Log.i(TAG, "网页标题:" + title);
|
||||
}
|
||||
|
||||
//加载进度回调
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
progressBar.setProgress(newProgress);
|
||||
}
|
||||
};
|
||||
|
||||
public boolean onKeyDownChild(int keyCode) {
|
||||
Log.i(TAG, "是否有上一个页面:" + webView.canGoBack());
|
||||
if (webView.canGoBack() && keyCode == KeyEvent.KEYCODE_BACK) {//点击返回按钮的时候判断有没有上一页
|
||||
webView.goBack(); // goBack()表示返回webView的上一页面
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
//释放资源
|
||||
webView.destroy();
|
||||
webView = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package com.zhidao.adas.client.other.router;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayoutMediator;
|
||||
import com.zhidao.adas.client.R;
|
||||
|
||||
|
||||
public class RouterActivity extends AppCompatActivity {
|
||||
private static final String[] TAB_TITLES = new String[]{"Bus", "Taxi"};
|
||||
private boolean isBus;
|
||||
private int currentPosition = 0;//默认选中bus
|
||||
|
||||
public static void newInstance(Context context, boolean isBus) {
|
||||
Intent intent = new Intent(context, RouterActivity.class);
|
||||
intent.putExtra("is_bus", isBus);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_router);
|
||||
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, TAB_TITLES);
|
||||
ViewPager2 viewPager = findViewById(R.id.view_pager);
|
||||
|
||||
viewPager.setAdapter(sectionsPagerAdapter);
|
||||
TabLayout tabs = findViewById(R.id.tabs);
|
||||
viewPager.setOffscreenPageLimit(1);
|
||||
TabLayoutMediator mediator = new TabLayoutMediator(tabs, viewPager, new TabLayoutMediator.TabConfigurationStrategy() {
|
||||
@Override
|
||||
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
|
||||
tab.setText(TAB_TITLES[position]);
|
||||
}
|
||||
});
|
||||
mediator.attach();
|
||||
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
super.onPageSelected(position);
|
||||
currentPosition = position;
|
||||
Log.i("dddd", "当前 Pos=" + currentPosition);
|
||||
}
|
||||
});
|
||||
findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!isClose(KeyEvent.KEYCODE_BACK))
|
||||
finish();
|
||||
}
|
||||
});
|
||||
findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
PlaceholderFragment fragment = (PlaceholderFragment) getViewPagerFragment(currentPosition);
|
||||
if (fragment != null) {
|
||||
fragment.onRefresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
isBus = intent.getBooleanExtra("is_bus", true);
|
||||
}
|
||||
currentPosition = isBus ? 0 : 1;
|
||||
viewPager.setCurrentItem(currentPosition, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param position fragment 的位置
|
||||
* @return
|
||||
*/
|
||||
private Fragment getViewPagerFragment(int position) {
|
||||
return getSupportFragmentManager().findFragmentByTag("f" + position);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return isClose(keyCode) || super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
private boolean isClose(int keyCode) {
|
||||
PlaceholderFragment fragment = (PlaceholderFragment) getViewPagerFragment(currentPosition);
|
||||
if (fragment != null) {
|
||||
return fragment.onKeyDownChild(keyCode);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.zhidao.adas.client.other.router;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class SectionsPagerAdapter extends FragmentStateAdapter {
|
||||
|
||||
private final String[] TAB_TITLES;
|
||||
public final Map<String, PlaceholderFragment> fragments = new HashMap<>();
|
||||
private final FragmentActivity fragmentActivity;
|
||||
|
||||
public SectionsPagerAdapter(@NonNull FragmentActivity fragmentActivity, String[] TAB_TITLES) {
|
||||
super(fragmentActivity);
|
||||
this.fragmentActivity = fragmentActivity;
|
||||
this.TAB_TITLES = TAB_TITLES;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
String url = "192.168.1.1";
|
||||
if ("Bus".equals(TAB_TITLES[position])) {
|
||||
url = "192.168.8.1";
|
||||
}
|
||||
return PlaceholderFragment.newInstance(url);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return TAB_TITLES.length;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,109 +0,0 @@
|
||||
package com.zhidao.adas.client.ssh;
|
||||
|
||||
|
||||
|
||||
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Key;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
|
||||
public class RSATool {
|
||||
private static final String KEY_ALGORITHM = "RSA";
|
||||
private static final String ECB_PKCS1_PADDING = "RSA/ECB/PKCS1Padding";
|
||||
|
||||
public static Map<String, Object> initKey() throws Exception {
|
||||
//实例化密钥生成器
|
||||
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM); //加密方式
|
||||
//初始化密钥生成器
|
||||
keyPairGenerator.initialize(512, new SecureRandom()); //长度
|
||||
//生成密钥对
|
||||
KeyPair keyPair = keyPairGenerator.generateKeyPair();
|
||||
//甲方公钥
|
||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
||||
//甲方私钥
|
||||
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
|
||||
//将密钥存储在map中
|
||||
Map<String, Object> keyMap = new HashMap<String, Object>();
|
||||
keyMap.put("PUBLIC_KEY", publicKey);
|
||||
keyMap.put("PRIVATE_KEY", privateKey);
|
||||
return keyMap;
|
||||
}
|
||||
|
||||
public static void getBase64() {
|
||||
try {
|
||||
Map<String, Object> map = initKey();
|
||||
byte[] privateKey = ((Key) map.get("PRIVATE_KEY")).getEncoded();
|
||||
byte[] publicKey = ((Key) map.get("PUBLIC_KEY")).getEncoded();
|
||||
// 将公私钥转为base64-法1
|
||||
// String privateBase64 = new String(Base64.encodeBase64(privateKey));
|
||||
// String publicBase64 = new String(Base64.encodeBase64(publicKey));
|
||||
// 将公私钥转为base64-法2
|
||||
String privateBase64 = Base64.encodeBase64String(privateKey);
|
||||
String publicBase64 = Base64.encodeBase64String(publicKey);
|
||||
CupidLogUtils.i("RSATool", "privateBase64=" + privateBase64);
|
||||
CupidLogUtils.i("RSATool", "publicBase64=" + publicBase64);
|
||||
String data = "mogo@ZHIDAO10";
|
||||
String encryptData = encryptByPublicKey(data, publicKey);
|
||||
CupidLogUtils.i("RSATool", "encryptData=" + encryptData);
|
||||
String decodeData = decodeByPrivateKey(encryptData, Base64.decodeBase64(privateBase64));
|
||||
CupidLogUtils.i("RSATool", "decodeData=" + decodeData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 公钥加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param key 密钥
|
||||
* @return String 加密数据 Base64类型
|
||||
*/
|
||||
public static String encryptByPublicKey(String data, byte[] key) throws Exception {
|
||||
//实例化密钥工厂
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
//初始化公钥
|
||||
//密钥材料转换
|
||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(key);
|
||||
//产生公钥
|
||||
PublicKey pubKey = keyFactory.generatePublic(x509KeySpec);
|
||||
//数据加密
|
||||
Cipher cipher = Cipher.getInstance(ECB_PKCS1_PADDING);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
|
||||
return Base64.encodeBase64String(cipher.doFinal(data.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 私钥解密
|
||||
*
|
||||
* @param data 待解密数据 Base64类型
|
||||
* @param key 密钥
|
||||
* @return String 解密数据
|
||||
*/
|
||||
public static String decodeByPrivateKey(String data, byte[] key) throws Exception {
|
||||
//取得私钥
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(key);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
//生成私钥
|
||||
PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
//数据解密
|
||||
Cipher cipher = Cipher.getInstance(ECB_PKCS1_PADDING);
|
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
return new String(cipher.doFinal(Base64.decodeBase64(data)));
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
package com.zhidao.adas.client.ssh;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.jcraft.jsch.ChannelExec;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.Session;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class SSH {
|
||||
private static final String TAG = SSH.class.getSimpleName();
|
||||
|
||||
private Session session = null;
|
||||
private ChannelExec channelExec = null;
|
||||
ByteArrayOutputStream err = null;
|
||||
StringBuffer outBuf = null;
|
||||
|
||||
public ByteArrayOutputStream getErr() {
|
||||
return err;
|
||||
}
|
||||
|
||||
public StringBuffer getOutBuf() {
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public ChannelExec getChannelExec() {
|
||||
return channelExec;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用用户名、密码连接
|
||||
*
|
||||
* @param host 主机ip
|
||||
* @param port 主机端口
|
||||
* @param username 主机用户名
|
||||
* @param password 主机密码
|
||||
* @throws JSchException
|
||||
*/
|
||||
public void connect(String host, int port, String username, String password) throws JSchException {
|
||||
JSch jsch = new JSch();
|
||||
session = jsch.getSession(username, host, port);
|
||||
session.setPassword(password);
|
||||
Properties config = new Properties();
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
session.setConfig(config);
|
||||
session.setTimeout(10000);
|
||||
session.connect();
|
||||
CupidLogUtils.i(TAG, "Connected to " + host + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用授信连接
|
||||
*
|
||||
* @param host 主机ip
|
||||
* @param username 主机用户名
|
||||
* @param privateKey 私钥路径
|
||||
* @throws JSchException
|
||||
*/
|
||||
public void connect(String host, String username, String privateKey) throws JSchException {
|
||||
JSch jsch = new JSch();
|
||||
jsch.addIdentity(privateKey);
|
||||
session = jsch.getSession(username, host);
|
||||
|
||||
Properties config = new Properties();
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
session.setConfig(config);
|
||||
session.setTimeout(30000);
|
||||
session.connect();
|
||||
CupidLogUtils.i(TAG, "Connected to " + host + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行
|
||||
*
|
||||
* @param cmd 命令
|
||||
* @return 状态
|
||||
* @throws JSchException
|
||||
* @throws IOException
|
||||
*/
|
||||
public SSHResult exec(String cmd) throws JSchException, IOException {
|
||||
return exec(cmd, null);
|
||||
}
|
||||
|
||||
public SSHResult exec(String cmd, String suPwd) throws JSchException, IOException {
|
||||
int exitStatus = 0;
|
||||
channelExec = (ChannelExec) session.openChannel("exec");
|
||||
channelExec.setInputStream(null);
|
||||
err = new ByteArrayOutputStream();
|
||||
channelExec.setErrStream(err);
|
||||
channelExec.setCommand(cmd);
|
||||
InputStream in = channelExec.getInputStream();
|
||||
OutputStream out = channelExec.getOutputStream();
|
||||
channelExec.connect();
|
||||
if (!TextUtils.isEmpty(suPwd) && (cmd.contains("sudo") || cmd.contains("su"))) {
|
||||
out.write((suPwd + "\n").getBytes()); //这里是密码后跟了一个换行符
|
||||
out.flush();
|
||||
}
|
||||
outBuf = new StringBuffer();
|
||||
byte[] tmp = new byte[1024];
|
||||
while (true) {
|
||||
while (in.available() > 0) {
|
||||
int i = in.read(tmp, 0, 1024);
|
||||
if (i < 0) break;
|
||||
outBuf.append(new String(tmp, 0, i));
|
||||
}
|
||||
if (channelExec.isClosed()) {
|
||||
if (in.available() > 0) continue;
|
||||
exitStatus = channelExec.getExitStatus();
|
||||
break;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
channelExec.disconnect();
|
||||
if (exitStatus == 0) {
|
||||
String outInfo = this.getOutBuf().toString();
|
||||
return new SSHResult(exitStatus, cmd, outInfo);
|
||||
} else {
|
||||
String errInfo = this.getErr().toString();
|
||||
return new SSHResult(exitStatus, cmd, errInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断开连接
|
||||
*/
|
||||
public void disConnect() {
|
||||
if (channelExec != null) {
|
||||
channelExec.disconnect();
|
||||
}
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.zhidao.adas.client.ssh;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.zhidao.support.adas.high.common.ThreadPoolManager;
|
||||
|
||||
public class SSHManager {
|
||||
private OnSShListener listener;
|
||||
|
||||
public interface OnSShListener {
|
||||
/**
|
||||
* 向IPC发送命令返回结果
|
||||
*
|
||||
* @param info
|
||||
*/
|
||||
void onSSHResult(SSHResult info);
|
||||
}
|
||||
|
||||
private String ipcConnectedIp;
|
||||
private SSH ssh;
|
||||
|
||||
public void shutdownIPC() {
|
||||
sendIPCCmd("sudo -S shutdown -h now");
|
||||
}
|
||||
|
||||
public void rebootIPC() {
|
||||
sendIPCCmd("sudo -S reboot");
|
||||
}
|
||||
|
||||
public void rebootAPDocker() {
|
||||
sendIPCCmd("docker restart autocar_default_1");
|
||||
}
|
||||
|
||||
private void sendIPCCmd(final String cmd) {
|
||||
if (ssh == null) {
|
||||
if (TextUtils.isEmpty(ipcConnectedIp)) {
|
||||
if (listener != null) {
|
||||
listener.onSSHResult(new SSHResult(SSHResult.RESULT_CODE.IP_UNKNOWN, cmd, "IPC IP未知"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
ThreadPoolManager.getsInstance().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ssh = new SSH();
|
||||
String encodePwd = SSHTool.getEncodePwd();
|
||||
String privateKey = SSHTool.getPrivateKey();
|
||||
try {
|
||||
String pwd = RSATool.decodeByPrivateKey(encodePwd, Base64.decodeBase64(privateKey));
|
||||
ssh.connect(ipcConnectedIp, 22, "reset", pwd);
|
||||
SSHResult result = ssh.exec(cmd, pwd);
|
||||
if (listener != null)
|
||||
listener.onSSHResult(result);
|
||||
} catch (Exception e) {
|
||||
if (listener != null)
|
||||
listener.onSSHResult(new SSHResult(SSHResult.RESULT_CODE.ERROR, cmd, e.getMessage()));
|
||||
e.printStackTrace();
|
||||
}
|
||||
ssh.disConnect();
|
||||
ssh = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.zhidao.adas.client.ssh;
|
||||
|
||||
import com.zhidao.adas.client.DataDistribution;
|
||||
import com.zhidao.adas.client.bean.MySSHResult;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
|
||||
/**
|
||||
* SSH返回结果
|
||||
*/
|
||||
public class SSHResult {
|
||||
|
||||
public void onSSHResult(final SSHResult info) {
|
||||
MySSHResult result = new MySSHResult(info.toString(), 0);
|
||||
DataDistribution.getInstance().addData(result);
|
||||
// showToastCenter("IPC命令下发结果:" + info.code + " 命令:" + info.cmd + " 信息:" + info.msg);
|
||||
// CupidLogUtils.w(TAG, "IPC命令下发结果:" + info.code + " 命令:" + info.cmd + " 信息:" + info.msg);
|
||||
}
|
||||
|
||||
|
||||
public interface RESULT_CODE {
|
||||
/**
|
||||
* 工控机IP未知
|
||||
*/
|
||||
int IP_UNKNOWN = -10001;
|
||||
/**
|
||||
* 网络异常或连接异常或IO异常
|
||||
*/
|
||||
int ERROR = -10000;
|
||||
/**
|
||||
* 命令下发成功 可能存在-1的情况
|
||||
* 在虚拟机的ubuntu系统发送reboot或shutdown或ls 命令返回的是0,在工控机发送reboot或shutdown返回-1 ls返回0
|
||||
*/
|
||||
int SEND_SUCCEED = 0;
|
||||
/**
|
||||
* 其他值根据Shell返回结果而定 >0
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public final int code;
|
||||
public final String cmd;
|
||||
public final String msg;
|
||||
|
||||
public SSHResult(int code, String cmd, String msg) {
|
||||
this.code = code;
|
||||
this.cmd = cmd;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SSHResult{" +
|
||||
"code=" + code +
|
||||
", cmd='" + cmd + '\'' +
|
||||
", msg='" + msg + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.zhidao.adas.client.ssh;
|
||||
|
||||
public class SSHTool {
|
||||
static {
|
||||
System.loadLibrary("sshtool");
|
||||
}
|
||||
|
||||
public static native String getEncodePwd();
|
||||
|
||||
public static native String getPrivateKey();
|
||||
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.adapter.LineAdapter;
|
||||
import com.zhidao.adas.client.base.BaseAdapter;
|
||||
import com.zhidao.adas.client.bean.AutoPilotMode;
|
||||
import com.zhidao.adas.client.bean.UpdateDataEvent;
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
|
||||
public class AutoPilotModeDialog extends Dialog {
|
||||
private RecyclerView recyclerView;
|
||||
private LineAdapter adapter;
|
||||
private List<AutoPilotMode> list;
|
||||
|
||||
public AutoPilotModeDialog(@NonNull Context context) {
|
||||
super(context, R.style.CustomDialog);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_autopilot_mode);
|
||||
//初始化界面控件
|
||||
initView();
|
||||
list = Constants.getPaths(getContext());
|
||||
initBtnRecyclerView();
|
||||
//初始化界面控件的事件
|
||||
initListener();
|
||||
setOnDismissListener(new OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
EventBus.getDefault().unregister(AutoPilotModeDialog.this);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
EventBus.getDefault().register(AutoPilotModeDialog.this);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onUpdateDataEvent(UpdateDataEvent event) {
|
||||
list = Constants.getPaths(getContext());
|
||||
if (adapter != null) {
|
||||
adapter.setData(list);
|
||||
}
|
||||
}
|
||||
|
||||
private void initBtnRecyclerView() {
|
||||
//初始info-recycle
|
||||
LinearLayoutManager nodLinearLayoutManage = new LinearLayoutManager(getContext());
|
||||
nodLinearLayoutManage.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
recyclerView.setLayoutManager(nodLinearLayoutManage);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
recyclerView.setHasFixedSize(true);
|
||||
//解决局部刷新闪屏问题
|
||||
SimpleItemAnimator animatorInfo = (SimpleItemAnimator) recyclerView.getItemAnimator();
|
||||
if (animatorInfo != null)
|
||||
animatorInfo.setSupportsChangeAnimations(false);
|
||||
//创建并设置Adapter
|
||||
adapter = new LineAdapter(list);
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener<AutoPilotMode>() {
|
||||
@Override
|
||||
public void onItemClick(int position, AutoPilotMode data) {
|
||||
MessagePad.Location startLocation = MessagePad.Location.newBuilder()
|
||||
.setLatitude(data.startLatLon.latitude)
|
||||
.setLongitude(data.startLatLon.longitude)
|
||||
.build();
|
||||
MessagePad.Location endLocation = MessagePad.Location.newBuilder()
|
||||
.setLatitude(data.endLatLon.latitude)
|
||||
.setLongitude(data.endLatLon.longitude)
|
||||
.build();
|
||||
MessagePad.RouteInfo.Builder builder = MessagePad.RouteInfo.newBuilder();
|
||||
builder.setStartLocation(startLocation);
|
||||
builder.setStartName(data.startName);
|
||||
builder.setEndLocation(endLocation);
|
||||
builder.setEndName(data.endName);
|
||||
List<MessagePad.Location> list = data.getWayLatLons();
|
||||
if (list != null)
|
||||
builder.addAllWayPoints(list);
|
||||
builder.setSpeedLimit(data.speedLimit);
|
||||
builder.setVehicleType(9);
|
||||
builder.setIsSpeakVoice(true);
|
||||
if (data.isBus) {
|
||||
builder.setRouteID(data.routeID);
|
||||
builder.setRouteName(data.routeName);
|
||||
}
|
||||
AdasManager.getInstance().sendAutoPilotModeReq(1, 0, builder.build());
|
||||
AutoPilotModeDialog.this.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面的确定和取消监听器
|
||||
*/
|
||||
private void initListener() {
|
||||
findViewById(R.id.settings).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getContext().startActivity(new Intent(getContext(), AutopilotConfigActivity.class));
|
||||
}
|
||||
});
|
||||
findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MessagePad.RouteInfo.Builder builder = MessagePad.RouteInfo.newBuilder();
|
||||
AdasManager.getInstance().sendAutoPilotModeReq(0, 0, builder.build());
|
||||
AutoPilotModeDialog.this.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化界面控件
|
||||
*/
|
||||
private void initView() {
|
||||
recyclerView = findViewById(R.id.recyclerView);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,342 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.util.Pair;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.zhidao.adas.client.DataDistribution;
|
||||
import com.zhidao.adas.client.OnAdasClientListener;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.adapter.AutopilotConfigAdapter;
|
||||
import com.zhidao.adas.client.base.BaseActivity;
|
||||
import com.zhidao.adas.client.bean.AutoPilotMode;
|
||||
import com.zhidao.adas.client.bean.DataShow;
|
||||
import com.zhidao.adas.client.bean.UpdateDataEvent;
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
import com.zhidao.support.adas.high.common.ThreadPoolManager;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class AutopilotConfigActivity extends BaseActivity {
|
||||
private static final String TAG = "CreateActivity";
|
||||
private Pair<String, OnAdasClientListener> listenerPair;
|
||||
private TextView toolbar_title;
|
||||
private RecyclerView recyclerView;
|
||||
private AutopilotConfigAdapter autopilotConfigAdapter;
|
||||
private GridLayoutManager linearLayoutManager;
|
||||
|
||||
private static final int WHAT_START = 0x01;
|
||||
private static final int WHAT_UPDATE_SHOW = 0x02;
|
||||
TextView no_date;
|
||||
private TextView lonText;
|
||||
private TextView latText;
|
||||
private double lon = -1;
|
||||
private double lat = -1;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_autopilot_cloud_config);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
recyclerView = findViewById(R.id.recyclerView);
|
||||
no_date = findViewById(R.id.no_date);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setTitle("");
|
||||
toolbar_title = findViewById(R.id.toolbar_title);
|
||||
toolbar_title.setText("创建线路");
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);//左侧添加一个默认的返回图标
|
||||
getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用
|
||||
initHandler();
|
||||
initRecyclerView();
|
||||
listenerPair = new Pair<>(Constants.TITLE.RECEIVE_GNSS_INFO, listener);
|
||||
toolbar_title.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
Toast.makeText(AutopilotConfigActivity.this, "恭喜解锁隐藏技能", Toast.LENGTH_LONG).show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
init();
|
||||
DataDistribution.getInstance().registerAdasClientListener(new Pair<>(Constants.TITLE.RECEIVE_GNSS_INFO, listener));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
DataDistribution.getInstance().unregisterAdasClientListener(new Pair<>(Constants.TITLE.RECEIVE_GNSS_INFO, listener));
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (autopilotConfigAdapter.getItemCount() == 0) {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
no_date.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
no_date.setVisibility(View.GONE);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initRecyclerView() {
|
||||
linearLayoutManager = new GridLayoutManager(this, 2);
|
||||
linearLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
//添加Android自带的分割线
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
||||
recyclerView.addItemDecoration(new HorizontalDividerItemDecoration(this));
|
||||
autopilotConfigAdapter = new AutopilotConfigAdapter(Constants.getPaths(this));
|
||||
recyclerView.setAdapter(autopilotConfigAdapter);
|
||||
autopilotConfigAdapter.setOnItemClickListener(new AutopilotConfigAdapter.OnHaveDataListener() {
|
||||
@Override
|
||||
public void onHaveData(boolean isHave) {
|
||||
if (isHave) {
|
||||
no_date.setVisibility(View.GONE);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
no_date.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void onSave() {
|
||||
List<AutoPilotMode> list = autopilotConfigAdapter.getDatas();
|
||||
if (list == null || list.isEmpty()) {
|
||||
Toast.makeText(AutopilotConfigActivity.this, "未找到可用数据,无法保存", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Toast.makeText(AutopilotConfigActivity.this, "正在保存...", Toast.LENGTH_SHORT).show();
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean isNull = false;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (list.get(i).isNull()) {
|
||||
isNull = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isNull) {
|
||||
Constants.setPath(AutopilotConfigActivity.this, list);
|
||||
}
|
||||
Message msg = Message.obtain();
|
||||
msg.what = WHAT_START;
|
||||
msg.obj = !isNull;
|
||||
|
||||
getHandler().sendMessage(msg);
|
||||
}
|
||||
};
|
||||
ThreadPoolManager.getsInstance().execute(runnable);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().post(new UpdateDataEvent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case WHAT_START:
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
if ((Boolean) msg.obj) {
|
||||
builder.setTitle("保存成功")
|
||||
.setMessage("配置保存成功啦")
|
||||
.setNegativeButton("退出",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setPositiveButton("确定",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
builder.setTitle("保存失败")
|
||||
.setMessage("请输入必填项\n所有输入框均必填\uD83E\uDD2A\n(Bus必须输入道路名称和道路ID)")
|
||||
.setPositiveButton("确认",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
}
|
||||
});
|
||||
}
|
||||
AlertDialog dialog = builder.show();
|
||||
// dialog.setCancelable(false);
|
||||
// dialog.setCanceledOnTouchOutside(false);
|
||||
break;
|
||||
case WHAT_UPDATE_SHOW:
|
||||
if (lonText != null)
|
||||
lonText.setText("Lon:" + lon);
|
||||
if (latText != null)
|
||||
latText.setText("Lat:" + lat);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_create, menu);
|
||||
MenuItem itemDel = menu.findItem(R.id.action_del_item);
|
||||
CheckBox del = itemDel.getActionView().findViewById(R.id.action_del);
|
||||
del.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (autopilotConfigAdapter != null) {
|
||||
autopilotConfigAdapter.setShowDel(isChecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
MenuItem itemLocation = menu.findItem(R.id.action_location_item);
|
||||
Button btn_lon = itemLocation.getActionView().findViewById(R.id.btn_lon);
|
||||
Button btn_lat = itemLocation.getActionView().findViewById(R.id.btn_lat);
|
||||
lonText = itemLocation.getActionView().findViewById(R.id.lon);
|
||||
latText = itemLocation.getActionView().findViewById(R.id.lat);
|
||||
btn_lon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (lon != -1) {
|
||||
findEditText(lon);
|
||||
}
|
||||
}
|
||||
});
|
||||
btn_lat.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (lat != -1) {
|
||||
findEditText(lat);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private void findEditText(double value) {
|
||||
View view = getWindow().getDecorView().findFocus();
|
||||
if (view instanceof EditText) {
|
||||
EditText editText = ((EditText) view);
|
||||
String content = String.valueOf(value);
|
||||
editText.setText(content);
|
||||
editText.setSelection(content.length());
|
||||
}
|
||||
}
|
||||
|
||||
private OnAdasClientListener listener = new OnAdasClientListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
List<DataShow> listGnssInfo = DataDistribution.getInstance().listGnssInfo;
|
||||
if (!listGnssInfo.isEmpty()) {
|
||||
String info = listGnssInfo.get(listGnssInfo.size() - 1).data;
|
||||
lon = Double.parseDouble(info.split("longitude: ")[1].split("\n")[0]);
|
||||
lat = Double.parseDouble(info.split("latitude: ")[1].split("\n")[0]);
|
||||
getHandler().sendEmptyMessage(WHAT_UPDATE_SHOW);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void onLocationEvent(GnssInfo info) {
|
||||
// if (info != null && info.bean != null) {
|
||||
// lon = info.bean.getLongitude();
|
||||
// lat = info.bean.getLatitude();
|
||||
// if (lonText != null)
|
||||
// lonText.setText("Lon:" + lon);
|
||||
// if (latText != null)
|
||||
// latText.setText("Lat:" + lat);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_settings_item:
|
||||
autopilotConfigAdapter.add();
|
||||
// linearLayoutManager.scrollToPositionWithOffset(dbAdapter.getItemCount() - 1, 0);
|
||||
recyclerView.scrollToPosition(autopilotConfigAdapter.getItemCount() - 1);
|
||||
return true;
|
||||
case R.id.action_save_item:
|
||||
onSave();
|
||||
return true;
|
||||
case android.R.id.home:
|
||||
onBack();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void onBack() {
|
||||
finish();
|
||||
// new AlertDialog.Builder(this)
|
||||
// .setTitle("退出提示")
|
||||
// .setMessage("是否配置页面")
|
||||
// .setNegativeButton("取消",
|
||||
// new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// dialog.cancel();
|
||||
// }
|
||||
// })
|
||||
// .setPositiveButton("确认",
|
||||
// new DialogInterface.OnClickListener() {
|
||||
// public void onClick(DialogInterface dialog, int whichButton) {
|
||||
// finish();
|
||||
// }
|
||||
// }).show();
|
||||
}
|
||||
|
||||
//返回键处理
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
onBack();
|
||||
return true;
|
||||
} else {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.ui.widget.SweeperVideoView;
|
||||
import com.zhidao.adas.client.utils.SysBarUtil;
|
||||
import com.zhidao.adas.client.utils.image.ImageLoaderManager;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* 摄像头数据展示
|
||||
*
|
||||
* @author xuxinchao
|
||||
* @description
|
||||
* @since: 2022/4/20
|
||||
*/
|
||||
public class BackCameraFloatWindow implements View.OnTouchListener {
|
||||
|
||||
private final Activity mContext;
|
||||
private WindowManager.LayoutParams mWindowParams;
|
||||
private WindowManager mWindowManager;
|
||||
|
||||
private View mFloatLayout;
|
||||
private float mInViewX;
|
||||
private float mInViewY;
|
||||
private float mDownInScreenX;
|
||||
private float mDownInScreenY;
|
||||
private float mInScreenX;
|
||||
private float mInScreenY;
|
||||
private SweeperVideoView image_view;
|
||||
private final boolean isFullScreen;
|
||||
private final OnBackCameraFloatWindowListener onBackCameraFloatWindowListener;
|
||||
|
||||
public interface OnBackCameraFloatWindowListener {
|
||||
void onClose();
|
||||
}
|
||||
|
||||
public BackCameraFloatWindow(Activity context, boolean isFullScreen, OnBackCameraFloatWindowListener onBackCameraFloatWindowListener) {
|
||||
this.mContext = context;
|
||||
this.isFullScreen = isFullScreen;
|
||||
this.onBackCameraFloatWindowListener = onBackCameraFloatWindowListener;
|
||||
initHandler();
|
||||
initFloatWindow();
|
||||
}
|
||||
|
||||
|
||||
private void initFloatWindow() {
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
if (inflater == null)
|
||||
return;
|
||||
mFloatLayout = (View) inflater.inflate(R.layout.layout_back_camera, null);
|
||||
image_view = mFloatLayout.findViewById(R.id.image_view);
|
||||
ImageView btn_close = mFloatLayout.findViewById(R.id.btn_close);
|
||||
btn_close.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onBackCameraFloatWindowListener != null) {
|
||||
onBackCameraFloatWindowListener.onClose();
|
||||
}
|
||||
}
|
||||
});
|
||||
mFloatLayout.setOnTouchListener(this);
|
||||
mWindowParams = new WindowManager.LayoutParams();
|
||||
// mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
// if (Build.VERSION.SDK_INT >= 26) {//8.0新特性
|
||||
// mWindowParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
// }else{
|
||||
// mWindowParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
// }
|
||||
|
||||
mWindowManager = mContext.getWindowManager();
|
||||
|
||||
mWindowParams.format = PixelFormat.RGBA_8888;
|
||||
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
mWindowParams.gravity = Gravity.START | Gravity.TOP;
|
||||
if (isFullScreen) {
|
||||
mWindowParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
mWindowParams.height = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
} else {
|
||||
mWindowParams.width = 1280;
|
||||
mWindowParams.height = 720;
|
||||
}
|
||||
// mWindowParams.alpha = 0.9F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
return floatLayoutTouch(motionEvent);
|
||||
}
|
||||
|
||||
private boolean floatLayoutTouch(MotionEvent motionEvent) {
|
||||
switch (motionEvent.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// 获取相对View的坐标,即以此View左上角为原点
|
||||
mInViewX = motionEvent.getX();
|
||||
mInViewY = motionEvent.getY();
|
||||
// 获取相对屏幕的坐标,即以屏幕左上角为原点
|
||||
mDownInScreenX = motionEvent.getRawX();
|
||||
mDownInScreenY = motionEvent.getRawY() - SysBarUtil.getSysBarHeight(mContext);
|
||||
mInScreenX = motionEvent.getRawX();
|
||||
mInScreenY = motionEvent.getRawY() - SysBarUtil.getSysBarHeight(mContext);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// 更新浮动窗口位置参数
|
||||
mInScreenX = motionEvent.getRawX();
|
||||
mInScreenY = motionEvent.getRawY() - SysBarUtil.getSysBarHeight(mContext);
|
||||
mWindowParams.x = (int) (mInScreenX - mInViewX);
|
||||
mWindowParams.y = (int) (mInScreenY - mInViewY);
|
||||
// 手指移动的时候更新小悬浮窗的位置
|
||||
mWindowManager.updateViewLayout(mFloatLayout, mWindowParams);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
// 如果手指离开屏幕时,xDownInScreen和xInScreen相等,且yDownInScreen和yInScreen相等,则视为触发了单击事件。
|
||||
if (mDownInScreenX == mInScreenX && mDownInScreenY == mInScreenY) {
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void showFloatWindow(float y) {
|
||||
if (mFloatLayout.getParent() == null) {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
// 默认固定位置,靠屏幕右边缘的中间
|
||||
mWindowManager.getDefaultDisplay().getMetrics(metrics);
|
||||
mWindowParams.x = metrics.widthPixels;
|
||||
mWindowParams.y = (int) (y);
|
||||
mWindowManager.addView(mFloatLayout, mWindowParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void hideFloatWindow() {
|
||||
if (mFloatLayout.getParent() != null)
|
||||
mWindowManager.removeView(mFloatLayout);
|
||||
}
|
||||
|
||||
public void setFloatLayoutAlpha(boolean alpha) {
|
||||
if (alpha)
|
||||
mFloatLayout.setAlpha((float) 0.5);
|
||||
else
|
||||
mFloatLayout.setAlpha(1);
|
||||
}
|
||||
|
||||
|
||||
public void onBackCameraVideo(byte[] data) {
|
||||
Message msg = Message.obtain();
|
||||
msg.obj = data;
|
||||
msg.what = 1;
|
||||
getHandler().sendMessage(msg);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private BaseHandler mBaseHandler;
|
||||
|
||||
|
||||
/**
|
||||
* 初始化一个Handler,如果需要使用Handler,先调用此方法,
|
||||
* 然后可以使用postRunnable(Runnable runnable),
|
||||
* sendMessage在handleMessage(Message msg)中接收msg
|
||||
*/
|
||||
public void initHandler() {
|
||||
mBaseHandler = new BaseHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回Handler,在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @return Handler
|
||||
*/
|
||||
public Handler getHandler() {
|
||||
return mBaseHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同Handler 的 handleMessage,
|
||||
* getHandler.sendMessage,发送的Message在此接收
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
protected void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
image_view.onSweeperFutianBackCameraVideo((byte[]) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static class BaseHandler extends Handler {
|
||||
private final WeakReference<BackCameraFloatWindow> mObjects;
|
||||
|
||||
public BaseHandler(BackCameraFloatWindow mPresenter) {
|
||||
mObjects = new WeakReference<BackCameraFloatWindow>(mPresenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
BackCameraFloatWindow mPresenter = mObjects.get();
|
||||
if (mPresenter != null)
|
||||
mPresenter.handleMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.adapter.ConnectStatusAdapter;
|
||||
import com.zhidao.adas.client.bean.IPCConnectState;
|
||||
import com.zhidao.adas.client.utils.MyLinearLayoutManager;
|
||||
import com.zhidao.adas.client.utils.SysBarUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xuxinchao
|
||||
* @description
|
||||
* @since: 2022/4/20
|
||||
*/
|
||||
public class FloatWindow implements View.OnTouchListener {
|
||||
|
||||
private final Activity mContext;
|
||||
private WindowManager.LayoutParams mWindowParams;
|
||||
private WindowManager mWindowManager;
|
||||
|
||||
private View mFloatLayout;
|
||||
private float mInViewX;
|
||||
private float mInViewY;
|
||||
private float mDownInScreenX;
|
||||
private float mDownInScreenY;
|
||||
private float mInScreenX;
|
||||
private float mInScreenY;
|
||||
private RecyclerView rv_status;
|
||||
private ConnectStatusAdapter adapter;
|
||||
private List<IPCConnectState> list;
|
||||
|
||||
public FloatWindow(Activity context, List<IPCConnectState> list) {
|
||||
this.mContext = context;
|
||||
this.list = list;
|
||||
initFloatWindow();
|
||||
}
|
||||
|
||||
public void refreshView() {
|
||||
if (adapter != null) {
|
||||
adapter.refreshView();
|
||||
}
|
||||
}
|
||||
|
||||
private void initRV() {
|
||||
//创建默认的线性LayoutManager 横向的GridLayoutManager
|
||||
MyLinearLayoutManager linearLayoutManager = new MyLinearLayoutManager(mContext);
|
||||
// linearLayoutManager.setStackFromEnd(true);//列表再底部开始展示,反转后由上面开始展示
|
||||
// linearLayoutManager.setReverseLayout(true);//列表翻转
|
||||
rv_status.setLayoutManager(linearLayoutManager);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
rv_status.setHasFixedSize(false);
|
||||
rv_status.setNestedScrollingEnabled(false);
|
||||
adapter = new ConnectStatusAdapter();
|
||||
adapter.setHasStableIds(true);
|
||||
rv_status.setAdapter(adapter);
|
||||
adapter.setData(list);
|
||||
}
|
||||
|
||||
private void initFloatWindow() {
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
if (inflater == null)
|
||||
return;
|
||||
mFloatLayout = (View) inflater.inflate(R.layout.layout_float, null);
|
||||
rv_status = mFloatLayout.findViewById(R.id.rv_status);
|
||||
mFloatLayout.setOnTouchListener(this);
|
||||
initRV();
|
||||
mWindowParams = new WindowManager.LayoutParams();
|
||||
// mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
// if (Build.VERSION.SDK_INT >= 26) {//8.0新特性
|
||||
// mWindowParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
// }else{
|
||||
// mWindowParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
// }
|
||||
|
||||
mWindowManager = mContext.getWindowManager();
|
||||
|
||||
mWindowParams.format = PixelFormat.RGBA_8888;
|
||||
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
mWindowParams.gravity = Gravity.START | Gravity.TOP;
|
||||
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
mWindowParams.alpha = 0.9F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
return floatLayoutTouch(motionEvent);
|
||||
}
|
||||
|
||||
private boolean floatLayoutTouch(MotionEvent motionEvent) {
|
||||
switch (motionEvent.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// 获取相对View的坐标,即以此View左上角为原点
|
||||
mInViewX = motionEvent.getX();
|
||||
mInViewY = motionEvent.getY();
|
||||
// 获取相对屏幕的坐标,即以屏幕左上角为原点
|
||||
mDownInScreenX = motionEvent.getRawX();
|
||||
mDownInScreenY = motionEvent.getRawY() - SysBarUtil.getSysBarHeight(mContext);
|
||||
mInScreenX = motionEvent.getRawX();
|
||||
mInScreenY = motionEvent.getRawY() - SysBarUtil.getSysBarHeight(mContext);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// 更新浮动窗口位置参数
|
||||
mInScreenX = motionEvent.getRawX();
|
||||
mInScreenY = motionEvent.getRawY() - SysBarUtil.getSysBarHeight(mContext);
|
||||
mWindowParams.x = (int) (mInScreenX - mInViewX);
|
||||
mWindowParams.y = (int) (mInScreenY - mInViewY);
|
||||
// 手指移动的时候更新小悬浮窗的位置
|
||||
mWindowManager.updateViewLayout(mFloatLayout, mWindowParams);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
// 如果手指离开屏幕时,xDownInScreen和xInScreen相等,且yDownInScreen和yInScreen相等,则视为触发了单击事件。
|
||||
if (mDownInScreenX == mInScreenX && mDownInScreenY == mInScreenY) {
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void showFloatWindow(float y) {
|
||||
if (mFloatLayout.getParent() == null) {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
// 默认固定位置,靠屏幕右边缘的中间
|
||||
mWindowManager.getDefaultDisplay().getMetrics(metrics);
|
||||
mWindowParams.x = metrics.widthPixels;
|
||||
mWindowParams.y = (int) (y);
|
||||
mWindowManager.addView(mFloatLayout, mWindowParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void hideFloatWindow() {
|
||||
if (mFloatLayout.getParent() != null)
|
||||
mWindowManager.removeView(mFloatLayout);
|
||||
}
|
||||
|
||||
public void setFloatLayoutAlpha(boolean alpha) {
|
||||
if (alpha)
|
||||
mFloatLayout.setAlpha((float) 0.5);
|
||||
else
|
||||
mFloatLayout.setAlpha(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.base.BaseActivity;
|
||||
|
||||
public class HelpActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_help);
|
||||
showToastCenter("点击屏幕任意位置,退出帮助页面");
|
||||
}
|
||||
|
||||
public void onBack(View view) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* DividerItemDecoration is a {@link RecyclerView.ItemDecoration} that can be used as a divider
|
||||
* between items of a {@link LinearLayoutManager}. It supports both {@link #HORIZONTAL} and
|
||||
* {@link #VERTICAL} orientations.
|
||||
*
|
||||
* <pre>
|
||||
* mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
|
||||
* mLayoutManager.getOrientation());
|
||||
* recyclerView.addItemDecoration(mDividerItemDecoration);
|
||||
* </pre>
|
||||
*/
|
||||
public class HorizontalDividerItemDecoration extends RecyclerView.ItemDecoration {
|
||||
public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
|
||||
public static final int VERTICAL = LinearLayout.VERTICAL;
|
||||
|
||||
private static final String TAG = "DividerItem";
|
||||
private static final int[] ATTRS = new int[]{android.R.attr.listDivider};
|
||||
|
||||
private Drawable mDivider;
|
||||
|
||||
|
||||
private final Rect mBounds = new Rect();
|
||||
|
||||
/**
|
||||
* Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a
|
||||
* {@link LinearLayoutManager}.
|
||||
*
|
||||
* @param context Current context, it will be used to access resources.
|
||||
*/
|
||||
public HorizontalDividerItemDecoration(Context context) {
|
||||
final TypedArray a = context.obtainStyledAttributes(ATTRS);
|
||||
mDivider = a.getDrawable(0);
|
||||
if (mDivider == null) {
|
||||
Log.w(TAG, "@android:attr/listDivider was not set in the theme used for this "
|
||||
+ "DividerItemDecoration. Please set that attribute all call setDrawable()");
|
||||
}
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the {@link Drawable} for this divider.
|
||||
*
|
||||
* @param drawable Drawable that should be used as a divider.
|
||||
*/
|
||||
public void setDrawable(@NonNull Drawable drawable) {
|
||||
if (drawable == null) {
|
||||
throw new IllegalArgumentException("Drawable cannot be null.");
|
||||
}
|
||||
mDivider = drawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link Drawable} for this divider.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawable() {
|
||||
return mDivider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
if (parent.getLayoutManager() == null || mDivider == null) {
|
||||
return;
|
||||
}
|
||||
drawHorizontal(c, parent);
|
||||
}
|
||||
|
||||
|
||||
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
|
||||
canvas.save();
|
||||
final int top;
|
||||
final int bottom;
|
||||
//noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
|
||||
if (parent.getClipToPadding()) {
|
||||
top = parent.getPaddingTop();
|
||||
bottom = parent.getHeight() - parent.getPaddingBottom();
|
||||
canvas.clipRect(parent.getPaddingLeft(), top,
|
||||
parent.getWidth() - parent.getPaddingRight(), bottom);
|
||||
} else {
|
||||
top = 0;
|
||||
bottom = parent.getHeight();
|
||||
}
|
||||
|
||||
final int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; ) {
|
||||
final View child = parent.getChildAt(i);
|
||||
parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
|
||||
final int right = mBounds.right + Math.round(child.getTranslationX());
|
||||
final int left = right - mDivider.getIntrinsicWidth();
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(canvas);
|
||||
i += 2;
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
|
||||
RecyclerView.State state) {
|
||||
if (mDivider == null) {
|
||||
outRect.set(0, 0, 0, 0);
|
||||
return;
|
||||
}
|
||||
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
|
||||
}
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import com.zhidao.adas.client.DataDistribution;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.adapter.DataShowAdapter;
|
||||
import com.zhidao.adas.client.base.BaseFragment;
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
import com.zhidao.adas.client.utils.MyLinearLayoutManager;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des
|
||||
* @date 2021/8/16
|
||||
*/
|
||||
public class InfoFragment extends BaseFragment {
|
||||
|
||||
private DataShowAdapter adapter;
|
||||
private TextView tvTitle;
|
||||
private String subTitle;
|
||||
private BackCameraFloatWindow backCameraFloatWindow;
|
||||
|
||||
public InfoFragment() {
|
||||
}
|
||||
|
||||
public InfoFragment(String title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_info, container, false);
|
||||
initView(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
setData();
|
||||
}
|
||||
|
||||
private View layout_update;
|
||||
|
||||
public void setTitle(String title) {
|
||||
if (tvTitle != null) {
|
||||
tvTitle.setText(title);
|
||||
} else {
|
||||
subTitle = title;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
hideFloatWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
if (hidden) {
|
||||
hideFloatWindow();
|
||||
}
|
||||
}
|
||||
|
||||
private void hideFloatWindow() {
|
||||
if (backCameraFloatWindow != null) {
|
||||
backCameraFloatWindow.hideFloatWindow();
|
||||
backCameraFloatWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void initView(View view) {
|
||||
tvTitle = view.findViewById(R.id.tv_title);
|
||||
RecyclerView rvInfo = view.findViewById(R.id.rv_info);
|
||||
layout_update = view.findViewById(R.id.layout_update);
|
||||
if (TextUtils.isEmpty(subTitle)) {
|
||||
tvTitle.setText(title);
|
||||
} else {
|
||||
tvTitle.setText(subTitle);
|
||||
subTitle = null;
|
||||
}
|
||||
tvTitle.setGravity(Gravity.CENTER);
|
||||
if (Constants.TITLE.RECEIVE_BACK_CAMERA_VIDEO.equals(title)) {
|
||||
Button button_full_screen = view.findViewById(R.id.btn_render_full_screen);
|
||||
Button button = view.findViewById(R.id.btn_render);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
button_full_screen.setVisibility(View.VISIBLE);
|
||||
button_full_screen.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showBackCameraFloatWindow(button_full_screen, true);
|
||||
}
|
||||
});
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showBackCameraFloatWindow(button, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
//创建默认的线性LayoutManager 横向的GridLayoutManager
|
||||
MyLinearLayoutManager linearLayoutManager = new MyLinearLayoutManager(this.getContext());
|
||||
// linearLayoutManager.setStackFromEnd(true);//列表再底部开始展示,反转后由上面开始展示
|
||||
// linearLayoutManager.setReverseLayout(true);//列表翻转
|
||||
rvInfo.setLayoutManager(linearLayoutManager);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
rvInfo.setHasFixedSize(false);
|
||||
rvInfo.setNestedScrollingEnabled(false);
|
||||
//升级按钮
|
||||
Button btn1 = view.findViewById(R.id.btn1);
|
||||
//升级按钮
|
||||
Button btn2 = view.findViewById(R.id.btn2);
|
||||
btn1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// AdasManager.getInstance().sendBaseInfo(IPCUpgradeInfo.affirm());
|
||||
}
|
||||
});
|
||||
btn2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// AdasManager.getInstance().sendBaseInfo(IPCUpgradeInfo.cancel());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
RecyclerView.ItemAnimator itemAnimator = rvInfo.getItemAnimator();
|
||||
if (itemAnimator != null) {
|
||||
itemAnimator.setAddDuration(0);
|
||||
itemAnimator.setChangeDuration(0);
|
||||
itemAnimator.setMoveDuration(0);
|
||||
itemAnimator.setRemoveDuration(0);
|
||||
((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
|
||||
}
|
||||
adapter = new DataShowAdapter();
|
||||
adapter.setHasStableIds(true);
|
||||
rvInfo.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void showBackCameraFloatWindow(View v, boolean isFullScreen) {
|
||||
if (isFullScreen) {
|
||||
hideFloatWindow();
|
||||
}
|
||||
if (backCameraFloatWindow == null) {
|
||||
backCameraFloatWindow = new BackCameraFloatWindow(getActivity(), isFullScreen, new BackCameraFloatWindow.OnBackCameraFloatWindowListener() {
|
||||
@Override
|
||||
public void onClose() {
|
||||
hideFloatWindow();
|
||||
}
|
||||
});
|
||||
final int[] location = new int[2];
|
||||
v.getLocationOnScreen(location);
|
||||
backCameraFloatWindow.showFloatWindow(location[1]);
|
||||
} else {
|
||||
hideFloatWindow();
|
||||
}
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
if (Constants.TITLE.RECEIVE_GNSS_INFO.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listGnssInfo);
|
||||
} else if (Constants.TITLE.RECEIVE_CHASSIS_STATES.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listChassisStates);
|
||||
} else if (Constants.TITLE.RECEIVE_TRACKED_OBJECTS.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listTrackedObjects);
|
||||
} else if (Constants.TITLE.RECEIVE_AUTOPILOT_STATE.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listAutopilotState);
|
||||
} else if (Constants.TITLE.RECEIVE_WARN.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listWarn);
|
||||
} else if (Constants.TITLE.RECEIVE_TRAJECTORY.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listTrajectory);
|
||||
} else if (Constants.TITLE.RECEIVE_ARRIVAL_NOTIFICATION.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listArrivalNotification);
|
||||
} else if (Constants.TITLE.RECEIVE_STATUS_QUERY_RESP.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listStatusInfo);
|
||||
} else if (Constants.TITLE.RECEIVE_OBU_SPAT.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listObuSpat);
|
||||
} else if (Constants.TITLE.RECEIVE_OBU_RSI.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listObuRsi);
|
||||
} else if (Constants.TITLE.RECEIVE_OBU_RSM.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listObuRsm);
|
||||
} else if (Constants.TITLE.RECEIVE_OBU_MAP.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listObuMap);
|
||||
} else if (Constants.TITLE.RECEIVE_RECORD_DATA_CONFIG_RESP.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listRecordDataConfig);
|
||||
} else if (Constants.TITLE.RECEIVE_GLOBAL_PATH_RESP.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listGlobalPathResp);
|
||||
} else if (Constants.TITLE.RECEIVE_RECORD_RESULT.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listRecordPanel);
|
||||
} else if (Constants.TITLE.RECEIVE_BAG_MANAGER_CMD.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listBagManagerCmd);
|
||||
} else if (Constants.TITLE.RECEIVE_REPORT_MESSAGE.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listMogoReportMessage);
|
||||
} else if (Constants.TITLE.RECEIVE_PERCEPTION_TRAFFIC_LIGHT.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listPerceptionTrafficLight);
|
||||
} else if (Constants.TITLE.RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listPredictionObstacleTrajectory);
|
||||
} else if (Constants.TITLE.RECEIVE_POINT_CLOUD_ORIGINAL.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listOriginalPointCloud);
|
||||
} else if (Constants.TITLE.RECEIVE_PLANNING_OBJECTS.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listPlanningObjects);
|
||||
} else if (Constants.TITLE.RECEIVE_PLANNING_DECISION_STATE.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listPlanningDecisionState);
|
||||
} else if (Constants.TITLE.RECEIVE_FUNCTION_STATES.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listFSMFunctionStates);
|
||||
} else if (Constants.TITLE.RECEIVE_BACK_CAMERA_VIDEO.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listBackCameraVideo);
|
||||
} else if (Constants.TITLE.RECEIVE_SWEEPER_TASK_INDEX_DATA.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listRoboSweeperTaskIndex);
|
||||
} else if (Constants.TITLE.RECEIVE_V2N_CONGESTION_EVENT.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listV2nCongestionEvent);
|
||||
} else if (Constants.TITLE.RECEIVE_V2N_GLOBAL_PATH_EVENTS.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listV2nGlobalPathEvents);
|
||||
}else if (Constants.TITLE.RECEIVE_GET_PARAM_RESP.equals(title)) {
|
||||
adapter.setData(DataDistribution.getInstance().listGetParamResp);
|
||||
} else {
|
||||
adapter.setData(DataDistribution.getInstance().listErrorData);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRefreshTitle = false;
|
||||
|
||||
@Override
|
||||
protected void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case WHAT_REFRESH_TRAFFIC_LIGHTS:
|
||||
//感知信号灯显示
|
||||
if (msg.obj == null) {
|
||||
if (isRefreshTitle) {
|
||||
tvTitle.setText(title);
|
||||
isRefreshTitle = false;
|
||||
}
|
||||
} else {
|
||||
isRefreshTitle = true;
|
||||
tvTitle.setText((String) msg.obj);
|
||||
}
|
||||
onRefreshView();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRefreshView() {
|
||||
if (adapter != null) {
|
||||
adapter.refreshView();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onBackCameraVideo(byte[] data) {
|
||||
if (backCameraFloatWindow != null) {
|
||||
backCameraFloatWindow.onBackCameraVideo(data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,310 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.mogo.support.obu.common.L;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.adapter.ConnectStatusAdapter;
|
||||
import com.zhidao.adas.client.bean.IPCConnectState;
|
||||
import com.zhidao.adas.client.utils.MyLinearLayoutManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* ping命令窗口
|
||||
*/
|
||||
public class PingFloatWindow implements View.OnTouchListener {
|
||||
private static final String TAG = PingFloatWindow.class.getSimpleName();
|
||||
private static final int WHAT_STATE = 8;
|
||||
private final Activity mContext;
|
||||
private WindowManager.LayoutParams mWindowParams;
|
||||
private WindowManager mWindowManager;
|
||||
|
||||
private View mFloatLayout;
|
||||
private float mInViewX;
|
||||
private float mInViewY;
|
||||
private float mDownInScreenX;
|
||||
private float mDownInScreenY;
|
||||
private float mInScreenX;
|
||||
private float mInScreenY;
|
||||
private RecyclerView rv_status;
|
||||
private ConnectStatusAdapter adapter;
|
||||
private final List<IPCConnectState> list = new ArrayList<>();
|
||||
private final String ip;
|
||||
private Timer timer;
|
||||
|
||||
public PingFloatWindow(Activity context, String ip) {
|
||||
this.mContext = context;
|
||||
this.ip = ip;
|
||||
initFloatWindow();
|
||||
initHandler();
|
||||
pingTimer(true);
|
||||
}
|
||||
|
||||
private void pingTimer(boolean isStart) {
|
||||
if (isStart) {
|
||||
if (timer == null) {
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
ping();
|
||||
}
|
||||
}, 100L, 2500L);//延时
|
||||
}
|
||||
} else {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ping() {
|
||||
Process p;
|
||||
try {
|
||||
//ping -c 3 -w 100 中 ,-c 是指ping的次数 3是指ping 3次 ,-w 100 以秒为单位指定超时间隔,是指超时时间为100秒
|
||||
p = Runtime.getRuntime().exec("ping -c 1 -w 2 " + ip);
|
||||
int status = p.waitFor();
|
||||
InputStream input = p.getInputStream();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(input));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
builder.append(line).append("\n");
|
||||
}
|
||||
String str = "IP:" + ip + " 是否可以连通:" + (status == 0 ? "是" : "否");
|
||||
L.i(TAG, builder.toString() + str);
|
||||
add(str, status == 0);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void add(String str, boolean isConnect) {
|
||||
|
||||
int color;
|
||||
if (isConnect) {
|
||||
color = R.color.connect_status_connected;
|
||||
} else {
|
||||
color = R.color.connect_status_disconnected;
|
||||
}
|
||||
IPCConnectState status = new IPCConnectState(str, color);
|
||||
list.add(0, status);
|
||||
if (list.size() > 100) {
|
||||
list.remove(list.size() - 1);
|
||||
}
|
||||
Message msg = Message.obtain();
|
||||
msg.what = WHAT_STATE;
|
||||
getHandler().sendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
public void refreshView() {
|
||||
if (adapter != null) {
|
||||
adapter.refreshView();
|
||||
}
|
||||
}
|
||||
|
||||
private void initRV() {
|
||||
//创建默认的线性LayoutManager 横向的GridLayoutManager
|
||||
MyLinearLayoutManager linearLayoutManager = new MyLinearLayoutManager(mContext);
|
||||
// linearLayoutManager.setStackFromEnd(true);//列表再底部开始展示,反转后由上面开始展示
|
||||
// linearLayoutManager.setReverseLayout(true);//列表翻转
|
||||
rv_status.setLayoutManager(linearLayoutManager);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
rv_status.setHasFixedSize(false);
|
||||
rv_status.setNestedScrollingEnabled(false);
|
||||
adapter = new ConnectStatusAdapter();
|
||||
adapter.setHasStableIds(true);
|
||||
rv_status.setAdapter(adapter);
|
||||
adapter.setData(list);
|
||||
}
|
||||
|
||||
private void initFloatWindow() {
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
if (inflater == null)
|
||||
return;
|
||||
mFloatLayout = (View) inflater.inflate(R.layout.layout_float, null);
|
||||
rv_status = mFloatLayout.findViewById(R.id.rv_status);
|
||||
mFloatLayout.setOnTouchListener(this);
|
||||
initRV();
|
||||
mWindowParams = new WindowManager.LayoutParams();
|
||||
// mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
// if (Build.VERSION.SDK_INT >= 26) {//8.0新特性
|
||||
// mWindowParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
// }else{
|
||||
// mWindowParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
// }
|
||||
|
||||
mWindowManager = mContext.getWindowManager();
|
||||
|
||||
mWindowParams.format = PixelFormat.RGBA_8888;
|
||||
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
mWindowParams.gravity = Gravity.START | Gravity.TOP;
|
||||
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
mWindowParams.alpha = 0.9F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
return floatLayoutTouch(motionEvent);
|
||||
}
|
||||
|
||||
private boolean floatLayoutTouch(MotionEvent motionEvent) {
|
||||
switch (motionEvent.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// 获取相对View的坐标,即以此View左上角为原点
|
||||
mInViewX = motionEvent.getX();
|
||||
mInViewY = motionEvent.getY();
|
||||
// 获取相对屏幕的坐标,即以屏幕左上角为原点
|
||||
mDownInScreenX = motionEvent.getRawX();
|
||||
mDownInScreenY = motionEvent.getRawY() - getSysBarHeight(mContext);
|
||||
mInScreenX = motionEvent.getRawX();
|
||||
mInScreenY = motionEvent.getRawY() - getSysBarHeight(mContext);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// 更新浮动窗口位置参数
|
||||
mInScreenX = motionEvent.getRawX();
|
||||
mInScreenY = motionEvent.getRawY() - getSysBarHeight(mContext);
|
||||
mWindowParams.x = (int) (mInScreenX - mInViewX);
|
||||
mWindowParams.y = (int) (mInScreenY - mInViewY);
|
||||
// 手指移动的时候更新小悬浮窗的位置
|
||||
mWindowManager.updateViewLayout(mFloatLayout, mWindowParams);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
// 如果手指离开屏幕时,xDownInScreen和xInScreen相等,且yDownInScreen和yInScreen相等,则视为触发了单击事件。
|
||||
if (mDownInScreenX == mInScreenX && mDownInScreenY == mInScreenY) {
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void showFloatWindow(float x, float y) {
|
||||
if (mFloatLayout.getParent() == null) {
|
||||
// DisplayMetrics metrics = new DisplayMetrics();
|
||||
// 默认固定位置,靠屏幕右边缘的中间
|
||||
// mWindowManager.getDefaultDisplay().getMetrics(metrics);
|
||||
mWindowParams.x = (int) x;
|
||||
mWindowParams.y = (int) (y);
|
||||
mWindowManager.addView(mFloatLayout, mWindowParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void hideFloatWindow() {
|
||||
pingTimer(false);
|
||||
if (getHandler() != null) {
|
||||
getHandler().removeCallbacksAndMessages(null);
|
||||
}
|
||||
if (mFloatLayout.getParent() != null)
|
||||
mWindowManager.removeView(mFloatLayout);
|
||||
|
||||
}
|
||||
|
||||
public void setFloatLayoutAlpha(boolean alpha) {
|
||||
if (alpha)
|
||||
mFloatLayout.setAlpha((float) 0.5);
|
||||
else
|
||||
mFloatLayout.setAlpha(1);
|
||||
}
|
||||
|
||||
private int sbar = -1;
|
||||
|
||||
// 获取系统状态栏高度
|
||||
public int getSysBarHeight(Context contex) {
|
||||
if (sbar == -1) {
|
||||
Class<?> c;
|
||||
Object obj;
|
||||
Field field;
|
||||
int x;
|
||||
sbar = 0;
|
||||
try {
|
||||
c = Class.forName("com.android.internal.R$dimen");
|
||||
obj = c.newInstance();
|
||||
field = c.getField("status_bar_height");
|
||||
x = Integer.parseInt(field.get(obj).toString());
|
||||
sbar = contex.getResources().getDimensionPixelSize(x);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sbar;
|
||||
}
|
||||
|
||||
|
||||
private BaseHandler mBaseHandler;
|
||||
|
||||
/**
|
||||
* 初始化一个Handler,如果需要使用Handler,先调用此方法,
|
||||
* 然后可以使用postRunnable(Runnable runnable),
|
||||
* sendMessage在handleMessage(Message msg)中接收msg
|
||||
*/
|
||||
public void initHandler() {
|
||||
mBaseHandler = new BaseHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回Handler,在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @return Handler
|
||||
*/
|
||||
public Handler getHandler() {
|
||||
return mBaseHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同Handler 的 handleMessage,
|
||||
* getHandler.sendMessage,发送的Message在此接收
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
protected void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case WHAT_STATE:
|
||||
refreshView();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static class BaseHandler extends Handler {
|
||||
private final WeakReference<PingFloatWindow> mObjects;
|
||||
|
||||
public BaseHandler(PingFloatWindow mPresenter) {
|
||||
mObjects = new WeakReference<PingFloatWindow>(mPresenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
PingFloatWindow mPresenter = mObjects.get();
|
||||
if (mPresenter != null)
|
||||
mPresenter.handleMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.adapter.SendCmdAdapter;
|
||||
import com.zhidao.adas.client.bean.SendCmd;
|
||||
import com.zhidao.adas.client.bean.SendCmdOption;
|
||||
import com.zhidao.adas.client.utils.Constants;
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
|
||||
|
||||
public class SendCmdDialog extends Dialog {
|
||||
private RecyclerView recyclerView;
|
||||
private final SendCmd<?> sendCmd;
|
||||
|
||||
public SendCmdDialog(@NonNull Context context, SendCmd<?> sendCmd) {
|
||||
super(context, R.style.CustomDialog);
|
||||
this.sendCmd = sendCmd;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_send_cmd);
|
||||
//初始化界面控件
|
||||
initView();
|
||||
initRecyclerView();
|
||||
//初始化界面控件的事件
|
||||
setOnDismissListener(new OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
}
|
||||
|
||||
private void initRecyclerView() {
|
||||
//创建默认的线性LayoutManager 横向的GridLayoutManager
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
recyclerView.setHasFixedSize(true);
|
||||
//解决局部刷新闪屏问题
|
||||
SimpleItemAnimator animator = (SimpleItemAnimator) recyclerView.getItemAnimator();
|
||||
if (animator != null)
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
//创建并设置Adapter
|
||||
SendCmdAdapter adapter = new SendCmdAdapter(sendCmd.value, new SendCmdAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(SendCmdOption<?> data) {
|
||||
String name = sendCmd.name;
|
||||
if (Constants.TITLE.SEND_PLANNING_CMD.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.PULL_OVER) {
|
||||
AdasManager.getInstance().sendPlanningPullOverCmd((int) data.value);
|
||||
} else if (data.tag == SendCmdOption.TAG.LANE_CHANGE) {
|
||||
AdasManager.getInstance().sendPlanningLaneChangeCmd((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_SET_DEMO_MODE_REQ.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.DEMO_MODE) {
|
||||
AdasManager.getInstance().sendDemoModeReq((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_BLIND_AREA.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.BLIND_AREA) {
|
||||
AdasManager.getInstance().sendBlindAreaCmd((boolean) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_V2N_TO_PNC.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.V2N_TO_PNC) {
|
||||
AdasManager.getInstance().sendV2nToPncCmd((boolean) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_SET_RAIN_MODE_REQ.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.RAIN_MODE) {
|
||||
AdasManager.getInstance().sendRainModeReq((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_DETOURING.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.DETOURING) {
|
||||
AdasManager.getInstance().sendDetouring((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_AEB.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.AEB) {
|
||||
AdasManager.getInstance().sendAebCmd((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_LANE_CHANGE_RESTRAIN_VALID.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.LANE_CHANGE_RESTRAIN_VALID) {
|
||||
AdasManager.getInstance().sendLaneChangeRestrainValid((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_STOP_YIELD_VALID.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.STOP_YIELD_VALID) {
|
||||
AdasManager.getInstance().sendStopYieldValid((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_HADMAP_SPEED_LIMIT_VALID.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.HADMAP_SPEED_LIMIT_VALID) {
|
||||
AdasManager.getInstance().sendHadmapSpeedLimitValid((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_RAMP_THETA_VALID.equals(name)) {
|
||||
if (data.tag == SendCmdOption.TAG.RAMP_THETA_VALID) {
|
||||
AdasManager.getInstance().sendRampThetaValid((int) data.value);
|
||||
}
|
||||
} else if (Constants.TITLE.SEND_GET_PARAM_REQ.equals(name)) {
|
||||
if (data.tag == com.zhidao.support.adas.high.common.Constants.PARAM_TYPE.UNKNOWN) {
|
||||
AdasManager.getInstance().sendGetAllParamReq();
|
||||
} else {
|
||||
AdasManager.getInstance().sendGetParamReq((int) data.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面控件
|
||||
*/
|
||||
private void initView() {
|
||||
recyclerView = findViewById(R.id.recyclerView);
|
||||
TextView title = findViewById(R.id.title);
|
||||
title.setText(sendCmd.name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,544 +0,0 @@
|
||||
package com.zhidao.adas.client.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import com.zhidao.adas.client.App;
|
||||
import com.zhidao.adas.client.BuildConfig;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.adapter.ConfigAdapter;
|
||||
import com.zhidao.adas.client.adapter.InterfaceAdapter;
|
||||
import com.zhidao.adas.client.base.BaseFragment;
|
||||
import com.zhidao.adas.client.bean.Config;
|
||||
import com.zhidao.adas.client.bean.InterfaceModel;
|
||||
import com.zhidao.adas.client.utils.RandomColor;
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
import com.zhidao.support.adas.high.bean.VersionCompatibility;
|
||||
import com.zhidao.support.adas.high.common.Constants;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
import com.zhidao.support.adas.high.common.MessageType;
|
||||
import com.zhidao.support.adas.high.common.autopilot.ability.AutopilotAbilityManager;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import chassis.Chassis;
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* @des 升级页面
|
||||
*/
|
||||
public class VersionFragment extends BaseFragment {
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS ", Locale.getDefault());
|
||||
private TextView ipsView;
|
||||
private EditText ipView;
|
||||
private RecyclerView recyclerView;
|
||||
private RecyclerView rec_registered;
|
||||
private RecyclerView rec_unregistered;
|
||||
private CheckBox registered_check_all;
|
||||
private CheckBox unregistered_check_all;
|
||||
private TextView hint_registered;
|
||||
private TextView hint_unregistered;
|
||||
private TextView can;
|
||||
private TextView gear_influence;
|
||||
private TextView gear;
|
||||
private TextView title_gear;
|
||||
private RadioButton rb_taxi;
|
||||
private RadioGroup rg;
|
||||
|
||||
private ConfigAdapter adapter;
|
||||
private InterfaceAdapter unregisteredAdapter;
|
||||
private InterfaceAdapter registeredAdapter;
|
||||
|
||||
private int role = Constants.TERMINAL_ROLE.DEBUG;//角色 默认调试屏
|
||||
|
||||
public VersionFragment() {
|
||||
}
|
||||
|
||||
|
||||
public VersionFragment(String title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_version, container, false);
|
||||
initView(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
showIps();
|
||||
showVersion();
|
||||
}
|
||||
|
||||
|
||||
private void showIps() {
|
||||
HashSet<String> ips = AdasManager.getInstance().getIPCFixationIPList(getActivity());
|
||||
if (ips != null && !ips.isEmpty()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
for (String ip : ips) {
|
||||
i++;
|
||||
builder.append(ip);
|
||||
if (i % 4 == 0) {
|
||||
builder.append("\n");
|
||||
} else {
|
||||
builder.append("\t\t\t\t");
|
||||
}
|
||||
}
|
||||
ipsView.setText(builder.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void initView(View view) {
|
||||
TextView tvTitle = view.findViewById(R.id.tv_title);
|
||||
Button btn1 = view.findViewById(R.id.btn1);
|
||||
ipView = view.findViewById(R.id.ip);
|
||||
Button btn2 = view.findViewById(R.id.btn2);
|
||||
ipsView = view.findViewById(R.id.ips_view);
|
||||
recyclerView = view.findViewById(R.id.config_list);
|
||||
rb_taxi = view.findViewById(R.id.rb_taxi);
|
||||
can = view.findViewById(R.id.can);
|
||||
gear_influence = view.findViewById(R.id.gear_influence);
|
||||
gear = view.findViewById(R.id.gear);
|
||||
title_gear = view.findViewById(R.id.title_gear);
|
||||
rg = view.findViewById(R.id.rg);
|
||||
initFragmentRecyclerView();
|
||||
CupidLogUtils.w("InfoFragment===>" + title);
|
||||
tvTitle.setText(title);
|
||||
tvTitle.setGravity(Gravity.CENTER);
|
||||
initRegistrationView(view);
|
||||
btn1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String ip = ipView.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(ip)) {
|
||||
Toast.makeText(getContext(), "请输入IP", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (AdasManager.getInstance().addIPCFixationIP(getContext(), ip)) {
|
||||
ipView.setText("");
|
||||
showIps();
|
||||
} else {
|
||||
Toast.makeText(getContext(), "IP已存在", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
btn2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String ip = ipView.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(ip)) {
|
||||
Toast.makeText(getContext(), "请输入IP", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (AdasManager.getInstance().delIPCFixationIP(getContext(), ip)) {
|
||||
ipView.setText("");
|
||||
showIps();
|
||||
} else {
|
||||
Toast.makeText(getContext(), "IP不存在", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (BuildConfig.IS_CLIENT) {
|
||||
view.findViewById(R.id.ipc_ip_config).setVisibility(View.GONE);
|
||||
view.findViewById(R.id.line1).setVisibility(View.GONE);
|
||||
tvTitle.setText("版本");
|
||||
}
|
||||
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
if (checkedId == R.id.rb_taxi) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_TAXI);
|
||||
gear("TAXI", BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_TAXI);
|
||||
} else if (checkedId == R.id.rb_bus) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_BUS);
|
||||
gear("BUS", BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_BUS);
|
||||
} else if (checkedId == R.id.rb_sweeper) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_SWEEPER);
|
||||
gear("SWEEPER", BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_SWEEPER);
|
||||
} else if (checkedId == R.id.rb_m1) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_M1);
|
||||
gear("M1", BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_M1);
|
||||
} else if (checkedId == R.id.rb_m2) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_M2);
|
||||
gear("M1", BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_M2);
|
||||
} else if (checkedId == R.id.rb_van) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_VAN);
|
||||
gear("VAN", BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_VAN);
|
||||
}
|
||||
}
|
||||
});
|
||||
gear("TAXI", BuildConfig.UNABLE_LAUNCH_AUTOPILOT_GEAR_TAXI);
|
||||
}
|
||||
|
||||
private void gear(String car, Set<Chassis.GearPosition> unableLaunchAutopilotGear) {
|
||||
title_gear.setText(car + "不能启动自动驾驶的档位:");
|
||||
String gear;
|
||||
if (unableLaunchAutopilotGear == null) {
|
||||
gear = "无限制";
|
||||
} else {
|
||||
gear = Arrays.toString(unableLaunchAutopilotGear.toArray());
|
||||
}
|
||||
this.gear.setText(gear);
|
||||
}
|
||||
|
||||
//根据连接状态更新数据
|
||||
@Override
|
||||
public void onConnectionIPCStatus(int ipcConnectionStatus) {
|
||||
super.onConnectionIPCStatus(ipcConnectionStatus);
|
||||
if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.DISCONNECTED || ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
showVersion();
|
||||
initRegistrationData();
|
||||
if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.DISCONNECTED) {
|
||||
clearRegistrationViewState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showVersion() {
|
||||
List<Config> list = new ArrayList<>();
|
||||
if (!BuildConfig.IS_CLIENT) {
|
||||
String ip = AdasManager.getInstance().getIpcConnectedIp();
|
||||
String temp = "";
|
||||
if (!TextUtils.isEmpty(ip)) {
|
||||
temp = ip + ":" + AdasManager.getInstance().getIpcConnectedPort();
|
||||
}
|
||||
MessagePad.CarConfigResp adasConfig = AdasManager.getInstance().getCarConfig();
|
||||
list.add(new Config("更新时间:", AdasManager.getInstance().getIpcConnectionStatus() == Constants.IPC_CONNECTION_STATUS.CONNECTED ? sdf.format(new Date()) : null));
|
||||
list.add(new Config("工控机IP:", temp));
|
||||
list.add(new Config("工控机版本:", adasConfig == null ? null : adasConfig.getDockVersion()));
|
||||
list.add(new Config("车牌号:", adasConfig == null ? null : adasConfig.getPlateNumber()));
|
||||
list.add(new Config("MAC地址:", adasConfig == null ? null : adasConfig.getMacAddress()));
|
||||
list.add(new Config("自动驾驶限速:", adasConfig == null ? null : adasConfig.getSpeedLimit() + "m/s"));
|
||||
list.add(new Config("最大自动驾驶限速:", adasConfig == null ? null : adasConfig.getMaxSpeedLimit() + "m/s"));
|
||||
list.add(new Config("最小加速度:", adasConfig == null ? null : adasConfig.getMinAcceleration() + "m/s²"));
|
||||
list.add(new Config("最大加速度:", adasConfig == null ? null : adasConfig.getMaxAcceleration() + "m/s²"));
|
||||
list.add(new Config("IPC通信协议版本:", adasConfig == null ? null : String.valueOf(adasConfig.getProtocolVersionValue())));
|
||||
list.add(new Config("APP通信协议版本:", String.valueOf(AdasManager.getInstance().getProtocolVersion())));
|
||||
VersionCompatibility versionCompatibility = AdasManager.getInstance().getVersionCompatibility();
|
||||
list.add(new Config("版本兼容性:", versionCompatibility == null ? null : versionCompatibility.toString()));
|
||||
}
|
||||
|
||||
list.add(new Config("ADAS LIB版本:", AdasManager.getInstance().getAdasVersion()));
|
||||
list.add(new Config("APP版本:", BuildConfig.VERSION_NAME));
|
||||
list.add(new Config("APP构建时间:", BuildConfig.BUILD_TIME));
|
||||
list.add(new Config("GIT分支:", BuildConfig.GIT_BRANCH_NAME));
|
||||
list.add(new Config("APK名称:", BuildConfig.APK_NAME));
|
||||
adapter.setData(list);
|
||||
}
|
||||
|
||||
private String gear() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Chassis.GearPosition gear = App.INSTANCE.gear;
|
||||
if (gear != null) {
|
||||
boolean b = AutopilotAbilityManager.getInstance().isLaunchAutopilot(gear);
|
||||
builder.append(" 当前档位:").append(gear.name());
|
||||
builder.append(" 是否可以启动自驾:").append(b);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String getAutopilotAbilityConfig(String value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void autopilotAbility(boolean isAutopilotAbility, String unableAutopilotReason) {
|
||||
if (getActivity() != null)
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
can.setTextColor(getResources().getColor(RandomColor.randomColor()));
|
||||
can.setText(getAutopilotAbilityConfig(isAutopilotAbility + ",原因:" + unableAutopilotReason));
|
||||
gear_influence.setTextColor(getResources().getColor(RandomColor.randomColor()));
|
||||
gear_influence.setText(gear());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void updateRefreshConfig(List<Config> list, Config temp) {
|
||||
int index = list.indexOf(temp);
|
||||
if (index < 0) {
|
||||
list.add(temp);
|
||||
if (getActivity() != null)
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.notifyItemInserted(list.size() - 1);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Config config = list.get(index);
|
||||
config.cover(temp);
|
||||
config.color = RandomColor.randomColor();
|
||||
if (getActivity() != null)
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRefreshView() {
|
||||
showVersion();
|
||||
}
|
||||
|
||||
private void initFragmentRecyclerView() {
|
||||
//创建默认的线性LayoutManager 横向的GridLayoutManager
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
recyclerView.setHasFixedSize(true);
|
||||
//解决局部刷新闪屏问题
|
||||
SimpleItemAnimator animator = (SimpleItemAnimator) recyclerView.getItemAnimator();
|
||||
if (animator != null)
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
//创建并设置Adapter
|
||||
adapter = new ConfigAdapter();
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
||||
private void initRegistrationView(View view) {
|
||||
recyclerView = view.findViewById(R.id.config_list);
|
||||
rec_registered = view.findViewById(R.id.rec_registered);
|
||||
rec_unregistered = view.findViewById(R.id.rec_unregistered);
|
||||
registered_check_all = view.findViewById(R.id.registered_check_all);
|
||||
unregistered_check_all = view.findViewById(R.id.unregistered_check_all);
|
||||
hint_unregistered = view.findViewById(R.id.hint_unregistered);
|
||||
hint_registered = view.findViewById(R.id.hint_registered);
|
||||
Button update = view.findViewById(R.id.update);
|
||||
initFragmentRecyclerView();
|
||||
initRegisteredRecyclerView();
|
||||
initUnregisteredRecyclerView();
|
||||
initSpinner(view);
|
||||
registered_check_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (buttonView.isPressed()) {
|
||||
registeredAdapter.setCheckAll(isChecked);
|
||||
unregisteredAdapter.setCheckAll(false);
|
||||
unregisteredAdapter.setEnabled(!isChecked);
|
||||
unregistered_check_all.setEnabled(!isChecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
registeredAdapter.setListener(new InterfaceAdapter.OnInterfaceAdapterListener() {
|
||||
@Override
|
||||
public void onCheckAll(boolean isCheckAll) {
|
||||
registered_check_all.setChecked(isCheckAll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckNum(int checkNum) {
|
||||
boolean isEnable = checkNum == 0;
|
||||
unregisteredAdapter.setEnabled(isEnable);
|
||||
unregistered_check_all.setEnabled(isEnable);
|
||||
}
|
||||
});
|
||||
unregistered_check_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (buttonView.isPressed()) {
|
||||
unregisteredAdapter.setCheckAll(isChecked);
|
||||
registeredAdapter.setCheckAll(false);
|
||||
registeredAdapter.setEnabled(!isChecked);
|
||||
registered_check_all.setEnabled(!isChecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
unregisteredAdapter.setListener(new InterfaceAdapter.OnInterfaceAdapterListener() {
|
||||
@Override
|
||||
public void onCheckAll(boolean isCheckAll) {
|
||||
unregistered_check_all.setChecked(isCheckAll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckNum(int checkNum) {
|
||||
boolean isEnable = checkNum == 0;
|
||||
registeredAdapter.setEnabled(isEnable);
|
||||
registered_check_all.setEnabled(isEnable);
|
||||
}
|
||||
});
|
||||
update.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
update();
|
||||
}
|
||||
});
|
||||
initRegistrationData();
|
||||
}
|
||||
|
||||
|
||||
private void update() {
|
||||
if (registeredAdapter.getCheckNum() == 0 && unregisteredAdapter.getCheckNum() == 0) {
|
||||
Toast.makeText(getContext(), "请选择后在更新", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Set<MessageType> set;
|
||||
if (registeredAdapter.getCheckNum() == 0) {
|
||||
//注册
|
||||
set = unregisteredAdapter.getCheckedModel();
|
||||
if (set == null || set.isEmpty()) {
|
||||
Toast.makeText(getContext(), "请选择要注册的接口", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (set.size() == 1) {
|
||||
AdasManager.getInstance().subscribeInterface(role, Constants.SUBSCRIBE_TYPE.SUBSCRIBE, set.iterator().next());
|
||||
} else {
|
||||
AdasManager.getInstance().subscribeInterface(role, Constants.SUBSCRIBE_TYPE.SUBSCRIBE, set);
|
||||
}
|
||||
} else {
|
||||
//取消注册
|
||||
set = registeredAdapter.getCheckedModel();
|
||||
if (set == null || set.isEmpty()) {
|
||||
Toast.makeText(getContext(), "请选择要取消注册的接口", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (set.size() == 1) {
|
||||
AdasManager.getInstance().subscribeInterface(role, Constants.SUBSCRIBE_TYPE.UNSUBSCRIBE, set.iterator().next());
|
||||
} else {
|
||||
AdasManager.getInstance().subscribeInterface(role, Constants.SUBSCRIBE_TYPE.UNSUBSCRIBE, set);
|
||||
}
|
||||
}
|
||||
clearRegistrationViewState();
|
||||
initRegistrationData();
|
||||
|
||||
}
|
||||
|
||||
private void clearRegistrationViewState() {
|
||||
registered_check_all.setChecked(false);
|
||||
unregistered_check_all.setChecked(false);
|
||||
registered_check_all.setEnabled(true);
|
||||
unregistered_check_all.setEnabled(true);
|
||||
if (registeredAdapter != null)
|
||||
registeredAdapter.notifyDataSetChanged();
|
||||
if (unregisteredAdapter != null)
|
||||
unregisteredAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void initRegistrationData() {
|
||||
//初始化数据
|
||||
Set<MessageType> set = AdasManager.getInstance().getSubscribedInterface();
|
||||
List<InterfaceModel> registeredList = new ArrayList<>();
|
||||
List<InterfaceModel> unregisteredList = new ArrayList<>();
|
||||
if (set != null && !set.isEmpty()) {
|
||||
registered_check_all.setVisibility(View.VISIBLE);
|
||||
for (MessageType messageType : set) {
|
||||
registeredList.add(new InterfaceModel(messageType));
|
||||
}
|
||||
} else {
|
||||
registered_check_all.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
set = AdasManager.getInstance().getUnsubscribedInterface();
|
||||
if (set != null && !set.isEmpty()) {
|
||||
unregistered_check_all.setVisibility(View.VISIBLE);
|
||||
for (MessageType messageType : set) {
|
||||
unregisteredList.add(new InterfaceModel(messageType));
|
||||
}
|
||||
} else {
|
||||
unregistered_check_all.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
registeredAdapter.setData(registeredList, 0);
|
||||
unregisteredAdapter.setData(unregisteredList, 0);
|
||||
hint_registered.setText("已注册接口(" + registeredAdapter.getItemCount() + ")");
|
||||
hint_unregistered.setText("未注册接口(" + unregisteredAdapter.getItemCount() + ")");
|
||||
}
|
||||
|
||||
|
||||
private void initRegisteredRecyclerView() {
|
||||
//创建默认的线性LayoutManager 横向的GridLayoutManager
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
rec_registered.setLayoutManager(linearLayoutManager);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
rec_registered.setHasFixedSize(false);
|
||||
rec_registered.setNestedScrollingEnabled(false);
|
||||
registeredAdapter = new InterfaceAdapter();
|
||||
rec_registered.setAdapter(registeredAdapter);
|
||||
}
|
||||
|
||||
private void initUnregisteredRecyclerView() {
|
||||
//创建默认的线性LayoutManager 横向的GridLayoutManager
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
rec_unregistered.setLayoutManager(linearLayoutManager);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
rec_unregistered.setHasFixedSize(false);
|
||||
rec_unregistered.setNestedScrollingEnabled(false);
|
||||
unregisteredAdapter = new InterfaceAdapter();
|
||||
rec_unregistered.setAdapter(unregisteredAdapter);
|
||||
}
|
||||
|
||||
|
||||
private void initSpinner(View view) {
|
||||
String[] s = {"司机", "乘客", "调试"};
|
||||
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item, s);
|
||||
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
Spinner sp = view.findViewById(R.id.spinner);
|
||||
sp.setAdapter(dataAdapter);
|
||||
sp.setSelection(2);
|
||||
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
role = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
package com.zhidao.adas.client.ui.special;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import com.zhidao.adas.client.App;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.adapter.SpecialVehicleAdapter;
|
||||
import com.zhidao.adas.client.base.BaseAdapter;
|
||||
import com.zhidao.adas.client.bean.SpecialVehicleBean;
|
||||
import com.zhidao.adas.client.ui.AutopilotConfigActivity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 特种车辆
|
||||
*/
|
||||
public class SpecialVehicleDialog extends Dialog {
|
||||
private RecyclerView recyclerView;
|
||||
private List<SpecialVehicleBean> list;
|
||||
|
||||
|
||||
public SpecialVehicleDialog(@NonNull Context context, List<SpecialVehicleBean> list) {
|
||||
super(context, R.style.CustomDialog);
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_autopilot_mode);
|
||||
//初始化界面控件
|
||||
initView();
|
||||
//初始化界面控件的事件
|
||||
initListener();
|
||||
initBtnRecyclerView();
|
||||
setOnDismissListener(new OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
}
|
||||
|
||||
|
||||
private void initBtnRecyclerView() {
|
||||
//初始info-recycle
|
||||
LinearLayoutManager nodLinearLayoutManage = new LinearLayoutManager(getContext());
|
||||
nodLinearLayoutManage.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
recyclerView.setLayoutManager(nodLinearLayoutManage);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
recyclerView.setHasFixedSize(true);
|
||||
//解决局部刷新闪屏问题
|
||||
SimpleItemAnimator animatorInfo = (SimpleItemAnimator) recyclerView.getItemAnimator();
|
||||
if (animatorInfo != null)
|
||||
animatorInfo.setSupportsChangeAnimations(false);
|
||||
//创建并设置Adapter
|
||||
SpecialVehicleAdapter adapter = new SpecialVehicleAdapter(list);
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener<SpecialVehicleBean>() {
|
||||
@Override
|
||||
public void onItemClick(int position, SpecialVehicleBean data) {
|
||||
if (data.options == null) {
|
||||
Toast.makeText(getContext(), "“" + data.name + "”暂未支持", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
data.showFloat(App.INSTANCE);
|
||||
SpecialVehicleDialog.this.dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面的确定和取消监听器
|
||||
*/
|
||||
private void initListener() {
|
||||
findViewById(R.id.settings).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getContext().startActivity(new Intent(getContext(), AutopilotConfigActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化界面控件
|
||||
*/
|
||||
private void initView() {
|
||||
recyclerView = findViewById(R.id.recyclerView);
|
||||
findViewById(R.id.settings).setVisibility(View.GONE);
|
||||
findViewById(R.id.cancel).setVisibility(View.GONE);
|
||||
TextView textView = findViewById(R.id.title);
|
||||
textView.setText("特种车辆");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,461 +0,0 @@
|
||||
package com.zhidao.adas.client.ui.special;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.AppCompatButton;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.bean.SpecialVehicleBean;
|
||||
import com.zhidao.adas.client.bean.SpecialVehicleOption;
|
||||
import com.zhidao.adas.client.utils.SysBarUtil;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
||||
/**
|
||||
* 2017/1/10.
|
||||
* Description:全局悬浮窗口
|
||||
*/
|
||||
|
||||
public class SpecialVehicleFloatWindow extends LinearLayout {
|
||||
|
||||
/*********************悬浮窗相关***********************/
|
||||
|
||||
private int sW;
|
||||
private int sH;
|
||||
private boolean isMaximize = true;//是否是最大化
|
||||
private WindowManager wm;
|
||||
//此wmParams变量为获取的全局变量,用以保存悬浮窗口的属性
|
||||
private WindowManager.LayoutParams wmParams;
|
||||
private int btnMaximizeW;
|
||||
private int btnMaximizeH;
|
||||
|
||||
/*********************CAN数据配置相关***********************/
|
||||
private final static int WHAT_UPDATE_DATA = 1;
|
||||
private BaseHandler mBaseHandler;
|
||||
private LinearLayout layout_btn;
|
||||
private HorizontalScrollView btn_list;
|
||||
private AppCompatButton btn_send;
|
||||
private RadioGroup rg_send_type;
|
||||
private TextView text;
|
||||
private TextView title;
|
||||
private TextView btn_maximize;
|
||||
private View can_parent;
|
||||
|
||||
private OnFloatWindowListener listener;
|
||||
private final SpecialVehicleBean specialVehicleBean;
|
||||
|
||||
public interface OnFloatWindowListener {
|
||||
void onBack();
|
||||
|
||||
void onMinimality();
|
||||
|
||||
void onMaximize();
|
||||
}
|
||||
|
||||
public boolean isMaximize() {
|
||||
return isMaximize;
|
||||
}
|
||||
|
||||
public void setOnFloatWindowListener(OnFloatWindowListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setWmParams(WindowManager.LayoutParams wmParams) {
|
||||
this.wmParams = wmParams;
|
||||
}
|
||||
|
||||
public SpecialVehicleFloatWindow(@NonNull Context context, @NonNull SpecialVehicleBean specialVehicleBean) {
|
||||
super(context, null, 0);
|
||||
this.specialVehicleBean = specialVehicleBean;
|
||||
wm = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
||||
//加载布局
|
||||
LayoutInflater.from(context).inflate(R.layout.dialog_special_vehicle_config, this, true);
|
||||
initParameter();
|
||||
initCanView();
|
||||
}
|
||||
|
||||
private void initParameter() {
|
||||
DisplayMetrics metrics2 = getResources().getDisplayMetrics();
|
||||
sW = metrics2.widthPixels;
|
||||
sH = metrics2.heightPixels;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
||||
if (isMaximize) {
|
||||
minimality();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
private float mInViewX;
|
||||
private float mInViewY;
|
||||
private float mDownInScreenX;
|
||||
private float mDownInScreenY;
|
||||
private float mInScreenX;
|
||||
private float mInScreenY;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// 获取相对View的坐标,即以此View左上角为原点
|
||||
mInViewX = event.getX();
|
||||
mInViewY = event.getY();
|
||||
// 获取相对屏幕的坐标,即以屏幕左上角为原点
|
||||
mDownInScreenX = event.getRawX();
|
||||
mDownInScreenY = event.getRawY() - SysBarUtil.getSysBarHeight(getContext());
|
||||
mInScreenX = event.getRawX();
|
||||
mInScreenY = event.getRawY() - SysBarUtil.getSysBarHeight(getContext());
|
||||
|
||||
if (!isMaximize) {
|
||||
btn_maximize.setPressed(true);
|
||||
btnMaximizeW = btn_maximize.getWidth();
|
||||
btnMaximizeH = btn_maximize.getHeight();
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// 更新浮动窗口位置参数
|
||||
mInScreenX = event.getRawX();
|
||||
mInScreenY = event.getRawY() - SysBarUtil.getSysBarHeight(getContext());
|
||||
wmParams.x = (int) (mInScreenX - mInViewX);
|
||||
wmParams.y = (int) (mInScreenY - mInViewY);
|
||||
updateViewLayout();
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
// 如果手指离开屏幕时,xDownInScreen和xInScreen相等,且yDownInScreen和yInScreen相等,则视为触发了单击事件。
|
||||
// if (mDownInScreenX == mInScreenX && mDownInScreenY == mInScreenY) {
|
||||
float temX = Math.abs(mDownInScreenX - mInScreenX);
|
||||
float temY = Math.abs(mDownInScreenY - mInScreenY);
|
||||
if (temX + temY < 10) {
|
||||
maximize();
|
||||
} else {
|
||||
if (isMaximize) {
|
||||
specialVehicleBean.setFloatWindowLocationMaxX(getContext(), wmParams.x);
|
||||
specialVehicleBean.setFloatWindowLocationMaxY(getContext(), wmParams.y);
|
||||
} else {
|
||||
btn_maximize.setPressed(false);
|
||||
// 抬起手指时让floatView屏幕左右边缘 距离20个像素
|
||||
// wmParams.x = wmParams.x <= (sW / 2) ? AmiConstants.SCREEN_MARGIN : sW - btnMaximizeW - AmiConstants.SCREEN_MARGIN;
|
||||
int tem = wmParams.x;
|
||||
if (tem < SpecialVehicleBean.SCREEN_MARGIN)
|
||||
tem = SpecialVehicleBean.SCREEN_MARGIN;
|
||||
else if (sW - (tem + btnMaximizeW) < SpecialVehicleBean.SCREEN_MARGIN) {
|
||||
tem = sW - btnMaximizeW - SpecialVehicleBean.SCREEN_MARGIN;
|
||||
}
|
||||
wmParams.x = tem;
|
||||
tem = wmParams.y;
|
||||
if (tem < SpecialVehicleBean.SCREEN_MARGIN)
|
||||
tem = SpecialVehicleBean.SCREEN_MARGIN;
|
||||
else if (sH - (tem + btnMaximizeH) < SpecialVehicleBean.SCREEN_MARGIN) {
|
||||
tem = sH - btnMaximizeH - SpecialVehicleBean.SCREEN_MARGIN;
|
||||
}
|
||||
wmParams.y = tem;
|
||||
updateViewLayout();
|
||||
specialVehicleBean.setFloatWindowLocationMinX(getContext(), wmParams.x);
|
||||
specialVehicleBean.setFloatWindowLocationMinY(getContext(), wmParams.y);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateViewLayout() {
|
||||
wm.updateViewLayout(this, wmParams);
|
||||
}
|
||||
|
||||
// 获取系统状态栏高度
|
||||
private int sbar = -1;
|
||||
|
||||
|
||||
/*****************************业务逻辑*******************************************/
|
||||
|
||||
|
||||
private void initCanView() {
|
||||
initHandler();
|
||||
can_parent = findViewById(R.id.can_parent);
|
||||
btn_list = findViewById(R.id.btn_list);
|
||||
btn_send = findViewById(R.id.btn_send);
|
||||
rg_send_type = findViewById(R.id.rg_send_type);
|
||||
text = findViewById(R.id.text);
|
||||
title = findViewById(R.id.title);
|
||||
title.setText(specialVehicleBean.name);
|
||||
btn_maximize = findViewById(R.id.btn_maximize);
|
||||
btn_maximize.setText(specialVehicleBean.simpleName);
|
||||
initListener();
|
||||
initBtnRecyclerView();
|
||||
initSendTypeView();
|
||||
}
|
||||
|
||||
private void initSendTypeView() {
|
||||
int resId;
|
||||
switch (specialVehicleBean.sendType) {
|
||||
default:
|
||||
case SpecialVehicleBean.SEND_TYPE.ONE:
|
||||
resId = R.id.btn_one;
|
||||
break;
|
||||
case SpecialVehicleBean.SEND_TYPE.MORE:
|
||||
resId = R.id.btn_more;
|
||||
break;
|
||||
case SpecialVehicleBean.SEND_TYPE.ALL:
|
||||
resId = R.id.btn_all;
|
||||
break;
|
||||
}
|
||||
rg_send_type.check(resId);
|
||||
btn_send.setVisibility(specialVehicleBean.sendType == SpecialVehicleBean.SEND_TYPE.ONE ? View.GONE : View.VISIBLE);
|
||||
rg_send_type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
View checkView = group.findViewById(checkedId);
|
||||
if (!checkView.isPressed()) {
|
||||
return;
|
||||
}
|
||||
int type = SpecialVehicleBean.SEND_TYPE.ONE;
|
||||
if (checkedId == R.id.btn_more) {
|
||||
type = SpecialVehicleBean.SEND_TYPE.MORE;
|
||||
} else {
|
||||
if (specialVehicleBean.sendType == SpecialVehicleBean.SEND_TYPE.MORE) {
|
||||
for (int i = 0; i < layout_btn.getChildCount(); i++) {
|
||||
LinearLayout view = (LinearLayout) layout_btn.getChildAt(i);
|
||||
RadioGroup radioGroup = view.findViewById(R.id.item_group);
|
||||
SpecialVehicleOption option = specialVehicleBean.options.get(i);
|
||||
if (option.moreCheckPos != -1) {
|
||||
option.moreCheckPos = -1;
|
||||
radioGroup.check(option.checkPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (checkedId == R.id.btn_one) {
|
||||
type = SpecialVehicleBean.SEND_TYPE.ONE;
|
||||
} else if (checkedId == R.id.btn_all) {
|
||||
type = SpecialVehicleBean.SEND_TYPE.ALL;
|
||||
}
|
||||
}
|
||||
specialVehicleBean.sendType = type;
|
||||
btn_send.setVisibility(type == SpecialVehicleBean.SEND_TYPE.ONE ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
});
|
||||
btn_send.setOnClickListener(onClickListener);
|
||||
}
|
||||
|
||||
|
||||
private void initListener() {
|
||||
findViewById(R.id.btn_back).setOnClickListener(onClickListener);
|
||||
findViewById(R.id.btn_minimality).setOnClickListener(onClickListener);
|
||||
}
|
||||
|
||||
public void minimality() {
|
||||
isMaximize = false;
|
||||
btn_maximize.setVisibility(VISIBLE);
|
||||
can_parent.setVisibility(GONE);
|
||||
if (listener != null) {
|
||||
listener.onMinimality();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void maximize() {
|
||||
isMaximize = true;
|
||||
if (listener != null) {
|
||||
listener.onMaximize();
|
||||
}
|
||||
btn_maximize.setVisibility(GONE);
|
||||
can_parent.setVisibility(VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
private final OnClickListener onClickListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
if (id == R.id.btn_back) {
|
||||
if (listener != null) {
|
||||
listener.onBack();
|
||||
}
|
||||
} else if (id == R.id.btn_minimality) {
|
||||
minimality();
|
||||
} else if (id == R.id.btn_send) {
|
||||
String cmd = specialVehicleBean.sendCmd(-1);
|
||||
updateText(0, cmd);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private void initBtnRecyclerView() {
|
||||
|
||||
layout_btn = new LinearLayout(getContext());
|
||||
btn_list.addView(layout_btn);
|
||||
layout_btn.setOrientation(LinearLayout.HORIZONTAL);
|
||||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) layout_btn.getLayoutParams();
|
||||
lp.gravity = Gravity.CENTER_VERTICAL;
|
||||
for (int i = 0; i < specialVehicleBean.options.size(); i++) {
|
||||
SpecialVehicleOption bean = specialVehicleBean.options.get(i);
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_special_vehicle, layout_btn, false);
|
||||
TextView name = view.findViewById(R.id.name);
|
||||
RadioGroup radioGroup = view.findViewById(R.id.item_group);
|
||||
|
||||
name.setText(bean.name);
|
||||
String[] value = bean.value;
|
||||
for (int j = 0; j < value.length; j++) {
|
||||
RadioButton button = LayoutInflater.from(getContext()).inflate(R.layout.item_special_vehicle_option_radio_btn, radioGroup, false)
|
||||
.findViewById(R.id.r_btn);
|
||||
button.setText(value[j]);
|
||||
button.setId(j);
|
||||
if (specialVehicleBean.tag.equals(SpecialVehicleBean.TAG.FTQSC)) {
|
||||
if (i == 1 || i == 2 || i == 3 || i == 4) {
|
||||
ViewGroup.LayoutParams layoutParams = button.getLayoutParams();
|
||||
layoutParams.width = 202;
|
||||
}
|
||||
}
|
||||
radioGroup.addView(button);
|
||||
}
|
||||
radioGroup.setTag(bean.tag);
|
||||
radioGroup.setOnCheckedChangeListener(onCheckedChangeListener);
|
||||
radioGroup.check(bean.checkPos);
|
||||
layout_btn.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
private final RadioGroup.OnCheckedChangeListener onCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
View checkView = group.findViewById(checkedId);
|
||||
if (checkView == null || !checkView.isPressed()) {
|
||||
return;
|
||||
}
|
||||
int tag = (int) group.getTag();
|
||||
SpecialVehicleOption bean = specialVehicleBean.options.get(tag);
|
||||
if (specialVehicleBean.sendType != SpecialVehicleBean.SEND_TYPE.MORE) {
|
||||
bean.checkPos = checkedId;
|
||||
String cmd = specialVehicleBean.sendCmd(tag);
|
||||
updateText(0, cmd);
|
||||
} else {
|
||||
bean.moreCheckPos = checkedId;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 更新文本
|
||||
*
|
||||
* @param tag 0--发送 1--接收
|
||||
* @param data 数据
|
||||
*/
|
||||
private void updateText(int tag, String data) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = WHAT_UPDATE_DATA;
|
||||
msg.obj = data;
|
||||
msg.arg1 = tag;
|
||||
getHandler().sendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化一个Handler,如果需要使用Handler,先调用此方法,
|
||||
* 然后可以使用postRunnable(Runnable runnable),
|
||||
* sendMessage在handleMessage(Message msg)中接收msg
|
||||
*/
|
||||
public void initHandler() {
|
||||
mBaseHandler = new BaseHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回Handler,在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @return Handler
|
||||
*/
|
||||
public Handler getHandler() {
|
||||
return mBaseHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同Handler的postRunnable
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*/
|
||||
protected void postRunnable(Runnable runnable) {
|
||||
postRunnableDelayed(runnable, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同Handler的postRunnableDelayed
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*/
|
||||
protected void postRunnableDelayed(Runnable runnable, long delayMillis) {
|
||||
if (mBaseHandler == null) initHandler();
|
||||
mBaseHandler.postDelayed(runnable, delayMillis);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同Handler 的 handleMessage,
|
||||
* getHandler.sendMessage,发送的Message在此接收
|
||||
* 在此之前确定已经调用initHandler()
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
protected void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case WHAT_UPDATE_DATA:
|
||||
if (msg.arg1 == 0) {
|
||||
text.setTextColor(Color.parseColor("#FFFFFF"));
|
||||
} else {
|
||||
text.setTextColor(Color.parseColor("#FF0000"));
|
||||
}
|
||||
String str = (String) msg.obj;
|
||||
if (str.length() < 100) {
|
||||
text.setTextSize(14);
|
||||
} else {
|
||||
text.setTextSize(10);
|
||||
}
|
||||
text.setText(str);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected static class BaseHandler extends Handler {
|
||||
private final WeakReference<SpecialVehicleFloatWindow> mObjects;
|
||||
|
||||
public BaseHandler(SpecialVehicleFloatWindow mPresenter) {
|
||||
mObjects = new WeakReference<SpecialVehicleFloatWindow>(mPresenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
SpecialVehicleFloatWindow mPresenter = mObjects.get();
|
||||
if (mPresenter != null)
|
||||
mPresenter.handleMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package com.zhidao.adas.client.ui.special;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.view.Gravity;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.zhidao.adas.client.bean.SpecialVehicleBean;
|
||||
|
||||
|
||||
public class SpecialVehicleFloatWindowManager implements SpecialVehicleFloatWindow.OnFloatWindowListener {
|
||||
private final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
|
||||
private SpecialVehicleFloatWindow floatWindow = null;
|
||||
private WindowManager wm = null;
|
||||
private final Context context;
|
||||
private final SpecialVehicleBean specialVehicleBean;
|
||||
|
||||
public SpecialVehicleFloatWindowManager(Context context, SpecialVehicleBean specialVehicleBean) {
|
||||
this.context = context;
|
||||
this.specialVehicleBean = specialVehicleBean;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (!createFloatWindow()) {
|
||||
if (floatWindow.isMaximize()) {
|
||||
floatWindow.minimality();
|
||||
} else {
|
||||
floatWindow.maximize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean createFloatWindow() {
|
||||
if (floatWindow == null) {
|
||||
wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
layoutParams.format = PixelFormat.RGBA_8888;
|
||||
layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;//| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||
layoutParams.gravity = Gravity.START | Gravity.TOP;
|
||||
layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.alpha = 0.9f;
|
||||
floatWindow = new SpecialVehicleFloatWindow(context, specialVehicleBean);
|
||||
floatWindow.setWmParams(layoutParams);
|
||||
floatWindow.setOnFloatWindowListener(this);
|
||||
layoutParams.x = specialVehicleBean.getFloatWindowLocationMaxX(context);
|
||||
layoutParams.y = specialVehicleBean.getFloatWindowLocationMaxY(context);
|
||||
wm.addView(floatWindow, layoutParams);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void removeFloatWindow() {
|
||||
if (floatWindow != null) {
|
||||
wm.removeView(floatWindow);
|
||||
floatWindow = null;
|
||||
wm = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBack() {
|
||||
removeFloatWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMinimality() {
|
||||
layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.x = specialVehicleBean.getFloatWindowLocationMinX(context);
|
||||
layoutParams.y = specialVehicleBean.getFloatWindowLocationMinY(context);
|
||||
layoutParams.alpha = 1f;
|
||||
if (floatWindow != null) {
|
||||
floatWindow.updateViewLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMaximize() {
|
||||
layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
|
||||
layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.x = specialVehicleBean.getFloatWindowLocationMaxX(context);
|
||||
layoutParams.y = specialVehicleBean.getFloatWindowLocationMaxY(context);
|
||||
layoutParams.alpha = 0.9f;
|
||||
if (floatWindow != null) {
|
||||
floatWindow.updateViewLayout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.zhidao.adas.client.ui.widget;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.zhidao.adas.client.utils.image.GlideRoundedCornersTransform;
|
||||
|
||||
/**
|
||||
* 清扫车摄像头展示View
|
||||
*/
|
||||
public class SweeperVideoView extends AppCompatImageView {
|
||||
private static final String TAG = SweeperVideoView.class.getSimpleName();
|
||||
private final RequestOptions requestOptions = new RequestOptions()
|
||||
.priority(Priority.HIGH)
|
||||
.skipMemoryCache(true)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.dontAnimate();
|
||||
|
||||
public SweeperVideoView(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SweeperVideoView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SweeperVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
public void onSweeperFutianBackCameraVideo(@NonNull byte[] data) {
|
||||
i++;
|
||||
Log.i(TAG, "数据源加载次数=" + i);
|
||||
Glide.with(SweeperVideoView.this)
|
||||
.asBitmap()
|
||||
.load(data)
|
||||
.placeholder(SweeperVideoView.this.getDrawable())
|
||||
// .optionalTransform(new GlideRoundedCornersTransform(50f, GlideRoundedCornersTransform.CornerType.ALL))
|
||||
.apply(requestOptions)
|
||||
.into(target);
|
||||
|
||||
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
private final CustomTarget<Bitmap> target = new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
j++;
|
||||
Log.i(TAG, "显示回调次数=" + j);
|
||||
//回调内容
|
||||
if (!resource.isRecycled()) {
|
||||
setImageBitmap(resource);
|
||||
} else {
|
||||
Log.i(TAG, "显示回调 Bitmap被回收");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
//这个方法在target被回收时调用,如果在除了imageView以外的地方引用了imageView中的bitmap,在这里清除引用以避免崩溃
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
package com.zhidao.adas.client.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.zhidao.adas.client.bean.AutoPilotMode;
|
||||
import com.zhidao.support.adas.high.common.JsonUtil;
|
||||
import com.zhidao.support.adas.high.common.MessageType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des
|
||||
* @date 2021/10/8
|
||||
*/
|
||||
public class Constants {
|
||||
public static final String ROOT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "IPCMonitoring" + File.separator;//程序外部存储跟目录
|
||||
public static final String FILE_PATH = ROOT_PATH + "Crash" + File.separator;
|
||||
|
||||
private static final String ALL_PATH = "all_path";//所有路线
|
||||
private static final String DEFAULT_PATH = "[{\"endLatLon\":{\"latitude\":40.19774,\"longitude\":116.72704},\"endName\":\"汇源果汁\",\"name\":\"北京市顺义区北小营镇\",\"speedLimit\":20.0,\"startLatLon\":{\"latitude\":40.20047,\"longitude\":116.73512},\"startName\":\"13号路口西\"},{\"endLatLon\":{\"latitude\":40.19996,\"longitude\":116.73584},\"endName\":\"13号路口(主路)\",\"name\":\"北京市顺义区北小营镇\",\"speedLimit\":20.0,\"startLatLon\":{\"latitude\":40.19763,\"longitude\":116.72686},\"startName\":\"汇源果汁\"}]";
|
||||
|
||||
public static List<AutoPilotMode> getPaths(Context context) {
|
||||
String json = PreferencesUtils.getString(context, ALL_PATH, DEFAULT_PATH);
|
||||
List<AutoPilotMode> list = JsonUtil.fromJson(json, new TypeToken<List<AutoPilotMode>>() {
|
||||
}.getType());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean setPath(Context context, List<AutoPilotMode> list) {
|
||||
if (list != null) {
|
||||
return PreferencesUtils.putString(context, ALL_PATH, JsonUtil.toJson(list));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean addPath(Context context, List<AutoPilotMode> list, AutoPilotMode mode) {
|
||||
if (list == null)
|
||||
list = new ArrayList<>();
|
||||
if (!list.contains(mode)) {
|
||||
list.add(mode);
|
||||
return PreferencesUtils.putString(context, ALL_PATH, JsonUtil.toJson(list));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean delPath(Context context, List<AutoPilotMode> list, AutoPilotMode mode) {
|
||||
if (list == null) {
|
||||
return PreferencesUtils.delete(context, ALL_PATH);
|
||||
} else {
|
||||
if (list.contains(mode)) {
|
||||
list.remove(mode);
|
||||
return PreferencesUtils.putString(context, ALL_PATH, JsonUtil.toJson(list));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/***********************是否使用固定IP******************/
|
||||
// 0:固定IP 1:指定 2:UDP
|
||||
private static final String IPC_CONNECTION_MODE = "ipc_connection_mode";
|
||||
|
||||
public static void setIpcConnectionMode(Context context, int type) {
|
||||
PreferencesUtils.putInt(context, IPC_CONNECTION_MODE, type);
|
||||
}
|
||||
|
||||
public static int getIpcConnectionMode(Context context) {
|
||||
return PreferencesUtils.getInt(context, IPC_CONNECTION_MODE, 0);
|
||||
}
|
||||
|
||||
public static boolean delIpcConnectionMode(Context context) {
|
||||
return PreferencesUtils.delete(context, IPC_CONNECTION_MODE);
|
||||
}
|
||||
|
||||
/***********************保存IP******************/
|
||||
private static final String IPC_IP = "ipc_ip";
|
||||
|
||||
public static void setIPCIp(Context context, String ip) {
|
||||
PreferencesUtils.putString(context, IPC_IP, ip);
|
||||
}
|
||||
|
||||
public static String getIPCIp(Context context) {
|
||||
return PreferencesUtils.getString(context, IPC_IP, null);
|
||||
}
|
||||
|
||||
public static boolean delIPCIp(Context context) {
|
||||
return PreferencesUtils.delete(context, IPC_IP);
|
||||
}
|
||||
|
||||
|
||||
/***********************保存使用过的IP列表******************/
|
||||
|
||||
|
||||
private static final String IPC_USED_IP = "ipc_used_ip";
|
||||
|
||||
public static List<String> getIpcUsedIps(Context context) {
|
||||
String json = PreferencesUtils.getString(context, IPC_USED_IP, null);
|
||||
if (TextUtils.isEmpty(json)) return null;
|
||||
List<String> list = JsonUtil.fromJson(json, new TypeToken<List<String>>() {
|
||||
}.getType());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean addIpcUsedIps(Context context, List<String> list, String mode) {
|
||||
if (list == null)
|
||||
list = new ArrayList<>();
|
||||
list.remove(mode);
|
||||
list.add(0, mode);
|
||||
if (list.size() > 10) {
|
||||
list.remove(list.size() - 1);
|
||||
}
|
||||
return PreferencesUtils.putString(context, IPC_USED_IP, JsonUtil.toJson(list));
|
||||
}
|
||||
|
||||
public static boolean delIpcUsedIps(Context context, List<String> list, String mode) {
|
||||
if (list == null) {
|
||||
return PreferencesUtils.delete(context, IPC_USED_IP);
|
||||
} else {
|
||||
if (list.contains(mode)) {
|
||||
list.remove(mode);
|
||||
return PreferencesUtils.putString(context, IPC_USED_IP, JsonUtil.toJson(list));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*********************存储超时检测按钮开关状态******************/
|
||||
private static final String TIMEOUT_ENABLE = "timeout_enable";
|
||||
|
||||
public static void setTimeoutEnable(Context context, boolean isEnable) {
|
||||
PreferencesUtils.putBoolean(context, TIMEOUT_ENABLE, isEnable);
|
||||
}
|
||||
|
||||
public static boolean getTimeoutEnable(Context context) {
|
||||
return PreferencesUtils.putBoolean(context, TIMEOUT_ENABLE, true);
|
||||
}
|
||||
|
||||
public static boolean delTimeoutEnable(Context context) {
|
||||
return PreferencesUtils.delete(context, TIMEOUT_ENABLE);
|
||||
}
|
||||
|
||||
|
||||
public interface TITLE {
|
||||
String RECEIVE_TRAJECTORY = MessageType.TYPE_RECEIVE_TRAJECTORY.desc;
|
||||
String RECEIVE_TRACKED_OBJECTS = MessageType.TYPE_RECEIVE_TRACKED_OBJECTS.desc;
|
||||
String RECEIVE_GNSS_INFO = MessageType.TYPE_RECEIVE_GNSS_INFO.desc;
|
||||
String RECEIVE_CHASSIS_STATES = MessageType.TYPE_RECEIVE_CHASSIS_STATES.desc;
|
||||
String RECEIVE_AUTOPILOT_STATE = MessageType.TYPE_RECEIVE_AUTOPILOT_STATE.desc;
|
||||
String RECEIVE_FUNCTION_STATES = MessageType.TYPE_RECEIVE_FUNCTION_STATES.desc;
|
||||
String RECEIVE_BACK_CAMERA_VIDEO = MessageType.TYPE_RECEIVE_BACK_CAMERA_VIDEO.desc;
|
||||
String RECEIVE_REPORT_MESSAGE = MessageType.TYPE_RECEIVE_REPORT_MESSAGE.desc;
|
||||
String RECEIVE_PERCEPTION_TRAFFIC_LIGHT = MessageType.TYPE_RECEIVE_PERCEPTION_TRAFFIC_LIGHT.desc;
|
||||
String RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY = MessageType.TYPE_RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY.desc;
|
||||
String RECEIVE_POINT_CLOUD_ORIGINAL = MessageType.TYPE_RECEIVE_POINT_CLOUD.desc;
|
||||
String RECEIVE_PLANNING_OBJECTS = MessageType.TYPE_RECEIVE_PLANNING_OBJECTS.desc;
|
||||
String RECEIVE_PLANNING_DECISION_STATE = MessageType.TYPE_RECEIVE_PLANNING_DECISION_STATE.desc;
|
||||
String RECEIVE_SWEEPER_TASK_INDEX_DATA = MessageType.TYPE_RECEIVE_SWEEPER_TASK_INDEX_DATA.desc;
|
||||
String RECEIVE_V2N_CONGESTION_EVENT = MessageType.TYPE_RECEIVE_V2N_CONGESTION_EVENT.desc;
|
||||
String RECEIVE_V2N_GLOBAL_PATH_EVENTS = MessageType.TYPE_RECEIVE_V2N_GLOBAL_PATH_EVENTS.desc;
|
||||
String RECEIVE_GET_PARAM_RESP = MessageType.TYPE_RECEIVE_GET_PARAM_RESP.desc;
|
||||
|
||||
// String RECEIVE_BASIC_INFO_REQ = "自动驾驶设备基础信息请求";
|
||||
String TITLE_CAR_CONFIG_RESP = "工控机版本\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t配置";
|
||||
String RECEIVE_CAR_CONFIG_RESP = "信息与配置";
|
||||
String RECEIVE_RECORD_RESULT = MessageType.TYPE_RECEIVE_RECORD_RESULT.desc;
|
||||
String RECEIVE_BAG_MANAGER_CMD = MessageType.TYPE_RECEIVE_BAG_MANAGER_CMD.desc;
|
||||
String RECEIVE_RECORD_DATA_CONFIG_RESP = MessageType.TYPE_RECEIVE_RECORD_DATA_CONFIG_RESP.desc;
|
||||
String RECEIVE_GLOBAL_PATH_RESP = MessageType.TYPE_RECEIVE_GLOBAL_PATH_RESP.desc;
|
||||
String RECEIVE_WARN = MessageType.TYPE_RECEIVE_WARN.desc;
|
||||
String RECEIVE_ARRIVAL_NOTIFICATION = MessageType.TYPE_RECEIVE_ARRIVAL_NOTIFICATION.desc;
|
||||
String RECEIVE_STATUS_QUERY_RESP = MessageType.TYPE_RECEIVE_STATUS_QUERY_RESP.desc;
|
||||
String RECEIVE_OBU_SPAT = "OBU SPAT信息";
|
||||
String RECEIVE_OBU_RSI = "OBU RSI信息";
|
||||
String RECEIVE_OBU_RSM = "OBU RSM信息";
|
||||
String RECEIVE_OBU_MAP = "OBU MAP信息";
|
||||
String RECEIVE_ERROR = "错误数据";
|
||||
|
||||
|
||||
String SEND_SET_AUTOPILOT_MODE_REQ = "自动驾驶模式";
|
||||
String SEND_GLOBAL_PATH_REQ = "自动驾驶路径查询";
|
||||
String SEND_SPECIAL_VEHICLE_TASK_CMD = "特种车辆";
|
||||
String SEND_STATUS_QUERY_REQ = "状态查询";
|
||||
String SEND_BASIC_INFO_RESP = "下发SN";
|
||||
String SEND_RECORD_DATA_5 = "数据采集5秒";
|
||||
String SEND_RECORD_DATA_START = "数据采集Start";
|
||||
String SEND_RECORD_DATA_END = "数据采集End";
|
||||
String SEND_TRAFFIC_LIGHT_DATA = "发送信号灯";
|
||||
String SEND_SET_AUTOPILOT_SPEED_REQ = "自动驾驶限速";
|
||||
String SEND_SYSTEM_CMD_REQ_REBOOT = "重启所有节点";
|
||||
String SEND_RECORD_CAUSE = "采集类型";
|
||||
String SEND_SET_DEMO_MODE_REQ = "演示模式";
|
||||
String SEND_SET_RAIN_MODE_REQ = "雨天模式";
|
||||
String SEND_RECORD_DATA_CONFIG_RESP = "数据采集配置";
|
||||
String SEND_DETOURING = "绕障类功能";
|
||||
String SEND_DETOURING_SPEED = "绕障速度阈值";
|
||||
String SEND_TRIP_INFO = "行程信息";
|
||||
String SEND_PLANNING_CMD = "Planning指令";
|
||||
String SEND_BLIND_AREA = "盲区数据开关";
|
||||
String SEND_V2N_TO_PNC = "V2N数据到PnC";
|
||||
String SEND_AEB = "AEB开关";
|
||||
String SEND_LANE_CHANGE_RESTRAIN_VALID = "限制绕障开关";
|
||||
String SEND_STOP_YIELD_VALID = "停车让行线前避让等待开关";
|
||||
String SEND_HADMAP_SPEED_LIMIT_VALID = "地图限速开关";
|
||||
String SEND_RAMP_THETA_VALID = "环岛模式开关";
|
||||
String SEND_GET_PARAM_REQ = "参数获取";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,293 +0,0 @@
|
||||
package com.zhidao.adas.client.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* ClassName: CrashHandler
|
||||
* Function: UncaughtException处理类,当程序发生Uncaught异常的时候,由该类来接管程序,并记录发送错误报告.
|
||||
*
|
||||
* @author Norris Norris.sly@gmail.com
|
||||
* @Date 2013 2013-3-24 下午12:27:10
|
||||
* @Fields ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* @Methods ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* 2013-3-24下午12:27:10 Modified By Norris
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* @see ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* @since Ver 1.0 I used to be a programmer like you, then I took an arrow in the knee
|
||||
*/
|
||||
public class CrashHandler implements UncaughtExceptionHandler {
|
||||
|
||||
/**
|
||||
* Log日志的tag
|
||||
* String : TAG
|
||||
*
|
||||
* @since 2013-3-21下午8:44:28
|
||||
*/
|
||||
private static final String TAG = "NorrisInfo";
|
||||
/**
|
||||
* 系统默认的UncaughtException处理类
|
||||
* Thread.UncaughtExceptionHandler : mDefaultHandler
|
||||
*
|
||||
* @since 2013-3-21下午8:44:43
|
||||
*/
|
||||
private UncaughtExceptionHandler mDefaultHandler;
|
||||
/**
|
||||
* CrashHandler实例
|
||||
* CrashHandler : mInstance
|
||||
*
|
||||
* @since 2013-3-21下午8:44:53
|
||||
*/
|
||||
private static CrashHandler mInstance = new CrashHandler();
|
||||
/**
|
||||
* 程序的Context对象
|
||||
* Context : mContext
|
||||
*
|
||||
* @since 2013-3-21下午8:45:02
|
||||
*/
|
||||
private Context mContext;
|
||||
/**
|
||||
* 用来存储设备信息和异常信息
|
||||
* Map<String,String> : mLogInfo
|
||||
*
|
||||
* @since 2013-3-21下午8:46:15
|
||||
*/
|
||||
private Map<String, String> mLogInfo = new HashMap<String, String>();
|
||||
/**
|
||||
* 用于格式化日期,作为日志文件名的一部分(FIXME 注意在windows下文件名无法使用:等符号!)
|
||||
* SimpleDateFormat : mSimpleDateFormat
|
||||
*
|
||||
* @since 2013-3-21下午8:46:39
|
||||
*/
|
||||
private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyyMMdd_HH-mm-ss");
|
||||
|
||||
/**
|
||||
* Creates a new instance of CrashHandler.
|
||||
*/
|
||||
private CrashHandler() {
|
||||
}
|
||||
|
||||
/**
|
||||
* getInstance:{获取CrashHandler实例 ,单例模式 }
|
||||
* ──────────────────────────────────
|
||||
*
|
||||
* @return CrashHandler
|
||||
* @throws
|
||||
* @since I used to be a programmer like you, then I took an arrow in the knee Ver 1.0
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* 2013-3-21下午8:52:24 Modified By Norris
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
*/
|
||||
public static CrashHandler getInstance() {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* init:{初始化}
|
||||
* ──────────────────────────────────
|
||||
*
|
||||
* @param paramContext
|
||||
* @return void
|
||||
* @throws
|
||||
* @since I used to be a programmer like you, then I took an arrow in the knee Ver 1.0
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* 2013-3-21下午8:52:45 Modified By Norris
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
*/
|
||||
public void init(Context paramContext) {
|
||||
mContext = paramContext;
|
||||
// 获取系统默认的UncaughtException处理器
|
||||
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
// 设置该CrashHandler为程序的默认处理器
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当UncaughtException发生时会转入该重写的方法来处理
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see UncaughtExceptionHandler#uncaughtException(Thread, Throwable)
|
||||
*/
|
||||
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
|
||||
// 获取设备参数信息
|
||||
getDeviceInfo(mContext);
|
||||
// mLogInfo.put("versionName", String.valueOf(BuildConfig.VERSION_CODE));
|
||||
// mLogInfo.put("versionCode", BuildConfig.VERSION_NAME);
|
||||
// 保存日志文件
|
||||
String result = saveCrashLogToFile(paramThrowable);
|
||||
mDefaultHandler.uncaughtException(paramThread, paramThrowable);
|
||||
// if (!handleException(paramThrowable) && mDefaultHandler != null) {
|
||||
// // 如果自定义的没有处理则让系统默认的异常处理器来处理
|
||||
// mDefaultHandler.uncaughtException(paramThread, paramThrowable);
|
||||
// } else {
|
||||
//// try {
|
||||
//// // 如果处理了,让程序继续运行1秒再退出,保证文件保存并上传到服务器
|
||||
//// paramThread.sleep(1000);
|
||||
//// } catch (InterruptedException e) {
|
||||
//// e.printStackTrace();
|
||||
//// }
|
||||
// // 退出程序
|
||||
// android.os.Process.killProcess(android.os.Process.myPid());
|
||||
// System.exit(1);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* handleException:{自定义错误处理,收集错误信息 发送错误报告等操作均在此完成.}
|
||||
* ──────────────────────────────────
|
||||
*
|
||||
* @param paramThrowable
|
||||
* @return true:如果处理了该异常信息;否则返回false.
|
||||
* @throws
|
||||
* @since I used to be a programmer like you, then I took an arrow in the knee Ver 1.0
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* 2013-3-24下午12:28:53 Modified By Norris
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
*/
|
||||
public boolean handleException(Throwable paramThrowable) {
|
||||
if (paramThrowable == null)
|
||||
return false;
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
Toast.makeText(mContext, "很抱歉,程序出现异常,即将退出", Toast.LENGTH_SHORT).show();
|
||||
Looper.loop();
|
||||
}
|
||||
}.start();
|
||||
// 获取设备参数信息
|
||||
getDeviceInfo(mContext);
|
||||
// 保存日志文件
|
||||
String result = saveCrashLogToFile(paramThrowable);
|
||||
//上传崩溃日志
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDeviceInfo:{获取设备参数信息}
|
||||
* ──────────────────────────────────
|
||||
*
|
||||
* @param paramContext
|
||||
* @throws
|
||||
* @since I used to be a programmer like you, then I took an arrow in the knee Ver 1.0
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* 2013-3-24下午12:30:02 Modified By Norris
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
*/
|
||||
public void getDeviceInfo(Context paramContext) {
|
||||
try {
|
||||
// 获得包管理器
|
||||
PackageManager mPackageManager = paramContext.getPackageManager();
|
||||
// 得到该应用的信息,即主Activity
|
||||
PackageInfo mPackageInfo = mPackageManager.getPackageInfo(
|
||||
paramContext.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
if (mPackageInfo != null) {
|
||||
String versionName = mPackageInfo.versionName == null ? "null"
|
||||
: mPackageInfo.versionName;
|
||||
String versionCode = mPackageInfo.versionCode + "";
|
||||
mLogInfo.put("versionName", versionName);
|
||||
mLogInfo.put("versionCode", versionCode);
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 反射机制
|
||||
Field[] mFields = Build.class.getDeclaredFields();
|
||||
// 迭代Build的字段key-value 此处的信息主要是为了在服务器端手机各种版本手机报错的原因
|
||||
for (Field field : mFields) {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
mLogInfo.put(field.getName(), field.get("").toString());
|
||||
Log.d(TAG, field.getName() + ":" + field.get(""));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* saveCrashLogToFile:{将崩溃的Log保存到本地}
|
||||
* TODO 可拓展,将Log上传至指定服务器路径
|
||||
* ──────────────────────────────────
|
||||
*
|
||||
* @param paramThrowable
|
||||
* @return FileName
|
||||
* @throws
|
||||
* @since I used to be a programmer like you, then I took an arrow in the knee Ver 1.0
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
* 2013-3-24下午12:31:01 Modified By Norris
|
||||
* ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
*/
|
||||
|
||||
|
||||
private String saveCrashLogToFile(Throwable paramThrowable) {
|
||||
StringBuffer mStringBuffer = new StringBuffer();
|
||||
for (Map.Entry<String, String> entry : mLogInfo.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
mStringBuffer.append(key + "=" + value + "\r\n");
|
||||
}
|
||||
Writer mWriter = new StringWriter();
|
||||
PrintWriter mPrintWriter = new PrintWriter(mWriter);
|
||||
paramThrowable.printStackTrace(mPrintWriter);
|
||||
paramThrowable.printStackTrace();
|
||||
Throwable mThrowable = paramThrowable.getCause();
|
||||
// 迭代栈队列把所有的异常信息写入writer中
|
||||
while (mThrowable != null) {
|
||||
mThrowable.printStackTrace(mPrintWriter);
|
||||
// 换行 每个个异常栈之间换行
|
||||
mThrowable = mThrowable.getCause();
|
||||
}
|
||||
|
||||
//记得关闭
|
||||
|
||||
String mResult = mWriter.toString();
|
||||
// String mResult = mWriter.toString().replace("\n", "").replace(":", "").replace("/", "").replace("\t", "");
|
||||
mStringBuffer.append(mResult);
|
||||
// 保存文件,设置文件名
|
||||
String mTime = mSimpleDateFormat.format(new Date());
|
||||
String mFileName = mContext.getPackageName() + "_Exception-" + mTime + ".log";
|
||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
try {
|
||||
File mDirectory = new File(Constants.FILE_PATH);
|
||||
Log.d(TAG, mDirectory.toString());
|
||||
if (!mDirectory.exists())
|
||||
mDirectory.mkdirs();
|
||||
FileOutputStream mFileOutputStream = new FileOutputStream(mDirectory + File.separator + mFileName);
|
||||
mFileOutputStream.write(mStringBuffer.toString().getBytes());
|
||||
mFileOutputStream.close();
|
||||
return mResult;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return mResult;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.zhidao.adas.client.utils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* @author nie yunlong
|
||||
* @des
|
||||
* @date 2021/2/5
|
||||
*/
|
||||
class FileUtils {
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*
|
||||
* @param data
|
||||
* @param name
|
||||
*/
|
||||
public static void createFile(Context context, String data, String name) {
|
||||
try {
|
||||
File file = new File(context.getExternalFilesDir(null) + "/" + name);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
Writer out = new FileWriter(file,true);
|
||||
out.write(data);
|
||||
out.append("\n");
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.zhidao.adas.client.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class MyLinearLayoutManager extends LinearLayoutManager {
|
||||
public MyLinearLayoutManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public MyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
|
||||
super(context, orientation, reverseLayout);
|
||||
}
|
||||
|
||||
public MyLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPredictiveItemAnimations() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
//override this method and implement code as below
|
||||
try {
|
||||
super.onLayoutChildren(recycler, state);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,434 +0,0 @@
|
||||
package com.zhidao.adas.client.utils;
|
||||
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* author:chenjs
|
||||
*/
|
||||
public class PermissionUtil {
|
||||
private static final String TAG = PermissionUtil.class.getSimpleName();
|
||||
private static final boolean LOG_FLAG = true;//日志标识
|
||||
|
||||
//日历
|
||||
private static final String[] Group_Calendar = {
|
||||
Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR
|
||||
};
|
||||
//照相机
|
||||
private static final String[] Group_Camera = {
|
||||
Manifest.permission.CAMERA
|
||||
};
|
||||
//通讯录
|
||||
private static final String[] Group_Contacts = {
|
||||
Manifest.permission.WRITE_CONTACTS, Manifest.permission.GET_ACCOUNTS,
|
||||
Manifest.permission.READ_CONTACTS
|
||||
};
|
||||
//定位
|
||||
private static final String[] Group_Location = {
|
||||
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
};
|
||||
//麦克风
|
||||
private static final String[] Group_Microphone = {
|
||||
Manifest.permission.RECORD_AUDIO
|
||||
};
|
||||
//电话
|
||||
private static final String[] Group_Phone = {
|
||||
Manifest.permission.READ_PHONE_STATE, Manifest.permission.CALL_PHONE,
|
||||
Manifest.permission.READ_CALL_LOG, Manifest.permission.WRITE_CALL_LOG,
|
||||
Manifest.permission.ADD_VOICEMAIL, Manifest.permission.USE_SIP,
|
||||
Manifest.permission.PROCESS_OUTGOING_CALLS
|
||||
};
|
||||
//传感器
|
||||
private static final String[] Group_Sensors = {
|
||||
Manifest.permission.BODY_SENSORS
|
||||
};
|
||||
//短信
|
||||
private static final String[] Group_Sms = {
|
||||
Manifest.permission.READ_SMS, Manifest.permission.SEND_SMS,
|
||||
Manifest.permission.RECEIVE_SMS, Manifest.permission.RECEIVE_MMS,
|
||||
Manifest.permission.RECEIVE_WAP_PUSH
|
||||
};
|
||||
//存储
|
||||
private static final String[] Group_Storage = {
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
};
|
||||
private static Map<String, String[]> m_PermissionGroupList = null;
|
||||
private static Map<String, String> m_PermissionsMappingList = null;
|
||||
|
||||
static {
|
||||
initMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限组名来申请一组权限
|
||||
*
|
||||
* @param context
|
||||
* @param permissionGroupName
|
||||
* @param requestCode
|
||||
* @param listener
|
||||
*/
|
||||
public static void requestByGroupName(Activity context, String permissionGroupName, int requestCode, OnPermissionsListener listener) {
|
||||
requestByGroupName(context, new String[]{permissionGroupName}, requestCode, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限组名来申请多组权限
|
||||
*
|
||||
* @param context Activity上下文
|
||||
* @param pgNameArray 多个要申请的权限组名称
|
||||
* @param requestCode 请求码
|
||||
* @param listener 回调接口
|
||||
*/
|
||||
public static void requestByGroupName(Activity context, String[] pgNameArray, int requestCode, OnPermissionsListener listener) {
|
||||
showLog("requestByPermissionGroup");
|
||||
try {
|
||||
//如果操作系统SDK级别在23之上(android6.0),就进行动态权限申请
|
||||
if (Build.VERSION.SDK_INT >= 23 && pgNameArray != null) {
|
||||
String[] permissionsList = getAppPermissionsList(context);//应用权限列表
|
||||
ArrayList<String> targetList = new ArrayList<>();
|
||||
if (permissionsList == null || permissionsList.length == 0) {
|
||||
showLog("获得权限列表为空");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String groupName : pgNameArray) {
|
||||
ArrayList<String> tmpPermissionList = isPermissionDeclared(permissionsList, groupName);
|
||||
if (tmpPermissionList == null) {//未找到
|
||||
showLog("未找到[" + groupName + "]中的权限");
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < tmpPermissionList.size(); i++) {
|
||||
//判断是否拥有权限
|
||||
int nRet = ContextCompat.checkSelfPermission(context, tmpPermissionList.get(i));
|
||||
if (nRet != PackageManager.PERMISSION_GRANTED) {
|
||||
targetList.add(tmpPermissionList.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (targetList.size() > 0) {
|
||||
showLog("进行以下权限申请:" + targetList.toString());
|
||||
String[] sList = targetList.toArray(new String[0]);
|
||||
ActivityCompat.requestPermissions(context, sList, requestCode);
|
||||
} else {
|
||||
showLog("全部权限都已授权");
|
||||
if (listener != null) {
|
||||
listener.onPermissionsOwned();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限名来申请一组权限
|
||||
*
|
||||
* @param context
|
||||
* @param permission
|
||||
* @param requestCode
|
||||
* @param listener
|
||||
*/
|
||||
public static void requestByPermissionName(Activity context, String permission, int requestCode, OnPermissionsListener listener) {
|
||||
requestByPermissionName(context, new String[]{permission}, requestCode, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限名来申请多组权限
|
||||
*
|
||||
* @param context Activity上下文
|
||||
* @param permissionArray 多个要申请的权限名称
|
||||
* @param requestCode 请求码
|
||||
* @param listener 回调接口
|
||||
*/
|
||||
public static void requestByPermissionName(Activity context, String[] permissionArray, int requestCode, OnPermissionsListener listener) {
|
||||
showLog("requestPermissions");
|
||||
try {
|
||||
//如果操作系统SDK级别在23之上(android6.0),就进行动态权限申请
|
||||
if (Build.VERSION.SDK_INT >= 23 && permissionArray != null) {
|
||||
ArrayList<String> targetList = new ArrayList<>();
|
||||
for (String strPermission : permissionArray) {
|
||||
//判断是否拥有权限
|
||||
int nRet = ContextCompat.checkSelfPermission(context, strPermission);
|
||||
if (nRet != PackageManager.PERMISSION_GRANTED) {
|
||||
targetList.add(strPermission);
|
||||
}
|
||||
}
|
||||
|
||||
if (targetList.size() > 0) {
|
||||
showLog("进行以下权限申请:" + targetList.toString());
|
||||
String[] sList = targetList.toArray(new String[0]);
|
||||
ActivityCompat.requestPermissions(context, sList, requestCode);
|
||||
} else {
|
||||
showLog("全部权限都已授权");
|
||||
if (listener != null) {
|
||||
listener.onPermissionsOwned();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对申请权限时的用户操作进行处理
|
||||
*
|
||||
* @param context
|
||||
* @param permissions 申请的权限
|
||||
* @param grantResults 各权限的授权状态
|
||||
* @param listener 回调接口
|
||||
* @param controlFlag 控制标识,用于判断当响应禁止列表后,是否继续处理可再申请列表(避免出现同时处理禁止列表和可再申请列表,互相干扰,比如弹出两个提示框)
|
||||
*/
|
||||
public static void onRequestPermissionsResult(Activity context, String[] permissions, int[] grantResults, OnPermissionsListener listener, boolean controlFlag) {
|
||||
try {
|
||||
ArrayList<String> requestList = new ArrayList<>();//可再申请列表
|
||||
ArrayList<String> banList = new ArrayList<>();//禁止列表
|
||||
for (int i = 0; i < permissions.length; i++) {
|
||||
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||
showLog("[" + permissions[i] + "]权限授权成功");
|
||||
} else {
|
||||
boolean nRet = ActivityCompat.shouldShowRequestPermissionRationale(context, permissions[i]);
|
||||
//Log.i(TAG,"shouldShowRequestPermissionRationale nRet="+nRet);
|
||||
if (nRet) {//允许重新申请
|
||||
requestList.add(permissions[i]);
|
||||
} else {//禁止申请
|
||||
banList.add(permissions[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
//优先对禁止列表进行判断
|
||||
if (banList.size() > 0) {
|
||||
if (listener != null) {
|
||||
listener.onPermissionsForbidden(permissions, grantResults, banList);
|
||||
}
|
||||
if (!controlFlag) {//对禁止列表处理后,且控制标识为false,则跳过对可再申请列表的处理
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (requestList.size() > 0) {
|
||||
if (listener != null) {
|
||||
listener.onPermissionsDenied(permissions, grantResults, requestList);
|
||||
}
|
||||
}
|
||||
if (banList.size() == 0 && requestList.size() == 0) {
|
||||
showLog("权限授权成功");
|
||||
if (listener != null) {
|
||||
listener.onPermissionsSucceed();
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断权限状态
|
||||
*
|
||||
* @param context
|
||||
* @param permission 权限名
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkPermission(Context context, String permission) {
|
||||
try {
|
||||
//如果操作系统SDK级别在23之上(android6.0),就进行动态权限申请
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
int nRet = ContextCompat.checkSelfPermission(context, permission);
|
||||
showLog("checkSelfPermission nRet=" + nRet);
|
||||
return nRet == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前应用清单中的权限列表
|
||||
*
|
||||
* @param context 应用上下文
|
||||
* @return
|
||||
*/
|
||||
public static String[] getAppPermissionsList(Context context) {
|
||||
try {
|
||||
PackageManager packageManager = context.getApplicationContext().getPackageManager();
|
||||
String packageName = context.getApplicationContext().getPackageName();
|
||||
String[] array = packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS).requestedPermissions;
|
||||
return array;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断权限列表中是否声明了指定权限组中的权限
|
||||
*
|
||||
* @param permissionList 权限列表
|
||||
* @param permissionGroup 权限组名
|
||||
* @return 存在则返回找到的权限组权限,否则返回null
|
||||
*/
|
||||
public static ArrayList<String> isPermissionDeclared(String[] permissionList, String permissionGroup) {
|
||||
try {
|
||||
if (permissionList != null && permissionGroup != null) {
|
||||
String[] pmGroup = m_PermissionGroupList.get(permissionGroup);
|
||||
if (pmGroup != null) {
|
||||
ArrayList<String> arrayList = new ArrayList<>();
|
||||
//遍历
|
||||
for (int i = 0; i < pmGroup.length; i++) {
|
||||
String strPermission = pmGroup[i];
|
||||
for (int j = 0; j < permissionList.length; j++) {
|
||||
if (strPermission.equals(permissionList[j])) {//找到指定权限组中的权限
|
||||
arrayList.add(strPermission);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (arrayList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得传入的权限名列表对应的中文名称
|
||||
*
|
||||
* @param permissionList 权限名列表
|
||||
* @return 集合
|
||||
*/
|
||||
public static Set<String> getPermissionsNameByChinese(String[] permissionList) {
|
||||
try {
|
||||
if (permissionList != null) {
|
||||
HashSet<String> nameSet = new HashSet<>();//确保集合元素不重复
|
||||
String tmpName;
|
||||
for (String strPermission : permissionList) {
|
||||
tmpName = m_PermissionsMappingList.get(strPermission);
|
||||
if (tmpName != null) {
|
||||
nameSet.add(tmpName);
|
||||
}
|
||||
}
|
||||
return nameSet;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void initMap() {
|
||||
if (m_PermissionGroupList == null) {
|
||||
m_PermissionGroupList = new HashMap<>();
|
||||
m_PermissionGroupList.put(Manifest.permission_group.CALENDAR, Group_Calendar);
|
||||
m_PermissionGroupList.put(Manifest.permission_group.CAMERA, Group_Camera);
|
||||
m_PermissionGroupList.put(Manifest.permission_group.CONTACTS, Group_Contacts);
|
||||
m_PermissionGroupList.put(Manifest.permission_group.LOCATION, Group_Location);
|
||||
m_PermissionGroupList.put(Manifest.permission_group.MICROPHONE, Group_Microphone);
|
||||
m_PermissionGroupList.put(Manifest.permission_group.PHONE, Group_Phone);
|
||||
m_PermissionGroupList.put(Manifest.permission_group.SENSORS, Group_Sensors);
|
||||
m_PermissionGroupList.put(Manifest.permission_group.SMS, Group_Sms);
|
||||
m_PermissionGroupList.put(Manifest.permission_group.STORAGE, Group_Storage);
|
||||
}
|
||||
|
||||
if (m_PermissionsMappingList == null) {
|
||||
m_PermissionsMappingList = new HashMap<>();
|
||||
//日历
|
||||
for (String strPermission : Group_Calendar) {
|
||||
m_PermissionsMappingList.put(strPermission, "日历");
|
||||
}
|
||||
//照相机
|
||||
for (String strPermission : Group_Camera) {
|
||||
m_PermissionsMappingList.put(strPermission, "摄像头");
|
||||
}
|
||||
//通讯录
|
||||
for (String strPermission : Group_Contacts) {
|
||||
m_PermissionsMappingList.put(strPermission, "通讯录");
|
||||
}
|
||||
//定位
|
||||
for (String strPermission : Group_Location) {
|
||||
m_PermissionsMappingList.put(strPermission, "位置");
|
||||
}
|
||||
//麦克风
|
||||
for (String strPermission : Group_Microphone) {
|
||||
m_PermissionsMappingList.put(strPermission, "麦克风");
|
||||
}
|
||||
//电话
|
||||
for (String strPermission : Group_Phone) {
|
||||
m_PermissionsMappingList.put(strPermission, "电话");
|
||||
}
|
||||
//传感器
|
||||
for (String strPermission : Group_Sensors) {
|
||||
m_PermissionsMappingList.put(strPermission, "传感器");
|
||||
}
|
||||
//短信
|
||||
for (String strPermission : Group_Sms) {
|
||||
m_PermissionsMappingList.put(strPermission, "短信");
|
||||
}
|
||||
//存储
|
||||
for (String strPermission : Group_Storage) {
|
||||
m_PermissionsMappingList.put(strPermission, "存储");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void showLog(String str) {
|
||||
if (LOG_FLAG) {
|
||||
Log.i(TAG, str);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnPermissionsListener {
|
||||
/**
|
||||
* 权限都已拥有时的处理
|
||||
*/
|
||||
void onPermissionsOwned();
|
||||
|
||||
/**
|
||||
* 权限被禁止时的处理
|
||||
*
|
||||
* @param permissions 申请的全部权限
|
||||
* @param grantResults 各权限的授权状态
|
||||
* @param pmList 禁止申请的权限列表
|
||||
*/
|
||||
void onPermissionsForbidden(String[] permissions, int[] grantResults, ArrayList<String> pmList);
|
||||
|
||||
/**
|
||||
* 权限被拒绝时的处理
|
||||
*
|
||||
* @param permissions
|
||||
* @param grantResults
|
||||
* @param pmList 可再申请的权限列表
|
||||
*/
|
||||
void onPermissionsDenied(String[] permissions, int[] grantResults, ArrayList<String> pmList);
|
||||
|
||||
/**
|
||||
* 权限申请成功时的处理
|
||||
*/
|
||||
void onPermissionsSucceed();
|
||||
}
|
||||
}
|
||||
@@ -1,286 +0,0 @@
|
||||
package com.zhidao.adas.client.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public class PreferencesUtils {
|
||||
|
||||
public static String PREFERENCE_NAME = "control";
|
||||
|
||||
public static boolean hasString(Context context, String key) {
|
||||
if (context == null) return false;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.contains(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* put string preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new value for the preference
|
||||
* @return True if the new values were successfully written to persistent
|
||||
* storage.
|
||||
*/
|
||||
public static boolean putString(Context context, String key, String value) {
|
||||
|
||||
if (context == null) return false;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putString(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get string preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference value if it exists, or null. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a string
|
||||
* @see #getString(Context, String, String)
|
||||
*/
|
||||
public static String getString(Context context, String key) {
|
||||
if (context == null) return null;
|
||||
return getString(context, key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* get string preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference value if it exists, or defValue. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a string
|
||||
*/
|
||||
public static String getString(Context context, String key,
|
||||
String defaultValue) {
|
||||
|
||||
if (context == null) return defaultValue;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getString(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* put int preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new value for the preference
|
||||
* @return True if the new values were successfully written to persistent
|
||||
* storage.
|
||||
*/
|
||||
public static boolean putInt(Context context, String key, int value) {
|
||||
|
||||
if (context == null) return false;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putInt(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get int preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference value if it exists, or -1. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a int
|
||||
* @see #getInt(Context, String, int)
|
||||
*/
|
||||
public static int getInt(Context context, String key) {
|
||||
|
||||
if (context == null) return -1;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return getInt(context, key, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get int preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference value if it exists, or defValue. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a int
|
||||
*/
|
||||
public static int getInt(Context context, String key, int defaultValue) {
|
||||
if (context == null) return defaultValue;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* put long preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new value for the preference
|
||||
* @return True if the new values were successfully written to persistent
|
||||
* storage.
|
||||
*/
|
||||
public static boolean putLong(Context context, String key, long value) {
|
||||
if (context == null) return false;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putLong(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get long preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference value if it exists, or -1. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a long
|
||||
* @see #getLong(Context, String, long)
|
||||
*/
|
||||
public static long getLong(Context context, String key) {
|
||||
if (context == null) return -1;
|
||||
return getLong(context, key, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get long preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference value if it exists, or defValue. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a long
|
||||
*/
|
||||
public static long getLong(Context context, String key, long defaultValue) {
|
||||
if (context == null) return defaultValue;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
|
||||
return settings.getLong(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* put float preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new value for the preference
|
||||
* @return True if the new values were successfully written to persistent
|
||||
* storage.
|
||||
*/
|
||||
public static boolean putFloat(Context context, String key, float value) {
|
||||
if (context == null) return false;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putFloat(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get float preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference value if it exists, or -1. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a float
|
||||
* @see #getFloat(Context, String, float)
|
||||
*/
|
||||
public static float getFloat(Context context, String key) {
|
||||
if (context == null) return -1;
|
||||
return getFloat(context, key, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get float preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference value if it exists, or defValue. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a float
|
||||
*/
|
||||
public static float getFloat(Context context, String key, float defaultValue) {
|
||||
if (context == null) return defaultValue;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getFloat(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* put boolean preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new value for the preference
|
||||
* @return True if the new values were successfully written to persistent
|
||||
* storage.
|
||||
*/
|
||||
public static boolean putBoolean(Context context, String key, boolean value) {
|
||||
if (context == null) return false;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get boolean preferences, default is false
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference value if it exists, or false. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a boolean
|
||||
* @see #getBoolean(Context, String, boolean)
|
||||
*/
|
||||
public static boolean getBoolean(Context context, String key) {
|
||||
if (context == null) return false;
|
||||
return getBoolean(context, key, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* get boolean preferences
|
||||
*
|
||||
* @param context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference value if it exists, or defValue. Throws
|
||||
* ClassCastException if there is a preference with this name that
|
||||
* is not a boolean
|
||||
*/
|
||||
public static boolean getBoolean(Context context, String key,
|
||||
boolean defaultValue) {
|
||||
if (context == null) return defaultValue;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
|
||||
public static boolean delete(Context context, String key) {
|
||||
if (context == null) return false;
|
||||
SharedPreferences settings = context.getSharedPreferences(
|
||||
PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.remove(key);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.zhidao.adas.client.utils;
|
||||
|
||||
import com.zhidao.adas.client.R;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class RandomColor {
|
||||
//随机颜色,且不与上一次重复
|
||||
private static Random randomColor;
|
||||
private static int tempColorIndex;
|
||||
private static int[] colors = {R.color.color1, R.color.color2, R.color.color3, R.color.color4, R.color.color5};
|
||||
|
||||
public static int randomColor() {
|
||||
randomColorTemp();
|
||||
return colors[tempColorIndex];
|
||||
}
|
||||
|
||||
private static void randomColorTemp() {
|
||||
if (randomColor == null)
|
||||
randomColor = new Random();
|
||||
int colorInt = randomColor.nextInt(colors.length);
|
||||
if (tempColorIndex == colorInt) {
|
||||
randomColorTemp();
|
||||
} else {
|
||||
tempColorIndex = colorInt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.zhidao.adas.client.utils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class SysBarUtil {
|
||||
private static int sbar = -1;
|
||||
|
||||
// 获取系统状态栏高度
|
||||
public static int getSysBarHeight(Context contex) {
|
||||
if (sbar == -1) {
|
||||
Class<?> c;
|
||||
Object obj;
|
||||
Field field;
|
||||
int x;
|
||||
sbar = 0;
|
||||
try {
|
||||
c = Class.forName("com.android.internal.R$dimen");
|
||||
obj = c.newInstance();
|
||||
field = c.getField("status_bar_height");
|
||||
x = Integer.parseInt(field.get(obj).toString());
|
||||
sbar = contex.getResources().getDimensionPixelSize(x);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sbar;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package com.zhidao.adas.client.utils.image;
|
||||
|
||||
|
||||
/**
|
||||
* Copyright (C) 2018 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* 高斯模糊
|
||||
*/
|
||||
public class BlurTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID ="com.zhidao.adas.client.utils.image.BlurTransformation." + VERSION;
|
||||
private static int MAX_RADIUS = 25;
|
||||
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||
|
||||
private int radius;
|
||||
private int sampling;
|
||||
|
||||
public BlurTransformation() {
|
||||
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
|
||||
|
||||
public BlurTransformation(int radius) {
|
||||
this(radius, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
|
||||
public BlurTransformation(int radius, int sampling) {
|
||||
this.radius = radius;
|
||||
this.sampling = sampling;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
int scaledWidth = width / sampling;
|
||||
int scaledHeight = height / sampling;
|
||||
|
||||
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_4444);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
|
||||
Paint paint = new Paint();
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof BlurTransformation &&
|
||||
((BlurTransformation) o).radius == radius &&
|
||||
((BlurTransformation) o).sampling == sampling;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + radius * 1000 + sampling * 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
package com.zhidao.adas.client.utils.image;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2018 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
public class FastBlur {
|
||||
|
||||
public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
|
||||
|
||||
// Stack Blur v1.0 from
|
||||
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
|
||||
//
|
||||
// Java Author: Mario Klingemann <mario at quasimondo.com>
|
||||
// http://incubator.quasimondo.com
|
||||
// created Feburary 29, 2004
|
||||
// Android port : Yahel Bouaziz <yahel at kayenko.com>
|
||||
// http://www.kayenko.com
|
||||
// ported april 5th, 2012
|
||||
|
||||
// This is a compromise between Gaussian Blur and Box blur
|
||||
// It creates much better looking blurs than Box Blur, but is
|
||||
// 7x faster than my Gaussian Blur implementation.
|
||||
//
|
||||
// I called it Stack Blur because this describes best how this
|
||||
// filter works internally: it creates a kind of moving stack
|
||||
// of colors whilst scanning through the image. Thereby it
|
||||
// just has to add one new block of color to the right side
|
||||
// of the stack and remove the leftmost color. The remaining
|
||||
// colors on the topmost layer of the stack are either added on
|
||||
// or reduced by one, depending on if they are on the right or
|
||||
// on the left side of the stack.
|
||||
//
|
||||
// If you are using this algorithm in your code please add
|
||||
// the following line:
|
||||
//
|
||||
// Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
|
||||
|
||||
Bitmap bitmap;
|
||||
if (canReuseInBitmap) {
|
||||
bitmap = sentBitmap;
|
||||
} else {
|
||||
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
|
||||
}
|
||||
|
||||
if (radius < 1) {
|
||||
return (null);
|
||||
}
|
||||
|
||||
int w = bitmap.getWidth();
|
||||
int h = bitmap.getHeight();
|
||||
|
||||
int[] pix = new int[w * h];
|
||||
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
|
||||
|
||||
int wm = w - 1;
|
||||
int hm = h - 1;
|
||||
int wh = w * h;
|
||||
int div = radius + radius + 1;
|
||||
|
||||
int r[] = new int[wh];
|
||||
int g[] = new int[wh];
|
||||
int b[] = new int[wh];
|
||||
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
|
||||
int vmin[] = new int[Math.max(w, h)];
|
||||
|
||||
int divsum = (div + 1) >> 1;
|
||||
divsum *= divsum;
|
||||
int dv[] = new int[256 * divsum];
|
||||
for (i = 0; i < 256 * divsum; i++) {
|
||||
dv[i] = (i / divsum);
|
||||
}
|
||||
|
||||
yw = yi = 0;
|
||||
|
||||
int[][] stack = new int[div][3];
|
||||
int stackpointer;
|
||||
int stackstart;
|
||||
int[] sir;
|
||||
int rbs;
|
||||
int r1 = radius + 1;
|
||||
int routsum, goutsum, boutsum;
|
||||
int rinsum, ginsum, binsum;
|
||||
|
||||
for (y = 0; y < h; y++) {
|
||||
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
|
||||
for (i = -radius; i <= radius; i++) {
|
||||
p = pix[yi + Math.min(wm, Math.max(i, 0))];
|
||||
sir = stack[i + radius];
|
||||
sir[0] = (p & 0xff0000) >> 16;
|
||||
sir[1] = (p & 0x00ff00) >> 8;
|
||||
sir[2] = (p & 0x0000ff);
|
||||
rbs = r1 - Math.abs(i);
|
||||
rsum += sir[0] * rbs;
|
||||
gsum += sir[1] * rbs;
|
||||
bsum += sir[2] * rbs;
|
||||
if (i > 0) {
|
||||
rinsum += sir[0];
|
||||
ginsum += sir[1];
|
||||
binsum += sir[2];
|
||||
} else {
|
||||
routsum += sir[0];
|
||||
goutsum += sir[1];
|
||||
boutsum += sir[2];
|
||||
}
|
||||
}
|
||||
stackpointer = radius;
|
||||
|
||||
for (x = 0; x < w; x++) {
|
||||
|
||||
r[yi] = dv[rsum];
|
||||
g[yi] = dv[gsum];
|
||||
b[yi] = dv[bsum];
|
||||
|
||||
rsum -= routsum;
|
||||
gsum -= goutsum;
|
||||
bsum -= boutsum;
|
||||
|
||||
stackstart = stackpointer - radius + div;
|
||||
sir = stack[stackstart % div];
|
||||
|
||||
routsum -= sir[0];
|
||||
goutsum -= sir[1];
|
||||
boutsum -= sir[2];
|
||||
|
||||
if (y == 0) {
|
||||
vmin[x] = Math.min(x + radius + 1, wm);
|
||||
}
|
||||
p = pix[yw + vmin[x]];
|
||||
|
||||
sir[0] = (p & 0xff0000) >> 16;
|
||||
sir[1] = (p & 0x00ff00) >> 8;
|
||||
sir[2] = (p & 0x0000ff);
|
||||
|
||||
rinsum += sir[0];
|
||||
ginsum += sir[1];
|
||||
binsum += sir[2];
|
||||
|
||||
rsum += rinsum;
|
||||
gsum += ginsum;
|
||||
bsum += binsum;
|
||||
|
||||
stackpointer = (stackpointer + 1) % div;
|
||||
sir = stack[(stackpointer) % div];
|
||||
|
||||
routsum += sir[0];
|
||||
goutsum += sir[1];
|
||||
boutsum += sir[2];
|
||||
|
||||
rinsum -= sir[0];
|
||||
ginsum -= sir[1];
|
||||
binsum -= sir[2];
|
||||
|
||||
yi++;
|
||||
}
|
||||
yw += w;
|
||||
}
|
||||
for (x = 0; x < w; x++) {
|
||||
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
|
||||
yp = -radius * w;
|
||||
for (i = -radius; i <= radius; i++) {
|
||||
yi = Math.max(0, yp) + x;
|
||||
|
||||
sir = stack[i + radius];
|
||||
|
||||
sir[0] = r[yi];
|
||||
sir[1] = g[yi];
|
||||
sir[2] = b[yi];
|
||||
|
||||
rbs = r1 - Math.abs(i);
|
||||
|
||||
rsum += r[yi] * rbs;
|
||||
gsum += g[yi] * rbs;
|
||||
bsum += b[yi] * rbs;
|
||||
|
||||
if (i > 0) {
|
||||
rinsum += sir[0];
|
||||
ginsum += sir[1];
|
||||
binsum += sir[2];
|
||||
} else {
|
||||
routsum += sir[0];
|
||||
goutsum += sir[1];
|
||||
boutsum += sir[2];
|
||||
}
|
||||
|
||||
if (i < hm) {
|
||||
yp += w;
|
||||
}
|
||||
}
|
||||
yi = x;
|
||||
stackpointer = radius;
|
||||
for (y = 0; y < h; y++) {
|
||||
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
|
||||
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
|
||||
|
||||
rsum -= routsum;
|
||||
gsum -= goutsum;
|
||||
bsum -= boutsum;
|
||||
|
||||
stackstart = stackpointer - radius + div;
|
||||
sir = stack[stackstart % div];
|
||||
|
||||
routsum -= sir[0];
|
||||
goutsum -= sir[1];
|
||||
boutsum -= sir[2];
|
||||
|
||||
if (x == 0) {
|
||||
vmin[y] = Math.min(y + r1, hm) * w;
|
||||
}
|
||||
p = x + vmin[y];
|
||||
|
||||
sir[0] = r[p];
|
||||
sir[1] = g[p];
|
||||
sir[2] = b[p];
|
||||
|
||||
rinsum += sir[0];
|
||||
ginsum += sir[1];
|
||||
binsum += sir[2];
|
||||
|
||||
rsum += rinsum;
|
||||
gsum += ginsum;
|
||||
bsum += binsum;
|
||||
|
||||
stackpointer = (stackpointer + 1) % div;
|
||||
sir = stack[stackpointer];
|
||||
|
||||
routsum += sir[0];
|
||||
goutsum += sir[1];
|
||||
boutsum += sir[2];
|
||||
|
||||
rinsum -= sir[0];
|
||||
ginsum -= sir[1];
|
||||
binsum -= sir[2];
|
||||
|
||||
yi += w;
|
||||
}
|
||||
}
|
||||
|
||||
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
|
||||
|
||||
return (bitmap);
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
package com.zhidao.adas.client.utils.image;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* Glide加载图片,使图片变成圆角图片工具
|
||||
* 基本用法Glide.with(this).load(imgUrl).apply(RequestOptions.bitmapTransform(GlideRoundedCornersTransform(this))).into(imageView)
|
||||
* 如果想用多个Transform可以使用{@link com.bumptech.glide.load.MultiTransformation} 进行Transform的融合
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class GlideRoundedCornersTransform extends CenterCrop {
|
||||
private float mRadius;
|
||||
private CornerType mCornerType;
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID = "GlideRoundedCornersTransform." + VERSION;
|
||||
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
|
||||
|
||||
/**
|
||||
* 待处理的圆角枚举
|
||||
*/
|
||||
public enum CornerType {
|
||||
ALL,
|
||||
TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT,
|
||||
TOP, BOTTOM, LEFT, RIGHT,
|
||||
TOP_LEFT_BOTTOM_RIGHT,
|
||||
TOP_RIGHT_BOTTOM_LEFT,
|
||||
TOP_LEFT_TOP_RIGHT_BOTTOM_RIGHT,
|
||||
TOP_RIGHT_BOTTOM_RIGHT_BOTTOM_LEFT,
|
||||
TOP_LEFT_TOP_RIGHT
|
||||
}
|
||||
|
||||
public GlideRoundedCornersTransform(float radius, CornerType cornerType) {
|
||||
super();
|
||||
mRadius = radius;
|
||||
mCornerType = cornerType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull BitmapPool pool,@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
Bitmap transform = super.transform(pool, toTransform, outWidth, outHeight);
|
||||
return roundCrop(pool, transform);
|
||||
}
|
||||
|
||||
private Bitmap roundCrop(BitmapPool pool, Bitmap source) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
|
||||
if (result == null) {
|
||||
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config
|
||||
.ARGB_8888);
|
||||
}
|
||||
Canvas canvas = new Canvas(result);
|
||||
Paint paint = new Paint();
|
||||
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader
|
||||
.TileMode.CLAMP));
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
Path path = new Path();
|
||||
drawRoundRect(canvas, paint, path, width, height);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void drawRoundRect(Canvas canvas, Paint paint, Path path, int width, int height) {
|
||||
float[] rids;
|
||||
switch (mCornerType) {
|
||||
case ALL:
|
||||
rids = new float[]{mRadius, mRadius, mRadius, mRadius, mRadius, mRadius, mRadius, mRadius};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case TOP_LEFT:
|
||||
rids = new float[]{mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
rids = new float[]{0.0f, 0.0f, mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case BOTTOM_RIGHT:
|
||||
rids = new float[]{0.0f, 0.0f, 0.0f, 0.0f, mRadius, mRadius, 0.0f, 0.0f};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case BOTTOM_LEFT:
|
||||
rids = new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, mRadius, mRadius};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case TOP:
|
||||
rids = new float[]{mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case BOTTOM:
|
||||
rids = new float[]{0.0f, 0.0f, 0.0f, 0.0f, mRadius, mRadius, mRadius, mRadius};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case LEFT:
|
||||
rids = new float[]{mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f, mRadius, mRadius};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case RIGHT:
|
||||
rids = new float[]{0.0f, 0.0f, mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case TOP_LEFT_BOTTOM_RIGHT:
|
||||
rids = new float[]{mRadius, mRadius, 0.0f, 0.0f, mRadius, mRadius, 0.0f, 0.0f};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case TOP_RIGHT_BOTTOM_LEFT:
|
||||
rids = new float[]{0.0f, 0.0f, mRadius, mRadius, 0.0f, 0.0f, mRadius, mRadius};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case TOP_LEFT_TOP_RIGHT_BOTTOM_RIGHT:
|
||||
rids = new float[]{mRadius, mRadius, mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case TOP_RIGHT_BOTTOM_RIGHT_BOTTOM_LEFT:
|
||||
rids = new float[]{0.0f, 0.0f, mRadius, mRadius, mRadius, mRadius, mRadius, mRadius};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
case TOP_LEFT_TOP_RIGHT:
|
||||
rids = new float[]{mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f};
|
||||
drawPath(rids, canvas, paint, path, width, height);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("RoundedCorners type not belong to CornerType");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rids 圆角的半径,依次为左上角xy半径,右上角,右下角,左下角
|
||||
*/
|
||||
private void drawPath(float[] rids, Canvas canvas, Paint paint, Path path, int width, int height) {
|
||||
path.addRoundRect(new RectF(0, 0, width, height), rids, Path.Direction.CW);
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof GlideRoundedCornersTransform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(MessageDigest messageDigest) {
|
||||
messageDigest.update(ID_BYTES);
|
||||
}
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
package com.zhidao.adas.client.utils.image;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* create by libo
|
||||
* create on 2018/12/26
|
||||
* description Glide图片加载工具类
|
||||
*/
|
||||
public class ImageLoaderManager {
|
||||
|
||||
/**
|
||||
* 默认加载方式
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void loadImage(Context context, String url, ImageView imageView) {
|
||||
RequestOptions requestOptions = new RequestOptions()
|
||||
.priority(Priority.HIGH)
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.dontAnimate();
|
||||
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.apply(requestOptions)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载圆形图片
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void loadCircleImage(Context context, String url, ImageView imageView) {
|
||||
RequestOptions requestOptions = new RequestOptions()
|
||||
.priority(Priority.HIGH)
|
||||
.dontAnimate()
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.bitmapTransform(new CircleCrop());
|
||||
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.apply(requestOptions)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载圆角图片
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
* @param radius 圆角大小
|
||||
*/
|
||||
public static void loadRoundImage(Context context, String url, ImageView imageView, int radius) {
|
||||
RequestOptions requestOptions = new RequestOptions()
|
||||
.priority(Priority.HIGH)
|
||||
.dontAnimate()
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.transforms(new CenterCrop(), new RoundedCorners(radius));
|
||||
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.apply(requestOptions)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载图片指定大小
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
public static void loadSizeImage(Context context, String url, ImageView imageView, int width, int height) {
|
||||
RequestOptions requestOptions = new RequestOptions()
|
||||
.priority(Priority.HIGH)
|
||||
.override(width, height)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE);
|
||||
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.apply(requestOptions)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载资源文件
|
||||
*
|
||||
* @param context
|
||||
* @param resId
|
||||
* @param imageView
|
||||
*/
|
||||
public static void loadImage(Context context, int resId, ImageView imageView) {
|
||||
RequestOptions requestOptions = new RequestOptions()
|
||||
.priority(Priority.HIGH)
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.centerCrop();
|
||||
|
||||
Glide.with(context)
|
||||
.load(resId)
|
||||
.apply(requestOptions)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载本地图片文件
|
||||
*
|
||||
* @param context
|
||||
* @param file
|
||||
* @param imageView
|
||||
*/
|
||||
public static void loadFileImage(Context context, File file, ImageView imageView) {
|
||||
RequestOptions requestOptions = new RequestOptions()
|
||||
.priority(Priority.HIGH)
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.centerCrop();
|
||||
|
||||
Glide.with(context)
|
||||
.load(file)
|
||||
.apply(requestOptions)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载高斯模糊
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
* @param radius 模糊级数 最大25
|
||||
*/
|
||||
public static void loadBlurImage(Context context, String url, ImageView imageView, int radius) {
|
||||
RequestOptions requestOptions = new RequestOptions()
|
||||
.override(300)
|
||||
.transforms(new BlurTransformation(radius));
|
||||
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.apply(requestOptions)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载gif图
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void loadGifImage(Context context, String url, ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.into(imageView);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="#7CFC00" android:state_pressed="true" />
|
||||
<item android:color="#7CFC00" android:state_checked="true" />
|
||||
<item android:color="#8B4513" android:state_selected="true" />
|
||||
<item android:color="#FFFFFF" />
|
||||
</selector>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="#7CFC00" android:state_pressed="true" />
|
||||
<item android:color="#7CFC00" android:state_checked="true" />
|
||||
<item android:color="#c9c9c9" android:state_enabled="false" />
|
||||
<item android:color="#000000" />
|
||||
|
||||
</selector>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#FAFFFFFF" />
|
||||
<stroke
|
||||
android:width="0.8dp"
|
||||
android:color="#81666666" />
|
||||
<!-- 圆角 -->
|
||||
<corners android:radius="6dp" />
|
||||
</shape>
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_checked="true">
|
||||
<shape android:shape="rectangle">
|
||||
<padding android:bottom="4dp" android:left="6dp" android:right="6dp" android:top="4dp" />
|
||||
<!-- 圆角深红色按钮 -->
|
||||
<solid android:color="#990033" />
|
||||
<corners android:radius="8dip" />
|
||||
<stroke android:width=".5dp" android:color="#ffffff" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:state_checked="false">
|
||||
<shape android:shape="rectangle">
|
||||
<padding android:bottom="4dp" android:left="6dp" android:right="6dp" android:top="4dp" />
|
||||
<!-- 圆角红色按钮 -->
|
||||
<solid android:color="@color/colorPrimary" />
|
||||
<corners android:radius="8dip" />
|
||||
<stroke android:width=".5dp" android:color="#ffffff" android:dashWidth="3dp" android:dashGap="3dp" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</selector>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<!-- 圆角红色按钮 -->
|
||||
<solid android:color="#E0000000" />
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.3 KiB |
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<!-- 圆角深红色按钮 -->
|
||||
<solid android:color="#4D0A0A" />
|
||||
<corners android:radius="8dip" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:state_pressed="false">
|
||||
<shape android:shape="rectangle">
|
||||
<!-- 圆角红色按钮 -->
|
||||
<solid android:color="#D9534F" />
|
||||
<corners android:radius="8dip" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</selector>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user