feat: 添加系统相册入口及重置默认打开方式功能
【功能更新】 1. 系统相册按钮: - 工具栏新增“系统相册”菜单项 (ic_cover)。 - 点击后通过 Intent 调用系统默认相册。 2. 重置按钮: - 工具栏新增“重置”菜单项 (ic_cover_reset)。 - 清除图库 ACTION_VIEW 的默认打开记录,恢复应用选择框。 - 兼容处理:API <= 30 自动清除,API > 30 提示适配限制说明。 【代码变更】 - MainActivity.java: 新增 action_gallery 与 action_reset_gallery 响应逻辑,包含异常捕获。 - menu_main.xml: 注册两个新菜单项。 - strings.xml: 新增 "system_gallery", "reset_gallery" 字符串资源。 【其他新增】 - 新增 ColorPaletteDialog 类及 dialog_color_palette.xml 布局。 - 新增 styles.xml 样式 ColorPaletteDialog。 - 新增重置图标资源 ic_cover_reset.xml。 - 更新 build.properties 版本配置。
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Tue Apr 28 17:22:34 GMT 2026
|
#Thu Apr 30 22:39:56 CST 2026
|
||||||
stageCount=10
|
stageCount=10
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.0
|
baseVersion=15.0
|
||||||
publishVersion=15.0.9
|
publishVersion=15.0.9
|
||||||
buildCount=18
|
buildCount=46
|
||||||
baseBetaVersion=15.0.10
|
baseBetaVersion=15.0.10
|
||||||
|
|||||||
@@ -289,7 +289,32 @@ private void loadAlbums() {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
if (id == R.id.action_settings) {
|
if (id == R.id.action_gallery) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
} else if (id == R.id.action_reset_gallery) {
|
||||||
|
// 清除 图库/ACTION_VIEW 图片 Uri 的默认打开记录
|
||||||
|
PackageManager pm = getPackageManager();
|
||||||
|
|
||||||
|
// 构建和你跳转一模一样的 Intent
|
||||||
|
Intent clearIntent = new Intent(Intent.ACTION_VIEW, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 仅在 API <= 30 时执行重置操作
|
||||||
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
|
||||||
|
String mimeType = clearIntent.resolveType(getContentResolver());
|
||||||
|
pm.clearPackagePreferredActivities(mimeType);
|
||||||
|
Toast.makeText(this, "已清除默认打开方式", Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
// API > 30 时,弹出提示说明适配限制
|
||||||
|
Toast.makeText(this, "应用开发资源有限,本应用适配目标安卓版本为 (" + Build.VERSION_CODES.R + ")。", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
Toast.makeText(this, "需要授予重置默认应用权限,请在系统设置中开启", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if (id == R.id.action_settings) {
|
||||||
startActivity(new Intent(this, SettingsActivity.class));
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
return true;
|
return true;
|
||||||
} else if (id == R.id.action_about) {
|
} else if (id == R.id.action_about) {
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package cc.winboll.studio.gallery.dialog;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import cc.winboll.studio.gallery.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 颜色表对话框
|
||||||
|
* 继承于普通对话框类,使用视图文件
|
||||||
|
*/
|
||||||
|
public class ColorPaletteDialog extends Dialog {
|
||||||
|
|
||||||
|
public ColorPaletteDialog(@NonNull Context context) {
|
||||||
|
super(context, R.style.ColorPaletteDialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorPaletteDialog(@NonNull Context context, int themeResId) {
|
||||||
|
super(context, themeResId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
// super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.dialog_color_palette);
|
||||||
|
|
||||||
|
TextView titleText = findViewById(R.id.title_text);
|
||||||
|
|
||||||
|
WindowManager.LayoutParams params = getWindow().getAttributes();
|
||||||
|
params.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||||
|
getWindow().setAttributes(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnColorItemClick {
|
||||||
|
void onColorClick(int color);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
gallery/src/main/res/drawable/ic_cover_reset.xml
Normal file
21
gallery/src/main/res/drawable/ic_cover_reset.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
|
||||||
|
<!-- 底层:黑色方框+对勾 -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#000000"
|
||||||
|
android:pathData="M21,3H3C1.9,3 1,3.9 1,5v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2V5C23,3.9 22.1,3 21,3zM21,19H3V5h18V19z"/>
|
||||||
|
<path
|
||||||
|
android:fillColor="#000000"
|
||||||
|
android:pathData="M9,12l2,2l4,-4l1.5,1.5L11,17l-3,-3z"/>
|
||||||
|
|
||||||
|
<!-- 上层 纯白色逆时针箭头 -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M12.63,2C18.16,2 22.64,6.5 22.64,12C22.64,17.5 18.16,22 12.63,22C9.12,22 6.05,20.18 4.26,17.43L5.84,16.18C7.25,18.47 9.76,20 12.64,20A8,8 0,0 0,20.64 12A8,8 0,0 0,12.64 4C8.56,4 5.2,7.06 4.71,11H7.47L3.73,14.73L0,11H2.69C3.19,5.95 7.45,2 12.63,2"/>
|
||||||
|
|
||||||
|
</vector>
|
||||||
16
gallery/src/main/res/layout/dialog_color_palette.xml
Normal file
16
gallery/src/main/res/layout/dialog_color_palette.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/bg_dialog"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@@ -2,6 +2,18 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_gallery"
|
||||||
|
android:title="@string/system_gallery"
|
||||||
|
android:icon="@drawable/ic_cover"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_reset_gallery"
|
||||||
|
android:title="@string/reset_gallery"
|
||||||
|
android:icon="@drawable/ic_cover_reset"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_trash"
|
android:id="@+id/action_trash"
|
||||||
android:title="@string/trash"
|
android:title="@string/trash"
|
||||||
|
|||||||
@@ -18,4 +18,6 @@
|
|||||||
<string name="no">No</string>
|
<string name="no">No</string>
|
||||||
<string name="debug_log">Debug Log</string>
|
<string name="debug_log">Debug Log</string>
|
||||||
<string name="debug_message">Debug log message</string>
|
<string name="debug_message">Debug log message</string>
|
||||||
|
<string name="system_gallery">系统相册</string>
|
||||||
|
<string name="reset_gallery">重置</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -8,4 +8,9 @@
|
|||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="ColorPaletteDialog" parent="Theme.AppCompat.Light.NoActionBar">
|
||||||
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
|
<item name="android:windowIsFloating">false</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user