Gallery2中Menu的分析

来源:互联网 发布:灯光编程教学视频 编辑:程序博客网 时间:2024/05/01 18:57
Gallery2中的Menu分析:
图库中的Menu的显示或隐藏主要在MenuExecutor.java类中的updateMenuOperation()
方法中判断。
通过传递过来的supported值来匹配是否显示对应Menu。
这里主要分析具体某张图片menu的显示:
在PhotoPage.java的updateMenuOperations()这个方法中:
 int supportedOperations = mCurrentPhoto.getSupportedOperations();
通过这个传递这个值来判断,
而这个值中的getSupportedOperations()方法在:LocalImage.java类中的getSupportedOperations()方


法。
在getSupportedOperations() 方法中:
 @Override
    public int getSupportedOperations() {
        int operation = SUPPORT_DELETE | SUPPORT_SHARE | SUPPORT_CROP
                | SUPPORT_SETAS | SUPPORT_EDIT | SUPPORT_INFO;
        if (BitmapUtils.isSupportedByRegionDecoder(mimeType)) {
            operation |= SUPPORT_FULL_IMAGE;
        }


        if (BitmapUtils.isRotationSupported(mimeType)) {
            operation |= SUPPORT_ROTATE;
        }


        if (GalleryUtils.isValidLocation(latitude, longitude)) {
            operation |= SUPPORT_SHOW_ON_MAP;
        }
        return operation;
    }
这里来获取支持显示哪些Menu.
例如判断某张图片是否要支持旋转:
在BitmapUtils.java类中 isRotationSupported()方法:
  public static boolean isRotationSupported(String mimeType) {
        if (mimeType == null) return false;

        mimeType = mimeType.toLowerCase();
        return mimeType.equals("image/jpeg");
    }
说明支持数据库中字段mimeType 值为"image/jpeg"的图片,即使jpg或jpeg的图片,
当你要添加支持更多格式图片旋转时只要在return中添加即可,如需要填加png图片:
return mimeType.equals("image/jpeg") ||mimeType.equals("image/png");
修个这里即可。