Android
2.3 adding GIF support to gallery3d-Overview (1)
For how gallery3d displays an image, see this user's gallery3d note.
Welcome to reprint, please be sure to indicate the source: http://blog.csdn.net/yihongyuelan
In gallery3d, the image display includes the thumbnail and a single big image display. When we click the thumbnail, there will be an animation effect, and then a large image will be displayed. If the displayed image is large, the big image may be blurred first and then displayed clearly. Let's take a look at the basic structure of gallery3d. 1:
Figure 1
This is the composition of the whole gallery3d and the relationship between them. What is the significance of this? Go back to the theme image shown in this article: thumbnail and big image.
Thumbnails are created by cacheservice in gallery3d. These thumbnails are cached in the path/mnt/sdcard/Android/data/COM. cooliris. Media. Thumbnails are displayed in fixed width and height (set in gridlayer) boxes, cacheservice. getimagelist obtains image information from the database, cacheservice. the refresh () method is used to create an album and put the image into the album.
The process of displaying large images. In the Android system, the scanned media file information (path, type, and so on) is stored in the database (/data/COM. android. providers. media/databases/external. DB). When a user clicks a thumbnail, the UI is re-painted, the real path of the thumbnail is obtained from the database, and the image decoder is called for decoding, return to the re-painted interface. After the resolution is successful, the image will be saved in the SD card as a cache, and the re-loading speed will be faster.
For the drawing of large images, each frame of the image will call ondrawframe to complete the rendering, and finally call the drawfocusitems () function in griddrawmanager. java. The final call Method for drawing a single image is drawdisplayitem (view, GL, displayitem, fstexture, pass_focus_content, null, 1.0f );
The Code is as follows:
private void drawDisplayItem(RenderView view, GL11 gl, DisplayItem displayItem, Texture texture, int pass, Texture previousTexture, float mixRatio) { GridCamera camera = mCamera; Vector3f animatedPosition = displayItem.mAnimatedPosition; float translateXf = animatedPosition.x * camera.mOneByScale; float translateYf = animatedPosition.y * camera.mOneByScale; float translateZf = -animatedPosition.z; int stackId = displayItem.getStackIndex(); final int maxDisplayedItemsPerSlot = (displayItem.mCurrentSlotIndex == mCurrentScaleSlot && mCurrentScaleSlot != Shared.INVALID) ? GridLayer.MAX_DISPLAYED_ITEMS_PER_FOCUSED_SLOT : GridLayer.MAX_DISPLAYED_ITEMS_PER_SLOT; if (pass == PASS_PLACEHOLDER || pass == PASS_FRAME_PLACEHOLDER) { translateZf = -0.04f; } else { if (pass == PASS_FRAME) translateZf += 0.02f; if ((pass == PASS_TEXT_LABEL || pass == PASS_LOCATION_LABEL || pass == PASS_SELECTION_LABEL) && !displayItem.isAlive()) { translateZf = 0.0f; } if (pass == PASS_TEXT_LABEL && translateZf > 0) { translateZf = 0.0f; } } boolean usingMixedTextures = false; boolean bind = false; if ((pass != PASS_THUMBNAIL_CONTENT) || (stackId < maxDisplayedItemsPerSlot && texture.isLoaded() && (previousTexture == null || previousTexture .isLoaded()))) { if (mixRatio == 1.0f || previousTexture == null || texture == previousTexture) { bind = view.bind(texture); } else if (mixRatio != 0.0f) { if (!texture.isLoaded() || !previousTexture.isLoaded()) { // Submit the previous texture to the load queue view.bind(previousTexture); bind = view.bind(texture); } else { usingMixedTextures = true; bind = view.bindMixed(previousTexture, texture, mixRatio); } } else { bind = view.bind(previousTexture); } } else if (stackId >= maxDisplayedItemsPerSlot && pass == PASS_THUMBNAIL_CONTENT) { mDisplayList.setAlive(displayItem, true); } if (!texture.isLoaded() || !bind) { if (pass == PASS_THUMBNAIL_CONTENT) { if (previousTexture != null && previousTexture.isLoaded() && translateZf == 0.0f) { translateZf = -0.08f; bind |= view.bind(previousTexture); } if (!bind) { return; } } else { return; } } else { if (pass == PASS_THUMBNAIL_CONTENT || pass == PASS_FOCUS_CONTENT) { if (!displayItem.mAlive) { mDisplayList.setAlive(displayItem, true); } } } gl.glTranslatef(-translateXf, -translateYf, -translateZf); float theta = (pass == PASS_FOCUS_CONTENT) ? displayItem.mAnimatedImageTheta + displayItem.mAnimatedTheta : displayItem.mAnimatedTheta; if (theta != 0.0f) { gl.glRotatef(theta, 0.0f, 0.0f, 1.0f); } float orientation = 0.0f; if (pass == PASS_THUMBNAIL_CONTENT && displayItem.mAnimatedImageTheta != 0.0f) { orientation = displayItem.mAnimatedImageTheta; } if (pass == PASS_FRAME || pass == PASS_FRAME_PLACEHOLDER) { GridQuadFrame.draw(gl); } else { GridQuad.draw(gl, orientation); } if (theta != 0.0f) { gl.glRotatef(-theta, 0.0f, 0.0f, 1.0f); } gl.glTranslatef(translateXf, translateYf, translateZf); if (usingMixedTextures) { view.unbindMixed(); } }
Summary
This article is just a summative note and does not have a detailed analysis of the Code. For gallery3d Code, some netizens have analyzed it in detail on the Internet, so I will not go into details here. At the same time, in Android 4.0, Google does not continue to use gallery3d, but overwrites its own published Gallery, that is, the gallery2 we see now, in addition, gallery3d in Android 2.3 is discarded (after all, this is a third-party application), so many things have changed on Android 4.0.