feat: 重构为 Fragment + 底部导航架构,新增当前壁纸页面和现代化 UI 设计
- 使用 ViewPager2 + BottomNavigationView 实现三个标签页(主页、壁纸、设置) - 主页采用 Material Design 3 风格,卡片式布局,视觉层次清晰 - 新增当前壁纸页面,支持大图预览、立即更换、下一张切换、相册打开 - 设置页面改为实时保存,移除保存按钮提升用户体验 - 修复立即更换和定时器功能,统一壁纸更换逻辑 - 新增 ImageLoader 工具类,优化图片加载和内存管理 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a5797b08a8
commit
24dd91aceb
29 files changed
+1779
-503
No files matched your search
@@ -6,7 +6,19 @@
|
||||
"Skill(superpowers:subagent-driven-development)",
|
||||
"Bash(git init:*)",
|
||||
"Bash(git add:*)",
|
||||
"Bash(git commit:*)"
|
||||
"Bash(git commit:*)",
|
||||
"Bash(git push:*)",
|
||||
"Bash(dir:*)",
|
||||
"mcp__plugin_context7_context7__resolve-library-id",
|
||||
"mcp__plugin_playwright_playwright__browser_navigate",
|
||||
"mcp__plugin_playwright_playwright__browser_type",
|
||||
"mcp__plugin_playwright_playwright__browser_click",
|
||||
"mcp__plugin_playwright_playwright__browser_snapshot",
|
||||
"mcp__plugin_serena_serena__initial_instructions",
|
||||
"mcp__plugin_serena_serena__get_symbols_overview",
|
||||
"mcp__plugin_serena_serena__find_file",
|
||||
"Bash(./gradlew assembleDebug --stacktrace 2>&1:*)",
|
||||
"Bash(gradle assembleDebug:*)"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -29,17 +29,6 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Settings Activity -->
|
||||
<activity
|
||||
android:name=".ui.SettingsActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/settings"
|
||||
android:parentActivityName=".ui.MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ui.MainActivity" />
|
||||
</activity>
|
||||
|
||||
<!-- Wallpaper Service -->
|
||||
<service
|
||||
android:name=".wallpaper.AutoWallpaperService"
|
||||
|
||||
@@ -9,17 +9,27 @@ 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";
|
||||
// 内部广播:用于通知壁纸服务更换壁纸(避免循环)
|
||||
private static final String ACTION_REFRESH_WALLPAPER_SERVICE = "cn.hugh.bz.gk2.ACTION_REFRESH_WALLPAPER_SERVICE";
|
||||
public static final String EXTRA_FORCE_CHANGE = "force_change";
|
||||
|
||||
@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);
|
||||
// 提取 force_change 标志,默认为 true(用户主动触发的更换)
|
||||
boolean forceChange = intent.getBooleanExtra(EXTRA_FORCE_CHANGE, true);
|
||||
Log.i(TAG, "Force change: " + forceChange);
|
||||
|
||||
// Schedule next change
|
||||
// 转发广播给 AutoWallpaperService,使用不同的 ACTION 避免循环
|
||||
Intent serviceIntent = new Intent(ACTION_REFRESH_WALLPAPER_SERVICE);
|
||||
serviceIntent.putExtra(EXTRA_FORCE_CHANGE, forceChange);
|
||||
context.sendBroadcast(serviceIntent);
|
||||
|
||||
// 如果服务已启用,调度下一次更换
|
||||
cn.hugh.bz.gk2.wallpaper.WallpaperPreferences prefs =
|
||||
new cn.hugh.bz.gk2.wallpaper.WallpaperPreferences(context);
|
||||
cn.hugh.bz.gk2.model.AppConfig config = prefs.loadConfig();
|
||||
@@ -32,11 +42,3 @@ public class WallpaperChangeReceiver extends BroadcastReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
package cn.hugh.bz.gk2.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import cn.hugh.bz.gk2.R;
|
||||
import cn.hugh.bz.gk2.utils.ImageLoader;
|
||||
import cn.hugh.bz.gk2.wallpaper.WallpaperPreferences;
|
||||
|
||||
/**
|
||||
* 当前壁纸 Fragment
|
||||
* 显示当前壁纸大图预览、壁纸信息和操作按钮
|
||||
*/
|
||||
public class CurrentWallpaperFragment extends Fragment {
|
||||
|
||||
private ImageView ivWallpaper;
|
||||
private TextView tvWallpaperPath;
|
||||
private TextView tvWallpaperSize;
|
||||
private Button btnChangeNow;
|
||||
private Button btnNext;
|
||||
private Button btnOpenInGallery;
|
||||
|
||||
private WallpaperPreferences prefs;
|
||||
private ImageLoader imageLoader;
|
||||
private cn.hugh.bz.gk2.utils.ImageScanner scanner;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_current_wallpaper, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
prefs = new WallpaperPreferences(requireContext());
|
||||
imageLoader = new ImageLoader(requireContext());
|
||||
scanner = new cn.hugh.bz.gk2.utils.ImageScanner(requireContext());
|
||||
|
||||
initViews(view);
|
||||
loadCurrentWallpaper();
|
||||
}
|
||||
|
||||
private void initViews(View view) {
|
||||
ivWallpaper = view.findViewById(R.id.ivWallpaper);
|
||||
tvWallpaperPath = view.findViewById(R.id.tvWallpaperPath);
|
||||
tvWallpaperSize = view.findViewById(R.id.tvWallpaperSize);
|
||||
btnChangeNow = view.findViewById(R.id.btnChangeNow);
|
||||
btnNext = view.findViewById(R.id.btnNext);
|
||||
btnOpenInGallery = view.findViewById(R.id.btnOpenInGallery);
|
||||
|
||||
btnChangeNow.setOnClickListener(v -> changeWallpaperNow());
|
||||
btnNext.setOnClickListener(v -> showNextWallpaper());
|
||||
btnOpenInGallery.setOnClickListener(v -> openInGallery());
|
||||
ivWallpaper.setOnClickListener(v -> openInGallery());
|
||||
}
|
||||
|
||||
private void loadCurrentWallpaper() {
|
||||
String currentUri = prefs.getLastUri();
|
||||
|
||||
if (currentUri == null || currentUri.isEmpty()) {
|
||||
showNoWallpaper();
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示加载状态
|
||||
tvWallpaperPath.setText("正在加载壁纸...");
|
||||
|
||||
// 在后台线程加载图片
|
||||
new Thread(() -> {
|
||||
Bitmap bitmap = imageLoader.loadImage(currentUri, 1080, 1920);
|
||||
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
if (bitmap != null) {
|
||||
ivWallpaper.setImageBitmap(bitmap);
|
||||
tvWallpaperPath.setText(getDisplayName(currentUri));
|
||||
tvWallpaperSize.setText(bitmap.getWidth() + " x " + bitmap.getHeight());
|
||||
} else {
|
||||
showError();
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void showNoWallpaper() {
|
||||
ivWallpaper.setImageDrawable(null);
|
||||
tvWallpaperPath.setText("尚未设置壁纸");
|
||||
tvWallpaperSize.setText("");
|
||||
btnChangeNow.setEnabled(false);
|
||||
btnNext.setEnabled(false);
|
||||
btnOpenInGallery.setEnabled(false);
|
||||
}
|
||||
|
||||
private void showError() {
|
||||
ivWallpaper.setImageDrawable(null);
|
||||
tvWallpaperPath.setText("加载壁纸失败");
|
||||
tvWallpaperSize.setText("");
|
||||
btnChangeNow.setEnabled(false);
|
||||
btnNext.setEnabled(false);
|
||||
btnOpenInGallery.setEnabled(false);
|
||||
}
|
||||
|
||||
private void changeWallpaperNow() {
|
||||
cn.hugh.bz.gk2.model.AppConfig config = prefs.loadConfig();
|
||||
|
||||
if (config.getSelectedFolders().isEmpty()) {
|
||||
Toast.makeText(requireContext(), "请先选择文件夹", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// 直接获取下一张壁纸,与"下一张"按钮相同的逻辑
|
||||
cn.hugh.bz.gk2.model.WallpaperImage nextImage = null;
|
||||
String lastUri = prefs.getLastUri();
|
||||
|
||||
if (config.getPlayMode() == cn.hugh.bz.gk2.model.PlayMode.SEQUENTIAL) {
|
||||
// 顺序模式:获取下一张
|
||||
int index = config.getCurrentIndex();
|
||||
nextImage = scanner.getImageAtIndex(config.getSelectedFolders(), index);
|
||||
if (nextImage != null) {
|
||||
config.setCurrentIndex(index + 1);
|
||||
}
|
||||
} else {
|
||||
// 随机模式:随机选择一张
|
||||
nextImage = scanner.getRandomImage(config.getSelectedFolders(), lastUri);
|
||||
}
|
||||
|
||||
if (nextImage != null) {
|
||||
// 保存新壁纸配置
|
||||
prefs.saveConfig(config);
|
||||
prefs.saveLastUri(nextImage.getUri());
|
||||
|
||||
// 发送广播通知壁纸服务更新显示
|
||||
Intent intent = new Intent("cn.hugh.bz.gk2.ACTION_CHANGE_WALLPAPER");
|
||||
intent.putExtra("force_change", false); // 只通知更新,不重新选择壁纸
|
||||
requireActivity().sendBroadcast(intent);
|
||||
|
||||
Toast.makeText(requireContext(), "壁纸已更换", Toast.LENGTH_SHORT).show();
|
||||
|
||||
// 延迟刷新预览
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
loadCurrentWallpaper();
|
||||
}, 500);
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "没有更多壁纸了", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void showNextWallpaper() {
|
||||
cn.hugh.bz.gk2.model.AppConfig config = prefs.loadConfig();
|
||||
|
||||
if (config.getSelectedFolders().isEmpty()) {
|
||||
Toast.makeText(requireContext(), "请先选择文件夹", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
cn.hugh.bz.gk2.model.WallpaperImage nextImage = null;
|
||||
String lastUri = prefs.getLastUri();
|
||||
|
||||
if (config.getPlayMode() == cn.hugh.bz.gk2.model.PlayMode.SEQUENTIAL) {
|
||||
// 顺序模式:获取下一张
|
||||
int index = config.getCurrentIndex();
|
||||
nextImage = scanner.getImageAtIndex(config.getSelectedFolders(), index);
|
||||
if (nextImage != null) {
|
||||
config.setCurrentIndex(index + 1);
|
||||
}
|
||||
} else {
|
||||
// 随机模式:随机选择一张
|
||||
nextImage = scanner.getRandomImage(config.getSelectedFolders(), lastUri);
|
||||
}
|
||||
|
||||
if (nextImage != null) {
|
||||
// 保存新壁纸配置
|
||||
prefs.saveConfig(config);
|
||||
prefs.saveLastUri(nextImage.getUri());
|
||||
|
||||
// 发送广播通知壁纸服务更新显示
|
||||
Intent intent = new Intent("cn.hugh.bz.gk2.ACTION_CHANGE_WALLPAPER");
|
||||
intent.putExtra("force_change", false); // 只通知更新,不重新选择壁纸
|
||||
requireActivity().sendBroadcast(intent);
|
||||
|
||||
Toast.makeText(requireContext(), "已切换到下一张", Toast.LENGTH_SHORT).show();
|
||||
|
||||
// 延迟刷新预览
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
loadCurrentWallpaper();
|
||||
}, 500);
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "没有更多壁纸了", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void openInGallery() {
|
||||
String currentUri = prefs.getLastUri();
|
||||
if (currentUri != null) {
|
||||
try {
|
||||
Uri uri = Uri.parse(currentUri);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(requireContext(), "无法打开相册", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getDisplayName(String uriString) {
|
||||
if (uriString == null || uriString.isEmpty()) {
|
||||
return "未知壁纸";
|
||||
}
|
||||
|
||||
try {
|
||||
Uri uri = Uri.parse(uriString);
|
||||
String path = uri.getLastPathSegment();
|
||||
if (path != null) {
|
||||
// 处理 content://com.android.externalstorage.documents/tree/primary%3ADCIM 这种格式
|
||||
if (path.contains(":")) {
|
||||
String[] parts = path.split(":");
|
||||
if (parts.length > 1) {
|
||||
path = parts[1];
|
||||
}
|
||||
}
|
||||
// 移除文件扩展名
|
||||
if (path.contains("/")) {
|
||||
String[] segments = path.split("/");
|
||||
path = segments[segments.length - 1];
|
||||
}
|
||||
return path;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
return "当前壁纸";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
loadCurrentWallpaper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
// 释放图片资源
|
||||
if (ivWallpaper != null) {
|
||||
ivWallpaper.setImageDrawable(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,458 @@
|
||||
package cn.hugh.bz.gk2.ui;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hugh.bz.gk2.R;
|
||||
import cn.hugh.bz.gk2.model.AppConfig;
|
||||
import cn.hugh.bz.gk2.model.PlayMode;
|
||||
import cn.hugh.bz.gk2.utils.AlarmScheduler;
|
||||
import cn.hugh.bz.gk2.utils.ImageScanner;
|
||||
import cn.hugh.bz.gk2.wallpaper.WallpaperPreferences;
|
||||
|
||||
/**
|
||||
* 主页 Fragment
|
||||
* 负责显示服务状态、文件夹选择、启用/禁用服务等功能
|
||||
*/
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
private TextView tvStatus;
|
||||
private View statusIndicator;
|
||||
private TextView tvFolderInfo;
|
||||
private Button btnToggle;
|
||||
private Button btnChangeNow;
|
||||
private Button btnSelectFolders;
|
||||
private ListView lvFolders;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
private WallpaperPreferences prefs;
|
||||
private AppConfig config;
|
||||
private ImageScanner scanner;
|
||||
private FolderAdapter folderAdapter;
|
||||
|
||||
// 文件夹选择回调接口
|
||||
public interface FolderPickerCallback {
|
||||
void launchFolderPicker(FolderPickerResultCallback callback);
|
||||
}
|
||||
|
||||
public interface FolderPickerResultCallback {
|
||||
void onFolderPicked(String uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_home, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
prefs = new WallpaperPreferences(requireContext());
|
||||
config = prefs.loadConfig();
|
||||
scanner = new ImageScanner(requireContext());
|
||||
|
||||
initViews(view);
|
||||
updateUI();
|
||||
|
||||
// 首次启动显示引导
|
||||
showFirstRunGuide();
|
||||
}
|
||||
|
||||
/**
|
||||
* 首次启动显示使用指南
|
||||
*/
|
||||
private void showFirstRunGuide() {
|
||||
boolean hasShownGuide = prefs.getBoolean("first_run_guide_shown", false);
|
||||
|
||||
if (!hasShownGuide) {
|
||||
new AlertDialog.Builder(requireContext())
|
||||
.setTitle("欢迎使用 BzForGk2")
|
||||
.setMessage(
|
||||
"使用步骤:\n\n" +
|
||||
"1. 点击「选择文件夹」添加图片文件夹\n" +
|
||||
"2. 点击「启用」按钮\n" +
|
||||
"3. 在弹出的壁纸选择界面选择「BzForGk2」\n" +
|
||||
"4. 设置完成!壁纸会自动更换"
|
||||
)
|
||||
.setPositiveButton("知道了", (dialog, which) -> {
|
||||
prefs.putBoolean("first_run_guide_shown", true);
|
||||
})
|
||||
.setCancelable(false)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void initViews(View view) {
|
||||
tvStatus = view.findViewById(R.id.tvStatus);
|
||||
statusIndicator = view.findViewById(R.id.statusIndicator);
|
||||
tvFolderInfo = view.findViewById(R.id.tvFolderInfo);
|
||||
btnToggle = view.findViewById(R.id.btnToggle);
|
||||
btnChangeNow = view.findViewById(R.id.btnChangeNow);
|
||||
btnSelectFolders = view.findViewById(R.id.btnSelectFolders);
|
||||
lvFolders = view.findViewById(R.id.lvFolders);
|
||||
progressBar = view.findViewById(R.id.progressBar);
|
||||
|
||||
// 设置文件夹列表适配器
|
||||
folderAdapter = new FolderAdapter(requireContext(), config.getSelectedFolders(), this::removeFolder);
|
||||
lvFolders.setAdapter(folderAdapter);
|
||||
|
||||
btnToggle.setOnClickListener(v -> toggleService());
|
||||
btnChangeNow.setOnClickListener(v -> changeWallpaperNow());
|
||||
btnSelectFolders.setOnClickListener(v -> openFolderPicker());
|
||||
}
|
||||
|
||||
private void toggleService() {
|
||||
if (config.getSelectedFolders().isEmpty()) {
|
||||
Toast.makeText(requireContext(), "请先选择文件夹", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean newState = !config.isEnabled();
|
||||
|
||||
if (newState) {
|
||||
// 每次启用都弹出壁纸设置引导
|
||||
showSetWallpaperDialog();
|
||||
// 注意:不在这里设置 enabled,而是在用户设置壁纸后再设置
|
||||
} else {
|
||||
config.setEnabled(newState);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
AlarmScheduler scheduler = new AlarmScheduler(requireContext());
|
||||
scheduler.cancelSchedule();
|
||||
Toast.makeText(requireContext(), "已禁用", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示引导设置壁纸的对话框
|
||||
*/
|
||||
private void showSetWallpaperDialog() {
|
||||
new AlertDialog.Builder(requireContext())
|
||||
.setTitle("设置动态壁纸")
|
||||
.setMessage("点击\"确定\"后将打开壁纸选择界面,请选择\"BzForGk2\"作为动态壁纸。\n\n设置完成后返回应用即可自动启用。")
|
||||
.setPositiveButton("确定", (dialog, which) -> {
|
||||
openWallpaperSelector();
|
||||
// 启用服务
|
||||
config.setEnabled(true);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
AlarmScheduler scheduler = new AlarmScheduler(requireContext());
|
||||
scheduler.scheduleWallpaperChange(config.getIntervalMinutes());
|
||||
|
||||
Toast.makeText(requireContext(), "已启用,请选择壁纸", Toast.LENGTH_LONG).show();
|
||||
updateUI();
|
||||
})
|
||||
.setNegativeButton("取消", null)
|
||||
.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开系统壁纸选择界面
|
||||
*/
|
||||
private void openWallpaperSelector() {
|
||||
try {
|
||||
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
|
||||
intent.putExtra(
|
||||
WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
|
||||
new android.content.ComponentName(requireContext(), cn.hugh.bz.gk2.wallpaper.AutoWallpaperService.class)
|
||||
);
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
// 如果上述方法失败,尝试打开壁纸选择器
|
||||
try {
|
||||
Intent intent = new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
|
||||
startActivity(intent);
|
||||
Toast.makeText(requireContext(), "请选择 BzForGk2 动态壁纸", Toast.LENGTH_LONG).show();
|
||||
} catch (Exception ex) {
|
||||
// 最后的备用方案:打开壁纸设置页面
|
||||
try {
|
||||
Intent intent = new Intent("android.settings.WALLPAPER_SETTINGS");
|
||||
startActivity(intent);
|
||||
Toast.makeText(requireContext(), "请选择 动态壁纸 → BzForGk2", Toast.LENGTH_LONG).show();
|
||||
} catch (Exception exc) {
|
||||
Toast.makeText(requireContext(), "无法打开壁纸设置,请手动去系统设置中选择", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void changeWallpaperNow() {
|
||||
if (config.getSelectedFolders().isEmpty()) {
|
||||
Toast.makeText(requireContext(), "请先选择文件夹", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// 直接获取下一张壁纸,与"下一张"按钮相同的逻辑
|
||||
cn.hugh.bz.gk2.model.WallpaperImage nextImage = null;
|
||||
String lastUri = prefs.getLastUri();
|
||||
|
||||
if (config.getPlayMode() == cn.hugh.bz.gk2.model.PlayMode.SEQUENTIAL) {
|
||||
// 顺序模式:获取下一张
|
||||
int index = config.getCurrentIndex();
|
||||
nextImage = scanner.getImageAtIndex(config.getSelectedFolders(), index);
|
||||
if (nextImage != null) {
|
||||
config.setCurrentIndex(index + 1);
|
||||
}
|
||||
} else {
|
||||
// 随机模式:随机选择一张
|
||||
nextImage = scanner.getRandomImage(config.getSelectedFolders(), lastUri);
|
||||
}
|
||||
|
||||
if (nextImage != null) {
|
||||
// 保存新壁纸配置
|
||||
prefs.saveConfig(config);
|
||||
prefs.saveLastUri(nextImage.getUri());
|
||||
|
||||
// 发送广播通知壁纸服务更新显示
|
||||
Intent intent = new Intent("cn.hugh.bz.gk2.ACTION_CHANGE_WALLPAPER");
|
||||
intent.putExtra("force_change", false); // 只通知更新,不重新选择壁纸
|
||||
requireActivity().sendBroadcast(intent);
|
||||
|
||||
Toast.makeText(requireContext(), "壁纸已更换", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "没有更多壁纸了", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void openFolderPicker() {
|
||||
// 通过 MainActivity 启动文件夹选择器
|
||||
if (getActivity() instanceof FolderPickerCallback) {
|
||||
((FolderPickerCallback) getActivity()).launchFolderPicker(uri -> {
|
||||
addFolder(uri);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void addFolder(String folderPath) {
|
||||
if (folderPath == null || config.getSelectedFolders().contains(folderPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
config.getSelectedFolders().add(folderPath);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
// 异步扫描文件夹
|
||||
Toast.makeText(requireContext(), "正在扫描文件夹...", Toast.LENGTH_SHORT).show();
|
||||
new Thread(() -> {
|
||||
scanner.scanFolder(folderPath);
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
updateUI();
|
||||
Toast.makeText(requireContext(), "已添加文件夹", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void removeFolder(int position) {
|
||||
if (position >= 0 && position < config.getSelectedFolders().size()) {
|
||||
String folderPath = config.getSelectedFolders().get(position);
|
||||
config.getSelectedFolders().remove(position);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
updateUI();
|
||||
Toast.makeText(requireContext(), "已移除文件夹", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
// Update status
|
||||
if (config.isEnabled()) {
|
||||
tvStatus.setText(R.string.status_enabled);
|
||||
btnToggle.setText(R.string.disable);
|
||||
btnChangeNow.setEnabled(true);
|
||||
// 更新状态指示器
|
||||
if (statusIndicator != null) {
|
||||
statusIndicator.setBackgroundResource(R.drawable.status_indicator_enabled);
|
||||
}
|
||||
} else {
|
||||
tvStatus.setText(R.string.status_disabled);
|
||||
btnToggle.setText(R.string.enable);
|
||||
btnChangeNow.setEnabled(false);
|
||||
// 更新状态指示器
|
||||
if (statusIndicator != null) {
|
||||
statusIndicator.setBackgroundResource(R.drawable.status_indicator_disabled);
|
||||
}
|
||||
}
|
||||
|
||||
// Update folder info - 使用缓存的数量,不重新扫描
|
||||
if (config.getSelectedFolders().isEmpty()) {
|
||||
tvFolderInfo.setText(R.string.no_folders);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
} else {
|
||||
// 显示进度条
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
progressBar.setIndeterminate(true);
|
||||
|
||||
// 异步获取图片数量
|
||||
tvFolderInfo.setText(String.format("已选择 %d 个文件夹,正在统计图片...",
|
||||
config.getSelectedFolders().size()));
|
||||
|
||||
new Thread(() -> {
|
||||
int imageCount = scanner.getTotalImageCount(config.getSelectedFolders());
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
tvFolderInfo.setText(String.format("已选择 %d 个文件夹,共 %d 张图片",
|
||||
config.getSelectedFolders().size(), imageCount));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
// Update folder list adapter
|
||||
if (folderAdapter != null) {
|
||||
folderAdapter.updateFolders(config.getSelectedFolders());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
config = prefs.loadConfig();
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件夹列表适配器
|
||||
*/
|
||||
private static class FolderAdapter extends ArrayAdapter<String> {
|
||||
private final Context context;
|
||||
private List<String> folders;
|
||||
private final java.util.Map<String, Integer> imageCounts = new java.util.HashMap<>();
|
||||
private ImageScanner scanner;
|
||||
private OnFolderRemoveListener removeListener;
|
||||
|
||||
public interface OnFolderRemoveListener {
|
||||
void onFolderRemove(int position);
|
||||
}
|
||||
|
||||
public FolderAdapter(Context context, List<String> folders, OnFolderRemoveListener listener) {
|
||||
super(context, R.layout.item_folder_card, folders);
|
||||
this.context = context;
|
||||
this.folders = new ArrayList<>(folders);
|
||||
this.scanner = new ImageScanner(context);
|
||||
this.removeListener = listener;
|
||||
// 异步加载图片数量
|
||||
loadImageCounts();
|
||||
}
|
||||
|
||||
public void updateFolders(List<String> newFolders) {
|
||||
this.folders = new ArrayList<>(newFolders);
|
||||
clear();
|
||||
addAll(newFolders);
|
||||
// 异步加载图片数量
|
||||
loadImageCounts();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void loadImageCounts() {
|
||||
new Thread(() -> {
|
||||
for (String folderUri : folders) {
|
||||
if (!imageCounts.containsKey(folderUri)) {
|
||||
int count = scanner.scanFolder(folderUri).size();
|
||||
imageCounts.put(folderUri, count);
|
||||
// 在主线程更新 UI
|
||||
new android.os.Handler(android.os.Looper.getMainLooper()).post(() ->
|
||||
notifyDataSetChanged()
|
||||
);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.item_folder_card, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.tvFolderName = convertView.findViewById(R.id.tvFolderName);
|
||||
holder.tvFolderPath = convertView.findViewById(R.id.tvFolderPath);
|
||||
holder.tvImageCount = convertView.findViewById(R.id.tvImageCount);
|
||||
holder.btnRemove = convertView.findViewById(R.id.btnRemove);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
String folderUri = folders.get(position);
|
||||
|
||||
// 解析 URI 获取文件夹名称
|
||||
Uri uri = Uri.parse(folderUri);
|
||||
String folderName = getLastPathSegment(uri);
|
||||
holder.tvFolderName.setText(folderName);
|
||||
holder.tvFolderPath.setText(folderUri);
|
||||
|
||||
// 使用缓存的图片数量
|
||||
Integer count = imageCounts.get(folderUri);
|
||||
if (count != null) {
|
||||
holder.tvImageCount.setText(count + " 张图片");
|
||||
} else {
|
||||
holder.tvImageCount.setText("正在扫描...");
|
||||
}
|
||||
|
||||
// 移除按钮
|
||||
final int positionFinal = position;
|
||||
holder.btnRemove.setOnClickListener(v -> {
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle("移除文件夹")
|
||||
.setMessage("确定要移除这个文件夹吗?")
|
||||
.setPositiveButton("确定", (dialog, which) -> {
|
||||
if (removeListener != null) {
|
||||
removeListener.onFolderRemove(positionFinal);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("取消", null)
|
||||
.show();
|
||||
});
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private String getLastPathSegment(Uri uri) {
|
||||
String path = uri.getLastPathSegment();
|
||||
if (path != null) {
|
||||
// 处理 content://com.android.externalstorage.documents/tree/primary%3ADCIM 这种格式
|
||||
if (path.contains(":")) {
|
||||
String[] parts = path.split(":");
|
||||
if (parts.length > 1) {
|
||||
return parts[1];
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
return "未知文件夹";
|
||||
}
|
||||
|
||||
// ViewHolder 模式优化
|
||||
private static class ViewHolder {
|
||||
TextView tvFolderName;
|
||||
TextView tvFolderPath;
|
||||
TextView tvImageCount;
|
||||
Button btnRemove;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +1,53 @@
|
||||
package cn.hugh.bz.gk2.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.google.android.material.navigation.NavigationBarView;
|
||||
|
||||
import cn.hugh.bz.gk2.R;
|
||||
import cn.hugh.bz.gk2.model.AppConfig;
|
||||
import cn.hugh.bz.gk2.model.PlayMode;
|
||||
import cn.hugh.bz.gk2.utils.AlarmScheduler;
|
||||
import cn.hugh.bz.gk2.utils.ImageScanner;
|
||||
import cn.hugh.bz.gk2.wallpaper.WallpaperPreferences;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
/**
|
||||
* 主 Activity
|
||||
* 作为 Fragment 容器,托管 ViewPager2 和 BottomNavigationView
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity implements HomeFragment.FolderPickerCallback {
|
||||
|
||||
private TextView tvStatus;
|
||||
private TextView tvFolderInfo;
|
||||
private Button btnToggle;
|
||||
private Button btnChangeNow;
|
||||
private Button btnSelectFolders;
|
||||
private Button btnSettings;
|
||||
private ListView lvFolders;
|
||||
private android.widget.ProgressBar progressBar;
|
||||
|
||||
private WallpaperPreferences prefs;
|
||||
private AppConfig config;
|
||||
private ImageScanner scanner;
|
||||
private FolderAdapter folderAdapter;
|
||||
private ViewPager2 viewPager;
|
||||
private BottomNavigationView bottomNav;
|
||||
private ViewPagerAdapter adapter;
|
||||
|
||||
// Folder picker launcher
|
||||
private final ActivityResultLauncher<Intent> folderPickerLauncher =
|
||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
private ActivityResultLauncher<Intent> folderPickerLauncher;
|
||||
private HomeFragment.FolderPickerResultCallback currentCallback;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
initFolderPickerLauncher();
|
||||
initViews();
|
||||
setupViewPager();
|
||||
setupBottomNav();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化文件夹选择器
|
||||
*/
|
||||
private void initFolderPickerLauncher() {
|
||||
folderPickerLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> {
|
||||
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
|
||||
Uri uri = result.getData().getData();
|
||||
if (uri != null) {
|
||||
@@ -62,363 +58,45 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// 保存完整的 URI 字符串
|
||||
String folderUri = uri.toString();
|
||||
addFolder(folderUri);
|
||||
|
||||
// 回调给 HomeFragment
|
||||
if (currentCallback != null) {
|
||||
currentCallback.onFolderPicked(folderUri);
|
||||
currentCallback = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
prefs = new WallpaperPreferences(this);
|
||||
config = prefs.loadConfig();
|
||||
scanner = new ImageScanner(this);
|
||||
|
||||
initViews();
|
||||
updateUI();
|
||||
|
||||
// 首次启动显示引导
|
||||
showFirstRunGuide();
|
||||
}
|
||||
|
||||
/**
|
||||
* 首次启动显示使用指南
|
||||
*/
|
||||
private void showFirstRunGuide() {
|
||||
boolean hasShownGuide = prefs.getBoolean("first_run_guide_shown", false);
|
||||
|
||||
if (!hasShownGuide) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("欢迎使用 BzForGk2")
|
||||
.setMessage(
|
||||
"使用步骤:\n\n" +
|
||||
"1. 点击「选择文件夹」添加图片文件夹\n" +
|
||||
"2. 点击「启用」按钮\n" +
|
||||
"3. 在弹出的壁纸选择界面选择「BzForGk2」\n" +
|
||||
"4. 设置完成!壁纸会自动更换"
|
||||
)
|
||||
.setPositiveButton("知道了", (dialog, which) -> {
|
||||
prefs.putBoolean("first_run_guide_shown", true);
|
||||
})
|
||||
.setCancelable(false)
|
||||
.show();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
tvStatus = findViewById(R.id.tvStatus);
|
||||
tvFolderInfo = findViewById(R.id.tvFolderInfo);
|
||||
btnToggle = findViewById(R.id.btnToggle);
|
||||
btnChangeNow = findViewById(R.id.btnChangeNow);
|
||||
btnSelectFolders = findViewById(R.id.btnSelectFolders);
|
||||
btnSettings = findViewById(R.id.btnSettings);
|
||||
lvFolders = findViewById(R.id.lvFolders);
|
||||
progressBar = findViewById(R.id.progressBar);
|
||||
|
||||
// 设置文件夹列表适配器
|
||||
folderAdapter = new FolderAdapter(this, config.getSelectedFolders());
|
||||
lvFolders.setAdapter(folderAdapter);
|
||||
|
||||
btnToggle.setOnClickListener(v -> toggleService());
|
||||
btnChangeNow.setOnClickListener(v -> changeWallpaperNow());
|
||||
btnSelectFolders.setOnClickListener(v -> openFolderPicker());
|
||||
btnSettings.setOnClickListener(v -> openSettings());
|
||||
viewPager = findViewById(R.id.viewPager);
|
||||
bottomNav = findViewById(R.id.bottomNav);
|
||||
}
|
||||
|
||||
private void toggleService() {
|
||||
if (config.getSelectedFolders().isEmpty()) {
|
||||
Toast.makeText(this, "请先选择文件夹", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
private void setupViewPager() {
|
||||
adapter = new ViewPagerAdapter(this);
|
||||
viewPager.setAdapter(adapter);
|
||||
viewPager.setUserInputEnabled(false); // 禁用滑动切换,只能通过底部导航切换
|
||||
}
|
||||
|
||||
boolean newState = !config.isEnabled();
|
||||
|
||||
if (newState) {
|
||||
// 每次启用都弹出壁纸设置引导
|
||||
showSetWallpaperDialog();
|
||||
// 注意:不在这里设置 enabled,而是在用户设置壁纸后再设置
|
||||
} else {
|
||||
config.setEnabled(newState);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
AlarmScheduler scheduler = new AlarmScheduler(this);
|
||||
scheduler.cancelSchedule();
|
||||
Toast.makeText(this, "已禁用", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
updateUI();
|
||||
private void setupBottomNav() {
|
||||
bottomNav.setOnItemSelectedListener(item -> {
|
||||
int position = item.getOrder();
|
||||
viewPager.setCurrentItem(position, false);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前壁纸是否是本应用的壁纸
|
||||
* 实现 HomeFragment.FolderPickerCallback 接口
|
||||
* 启动文件夹选择器
|
||||
*/
|
||||
private boolean isWallpaperActive() {
|
||||
// 简化检查:检查是否有壁纸设置记录
|
||||
return prefs.getBoolean("wallpaper_set", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示引导设置壁纸的对话框
|
||||
*/
|
||||
private void showSetWallpaperDialog() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("设置动态壁纸")
|
||||
.setMessage("点击\"确定\"后将打开壁纸选择界面,请选择\"BzForGk2\"作为动态壁纸。\n\n设置完成后返回应用即可自动启用。")
|
||||
.setPositiveButton("确定", (dialog, which) -> {
|
||||
openWallpaperSelector();
|
||||
// 启用服务
|
||||
config.setEnabled(true);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
AlarmScheduler scheduler = new AlarmScheduler(this);
|
||||
scheduler.scheduleWallpaperChange(config.getIntervalMinutes());
|
||||
|
||||
Toast.makeText(this, "已启用,请选择壁纸", Toast.LENGTH_LONG).show();
|
||||
updateUI();
|
||||
})
|
||||
.setNegativeButton("取消", null)
|
||||
.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开系统壁纸选择界面
|
||||
*/
|
||||
private void openWallpaperSelector() {
|
||||
try {
|
||||
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
|
||||
intent.putExtra(
|
||||
WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
|
||||
new android.content.ComponentName(this, cn.hugh.bz.gk2.wallpaper.AutoWallpaperService.class)
|
||||
);
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
// 如果上述方法失败,尝试打开壁纸选择器
|
||||
try {
|
||||
Intent intent = new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
|
||||
startActivity(intent);
|
||||
Toast.makeText(this, "请选择 BzForGk2 动态壁纸", Toast.LENGTH_LONG).show();
|
||||
} catch (Exception ex) {
|
||||
// 最后的备用方案:打开壁纸设置页面
|
||||
try {
|
||||
Intent intent = new Intent("android.settings.WALLPAPER_SETTINGS");
|
||||
startActivity(intent);
|
||||
Toast.makeText(this, "请选择 动态壁纸 → BzForGk2", Toast.LENGTH_LONG).show();
|
||||
} catch (Exception exc) {
|
||||
Toast.makeText(this, "无法打开壁纸设置,请手动去系统设置中选择", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void changeWallpaperNow() {
|
||||
if (config.getSelectedFolders().isEmpty()) {
|
||||
Toast.makeText(this, "请先选择文件夹", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger wallpaper refresh
|
||||
Intent intent = new Intent("cn.hugh.bz.gk2.ACTION_REFRESH_WALLPAPER");
|
||||
sendBroadcast(intent);
|
||||
|
||||
Toast.makeText(this, "壁纸已更换", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void openFolderPicker() {
|
||||
@Override
|
||||
public void launchFolderPicker(HomeFragment.FolderPickerResultCallback callback) {
|
||||
this.currentCallback = callback;
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
folderPickerLauncher.launch(intent);
|
||||
}
|
||||
|
||||
private void openSettings() {
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void addFolder(String folderPath) {
|
||||
if (folderPath == null || config.getSelectedFolders().contains(folderPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
config.getSelectedFolders().add(folderPath);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
// 异步扫描文件夹
|
||||
Toast.makeText(this, "正在扫描文件夹...", Toast.LENGTH_SHORT).show();
|
||||
new Thread(() -> {
|
||||
scanner.scanFolder(folderPath);
|
||||
runOnUiThread(() -> {
|
||||
updateUI();
|
||||
Toast.makeText(this, "已添加文件夹", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void removeFolder(int position) {
|
||||
if (position >= 0 && position < config.getSelectedFolders().size()) {
|
||||
String folderPath = config.getSelectedFolders().get(position);
|
||||
config.getSelectedFolders().remove(position);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
updateUI();
|
||||
Toast.makeText(this, "已移除文件夹", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
// Update status
|
||||
if (config.isEnabled()) {
|
||||
tvStatus.setText(R.string.status_enabled);
|
||||
btnToggle.setText(R.string.disable);
|
||||
btnChangeNow.setEnabled(true);
|
||||
} else {
|
||||
tvStatus.setText(R.string.status_disabled);
|
||||
btnToggle.setText(R.string.enable);
|
||||
btnChangeNow.setEnabled(false);
|
||||
}
|
||||
|
||||
// Update folder info - 使用缓存的数量,不重新扫描
|
||||
if (config.getSelectedFolders().isEmpty()) {
|
||||
tvFolderInfo.setText(R.string.no_folders);
|
||||
progressBar.setVisibility(android.view.View.GONE);
|
||||
} else {
|
||||
// 显示进度条
|
||||
progressBar.setVisibility(android.view.View.VISIBLE);
|
||||
progressBar.setIndeterminate(true);
|
||||
|
||||
// 异步获取图片数量
|
||||
tvFolderInfo.setText(String.format("已选择 %d 个文件夹,正在统计图片...",
|
||||
config.getSelectedFolders().size()));
|
||||
|
||||
new Thread(() -> {
|
||||
int imageCount = scanner.getTotalImageCount(config.getSelectedFolders());
|
||||
runOnUiThread(() -> {
|
||||
tvFolderInfo.setText(String.format("已选择 %d 个文件夹,共 %d 张图片",
|
||||
config.getSelectedFolders().size(), imageCount));
|
||||
progressBar.setVisibility(android.view.View.GONE);
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
// Update folder list adapter
|
||||
if (folderAdapter != null) {
|
||||
folderAdapter.updateFolders(config.getSelectedFolders());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
config = prefs.loadConfig();
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件夹列表适配器
|
||||
*/
|
||||
private class FolderAdapter extends ArrayAdapter<String> {
|
||||
private final Context context;
|
||||
private List<String> folders;
|
||||
private final java.util.Map<String, Integer> imageCounts = new java.util.HashMap<>();
|
||||
|
||||
public FolderAdapter(Context context, List<String> folders) {
|
||||
super(context, R.layout.item_folder, folders);
|
||||
this.context = context;
|
||||
this.folders = new ArrayList<>(folders);
|
||||
// 异步加载图片数量
|
||||
loadImageCounts();
|
||||
}
|
||||
|
||||
public void updateFolders(List<String> newFolders) {
|
||||
this.folders = new ArrayList<>(newFolders);
|
||||
clear();
|
||||
addAll(newFolders);
|
||||
// 异步加载图片数量
|
||||
loadImageCounts();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void loadImageCounts() {
|
||||
new Thread(() -> {
|
||||
for (String folderUri : folders) {
|
||||
if (!imageCounts.containsKey(folderUri)) {
|
||||
int count = scanner.scanFolder(folderUri).size();
|
||||
imageCounts.put(folderUri, count);
|
||||
runOnUiThread(() -> notifyDataSetChanged());
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.item_folder, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.tvFolderName = convertView.findViewById(R.id.tvFolderName);
|
||||
holder.tvFolderPath = convertView.findViewById(R.id.tvFolderPath);
|
||||
holder.tvImageCount = convertView.findViewById(R.id.tvImageCount);
|
||||
holder.btnRemove = convertView.findViewById(R.id.btnRemove);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
String folderUri = folders.get(position);
|
||||
|
||||
// 解析 URI 获取文件夹名称
|
||||
Uri uri = Uri.parse(folderUri);
|
||||
String folderName = getLastPathSegment(uri);
|
||||
holder.tvFolderName.setText(folderName);
|
||||
holder.tvFolderPath.setText(folderUri);
|
||||
|
||||
// 使用缓存的图片数量
|
||||
Integer count = imageCounts.get(folderUri);
|
||||
if (count != null) {
|
||||
holder.tvImageCount.setText(count + " 张图片");
|
||||
} else {
|
||||
holder.tvImageCount.setText("正在扫描...");
|
||||
}
|
||||
|
||||
// 移除按钮
|
||||
holder.btnRemove.setOnClickListener(v -> {
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle("移除文件夹")
|
||||
.setMessage("确定要移除这个文件夹吗?")
|
||||
.setPositiveButton("确定", (dialog, which) -> {
|
||||
removeFolder(position);
|
||||
})
|
||||
.setNegativeButton("取消", null)
|
||||
.show();
|
||||
});
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private String getLastPathSegment(Uri uri) {
|
||||
String path = uri.getLastPathSegment();
|
||||
if (path != null) {
|
||||
// 处理 content://com.android.externalstorage.documents/tree/primary%3ADCIM 这种格式
|
||||
if (path.contains(":")) {
|
||||
String[] parts = path.split(":");
|
||||
if (parts.length > 1) {
|
||||
return parts[1];
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
return "未知文件夹";
|
||||
}
|
||||
|
||||
// ViewHolder 模式优化
|
||||
private class ViewHolder {
|
||||
TextView tvFolderName;
|
||||
TextView tvFolderPath;
|
||||
TextView tvImageCount;
|
||||
Button btnRemove;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package cn.hugh.bz.gk2.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import cn.hugh.bz.gk2.R;
|
||||
import cn.hugh.bz.gk2.model.AppConfig;
|
||||
import cn.hugh.bz.gk2.model.PlayMode;
|
||||
import cn.hugh.bz.gk2.utils.AlarmScheduler;
|
||||
import cn.hugh.bz.gk2.wallpaper.WallpaperPreferences;
|
||||
|
||||
/**
|
||||
* 设置 Fragment
|
||||
* 负责播放模式、更换间隔、返回桌面更换等设置
|
||||
* 所有设置实时保存,无需保存按钮
|
||||
*/
|
||||
public class SettingsFragment extends Fragment {
|
||||
|
||||
private RadioButton rbSequential;
|
||||
private RadioButton rbRandom;
|
||||
private RadioGroup rgPlayMode;
|
||||
private SeekBar seekBarInterval;
|
||||
private TextView tvIntervalValue;
|
||||
private Switch switchChangeOnReturn;
|
||||
|
||||
private WallpaperPreferences prefs;
|
||||
private AppConfig config;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_settings, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
prefs = new WallpaperPreferences(requireContext());
|
||||
config = prefs.loadConfig();
|
||||
|
||||
initViews(view);
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
private void initViews(View view) {
|
||||
rbSequential = view.findViewById(R.id.rbSequential);
|
||||
rbRandom = view.findViewById(R.id.rbRandom);
|
||||
rgPlayMode = view.findViewById(R.id.rgPlayMode);
|
||||
seekBarInterval = view.findViewById(R.id.seekBarInterval);
|
||||
tvIntervalValue = view.findViewById(R.id.tvIntervalValue);
|
||||
switchChangeOnReturn = view.findViewById(R.id.switchChangeOnReturn);
|
||||
|
||||
// 播放模式切换监听器(实时保存)
|
||||
rgPlayMode.setOnCheckedChangeListener((group, checkedId) -> {
|
||||
PlayMode playMode = rbSequential.isChecked() ? PlayMode.SEQUENTIAL : PlayMode.RANDOM;
|
||||
config.setPlayMode(playMode);
|
||||
prefs.saveConfig(config);
|
||||
});
|
||||
|
||||
// 间隔调节监听器(实时保存)
|
||||
seekBarInterval.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
tvIntervalValue.setText(progress + " 分钟");
|
||||
|
||||
// 实时保存配置
|
||||
config.setIntervalMinutes(progress);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
// 如果服务已启用,重新调度定时器
|
||||
if (config.isEnabled() && fromUser) {
|
||||
AlarmScheduler scheduler = new AlarmScheduler(requireContext());
|
||||
scheduler.scheduleWallpaperChange(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// Do nothing
|
||||
}
|
||||
});
|
||||
|
||||
// 返回桌面更换开关监听器(实时保存)
|
||||
switchChangeOnReturn.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
config.setChangeOnReturnToHome(isChecked);
|
||||
prefs.saveConfig(config);
|
||||
});
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
rbSequential.setChecked(config.getPlayMode() == PlayMode.SEQUENTIAL);
|
||||
rbRandom.setChecked(config.getPlayMode() == PlayMode.RANDOM);
|
||||
seekBarInterval.setProgress(config.getIntervalMinutes());
|
||||
tvIntervalValue.setText(config.getIntervalMinutes() + " 分钟");
|
||||
switchChangeOnReturn.setChecked(config.isChangeOnReturnToHome());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
config = prefs.loadConfig();
|
||||
loadConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.hugh.bz.gk2.ui;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
/**
|
||||
* ViewPager2 适配器,用于管理三个 Fragment 页面
|
||||
*/
|
||||
public class ViewPagerAdapter extends FragmentStateAdapter {
|
||||
private static final int NUM_PAGES = 3;
|
||||
|
||||
public ViewPagerAdapter(FragmentActivity fa) {
|
||||
super(fa);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return new HomeFragment();
|
||||
case 1:
|
||||
return new CurrentWallpaperFragment();
|
||||
case 2:
|
||||
return new SettingsFragment();
|
||||
default:
|
||||
return new HomeFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return NUM_PAGES;
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ public class AlarmScheduler {
|
||||
// Create pending intent
|
||||
Intent intent = new Intent(context, WallpaperChangeReceiver.class);
|
||||
intent.setAction(WallpaperChangeReceiver.ACTION_CHANGE_WALLPAPER);
|
||||
// 定时器触发的更换不是强制更换,会根据配置决定是否更换
|
||||
intent.putExtra(WallpaperChangeReceiver.EXTRA_FORCE_CHANGE, false);
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package cn.hugh.bz.gk2.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 图片加载工具类
|
||||
* 用于加载和优化图片
|
||||
*/
|
||||
public class ImageLoader {
|
||||
private static final String TAG = "ImageLoader";
|
||||
|
||||
private final Context context;
|
||||
|
||||
public ImageLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载图片并进行采样优化
|
||||
*
|
||||
* @param uriString 图片 URI 字符串
|
||||
* @param reqWidth 请求的宽度
|
||||
* @param reqHeight 请求的高度
|
||||
* @return Bitmap 对象,失败返回 null
|
||||
*/
|
||||
public Bitmap loadImage(String uriString, int reqWidth, int reqHeight) {
|
||||
if (uriString == null || uriString.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (uriString.startsWith("content://")) {
|
||||
// 使用 DocumentFile API
|
||||
Uri uri = Uri.parse(uriString);
|
||||
DocumentFile file = DocumentFile.fromSingleUri(context, uri);
|
||||
if (file != null && file.exists()) {
|
||||
InputStream inputStream = context.getContentResolver().openInputStream(uri);
|
||||
if (inputStream != null) {
|
||||
Bitmap bitmap = decodeSampledBitmapFromStream(inputStream, reqWidth, reqHeight);
|
||||
inputStream.close();
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 使用传统 File API
|
||||
File file = new File(uriString);
|
||||
if (file.exists()) {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
Bitmap bitmap = decodeSampledBitmapFromStream(fis, reqWidth, reqHeight);
|
||||
fis.close();
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error loading image: " + uriString, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从输入流中加载并采样图片
|
||||
*/
|
||||
private Bitmap decodeSampledBitmapFromStream(InputStream inputStream, int reqWidth, int reqHeight) {
|
||||
try {
|
||||
// 第一次解析:只获取图片尺寸
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
byte[] buffer = readAllBytes(inputStream);
|
||||
BitmapFactory.decodeByteArray(buffer, 0, buffer.length, options);
|
||||
|
||||
// 计算采样率
|
||||
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
|
||||
|
||||
// 第二次解析:加载图片
|
||||
options.inJustDecodeBounds = false;
|
||||
return BitmapFactory.decodeByteArray(buffer, 0, buffer.length, options);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error decoding bitmap from stream", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取输入流的所有字节
|
||||
*/
|
||||
private byte[] readAllBytes(InputStream inputStream) throws Exception {
|
||||
java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
|
||||
int nRead;
|
||||
byte[] data = new byte[16384]; // 16KB buffer
|
||||
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
}
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算采样率
|
||||
*/
|
||||
private int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
|
||||
final int height = options.outHeight;
|
||||
final int width = options.outWidth;
|
||||
int inSampleSize = 1;
|
||||
|
||||
if (height > reqHeight || width > reqWidth) {
|
||||
final int halfHeight = height / 2;
|
||||
final int halfWidth = width / 2;
|
||||
|
||||
// 计算最大的 2 的幂次方,使得采样后的尺寸大于等于请求尺寸
|
||||
while ((halfHeight / inSampleSize) >= reqHeight
|
||||
&& (halfWidth / inSampleSize) >= reqWidth) {
|
||||
inSampleSize *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
return inSampleSize;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
super.onCreate();
|
||||
|
||||
// Register refresh receiver
|
||||
android.content.IntentFilter filter = new android.content.IntentFilter("cn.hugh.bz.gk2.ACTION_REFRESH_WALLPAPER");
|
||||
android.content.IntentFilter filter = new android.content.IntentFilter("cn.hugh.bz.gk2.ACTION_REFRESH_WALLPAPER_SERVICE");
|
||||
registerReceiver(refreshReceiver, filter);
|
||||
}
|
||||
|
||||
@@ -44,9 +44,10 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
private final android.content.BroadcastReceiver refreshReceiver = new android.content.BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(android.content.Context context, android.content.Intent intent) {
|
||||
if ("cn.hugh.bz.gk2.ACTION_REFRESH_WALLPAPER".equals(intent.getAction())) {
|
||||
if ("cn.hugh.bz.gk2.ACTION_REFRESH_WALLPAPER_SERVICE".equals(intent.getAction())) {
|
||||
if (engine != null) {
|
||||
engine.refreshWallpaper();
|
||||
boolean forceChange = intent.getBooleanExtra("force_change", false);
|
||||
engine.refreshWallpaper(forceChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +61,7 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
private int width;
|
||||
private int height;
|
||||
private boolean visible = false;
|
||||
private boolean forceChangeNext = false;
|
||||
|
||||
public WallpaperEngine() {
|
||||
this.imageLoader = new ImageLoader(AutoWallpaperService.this);
|
||||
@@ -104,7 +106,10 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
this.visible = false;
|
||||
}
|
||||
|
||||
public void refreshWallpaper() {
|
||||
public void refreshWallpaper(boolean forceChange) {
|
||||
if (forceChange) {
|
||||
forceChangeNext = true;
|
||||
}
|
||||
if (visible) {
|
||||
handler.post(this::drawWallpaper);
|
||||
}
|
||||
@@ -133,8 +138,10 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
WallpaperImage image;
|
||||
|
||||
// 核心逻辑:根据配置决定是否更换壁纸
|
||||
if (config.isChangeOnReturnToHome()) {
|
||||
// 开启状态:每次返回桌面都更换到下一张
|
||||
boolean shouldChange = forceChangeNext || config.isChangeOnReturnToHome();
|
||||
|
||||
if (shouldChange) {
|
||||
// 强制更换或开启返回桌面更换:获取下一张壁纸
|
||||
image = getNextWallpaper(config);
|
||||
|
||||
if (image != null) {
|
||||
@@ -162,6 +169,9 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重置强制更换标志
|
||||
forceChangeNext = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error drawing wallpaper", e);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M8,5v14l11,-7z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/status_disabled" />
|
||||
<size
|
||||
android:width="12dp"
|
||||
android:height="12dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/status_enabled" />
|
||||
<size
|
||||
android:width="12dp"
|
||||
android:height="12dp" />
|
||||
</shape>
|
||||
@@ -7,105 +7,21 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvStatus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/status_disabled"
|
||||
android:textSize="18sp"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvTitle"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnToggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/enable"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvStatus"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnChangeNow"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/change_now"
|
||||
android:layout_marginTop="8dp"
|
||||
android:enabled="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnToggle"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSelectFolders"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/select_folders"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnChangeNow"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSettings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnSelectFolders"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvFolderInfo"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/no_folders"
|
||||
android:textAlignment="center"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnSettings"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvFolderInfo"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/lvFolders"
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/progressBar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/bottomNav"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/bottomNav"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/windowBackground"
|
||||
app:menu="@menu/bottom_nav_menu"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
tools:context=".ui.CurrentWallpaperFragment">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivWallpaper"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:background="@android:color/darker_gray"
|
||||
android:adjustViewBounds="true"
|
||||
android:maxHeight="400dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintDimensionRatio="9:16"
|
||||
android:contentDescription="当前壁纸预览" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvWallpaperPath"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="当前壁纸路径"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="16dp"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="middle"
|
||||
app:layout_constraintTop_toBottomOf="@id/ivWallpaper"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvWallpaperSize"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="尺寸"
|
||||
android:textSize="12sp"
|
||||
android:layout_marginTop="4dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvWallpaperPath"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnChangeNow"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="立即更换"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvWallpaperSize"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnNext"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="下一张"
|
||||
android:layout_marginTop="8dp"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnChangeNow"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnOpenInGallery"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="在相册中打开"
|
||||
android:layout_marginTop="8dp"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnNext"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
@@ -0,0 +1,207 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/background"
|
||||
android:fillViewport="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<!-- 顶部标题卡片 -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardElevation="4dp"
|
||||
app:cardCornerRadius="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
|
||||
<!-- 状态指示器 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<View
|
||||
android:id="@+id/statusIndicator"
|
||||
android:layout_width="12dp"
|
||||
android:layout_height="12dp"
|
||||
android:background="@drawable/status_indicator_disabled"
|
||||
android:layout_marginEnd="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvStatus"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/status_disabled"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 操作按钮组 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnToggle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/enable"
|
||||
android:textSize="16sp"
|
||||
app:icon="@drawable/ic_play"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="8dp"
|
||||
app:cornerRadius="12dp"
|
||||
style="@style/Widget.Material3.Button" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnChangeNow"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="@string/change_now"
|
||||
android:textSize="16sp"
|
||||
android:enabled="false"
|
||||
app:icon="@drawable/ic_refresh"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="8dp"
|
||||
app:cornerRadius="12dp"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<!-- 文件夹管理卡片 -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardElevation="4dp"
|
||||
app:cardCornerRadius="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
|
||||
<!-- 标题和按钮 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="图片文件夹"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary"
|
||||
android:drawableStart="@drawable/ic_folder"
|
||||
android:drawablePadding="8dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnSelectFolders"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:text="@string/select_folders"
|
||||
android:textSize="14sp"
|
||||
app:icon="@drawable/ic_add"
|
||||
app:iconGravity="textStart"
|
||||
app:cornerRadius="12dp"
|
||||
style="@style/Widget.Material3.Button.TonalButton" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 文件夹信息 -->
|
||||
<TextView
|
||||
android:id="@+id/tvFolderInfo"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/no_folders"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:gravity="center" />
|
||||
|
||||
<!-- 进度条 -->
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<!-- 文件夹列表卡片 -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardElevation="4dp"
|
||||
app:cardCornerRadius="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="已选择的文件夹"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary"
|
||||
android:layout_marginBottom="12dp" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/lvFolders"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="@null"
|
||||
android:dividerHeight="0dp"
|
||||
tools:listitem="@layout/item_folder_card" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
@@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp"
|
||||
tools:context=".ui.SettingsFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPlayModeLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="播放模式"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/rgPlayMode"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPlayModeLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbSequential"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="顺序播放" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbRandom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="随机播放" />
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvIntervalLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="更换间隔(分钟)"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/rgPlayMode"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarInterval"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="60"
|
||||
android:min="1"
|
||||
android:progress="30"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvIntervalLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvIntervalValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="30 分钟"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/seekBarInterval"
|
||||
app:layout_constraintStart_toStartOf="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_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_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" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:cardElevation="2dp"
|
||||
app:cardCornerRadius="12dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<!-- 文件夹名称和路径 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/ic_folder"
|
||||
android:tint="@color/primary"
|
||||
android:contentDescription="文件夹图标" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="12dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvFolderName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="文件夹名称"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvFolderPath"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="content://..."
|
||||
android:textSize="12sp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textColor="@color/text_hint"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="middle" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 图片数量和操作按钮 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvImageCount"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="0 张图片"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:drawableStart="@drawable/ic_image"
|
||||
android:drawablePadding="4dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnRemove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
android:text="移除"
|
||||
android:textSize="12sp"
|
||||
app:icon="@drawable/ic_delete"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="4dp"
|
||||
app:cornerRadius="8dp"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/nav_home"
|
||||
android:icon="@drawable/ic_home"
|
||||
android:title="@string/nav_home"
|
||||
android:orderInCategory="0" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_wallpaper"
|
||||
android:icon="@drawable/ic_image"
|
||||
android:title="@string/nav_wallpaper"
|
||||
android:orderInCategory="1" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_settings"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:title="@string/nav_settings"
|
||||
android:orderInCategory="2" />
|
||||
</menu>
|
||||
@@ -8,6 +8,30 @@
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
|
||||
<!-- 主题颜色 -->
|
||||
<color name="primary">#6750A4</color>
|
||||
<color name="primary_dark">#4F378B</color>
|
||||
<color name="accent">#D0BCFF</color>
|
||||
|
||||
<!-- 背景和文本颜色 -->
|
||||
<color name="background">#FFFDF7</color>
|
||||
<color name="surface">#FFFBFE</color>
|
||||
<color name="text_primary">#1C1B1F</color>
|
||||
<color name="text_secondary">#49454F</color>
|
||||
<color name="text_hint">#79747E</color>
|
||||
|
||||
<!-- 状态颜色 -->
|
||||
<color name="status_enabled">#4CAF50</color>
|
||||
<color name="status_disabled">#9CA3AF</color>
|
||||
|
||||
<!-- 功能颜色 -->
|
||||
<color name="error">#B3261E</color>
|
||||
<color name="success">#4CAF50</color>
|
||||
|
||||
<!-- 卡片颜色 -->
|
||||
<color name="card_background">#FFFFFF</color>
|
||||
<color name="card_stroke">#E0E0E0</color>
|
||||
|
||||
<!-- Launcher icon colors -->
|
||||
<color name="ic_launcher_background">#FF6200EE</color>
|
||||
<color name="ic_launcher_foreground">#FFFFFFFF</color>
|
||||
|
||||
@@ -15,4 +15,9 @@
|
||||
<!-- 返回桌面更换壁纸 -->
|
||||
<string name="setting_change_on_return_title">返回桌面更换壁纸</string>
|
||||
<string name="setting_change_on_return_desc">每次返回桌面或解锁时自动更换到下一张壁纸</string>
|
||||
|
||||
<!-- 底部导航标签 -->
|
||||
<string name="nav_home">主页</string>
|
||||
<string name="nav_wallpaper">壁纸</string>
|
||||
<string name="nav_settings">设置</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user