feat: 添加 WallpaperChangeReceiver 广播接收器
实现了接收定时任务的广播接收器,触发壁纸更新 - 接收 ACTION_CHANGE_WALLPAPER 广播 - 刷新当前壁纸 - 调度下一次壁纸更换 - 持久化配置支持 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cef3caf355
commit
10f96fa99d
1 file changed
+42
@@ -0,0 +1,42 @@
|
||||
package cn.hugh.bz.gk2.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import cn.hugh.bz.gk2.utils.AlarmScheduler;
|
||||
|
||||
public class WallpaperChangeReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "WallpaperChangeReceiver";
|
||||
public static final String ACTION_CHANGE_WALLPAPER = "cn.hugh.bz.gk2.ACTION_CHANGE_WALLPAPER";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (ACTION_CHANGE_WALLPAPER.equals(intent.getAction())) {
|
||||
Log.i(TAG, "Received wallpaper change request");
|
||||
|
||||
// Refresh wallpaper
|
||||
WallpaperRefreshHelper.refreshWallpaper(context);
|
||||
|
||||
// Schedule next change
|
||||
cn.hugh.bz.gk2.wallpaper.WallpaperPreferences prefs =
|
||||
new cn.hugh.bz.gk2.wallpaper.WallpaperPreferences(context);
|
||||
cn.hugh.bz.gk2.model.AppConfig config = prefs.loadConfig();
|
||||
|
||||
if (config.isEnabled()) {
|
||||
AlarmScheduler scheduler = new AlarmScheduler(context);
|
||||
scheduler.scheduleWallpaperChange(config.getIntervalMinutes());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper class to refresh wallpaper
|
||||
class WallpaperRefreshHelper {
|
||||
static void refreshWallpaper(Context context) {
|
||||
// Send broadcast to wallpaper service
|
||||
Intent intent = new Intent("cn.hugh.bz.gk2.ACTION_REFRESH_WALLPAPER");
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user