feat: 添加返回桌面更换壁纸配置开关
允许用户控制是否在返回桌面时自动更换壁纸,默认开启以提供更好的用户体验。 新增功能: - 添加 changeOnReturnToHome 配置项(默认开启) - 设置界面新增开关控件,支持用户自定义 - 优化壁纸服务逻辑,根据配置决定是否更换壁纸 - 关闭状态下复用当前壁纸,减少性能消耗 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d304297f2c
commit
a5797b08a8
6 files changed
+87
-8
No files matched your search
@@ -8,6 +8,7 @@ public class AppConfig {
|
|||||||
private int intervalMinutes;
|
private int intervalMinutes;
|
||||||
private boolean isEnabled;
|
private boolean isEnabled;
|
||||||
private int currentIndex;
|
private int currentIndex;
|
||||||
|
private boolean changeOnReturnToHome;
|
||||||
|
|
||||||
public AppConfig() {
|
public AppConfig() {
|
||||||
this.selectedFolders = new java.util.ArrayList<>();
|
this.selectedFolders = new java.util.ArrayList<>();
|
||||||
@@ -15,6 +16,7 @@ public class AppConfig {
|
|||||||
this.intervalMinutes = 30;
|
this.intervalMinutes = 30;
|
||||||
this.isEnabled = false;
|
this.isEnabled = false;
|
||||||
this.currentIndex = 0;
|
this.currentIndex = 0;
|
||||||
|
this.changeOnReturnToHome = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters and Setters
|
// Getters and Setters
|
||||||
@@ -32,4 +34,7 @@ public class AppConfig {
|
|||||||
|
|
||||||
public int getCurrentIndex() { return currentIndex; }
|
public int getCurrentIndex() { return currentIndex; }
|
||||||
public void setCurrentIndex(int index) { this.currentIndex = index; }
|
public void setCurrentIndex(int index) { this.currentIndex = index; }
|
||||||
|
|
||||||
|
public boolean isChangeOnReturnToHome() { return changeOnReturnToHome; }
|
||||||
|
public void setChangeOnReturnToHome(boolean changeOnReturnToHome) { this.changeOnReturnToHome = changeOnReturnToHome; }
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import android.widget.Button;
|
|||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
private RadioButton rbRandom;
|
private RadioButton rbRandom;
|
||||||
private SeekBar seekBarInterval;
|
private SeekBar seekBarInterval;
|
||||||
private TextView tvIntervalValue;
|
private TextView tvIntervalValue;
|
||||||
|
private Switch switchChangeOnReturn;
|
||||||
private Button btnSave;
|
private Button btnSave;
|
||||||
|
|
||||||
private WallpaperPreferences prefs;
|
private WallpaperPreferences prefs;
|
||||||
@@ -44,6 +46,7 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
rbRandom = findViewById(R.id.rbRandom);
|
rbRandom = findViewById(R.id.rbRandom);
|
||||||
seekBarInterval = findViewById(R.id.seekBarInterval);
|
seekBarInterval = findViewById(R.id.seekBarInterval);
|
||||||
tvIntervalValue = findViewById(R.id.tvIntervalValue);
|
tvIntervalValue = findViewById(R.id.tvIntervalValue);
|
||||||
|
switchChangeOnReturn = findViewById(R.id.switchChangeOnReturn);
|
||||||
btnSave = findViewById(R.id.btnSave);
|
btnSave = findViewById(R.id.btnSave);
|
||||||
|
|
||||||
seekBarInterval.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
seekBarInterval.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@@ -67,6 +70,7 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
rbRandom.setChecked(config.getPlayMode() == PlayMode.RANDOM);
|
rbRandom.setChecked(config.getPlayMode() == PlayMode.RANDOM);
|
||||||
seekBarInterval.setProgress(config.getIntervalMinutes());
|
seekBarInterval.setProgress(config.getIntervalMinutes());
|
||||||
tvIntervalValue.setText(config.getIntervalMinutes() + " 分钟");
|
tvIntervalValue.setText(config.getIntervalMinutes() + " 分钟");
|
||||||
|
switchChangeOnReturn.setChecked(config.isChangeOnReturnToHome());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveConfig() {
|
private void saveConfig() {
|
||||||
@@ -78,6 +82,9 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
int interval = seekBarInterval.getProgress();
|
int interval = seekBarInterval.getProgress();
|
||||||
config.setIntervalMinutes(interval);
|
config.setIntervalMinutes(interval);
|
||||||
|
|
||||||
|
// Update change on return to home
|
||||||
|
config.setChangeOnReturnToHome(switchChangeOnReturn.isChecked());
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
prefs.saveConfig(config);
|
prefs.saveConfig(config);
|
||||||
|
|
||||||
|
|||||||
@@ -130,15 +130,37 @@ public class AutoWallpaperService extends WallpaperService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperImage image = getNextWallpaper(config);
|
WallpaperImage image;
|
||||||
if (image != null) {
|
|
||||||
drawImage(canvas, image.getUri());
|
|
||||||
|
|
||||||
// Save config
|
// 核心逻辑:根据配置决定是否更换壁纸
|
||||||
prefs.saveConfig(config);
|
if (config.isChangeOnReturnToHome()) {
|
||||||
prefs.saveLastUri(image.getUri());
|
// 开启状态:每次返回桌面都更换到下一张
|
||||||
|
image = getNextWallpaper(config);
|
||||||
|
|
||||||
|
if (image != null) {
|
||||||
|
drawImage(canvas, image.getUri());
|
||||||
|
prefs.saveConfig(config);
|
||||||
|
prefs.saveLastUri(image.getUri());
|
||||||
|
} else {
|
||||||
|
drawPlaceholder(canvas);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
drawPlaceholder(canvas);
|
// 关闭状态:使用当前壁纸(不更换)
|
||||||
|
String lastUri = prefs.getLastUri();
|
||||||
|
if (lastUri != null) {
|
||||||
|
// 复用当前壁纸
|
||||||
|
drawImage(canvas, lastUri);
|
||||||
|
} else {
|
||||||
|
// 没有当前壁纸,使用下一张
|
||||||
|
image = getNextWallpaper(config);
|
||||||
|
if (image != null) {
|
||||||
|
drawImage(canvas, image.getUri());
|
||||||
|
prefs.saveConfig(config);
|
||||||
|
prefs.saveLastUri(image.getUri());
|
||||||
|
} else {
|
||||||
|
drawPlaceholder(canvas);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class WallpaperPreferences {
|
|||||||
private static final String KEY_ENABLED = "enabled";
|
private static final String KEY_ENABLED = "enabled";
|
||||||
private static final String KEY_CURRENT_INDEX = "current_index";
|
private static final String KEY_CURRENT_INDEX = "current_index";
|
||||||
private static final String KEY_LAST_URI = "last_uri";
|
private static final String KEY_LAST_URI = "last_uri";
|
||||||
|
private static final String KEY_CHANGE_ON_RETURN = "change_on_return_to_home";
|
||||||
|
|
||||||
private final SharedPreferences prefs;
|
private final SharedPreferences prefs;
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
@@ -46,6 +47,7 @@ public class WallpaperPreferences {
|
|||||||
config.setIntervalMinutes(prefs.getInt(KEY_INTERVAL, 30));
|
config.setIntervalMinutes(prefs.getInt(KEY_INTERVAL, 30));
|
||||||
config.setEnabled(prefs.getBoolean(KEY_ENABLED, false));
|
config.setEnabled(prefs.getBoolean(KEY_ENABLED, false));
|
||||||
config.setCurrentIndex(prefs.getInt(KEY_CURRENT_INDEX, 0));
|
config.setCurrentIndex(prefs.getInt(KEY_CURRENT_INDEX, 0));
|
||||||
|
config.setChangeOnReturnToHome(prefs.getBoolean(KEY_CHANGE_ON_RETURN, true));
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@@ -59,6 +61,7 @@ public class WallpaperPreferences {
|
|||||||
editor.putInt(KEY_INTERVAL, config.getIntervalMinutes());
|
editor.putInt(KEY_INTERVAL, config.getIntervalMinutes());
|
||||||
editor.putBoolean(KEY_ENABLED, config.isEnabled());
|
editor.putBoolean(KEY_ENABLED, config.isEnabled());
|
||||||
editor.putInt(KEY_CURRENT_INDEX, config.getCurrentIndex());
|
editor.putInt(KEY_CURRENT_INDEX, config.getCurrentIndex());
|
||||||
|
editor.putBoolean(KEY_CHANGE_ON_RETURN, config.isChangeOnReturnToHome());
|
||||||
|
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,13 +91,51 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvChangeOnReturnLabel"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/setting_change_on_return_title"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvIntervalValue"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvChangeOnReturnDesc"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/setting_change_on_return_desc"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="@android:color/darker_gray"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvChangeOnReturnLabel"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/switchChangeOnReturn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:checked="true"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvChangeOnReturnDesc"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnSave"
|
android:id="@+id/btnSave"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="保存"
|
android:text="保存"
|
||||||
android:layout_marginTop="24dp"
|
android:layout_marginTop="24dp"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tvIntervalValue"
|
app:layout_constraintTop_toBottomOf="@id/switchChangeOnReturn"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
|||||||
@@ -11,4 +11,8 @@
|
|||||||
<string name="status_disabled">已停止</string>
|
<string name="status_disabled">已停止</string>
|
||||||
<string name="next_change">下次更换:%d 分钟</string>
|
<string name="next_change">下次更换:%d 分钟</string>
|
||||||
<string name="no_folders">未选择文件夹</string>
|
<string name="no_folders">未选择文件夹</string>
|
||||||
|
|
||||||
|
<!-- 返回桌面更换壁纸 -->
|
||||||
|
<string name="setting_change_on_return_title">返回桌面更换壁纸</string>
|
||||||
|
<string name="setting_change_on_return_desc">每次返回桌面或解锁时自动更换到下一张壁纸</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in new issue
Block a user