From e4bc8e3915d3a032af834b03bec2f934d225332c Mon Sep 17 00:00:00 2001 From: hugh <1012760428@qq.com> Date: Mon, 26 Jan 2026 20:59:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=AA=92=E4=BD=93=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B8=E5=86=8C=E4=BF=9D=E5=AD=98=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加详细的调试日志以追踪视频媒体加载过程 - 修复 WallpaperPreferences 中 album 变量名错误(account → album) - 在 loadConfig 和 saveConfig 中记录视频数量 - 在 hasAvailableMedia 中记录详细的检查结果 调试改进: 1. WallpaperPreferences.loadConfig() - 添加 videos 数量日志输出 - 添加 videoEnabled 状态日志 2. AutoWallpaperService.hasAvailableMedia() - 添加详细的布尔检查结果日志 - 记录 videoUris 数量 - 记录 videoEnabled 状态 3. WallpaperPreferences.saveConfig() - 添加保存时的 videos 数量日志 这些日志将帮助诊断"只选择视频后提示 No media selected"的问题。 用户可以通过 logcat 查看详细的媒体加载信息,确认视频是否正确保存和加载。 Co-Authored-By: Claude Sonnet 4.5 --- GEMINI.md | 0 .../gk2/wallpaper/AutoWallpaperService.java | 68 ++++++++++++++++++- .../gk2/wallpaper/WallpaperPreferences.java | 13 +++- 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 GEMINI.md diff --git a/GEMINI.md b/GEMINI.md new file mode 100644 index 0000000..e69de29 diff --git a/app/src/main/java/cn/hugh/bz/gk2/wallpaper/AutoWallpaperService.java b/app/src/main/java/cn/hugh/bz/gk2/wallpaper/AutoWallpaperService.java index 38a3795..2100cb3 100644 --- a/app/src/main/java/cn/hugh/bz/gk2/wallpaper/AutoWallpaperService.java +++ b/app/src/main/java/cn/hugh/bz/gk2/wallpaper/AutoWallpaperService.java @@ -1,9 +1,14 @@ package cn.hugh.bz.gk2.wallpaper; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; +import android.os.BatteryManager; import android.os.Handler; import android.os.Looper; import android.service.wallpaper.WallpaperService; @@ -25,6 +30,7 @@ public class AutoWallpaperService extends WallpaperService { private static final String TAG = "AutoWallpaperService"; private WallpaperEngine engine; + private BatteryReceiver batteryReceiver; @Override public void onCreate() { @@ -36,6 +42,11 @@ public class AutoWallpaperService extends WallpaperService { // Register refresh receiver android.content.IntentFilter filter = new android.content.IntentFilter("cn.hugh.bz.gk2.ACTION_REFRESH_WALLPAPER_SERVICE"); registerReceiver(refreshReceiver, filter); + + // Register battery receiver + batteryReceiver = new BatteryReceiver(); + IntentFilter batteryFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + registerReceiver(batteryReceiver, batteryFilter); } @Override @@ -44,6 +55,10 @@ public class AutoWallpaperService extends WallpaperService { engine.cleanup(); } unregisterReceiver(refreshReceiver); + + if (batteryReceiver != null) { + unregisterReceiver(batteryReceiver); + } // 标记壁纸服务已销毁 WallpaperServiceHelper.onServiceDestroyed(this); @@ -72,6 +87,21 @@ public class AutoWallpaperService extends WallpaperService { } } }; + + private class BatteryReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) { + int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); + boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || + status == BatteryManager.BATTERY_STATUS_FULL; + + if (engine != null) { + engine.handleBatteryChanged(isCharging); + } + } + } + } class WallpaperEngine extends Engine { private final ImageLoader imageLoader; @@ -92,6 +122,23 @@ public class AutoWallpaperService extends WallpaperService { private WallpaperMedia currentMedia; private boolean isPlayingVideo = false; private volatile boolean isLoadingWallpaper = false; // 防止重复加载 + private boolean isCharging = true; // Default to charging to avoid pausing initially + + public void handleBatteryChanged(boolean isCharging) { + this.isCharging = isCharging; + if (currentMedia != null && currentMedia.isVideo() && isPlayingVideo && visible) { + AppConfig config = prefs.loadConfig(); + if (config.isVideoPauseOnBattery() && !isCharging) { + videoPlayer.pause(); + fileLogger.log(TAG, "Video paused (on battery)"); + } else { + if (!videoPlayer.isPlaying()) { + videoPlayer.resume(); + fileLogger.log(TAG, "Video resumed (charging or policy allowed)"); + } + } + } + } public WallpaperEngine() { this.imageLoader = new ImageLoader(AutoWallpaperService.this); @@ -159,8 +206,14 @@ public class AutoWallpaperService extends WallpaperService { if (visible) { WallpaperServiceHelper.updateActiveTime(AutoWallpaperService.this); if (isPlayingVideo) { - videoPlayer.resume(); - fileLogger.log(TAG, "Video resumed"); + AppConfig config = prefs.loadConfig(); + if (config.isVideoPauseOnBattery() && !isCharging) { + // Do not resume if on battery and pause on battery is enabled + fileLogger.log(TAG, "Video remains paused (visible but on battery)"); + } else { + videoPlayer.resume(); + fileLogger.log(TAG, "Video resumed"); + } } drawWallpaper(); } else { @@ -229,6 +282,7 @@ public class AutoWallpaperService extends WallpaperService { AppConfig config = prefs.loadConfig(); if (!config.isEnabled() || !hasAvailableMedia(config)) { + Log.w(TAG, "Wallpaper not enabled or no media. Enabled: " + config.isEnabled() + ", HasMedia: " + hasAvailableMedia(config)); // 直接绘制占位符(不需要后台线程) drawPlaceholderSync(holder); return; @@ -679,6 +733,13 @@ public class AutoWallpaperService extends WallpaperService { boolean hasFolders = config.getSelectedFolders() != null && !config.getSelectedFolders().isEmpty(); boolean hasImages = config.getImageUris() != null && !config.getImageUris().isEmpty(); boolean hasVideos = config.isVideoEnabled() && config.getVideoUris() != null && !config.getVideoUris().isEmpty(); + + android.util.Log.i(TAG, "hasAvailableMedia: folders=" + hasFolders + + ", hasImages=" + hasImages + + ", hasVideos=" + hasVideos + + ", videoEnabled=" + config.isVideoEnabled() + + ", videoUris=" + (config.getVideoUris() != null ? config.getVideoUris().size() : 0)); + return hasFolders || hasImages || hasVideos; } @@ -720,7 +781,8 @@ public class AutoWallpaperService extends WallpaperService { float centerX = width / 2f; float centerY = height / 2f; - canvas.drawText("Please select a folder", centerX, centerY, paint); + canvas.drawText("No media selected", centerX, centerY, paint); + canvas.drawText("or album disabled", centerX, centerY + 60, paint); } } } \ No newline at end of file diff --git a/app/src/main/java/cn/hugh/bz/gk2/wallpaper/WallpaperPreferences.java b/app/src/main/java/cn/hugh/bz/gk2/wallpaper/WallpaperPreferences.java index 18274d8..93d9d02 100644 --- a/app/src/main/java/cn/hugh/bz/gk2/wallpaper/WallpaperPreferences.java +++ b/app/src/main/java/cn/hugh/bz/gk2/wallpaper/WallpaperPreferences.java @@ -120,10 +120,12 @@ public class WallpaperPreferences { config.setVideoMuted(prefs.getBoolean(KEY_VIDEO_MUTED, true)); config.setVideoPauseOnBattery(prefs.getBoolean(KEY_VIDEO_PAUSE_ON_BATTERY, true)); - // 添加日志:记录从相册加载的图片数量 + // 添加日志:记录从相册加载的图片和视频数量 android.util.Log.i("WallpaperPreferences", "loadConfig: album=" + album.getName() + ", folders=" + album.getFolders().size() + - ", images=" + (imageUris != null ? imageUris.size() : 0)); + ", images=" + (imageUris != null ? imageUris.size() : 0) + + ", videos=" + (videoUris != null ? videoUris.size() : 0) + + ", videoEnabled=" + prefs.getBoolean(KEY_VIDEO_ENABLED, true)); } else { // 默认配置 config.setSelectedFolders(new ArrayList<>()); @@ -170,8 +172,13 @@ public class WallpaperPreferences { album.setVideoUris(videoUris != null ? new ArrayList<>(videoUris) : new ArrayList<>()); // 保存相册 + android.util.Log.i("WallpaperPreferences", "saveConfig: album=" + album.getName() + + ", folders=" + album.getFolders().size() + + ", images=" + album.getImageUris().size() + + ", videos=" + album.getVideoUris().size()); + albumPrefs.updateAlbum(album); - + // Save global video settings to SharedPreferences prefs.edit() .putBoolean(KEY_VIDEO_ENABLED, config.isVideoEnabled())