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 e147b2a..6467c1c 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 @@ -125,6 +125,10 @@ public class AutoWallpaperService extends WallpaperService { private boolean isCharging = true; // Default to charging to avoid pausing initially private boolean changeOnReturn = false; // 标志:是否因返回桌面而需要更换壁纸 + // 双击检测相关 + private long lastTapTime = 0; + private static final long DOUBLE_TAP_TIMEOUT = 300; // 双击间隔时间(毫秒) + public void handleBatteryChanged(boolean isCharging) { this.isCharging = isCharging; if (currentMedia != null && currentMedia.isVideo() && isPlayingVideo && visible) { @@ -897,5 +901,35 @@ public class AutoWallpaperService extends WallpaperService { canvas.drawText("No media selected", centerX, centerY, paint); canvas.drawText("or album disabled", centerX, centerY + 60, paint); } + + @Override + public void onTouchEvent(android.view.MotionEvent event) { + super.onTouchEvent(event); + + // 只处理 ACTION_DOWN 事件 + if (event.getAction() != android.view.MotionEvent.ACTION_DOWN) { + return; + } + + // 检查是否启用了双击功能 + AppConfig config = prefs.loadConfig(); + if (!config.isDoubleTapEnabled()) { + return; + } + + long currentTime = System.currentTimeMillis(); + long timeDiff = currentTime - lastTapTime; + + if (timeDiff < DOUBLE_TAP_TIMEOUT) { + // 检测到双击 + fileLogger.log(TAG, "Double tap detected, changing wallpaper"); + forceChangeNext = true; + handler.post(this::drawWallpaper); + lastTapTime = 0; // 重置,避免三击被识别为两次双击 + } else { + // 记录单击时间 + lastTapTime = currentTime; + } + } } } \ No newline at end of file