feat: 重构主窗口菜单,将系统相册入口移至图片浏览窗口
- MainActivity: 移除 action_gallery 按钮,替换为 action_mi_gallery (小米相册) - MainActivity: 移除 action_reset_gallery 按钮及响应代码 - ImageViewerActivity: 新增 btn_gallery 按钮,点击当前浏览图片打开相册选择器 - menu_main: 删除 action_gallery 和 action_reset_gallery 菜单项 - drawable: ic_cover 颜色改为白色以适配暗色工具栏 - drawable: 新增 ic_mi_gallery (小米相册图标),删除 ic_cover_reset - strings: 新增 mi_gallery 字符串资源
This commit is contained in:
@@ -12,6 +12,7 @@ import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Toast;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -34,6 +35,7 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha
|
||||
private ImageButton btnShare;
|
||||
private ImageButton btnInfo;
|
||||
private ImageButton btnBg;
|
||||
private ImageButton btnGallery;
|
||||
private int bgType = 0;
|
||||
private GestureDetector gestureDetector;
|
||||
private TrashManager trashManager;
|
||||
@@ -63,6 +65,8 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha
|
||||
btnInfo = findViewById(R.id.btn_info);
|
||||
btnBg = findViewById(R.id.btn_bg);
|
||||
|
||||
btnGallery = findViewById(R.id.btn_gallery);
|
||||
|
||||
applyBg();
|
||||
|
||||
ImagePagerAdapter adapter = new ImagePagerAdapter(imageUrls, bgType);
|
||||
@@ -119,6 +123,20 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha
|
||||
switchBg();
|
||||
}
|
||||
});
|
||||
|
||||
btnGallery.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(ImageViewerActivity.this, "Gallery", Toast.LENGTH_SHORT).show();
|
||||
if (imageUrls != null && currentPosition >= 0 && currentPosition < imageUrls.size()) {
|
||||
Uri imageUri = imageUrls.get(currentPosition);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(imageUri, "image/*");
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
startActivity(Intent.createChooser(intent, "打开相册"));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void toggleToolbar() {
|
||||
|
||||
@@ -289,31 +289,12 @@ private void loadAlbums() {
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_gallery) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
if (id == R.id.action_mi_gallery) {
|
||||
Toast.makeText(this, "Gallery clicked", Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_APP_GALLERY);
|
||||
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));
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user