gallery note

本文介绍了用于在SD卡上存储和读取缓存数据的DiskCache类,并详细解释了其内部实现,包括SparseArray、Record类以及如何使用CacheService进行数据操作。此外,文章还涉及了与缓存相关的类和组件,如AlbumCache、MediaFeed等,以及OpenGL在渲染视图中的应用。

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

DiskCache.java

A class used to store cache data into theSD card, or read cache from it.

Fields

private LongSparseArray<Record> mIndexMap;

privatefinal LongSparseArray<RandomAccessFile> mChunkFiles

 

LongSparseArray: SparseArrays map longs to Objects. Unlike a normal array of Objects,there can be gaps in the indices. It is intended to be more efficient thanusing a HashMap to map Longs to Objects.

 

mIndexMap: a map from (long) keyto a record which indiactes the offset / size of the data stored in the chunkfile.

 

private static final class Record {

        …

        public final long timestamp;

        public final int chunk;

        public final int offset;

        public final int size;

        public final int sizeOnDisk;

    }

 

mChunkFiles: a map from (Record.) chunkto the random access chunk files.

 

Methods

publicbyte[] get(long key, long timestamp)

publicvoid put(long key, byte[] data, long timestamp)

 

get:

 

put:

 

CacheService.java

extends IntentService

   IntentService is a base class for Servicesthat handle asynchronous requests (expressedas Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent inturn using a worker thread, and stops itself when it runs out of work.   To use it, extend IntentService andimplement onHandleIntent(Intent).IntentService will receive the Intents, launch a worker thread, and stop theservice as appropriate.

All requests are handled on a singleworker thread -- they may take as long as necessary (and will not block theapplication's main loop), but only one request will be processed at a time.

A class used to store cache data into the SD card, or read cachefrom it.

 

 

Fields

publicstaticfinal DiskCache sAlbumCache = new DiskCache("local-album-cache");

publicstaticfinal DiskCache sMetaAlbumCache = new DiskCache("local-meta-cache");

publicstaticfinal DiskCache sSkipThumbnailIds = new DiskCache("local-skip-cache");

 

privatestatic ImageList sList = null;

 

 

 

 

 

 

 

LongSparseArray: SparseArrays map longs to Objects. Unlike a normal array of Objects,there can be gaps

 


 

Gallery.java    is the mainand launcher activity.

App.java    hooks up other activity classes to App,including Gallery.

ImageManager.java    is usedto retrieve and store images in the media content provider.

MediaFeed, MediaSets负责相册集的加载

RenderView.java    extendsGLSurfaceView

 

SDK 中的 android.opengl.GLSurfaceView 类提供如下功能: 

·  在 OpenGL ES 和 View 系统之间建立联系;

·得 OpenGL ES 可以工作在 Activity 生命周期中;

·可选择合适的 frame buffer 像素格式;

·创建并管理一个单独的渲染线程,可以实现平滑的动画;

·提供 debugging 工具和 API。

 

GLSurfaceView.Render 接口负责调用OpenGL来渲染一帧画面,有三个方法: 

·        onSurfaceCreated():  该方法在渲染开始前调用,OpenGL ES 的绘制上下文被重建时也会被调用。当 activity 暂停时绘制上下文会丢失,当 activity 继续时,绘制上下文会被重建。另外,创建长期存在的 OpenGL 资源(如 texture)往往也在这里进行。 

·        onSurfaceChanged():  当 surface 的尺寸发生改变时该方法被调用。往往在这里设置 viewport。若你的 camera 是固定的,也可以在这里设置 camera。 

·        onDrawFrame():  每帧都通过该方法进行绘制。绘制时通常先调用 glClear 函数来清空 framebuffer,然后在调用 OpenGL ES 的起它的接口进行绘制。 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值