Gallery 打开gif图像

本文详细介绍了在 Gallery 应用中打开和显示 GIF 图像的流程,从 `GalleryActivity` 的 `startViewAction()` 方法开始,涉及到 `DataManager` 中的 `findPathByUri()` 用于查找媒体路径,`UriSource` 和 `LocalSource` 处理不同的数据源。在处理 GIF 图像时,`UriImage` 类的角色关键,提供请求图像和大图的 Job。`PhotoPage` 中的 `onCreate()` 方法根据数据创建相应的数据适配器,如 `PhotoDataAdapter` 或 `SinglePhotoDataAdapter`,以展示动态(原图)或缩略图。整个过程揭示了 Gallery 如何处理不同类型 URI 的媒体文件,特别是 GIF 图像的显示逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

packages/apps/SnapdragonGallery/src/com/android/gallery3d/app/

GalleryActivity.java

//打开显示view

//碰到过类似问题,如果从安全角度来看,这本不算gallery的一个bug, 它主要关系到是否允许用户通过滑动来查看其它照片的问题

startViewAction(){

          Path itemPath = dm.findPathByUri(uri, contentType);
         Path albumPath = dm.getDefaultSetOf(itemPath);

                boolean singleItemOnly = (albumPath == null) || intent.getBooleanExtra("SingleItemOnly", false);
                if (!singleItemOnly) {
                    data.putString(PhotoPage.KEY_MEDIA_SET_PATH, albumPath.toString());
                }

         getStateManager().startState(SinglePhotoPage.class, data);

}

 

DataManager.java

findPathByUri(){

     for (MediaSource source : mSourceMap.values()) {//主要有两个LocalSource 和  UriSource

        }

}

getDefaultSetOf(){

   MediaSource source = mSourceMap.get(item.getPrefix());//Prefix 为local 和 uri

}

 

UriSource   UriImage

LocalSource LocalAlbumSet  LocalAlbum  LocalImage LocalVideo

 

UriImage.java

//DrmHelper     DRM:数字版权管理

    @Override
    public Job<Bitmap> requestImage(int type) {
        return new BitmapJob(type);
    }

    @Override
    public Job<BitmapRegionDecoder> requestLargeImage() {
        return new RegionDecoderJob();
    }

 

startViewAction.  uri=content://media/external/images/media/215contentType=image/gif
 GalleryActivity: startViewAction.  (itemPath )=/local/image/item/215
 GalleryActivity: startViewAction.  (albumPath )=/local/all/540528482

 

startViewAction.  uri=content://com.android.providers.media.documents/document/image%3A240contentType=image/gif
GalleryActivity: startViewAction.  (itemPath )=/uri/content%3A%2F%2Fcom.android.providers.media.documents%2Fdocument%2Fimage%253A240/image%2Fgif
GalleryActivity: startViewAction.  (albumPath == null)=true

 

 

PhotoPage.java

onCreate(){

           mMenuExecutor = new MenuExecutor(mActivity, mSelectionManager);
        mPhotoView = new PhotoView(mActivity);//显示的view
        mPhotoView.setListener(this);


          mSetPathString = data.getString(KEY_MEDIA_SET_PATH);

         (mSetPathString != null){ //打开动态(原图)  PhotoDataAdapter

             PhotoDataAdapter pda = new PhotoDataAdapter(
                    mActivity, mPhotoView, mMediaSet, itemPath, mCurrentIndex,
                    mAppBridge == null ? -1 : 0,
                    mAppBridge == null ? false : mAppBridge.isPanorama(),
                    mAppBridge == null ? false : mAppBridge.isStaticCamera());
            mModel = pda;
            mPhotoView.setModel(mModel);

          }else {// Get default media set by the URI  //否则,就是缩列图 (只有一帧)  SinglePhotoDataAdapter
            Log.w(TAG, "Get default media set by the URI ");
            MediaItem mediaItem = (MediaItem)
                    mActivity.getDataManager().getMediaObject(itemPath);
            mModel = new SinglePhotoDataAdapter(mActivity, mPhotoView, mediaItem);
            mPhotoView.setModel(mModel);
            updateCurrentPhoto(mediaItem);

           }

}

 

 

 

SinglePhotoDataAdapter.java

onDecodeLargeComplete();//原图显示

onDecodeThumbComplete();//缩列图显示

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值