「Update」
1、增加对皮肤包中的Raw文件拷贝到/sdcard/Android/packagename/raw
This commit is contained in:
@@ -21,6 +21,7 @@ import com.mogo.cloud.trafficlive.api.ITrafficIntersectionLiveCallBack;
|
||||
import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive;
|
||||
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;
|
||||
@@ -86,13 +87,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
Skin skin;
|
||||
if (isCheck) {
|
||||
skin = new Skin(
|
||||
"ce67cbe250672c6b44720f0f08f43ca1",
|
||||
"YiXin-skin_v1_2024_10_15.apk",
|
||||
"https://carlife-static-1255510688.cos.ap-beijing.myqcloud.com/MoGoEagleEye/YiXin-skin_v1_2024_10_15.apk"
|
||||
"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"
|
||||
);
|
||||
|
||||
//换肤
|
||||
SkinManager.getInstance().selectSkin(this, skin);
|
||||
SkinManager.getInstance().downloadSkin(this, skin);
|
||||
|
||||
} else {
|
||||
SkinManager.getInstance().loadSkin("");
|
||||
@@ -102,10 +103,10 @@ 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);
|
||||
// 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);
|
||||
});
|
||||
|
||||
btnJumpRoadCondition = findViewById(R.id.btnJumpRoadcondition);
|
||||
|
||||
BIN
app/src/main/res/raw/biz_login_bus_bg.mp4
Normal file
BIN
app/src/main/res/raw/biz_login_bus_bg.mp4
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.49.7-debug
|
||||
MOGO_SKIN_VERSION=1.4.7.49.10-debug
|
||||
|
||||
@@ -53,6 +53,8 @@ public class SkinAttribute {
|
||||
for (int i = 0; i < attrs.getAttributeCount(); i++) {
|
||||
//获得属性名
|
||||
String attributeName = attrs.getAttributeName(i);
|
||||
// 筛选配置了换肤属性的View,防止因为换肤导致。动态控制了状态的View被还原的问题;
|
||||
|
||||
//是否符合 需要筛选的属性名
|
||||
if (mAttributes.contains(attributeName)) {
|
||||
//属性名写法
|
||||
|
||||
@@ -136,7 +136,7 @@ public class SkinManager extends Observable {
|
||||
/**
|
||||
* 下载皮肤包
|
||||
*/
|
||||
public void selectSkin(Context context, Skin skin) {
|
||||
public void downloadSkin(Context context, Skin skin) {
|
||||
File theme = new File(FileUtils.getExternalAppDirectory(context), "theme");
|
||||
if (theme.exists() && theme.isFile()) {
|
||||
theme.delete();
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
package com.mogo.skin.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class FileUtils {
|
||||
private static final String TAG = "FileUtils";
|
||||
|
||||
/**
|
||||
* 获取应用特定的外部存储目录。
|
||||
@@ -34,4 +41,59 @@ public class FileUtils {
|
||||
// 创建并返回子目录
|
||||
return new File(externalFilesDir, subDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定的Raw文件全都拷贝出来
|
||||
*
|
||||
* @param fields 获取raw文件夹的资源ID
|
||||
*/
|
||||
public static void copyAppRawToFile(Context context, Field[] fields) {
|
||||
for (Field field : fields) {// 将资源文件的名称添加到列表中
|
||||
copyRawToFile(SkinResources.getInstance().getIdentifier(field.getName(), "raw"),
|
||||
getExternalAppDirectory(context).getAbsolutePath() + "/raw/");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 raw 目录下的文件复制到外部存储的指定路径
|
||||
*
|
||||
* @param rawResId raw 目录下的资源 ID
|
||||
* @param targetPath 外部存储的目标路径
|
||||
* @return 是否复制成功
|
||||
*/
|
||||
public static boolean copyRawToFile(int rawResId, String targetPath) {
|
||||
try {
|
||||
// 获取 raw 目录下的文件输入流
|
||||
InputStream inputStream = SkinResources.getInstance().getRawInputStream(rawResId);
|
||||
|
||||
// 创建目标文件夹
|
||||
File targetDirectory = new File(targetPath);
|
||||
if (!targetDirectory.exists()) {
|
||||
targetDirectory.mkdirs();
|
||||
}
|
||||
|
||||
// 构建目标文件路径
|
||||
String fileName = SkinResources.getInstance().getResName(rawResId) + ".mp4"; // 根据实际情况更改文件名
|
||||
File targetFile = new File(targetDirectory, fileName);
|
||||
|
||||
// 创建目标文件输出流
|
||||
OutputStream outputStream = new FileOutputStream(targetFile);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
|
||||
while ((length = inputStream.read(buffer)) > 0) {
|
||||
outputStream.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
outputStream.close();
|
||||
inputStream.close();
|
||||
|
||||
Log.i(TAG, "File copied successfully to " + targetFile.getAbsolutePath());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to copy file", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,11 @@ public class SkinResources {
|
||||
|
||||
private boolean isDefaultSkin = true;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
|
||||
private SkinResources(Context context) {
|
||||
mContext = context;
|
||||
mAppResources = context.getResources();
|
||||
}
|
||||
|
||||
@@ -78,6 +81,44 @@ public class SkinResources {
|
||||
return skinId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2.根据名字和类型获取原始app中的ID
|
||||
*/
|
||||
public int getIdentifier(String resName, String resType) {
|
||||
return mAppResources.getIdentifier(resName, resType, mContext.getPackageName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 1.通过原始app中的resId(R.color.XX)获取到自己的 名字
|
||||
*/
|
||||
public String getResName(int resId) {
|
||||
//在皮肤包中不一定就是 当前程序的 id
|
||||
//获取对应id 在当前的名称 colorPrimary
|
||||
//R.drawable.ic_launcher
|
||||
return mAppResources.getResourceEntryName(resId);//ic_launcher
|
||||
}
|
||||
|
||||
/**
|
||||
* 将资源 ID 转换为 android.resource:// URL 格式
|
||||
*
|
||||
* @param resId 资源 ID
|
||||
* @return 资源的 android.resource:// URL 地址
|
||||
*/
|
||||
public String getResourceUrl(int resId) {
|
||||
String packageName = mContext.getPackageName();
|
||||
return "android.resource://" + packageName + "/" + resId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1.通过原始app中的resId(R.raw.XX)获取,拷贝到sdk的外部存储的文件路径
|
||||
*/
|
||||
public String getRawMp4FilePath(int resId) {
|
||||
if (isDefaultSkin) {
|
||||
return getResourceUrl(resId);
|
||||
}
|
||||
return "file:///" + FileUtils.getExternalAppDirectory(mContext).getAbsolutePath() + "/raw/" + getResName(resId) + ".mp4";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取皮肤中的Raw文件InputStream
|
||||
*
|
||||
@@ -97,6 +138,7 @@ public class SkinResources {
|
||||
|
||||
/**
|
||||
* 获取Raw的byte[]
|
||||
*
|
||||
* @param resId
|
||||
* @return
|
||||
*/
|
||||
@@ -141,6 +183,7 @@ public class SkinResources {
|
||||
|
||||
/**
|
||||
* 输入主APP的ID,到皮肤APK文件中去找到对应ID的颜色值
|
||||
*
|
||||
* @param resId
|
||||
* @return
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user