diff --git a/gallery/build.properties b/gallery/build.properties index d532b55..b9a9b97 100644 --- a/gallery/build.properties +++ b/gallery/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Sat Apr 25 19:16:31 CST 2026 +#Sat Apr 25 19:42:01 CST 2026 stageCount=3 libraryProject= baseVersion=15.0 publishVersion=15.0.2 -buildCount=4 +buildCount=8 baseBetaVersion=15.0.3 diff --git a/gallery/src/main/java/cc/winboll/studio/gallery/ImagePagerAdapter.java b/gallery/src/main/java/cc/winboll/studio/gallery/ImagePagerAdapter.java index b7942da..8e46532 100644 --- a/gallery/src/main/java/cc/winboll/studio/gallery/ImagePagerAdapter.java +++ b/gallery/src/main/java/cc/winboll/studio/gallery/ImagePagerAdapter.java @@ -16,10 +16,25 @@ import cc.winboll.studio.libappbase.LogUtils; public class ImagePagerAdapter extends PagerAdapter { public static final String TAG = "ImagePagerAdapter"; private ArrayList imageUrls; + private int bgType; - public ImagePagerAdapter(ArrayList imageUrls) { + public ImagePagerAdapter(ArrayList imageUrls, int bgType) { this.imageUrls = imageUrls; - LogUtils.d(TAG, "ImagePagerAdapter created with " + imageUrls.size() + " images"); + this.bgType = bgType; + LogUtils.d(TAG, "ImagePagerAdapter created with " + imageUrls.size() + " images, bgType=" + bgType); + } + + private int getBgRes() { + switch (bgType) { + case 0: + return R.drawable.bg_checkerboard; + case 1: + return R.drawable.bg_white; + case 2: + return R.drawable.bg_black; + default: + return R.drawable.bg_checkerboard; + } } @Override @@ -32,6 +47,7 @@ public class ImagePagerAdapter extends PagerAdapter { public Object instantiateItem(@NonNull ViewGroup container, int position) { View view = LayoutInflater.from(container.getContext()) .inflate(R.layout.item_image_pager, container, false); + view.setBackgroundResource(getBgRes()); ImageView imageView = view.findViewById(R.id.image); Glide.with(imageView.getContext()) diff --git a/gallery/src/main/java/cc/winboll/studio/gallery/ImageViewerActivity.java b/gallery/src/main/java/cc/winboll/studio/gallery/ImageViewerActivity.java index 13208a5..aa941ac 100644 --- a/gallery/src/main/java/cc/winboll/studio/gallery/ImageViewerActivity.java +++ b/gallery/src/main/java/cc/winboll/studio/gallery/ImageViewerActivity.java @@ -33,8 +33,11 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha private ImageButton btnDelete; private ImageButton btnShare; private ImageButton btnInfo; + private ImageButton btnBg; + private int bgType = 0; private GestureDetector gestureDetector; private TrashManager trashManager; + private Preferences prefs; @Override protected void onCreate(Bundle savedInstanceState) { @@ -49,6 +52,8 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha currentPosition = getIntent().getIntExtra(EXTRA_POSITION, 0); trashManager = new TrashManager(this); + prefs = new Preferences(this); + bgType = prefs.getBgType(); viewPager = findViewById(R.id.view_pager); toolbar = findViewById(R.id.toolbar); @@ -56,8 +61,11 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha btnDelete = findViewById(R.id.btn_delete); btnShare = findViewById(R.id.btn_share); btnInfo = findViewById(R.id.btn_info); + btnBg = findViewById(R.id.btn_bg); - ImagePagerAdapter adapter = new ImagePagerAdapter(imageUrls); + applyBg(); + + ImagePagerAdapter adapter = new ImagePagerAdapter(imageUrls, bgType); viewPager.setAdapter(adapter); viewPager.setCurrentItem(currentPosition); viewPager.addOnPageChangeListener(this); @@ -104,6 +112,13 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha showImageInfo(); } }); + + btnBg.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + switchBg(); + } + }); } private void toggleToolbar() { @@ -114,6 +129,52 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha } } + private void applyBg() { + int bgRes; + switch (bgType) { + case 0: + bgRes = R.drawable.bg_checkerboard; + break; + case 1: + bgRes = R.drawable.bg_white; + break; + case 2: + bgRes = R.drawable.bg_black; + break; + default: + bgRes = R.drawable.bg_checkerboard; + } + View container = findViewById(R.id.container); + if (container != null) { + container.setBackgroundResource(bgRes); + } + } + + private void switchBg() { + final String[] bgNames = {"灰白相间", "全白", "全黑"}; + final int[] bgResources = {R.drawable.bg_checkerboard, R.drawable.bg_white, R.drawable.bg_black}; + + new AlertDialog.Builder(this) + .setTitle("选择背景") + .setSingleChoiceItems(bgNames, bgType, new android.content.DialogInterface.OnClickListener() { + @Override + public void onClick(android.content.DialogInterface dialog, int which) { + bgType = which; + prefs.setBgType(which); + int currentItem = viewPager.getCurrentItem(); + View container = findViewById(R.id.container); + if (container != null) { + container.setBackgroundResource(bgResources[which]); + } + viewPager.setAdapter(new ImagePagerAdapter(imageUrls, bgType)); + viewPager.setCurrentItem(currentItem); + dialog.dismiss(); + } + }) + .setNegativeButton("取消", null) + .show(); + } + private void showDeleteDialog() { new AlertDialog.Builder(this) .setMessage("Delete to trash?") @@ -178,7 +239,7 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha if (currentPosition >= imageUrls.size()) { currentPosition = imageUrls.size() - 1; } - viewPager.setAdapter(new ImagePagerAdapter(imageUrls)); + viewPager.setAdapter(new ImagePagerAdapter(imageUrls, bgType)); viewPager.setCurrentItem(currentPosition); } } diff --git a/gallery/src/main/java/cc/winboll/studio/gallery/Preferences.java b/gallery/src/main/java/cc/winboll/studio/gallery/Preferences.java index 5c069ea..500cb25 100644 --- a/gallery/src/main/java/cc/winboll/studio/gallery/Preferences.java +++ b/gallery/src/main/java/cc/winboll/studio/gallery/Preferences.java @@ -8,6 +8,8 @@ public class Preferences { public static final String TAG = "Preferences"; private static final String PREF_NAME = "gallery_prefs"; private static final String KEY_FOLDER_PATH = "folder_path"; + private static final String KEY_BG_TYPE = "bg_type"; + private static final int DEFAULT_BG_TYPE = 0; private static final String DEFAULT_PATH = "/storage/emulated/0/Pictures/Gallery/owner"; public static String getDefaultPath() { @@ -30,4 +32,13 @@ public class Preferences { LogUtils.d(TAG, "setFolderPath: " + path); prefs.edit().putString(KEY_FOLDER_PATH, path).apply(); } + + public int getBgType() { + return prefs.getInt(KEY_BG_TYPE, DEFAULT_BG_TYPE); + } + + public void setBgType(int type) { + LogUtils.d(TAG, "setBgType: " + type); + prefs.edit().putInt(KEY_BG_TYPE, type).apply(); + } } \ No newline at end of file diff --git a/gallery/src/main/res/drawable/bg_black.xml b/gallery/src/main/res/drawable/bg_black.xml new file mode 100644 index 0000000..e0fb6f9 --- /dev/null +++ b/gallery/src/main/res/drawable/bg_black.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/gallery/src/main/res/drawable/bg_white.xml b/gallery/src/main/res/drawable/bg_white.xml new file mode 100644 index 0000000..0c561be --- /dev/null +++ b/gallery/src/main/res/drawable/bg_white.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/gallery/src/main/res/drawable/ic_bg.xml b/gallery/src/main/res/drawable/ic_bg.xml new file mode 100644 index 0000000..0580837 --- /dev/null +++ b/gallery/src/main/res/drawable/ic_bg.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/gallery/src/main/res/layout/activity_image_viewer.xml b/gallery/src/main/res/layout/activity_image_viewer.xml index 3e6971e..6dc886d 100644 --- a/gallery/src/main/res/layout/activity_image_viewer.xml +++ b/gallery/src/main/res/layout/activity_image_viewer.xml @@ -52,6 +52,14 @@ android:src="@drawable/ic_info" android:contentDescription="Info"/> + + + android:layout_height="match_parent">