「Update」
1、增加皮肤包校验后删除其它皮肤包的操作
This commit is contained in:
@@ -22,6 +22,7 @@ import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive;
|
||||
import com.mogo.skin.Skin;
|
||||
import com.mogo.skin.SkinManager;
|
||||
import com.mogo.skin.utils.SkinPreference;
|
||||
import com.mogo.skin.utils.SkinResources;
|
||||
import com.mogo.v2x.V2XManager;
|
||||
import com.mogo.v2x.callback.IV2XCallback;
|
||||
import com.mogo.v2x.config.V2XConfig;
|
||||
@@ -85,10 +86,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
Skin skin;
|
||||
if (isCheck) {
|
||||
skin = new Skin(
|
||||
"6992d2f7862d9255f7a02e0917302f4e",
|
||||
"YiXin-skin.skin",
|
||||
"https://carlife-static-1255510688.cos.ap-beijing.myqcloud.com/MoGoEagleEye/YiXin-skin.skin"
|
||||
|
||||
"7af685334eb2b6724765dae1597cb214",
|
||||
"YiXin-skin_v1_2024_10_14.apk",
|
||||
"https://carlife-static-1255510688.cos.ap-beijing.myqcloud.com/MoGoEagleEye/YiXin-skin_v1_2024_10_14.apk"
|
||||
);
|
||||
|
||||
//换肤
|
||||
@@ -102,6 +102,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
btnJumpLocation = findViewById(R.id.btnJumpLocation);
|
||||
btnJumpLocation.setOnClickListener(v -> {
|
||||
// getResources().openRawResource(R.raw.m2);
|
||||
// SkinResources.getInstance().getRawResourceBytes(R.raw.m2);
|
||||
Intent intent = new Intent(MainActivity.this, LocationActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
BIN
app/src/main/res/raw/m2.nt3d
Normal file
BIN
app/src/main/res/raw/m2.nt3d
Normal file
Binary file not shown.
@@ -58,4 +58,4 @@ MOGO_TELEMATIC_VERSION=1.4.7.42
|
||||
# v2x
|
||||
MOGO_V2X_VERSION=1.4.7.42
|
||||
# SKIN
|
||||
MOGO_SKIN_VERSION=1.4.7.47
|
||||
MOGO_SKIN_VERSION=1.4.7.48
|
||||
|
||||
@@ -13,9 +13,21 @@ public class MoGoApplication extends MultiDexApplication {
|
||||
}
|
||||
```
|
||||
##### 基础控件0改动完成资源替换,只需要保持使用的「资源文件:drawable、string、color等」皮肤包与APP中保持一致即可
|
||||
TextView 控件的静态文字一定要用string.xml 的方式引用文字显示
|
||||
例如:
|
||||
```xml
|
||||
<TextView
|
||||
android:id="@+id/tvDevicesId"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:text="@string/devicesId"
|
||||
android:textColor="@color/colorAccent"
|
||||
android:textSize="20dp" />
|
||||
```
|
||||
##### 如果代码中动态控制了 ImageView 的 src、background 一定要在 XML 中替换成 SkinImageView.java
|
||||
|
||||
##### 代码中设置:图片、文字、颜色
|
||||
##### 代码中动态获取资源设置:图片、文字、颜色
|
||||
```java
|
||||
// 获取颜色
|
||||
SkinResources.getInstance().getColor(resId);
|
||||
@@ -29,6 +41,12 @@ SkinResources.getInstance().getString(resId);
|
||||
// 获取指定的资源id
|
||||
SkinResources.getInstance().getIdentifier(resId);
|
||||
|
||||
// 获取指定的Raw资源 InputStream
|
||||
SkinResources.getInstance().getRawInputStream(resId);
|
||||
|
||||
// 获取指定的Raw资源的byte[]
|
||||
SkinResources.getInstance().getRawResourceBytes(resId);
|
||||
|
||||
```
|
||||
|
||||
#### 手动控制切换皮肤
|
||||
|
||||
@@ -120,7 +120,9 @@ public class SkinManager extends Observable {
|
||||
theme.delete();
|
||||
}
|
||||
theme.mkdirs();
|
||||
// 获取皮肤插件文件对象
|
||||
File skinFile = skin.getSkinFile(theme);
|
||||
// 判断是否存在
|
||||
if (skinFile.exists()) {
|
||||
Log.e("SkinActivity", "皮肤已存在,开始换肤……");
|
||||
SkinManager.getInstance().loadSkin(skin.path);
|
||||
@@ -152,7 +154,8 @@ public class SkinManager extends Observable {
|
||||
//皮肤包的md5校验 防止下载文件损坏(但是会减慢速度。从数据库查询已下载皮肤表数据库中保留md5字段)
|
||||
if (TextUtils.equals(SkinUtils.getSkinMD5(skinFile), skin.md5)) {
|
||||
Log.d("SkinActivity", "校验成功,修改文件名。");
|
||||
|
||||
// 校验文件签名没问题后删除其他主题
|
||||
deleteFilesExcept(theme,skin.file.getName());
|
||||
} else {
|
||||
Log.e("SkinActivity", "皮肤文件校验出错,本地文件MD5 与云端文件MD5 不一致。");
|
||||
Toast.makeText(mApplication, "皮肤文件校验出错,本地文件MD5 与云端文件MD5 不一致。", Toast.LENGTH_SHORT).show();
|
||||
@@ -182,4 +185,25 @@ public class SkinManager extends Observable {
|
||||
|
||||
return new DownloadManager(skin.url, theme, downloadListener);
|
||||
}
|
||||
|
||||
public static void deleteFilesExcept(File directory, String fileNameToKeep) {
|
||||
if (directory == null || !directory.exists() || !directory.isDirectory()) {
|
||||
throw new IllegalArgumentException("Provided path is not a valid directory: " + directory);
|
||||
}
|
||||
|
||||
// 获取目录下的所有文件和子目录
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
// 如果文件名不等于要保留的文件名,并且不是目录,则删除
|
||||
if (!file.getName().equals(fileNameToKeep) && !file.isDirectory()) {
|
||||
if (file.delete()) {
|
||||
System.out.println("Deleted: " + file.getAbsolutePath());
|
||||
} else {
|
||||
System.err.println("Failed to delete: " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user