From d8fdafd489db6e8487bfa53432791e9e908a97fd Mon Sep 17 00:00:00 2001 From: hugh <1012760428@qq.com> Date: Sat, 31 Jan 2026 22:11:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=B9=B6=E5=AE=9E=E7=8E=B0=E5=9B=9B=E6=8C=87?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=BC=B9=E5=87=BA=E7=B3=BB=E7=BB=9F=E5=A3=81?= =?UTF-8?q?=E7=BA=B8=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 WallpaperMedia 构造器参数错误,提供完整的6个参数 - 修复 Toast 中的 context 引用,使用 AutoWallpaperService.this - 实现四指点击时弹出系统壁纸设置对话框 - 如果有固定壁纸,直接传入 URI 到系统壁纸设置 - 如果没有固定壁纸,恢复自动更新并显示提示 Co-Authored-By: Claude Sonnet 4.5 --- .../gk2/wallpaper/AutoWallpaperService.java | 78 ++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) 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 bfa8c05..229d28a 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 @@ -353,6 +353,35 @@ public class AutoWallpaperService extends WallpaperService { // Load current wallpaper config AppConfig config = prefs.loadConfig(); + // 检查是否启用了固定壁纸 + if (config.isFixedWallpaperEnabled() && config.getFixedWallpaperUri() != null) { + String fixedUri = config.getFixedWallpaperUri(); + fileLogger.log(TAG, "Fixed wallpaper enabled: " + fixedUri); + + // 停止视频播放 + stopVideo(); + + // 加载固定壁纸(仅支持图片) + // 从 URI 中提取文件名作为显示名称 + String displayName = "Fixed Wallpaper"; + if (fixedUri.contains("/")) { + String[] parts = fixedUri.split("/"); + displayName = parts[parts.length - 1]; + } + + WallpaperMedia fixedMedia = new WallpaperMedia( + fixedUri, + null, // folderPath + displayName, + System.currentTimeMillis(), // lastModified + 0, // fileSize + MediaType.IMAGE + ); + fileLogger.log(TAG, "Displaying fixed wallpaper: " + fixedUri); + loadAndDrawImageAsync(holder, fixedMedia, config, false); + return; + } + if (!config.isEnabled() || !hasAvailableMedia(config)) { Log.w(TAG, "Wallpaper not enabled or no media. Enabled: " + config.isEnabled() + ", HasMedia: " + hasAvailableMedia(config)); // 直接绘制占位符(不需要后台线程) @@ -946,7 +975,54 @@ public class AutoWallpaperService extends WallpaperService { public void onTouchEvent(android.view.MotionEvent event) { super.onTouchEvent(event); - // 只处理 ACTION_DOWN 事件 + // 检测多指点击(四指点击恢复自动更新) + int pointerCount = event.getPointerCount(); + int action = event.getAction() & android.view.MotionEvent.ACTION_MASK; + + if (pointerCount >= 4 && action == android.view.MotionEvent.ACTION_POINTER_DOWN) { + fileLogger.log(TAG, "Four-finger tap detected, launching wallpaper picker"); + + // 获取固定壁纸的 URI + AppConfig config = prefs.loadConfig(); + String fixedWallpaperUri = config.getFixedWallpaperUri(); + + if (fixedWallpaperUri != null && !fixedWallpaperUri.isEmpty()) { + // 有固定壁纸,直接启动系统壁纸设置并传入 URI + Uri uri = Uri.parse(fixedWallpaperUri); + + Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); + intent.addCategory(Intent.CATEGORY_DEFAULT); + intent.setDataAndType(uri, "image/*"); + intent.putExtra("mimeType", "image/*"); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + + try { + startActivity(intent); + fileLogger.log(TAG, "Launched system wallpaper picker with fixed wallpaper"); + } catch (Exception e) { + Log.e(TAG, "Failed to launch wallpaper picker", e); + fileLogger.error(TAG, "Failed to launch wallpaper picker: " + e.getMessage(), e); + } + } else { + // 没有固定壁纸,只恢复自动更新 + fileLogger.log(TAG, "No fixed wallpaper set, just resuming auto-update"); + + // 清除固定壁纸设置(确保干净) + config.setFixedWallpaperEnabled(false); + config.setFixedWallpaperUri(null); + prefs.saveConfig(config); + + // 恢复自动更新 + forceChangeNext = true; + handler.post(() -> { + android.widget.Toast.makeText(AutoWallpaperService.this, "已恢复自动更新", android.widget.Toast.LENGTH_SHORT).show(); + drawWallpaper(); + }); + } + return; + } + + // 只处理 ACTION_DOWN 事件(用于双击检测) if (event.getAction() != android.view.MotionEvent.ACTION_DOWN) { return; }