GalleryNote

If the “picture” icon is clicked on Launcher activity, it brings up GalleryPicker activity. The GalleryPicker activity calls ImageManager to query folders which contains image files from MediaProvider. (When reading source code, remember that the gallery and bucket symbol equals to folder.) For each folder, it generates a 142*142 mini thumbnail to represent the folder according to the number of images in the folder. For a single image, that image draws over the whole folder. For four or more images, only the first four photos are selected to make the image.

If no or only one image folders, it automatically launches ImageGallery2 activity to view the folder.

If more than one image folders, it uses GridView to display these auto-generated 142*142 mini thumbnails, when user clicks on any item, it also launches ImageGallery2 activity to view the corresponding folder.

ImageGallery2 creates a background thread to call ImageManager to retrieve a 96*96(defined by MINI_THUMB_TARGET_SIZE) mini thumbnail for any image in the folder. ImageManager first queries whether the mini thumbnail has generated before from MediaProver. If not, it will generate one and update to MediaProvider. The generated method has a special performance consideration: If original image file contains thumbnail picture, it will be used(For some JPEG EXIF file, it may have). All these thumbnails will be saved into one random file in the folder “$(EXTERNAL_STORAGE)/dcim/.thumbnails” by ImageManager. One thumbnail occupies exactly 10000 bytes(defined by sBytesPerMiniThumb) in the file. The file name’s format is “.thumbdata3-XXX”. 3 is MINI_THUMB_DATA_FILE_VERSION. XXX is some kind of hash code corresponding to a folder.

ImageGallery2 implements an important feature just like Windows: It tracks the current position and only fetches these mini thumbnails can be seen at the current position. Other unseen pictures won’t be fetched. So that user can quickly see mini thumbnails when he scrolls down or up. The feature is implemented in GridViewSpecial and ImageBlockManager.

If a mini thumbnail icon is clicked in ImageGallery2, the ViewImage activity will be launched to view the corresponding image. Here's the loading strategy.  For any given image, load the thumbnail into memory and post a callback to display the resulting bitmap. Then proceed to load the full image bitmap. All these are implemented in ImageGetter. The thumbnail also is generated only once, as long as generated by ImageManager, it will be saved into “$(EXTERNAL_STORAGE)/dcim/.thumbnails/YYY.jpg”. YYY is some kind of hash code corresponding to an image file. ImageManager also updates to MediaProvider for history use. The maximum thumbnail size is 320*320(define by THUMBNAIL_TARGET_SIZE).

For sliding show feature, it’s implemented in SlideShow activity which will be started from ImageGallery2 and GalleryPicker as the result of one menu item click.

你可能感兴趣的:(gallery)