[dev_opt_2.15.0]工具箱系统版本View更改

This commit is contained in:
xuxinchao
2023-03-30 17:38:42 +08:00
parent c8ef1d7a52
commit 86df90cd10
6 changed files with 87 additions and 28 deletions

View File

@@ -0,0 +1,67 @@
package com.mogo.eagle.core.utilcode.util;
import android.text.TextUtils;
import android.util.Log;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 工控机版本转换工具类
*/
public class ParseVersionUtils {
private final static Pattern pattern = Pattern.compile("\\d+\\.\\d+\\.\\d+");
public static String parseVersion(String ver) {
String version = "";
if (!TextUtils.isEmpty(ver)) {
try {
Matcher matcher = pattern.matcher(ver);
if (matcher.find()) {
String group = matcher.group();
if (!TextUtils.isEmpty(group)) {
version = group;
}
}
} catch (Exception e) {
Log.e("AdasManager", "版本解析失败=" + ver, e);
}
}
return version;
}
/**
* 解析版本 格式 xxx.xxx.xxx(x的数量不固定)
* 如果用于比较仅适用于非个位数非0的字符串例如"12.03.04" 解析出为120304可能无法正常对比
* 目前已用于DockerVersion和MaserVersion的解析
*
* @param isUseAll 是否使用全部截取数据 true表示 12.34.56 截取之后 123456 false表示12.34.56 截取之后 12
* @param ver 版本字符串 例如:"MAP-taxi_RoboTaxi_df_2.8.0.3_20220928_test" 解析结果为280
* @return -1表示解析失败
*/
public static int parseVersion(boolean isUseAll, String ver) {
int version = -1;
if (!TextUtils.isEmpty(ver)) {
try {
Matcher matcher = pattern.matcher(ver);
if (matcher.find()) {
String group = matcher.group();
if (!TextUtils.isEmpty(group)) {
if (isUseAll) {
group = group.replace(".", "");
} else {
group = group.split("\\.")[0];
}
version = Integer.parseInt(group);
}
}
} catch (Exception e) {
Log.e("AdasManager", "版本解析失败=" + ver, e);
}
}
return version;
}
}