fix: 修复编译错误并实现四指点击弹出系统壁纸设置

- 修复 WallpaperMedia 构造器参数错误,提供完整的6个参数
- 修复 Toast 中的 context 引用,使用 AutoWallpaperService.this
- 实现四指点击时弹出系统壁纸设置对话框
- 如果有固定壁纸,直接传入 URI 到系统壁纸设置
- 如果没有固定壁纸,恢复自动更新并显示提示

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hughhuangandClaude Sonnet 4.5 committed 2026-01-31 22:11:53 +08:00
1 parent 9644982c43
commit d8fdafd489
1 file changed
+77 -1
@@ -353,6 +353,35 @@ public class AutoWallpaperService extends WallpaperService {
// Load current wallpaper config // Load current wallpaper config
AppConfig config = prefs.loadConfig(); 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)) { if (!config.isEnabled() || !hasAvailableMedia(config)) {
Log.w(TAG, "Wallpaper not enabled or no media. Enabled: " + config.isEnabled() + ", HasMedia: " + 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) { public void onTouchEvent(android.view.MotionEvent event) {
super.onTouchEvent(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) { if (event.getAction() != android.view.MotionEvent.ACTION_DOWN) {
return; return;
} }