[dev_opt_2.15.0]工具箱系统版本View更改
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user