「Update」
1、完成只针对video_开头的raw文件的复制和引用替换。 2、增加皮肤包下载回调。
This commit is contained in:
@@ -23,7 +23,6 @@ import com.mogo.skin.Skin;
|
||||
import com.mogo.skin.SkinManager;
|
||||
import com.mogo.skin.utils.FileUtils;
|
||||
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;
|
||||
@@ -87,13 +86,23 @@ public class MainActivity extends AppCompatActivity {
|
||||
Skin skin;
|
||||
if (isCheck) {
|
||||
skin = new Skin(
|
||||
"9b69f8c4a2b3b953e1600930eda6a099",
|
||||
"YiXin-skin_v1_2024_10_23.zip",
|
||||
"https://carlife-static-1255510688.cos.ap-beijing.myqcloud.com/MoGoEagleEye/YiXin-skin_v1_2024_10_23.zip"
|
||||
"88a7b397d6a03966aa332aea17f5210a",
|
||||
"YiXin-skin_v1_2024_10_24.apk",
|
||||
"https://carlife-static-1255510688.cos.ap-beijing.myqcloud.com/MoGoEagleEye/YiXin-skin_v1_2024_10_24.apk"
|
||||
);
|
||||
|
||||
//换肤
|
||||
SkinManager.getInstance().downloadSkin(this, skin);
|
||||
SkinManager.getInstance().downloadSkin(this, skin, new SkinManager.SkinLoadListener() {
|
||||
@Override
|
||||
public void onLoadSuccess() {
|
||||
FileUtils.copyVideoRawToFile(MainActivity.this, R.raw.class.getFields());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
SkinManager.getInstance().loadSkin("");
|
||||
@@ -103,10 +112,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
btnJumpLocation = findViewById(R.id.btnJumpLocation);
|
||||
btnJumpLocation.setOnClickListener(v -> {
|
||||
// FileUtils.copyRawToFile(R.raw.biz_login_bus_bg, FileUtils.getExternalAppDirectory(getApplicationContext()).getAbsolutePath() + "/raw/");
|
||||
FileUtils.copyAppRawToFile(this, R.raw.class.getFields());
|
||||
// Intent intent = new Intent(MainActivity.this, LocationActivity.class);
|
||||
// startActivity(intent);
|
||||
//// FileUtils.copyRawToFile(R.raw.biz_login_bus_bg, FileUtils.getExternalAppDirectory(getApplicationContext()).getAbsolutePath() + "/raw/");
|
||||
// FileUtils.copyVideoRawToFile(this, R.raw.class.getFields());
|
||||
Intent intent = new Intent(MainActivity.this, LocationActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
btnJumpRoadCondition = findViewById(R.id.btnJumpRoadcondition);
|
||||
|
||||
@@ -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.49.10-debug
|
||||
MOGO_SKIN_VERSION=1.4.7.49.11-debug
|
||||
|
||||
@@ -30,6 +30,11 @@ public class SkinManager extends Observable {
|
||||
|
||||
private static Application mApplication;
|
||||
private static SkinManager instance;
|
||||
|
||||
/**
|
||||
* 皮肤加载回调监听
|
||||
*/
|
||||
private SkinLoadListener mSkinLoadListener;
|
||||
/**
|
||||
* Activity生命周期回调
|
||||
*/
|
||||
@@ -136,7 +141,7 @@ public class SkinManager extends Observable {
|
||||
/**
|
||||
* 下载皮肤包
|
||||
*/
|
||||
public void downloadSkin(Context context, Skin skin) {
|
||||
public void downloadSkin(Context context, Skin skin, SkinLoadListener skinLoadListener) {
|
||||
File theme = new File(FileUtils.getExternalAppDirectory(context), "theme");
|
||||
if (theme.exists() && theme.isFile()) {
|
||||
theme.delete();
|
||||
@@ -151,13 +156,13 @@ public class SkinManager extends Observable {
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "皮肤不存在,开始下载……skin=" + skin);
|
||||
DownloadManager manager = getDownloadManager(skin, theme);
|
||||
DownloadManager manager = getDownloadManager(skin, theme, skinLoadListener);
|
||||
// 启动文件下载
|
||||
manager.startDownload();
|
||||
|
||||
}
|
||||
|
||||
private static DownloadManager getDownloadManager(Skin skin, File themeDirectory) {
|
||||
private static DownloadManager getDownloadManager(Skin skin, File themeDirectory, SkinLoadListener skinLoadListener) {
|
||||
DownloadManager.DownloadListener downloadListener = new DownloadManager.DownloadListener() {
|
||||
@Override
|
||||
public void onProgressUpdate(int progress) {
|
||||
@@ -179,14 +184,19 @@ public class SkinManager extends Observable {
|
||||
Log.d(TAG, "DownloadManager 校验成功,修改文件名。");
|
||||
// 加载指定皮肤包
|
||||
SkinManager.getInstance().loadSkin(skin.getPathLocal());
|
||||
// 回调给使用方成功
|
||||
skinLoadListener.onLoadSuccess();
|
||||
// 校验文件签名没问题后删除其他主题
|
||||
deleteFilesExcept(themeDirectory, skin.getSkinFileName());
|
||||
} else {
|
||||
// 回调给使用方成功
|
||||
skinLoadListener.onLoadFailed(new Exception("皮肤文件校验出错,本地文件MD5 与云端文件MD5 不一致。"));
|
||||
Log.e(TAG, "DownloadManager 皮肤文件校验出错,本地文件MD5 与云端文件MD5 不一致。");
|
||||
Toast.makeText(mApplication, "皮肤文件校验出错,本地文件MD5 与云端文件MD5 不一致。", Toast.LENGTH_SHORT).show();
|
||||
// TODO 删除本地皮肤文件,并重新下载(这个操作比较危险,需要严格保证配置文件中的md5与实际皮肤包一致,否则将是灾难)
|
||||
}
|
||||
} catch (Exception e) {
|
||||
skinLoadListener.onLoadFailed(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -195,6 +205,7 @@ public class SkinManager extends Observable {
|
||||
public void onDownloadFailed(Exception e) {
|
||||
// 下载失败后的处理
|
||||
Log.e(TAG, "DownloadManager onDownloadFailed");
|
||||
skinLoadListener.onLoadFailed(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -202,6 +213,7 @@ public class SkinManager extends Observable {
|
||||
public void onAlreadyDownloading(String url) {
|
||||
// 处理重复下载的情况
|
||||
Log.w(TAG, "DownloadManager onAlreadyDownloading url=" + url);
|
||||
skinLoadListener.onLoadFailed(new Exception("DownloadManager onAlreadyDownloading url=" + url));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -240,4 +252,15 @@ public class SkinManager extends Observable {
|
||||
// 尝试重命名文件
|
||||
return oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 皮肤加载回调
|
||||
*/
|
||||
public interface SkinLoadListener {
|
||||
void onLoadSuccess();
|
||||
|
||||
void onLoadFailed(Exception e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,10 +47,13 @@ public class FileUtils {
|
||||
*
|
||||
* @param fields 获取raw文件夹的资源ID
|
||||
*/
|
||||
public static void copyAppRawToFile(Context context, Field[] fields) {
|
||||
public static void copyVideoRawToFile(Context context, Field[] fields) {
|
||||
for (Field field : fields) {// 将资源文件的名称添加到列表中
|
||||
copyRawToFile(SkinResources.getInstance().getIdentifier(field.getName(), "raw"),
|
||||
getExternalAppDirectory(context).getAbsolutePath() + "/raw/");
|
||||
// 过滤名称带有Video的Raw文件到指定目录
|
||||
if (field.getName().startsWith("video_")) {
|
||||
copyVideoRawToFile(SkinResources.getInstance().getIdentifier(field.getName(), "raw"),
|
||||
getExternalAppDirectory(context).getAbsolutePath() + "/raw/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +64,7 @@ public class FileUtils {
|
||||
* @param targetPath 外部存储的目标路径
|
||||
* @return 是否复制成功
|
||||
*/
|
||||
public static boolean copyRawToFile(int rawResId, String targetPath) {
|
||||
public static boolean copyVideoRawToFile(int rawResId, String targetPath) {
|
||||
try {
|
||||
// 获取 raw 目录下的文件输入流
|
||||
InputStream inputStream = SkinResources.getInstance().getRawInputStream(rawResId);
|
||||
|
||||
Reference in New Issue
Block a user