fix(app-ui): 整頁背景(BG0) applyBackground 改用 Glide 載入(本地檔優先/URL 網路 fallback,正確解 webp)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d224354c23
commit
fa5525ad87
@ -105,26 +105,49 @@ public class UiSkin {
|
||||
|
||||
/**
|
||||
* 把某部位的後台設定圖套成指定 View 的「背景」(整頁背景等);未設定則不動、保留原背景。
|
||||
* 使用預先下載到本地的快取檔(UiSkin.save 時已 preload)。
|
||||
* 用 Glide 載入(有本地快取檔用檔案、否則直接以 URL 下載=網路 fallback),能正確解 webp。
|
||||
*/
|
||||
public static void applyBackground(String partKey, View view) {
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String url = getUrl(view.getContext(), partKey);
|
||||
final android.content.Context ctx = view.getContext();
|
||||
if (ctx instanceof android.app.Activity) {
|
||||
android.app.Activity a = (android.app.Activity) ctx;
|
||||
if (a.isFinishing() || a.isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String url = getUrl(ctx, partKey);
|
||||
if (url == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
java.io.File f = new com.unibuy.smartdevice.tools.HttpConnect().getFileFromUrl(url);
|
||||
if (f != null && f.exists()) {
|
||||
android.graphics.drawable.Drawable d = android.graphics.drawable.Drawable.createFromPath(f.getAbsolutePath());
|
||||
if (d != null) {
|
||||
view.setBackground(d);
|
||||
Object model = url; // 預設用 URL(無本地檔時走網路)
|
||||
try {
|
||||
java.io.File f = new com.unibuy.smartdevice.tools.HttpConnect().getFileFromUrl(url);
|
||||
if (f != null && f.exists()) {
|
||||
model = f; // 有本地快取檔優先用檔案
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
com.bumptech.glide.Glide.with(ctx)
|
||||
.load(model)
|
||||
.into(new com.bumptech.glide.request.target.CustomTarget<android.graphics.drawable.Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(android.graphics.drawable.Drawable resource,
|
||||
com.bumptech.glide.request.transition.Transition<? super android.graphics.drawable.Drawable> transition) {
|
||||
view.setBackground(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(android.graphics.drawable.Drawable placeholder) {
|
||||
}
|
||||
});
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user