diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/gallery3d/app/CropImage.java | 3 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/MoviePlayer.java | 5 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/Wallpaper.java | 6 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/LocalImage.java | 3 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/GLRootView.java | 3 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/TileImageView.java | 13 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/TileImageViewAdapter.java | 50 |
7 files changed, 67 insertions, 16 deletions
diff --git a/src/com/android/gallery3d/app/CropImage.java b/src/com/android/gallery3d/app/CropImage.java index 294e285ea..f2646978a 100644 --- a/src/com/android/gallery3d/app/CropImage.java +++ b/src/com/android/gallery3d/app/CropImage.java @@ -33,7 +33,6 @@ import android.graphics.Rect; import android.graphics.RectF; import android.media.ExifInterface; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; @@ -370,7 +369,7 @@ public class CropImage extends AbstractGalleryActivity { } } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) private static void setImageSize(ContentValues values, int width, int height) { // The two fields are available since ICS but got published in JB if (ApiHelper.HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT) { diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java index c0f0ce739..98d7a6434 100644 --- a/src/com/android/gallery3d/app/MoviePlayer.java +++ b/src/com/android/gallery3d/app/MoviePlayer.java @@ -29,7 +29,6 @@ import android.graphics.Color; import android.media.AudioManager; import android.media.MediaPlayer; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.view.KeyEvent; @@ -179,7 +178,7 @@ public class MoviePlayer implements } } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) private void setOnSystemUiVisibilityChangeListener() { if (!ApiHelper.HAS_VIEW_SYSTEM_UI_FLAG_HIDE_NAVIGATION) return; @@ -213,7 +212,7 @@ public class MoviePlayer implements }); } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) private void showSystemUi(boolean visible) { if (!ApiHelper.HAS_VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE) return; diff --git a/src/com/android/gallery3d/app/Wallpaper.java b/src/com/android/gallery3d/app/Wallpaper.java index d64eecdcf..1ece66c49 100644 --- a/src/com/android/gallery3d/app/Wallpaper.java +++ b/src/com/android/gallery3d/app/Wallpaper.java @@ -25,6 +25,8 @@ import android.os.Build; import android.os.Bundle; import android.view.Display; +import com.android.gallery3d.common.ApiHelper; + /** * Wallpaper picker for the gallery application. This just redirects to the * standard pick action. @@ -61,10 +63,10 @@ public class Wallpaper extends Activity { } @SuppressWarnings("deprecation") - @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) + @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB_MR2) private Point getDefaultDisplaySize(Point size) { Display d = getWindowManager().getDefaultDisplay(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { + if (Build.VERSION.SDK_INT >= ApiHelper.VERSION_CODES.HONEYCOMB_MR2) { d.getSize(size); } else { size.set(d.getWidth(), d.getHeight()); diff --git a/src/com/android/gallery3d/data/LocalImage.java b/src/com/android/gallery3d/data/LocalImage.java index c432ab44d..316e32469 100644 --- a/src/com/android/gallery3d/data/LocalImage.java +++ b/src/com/android/gallery3d/data/LocalImage.java @@ -25,7 +25,6 @@ import android.graphics.BitmapFactory; import android.graphics.BitmapRegionDecoder; import android.media.ExifInterface; import android.net.Uri; -import android.os.Build; import android.provider.MediaStore.Images; import android.provider.MediaStore.Images.ImageColumns; import android.provider.MediaStore.MediaColumns; @@ -86,7 +85,7 @@ public class LocalImage extends LocalMediaItem { updateWidthAndHeightProjection(); } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) private static void updateWidthAndHeightProjection() { if (ApiHelper.HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT) { PROJECTION[INDEX_WIDTH] = MediaColumns.WIDTH; diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java index 2068520aa..478cb4f87 100644 --- a/src/com/android/gallery3d/ui/GLRootView.java +++ b/src/com/android/gallery3d/ui/GLRootView.java @@ -21,7 +21,6 @@ import android.content.Context; import android.graphics.Matrix; import android.graphics.PixelFormat; import android.opengl.GLSurfaceView; -import android.os.Build; import android.os.Process; import android.os.SystemClock; import android.util.AttributeSet; @@ -539,7 +538,7 @@ public class GLRootView extends GLSurfaceView } @Override - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) public void setLightsOutMode(boolean enabled) { int flags = 0; if (enabled) { diff --git a/src/com/android/gallery3d/ui/TileImageView.java b/src/com/android/gallery3d/ui/TileImageView.java index adbf850c1..fc61efd64 100644 --- a/src/com/android/gallery3d/ui/TileImageView.java +++ b/src/com/android/gallery3d/ui/TileImageView.java @@ -23,6 +23,7 @@ import android.graphics.RectF; import android.util.FloatMath; import com.android.gallery3d.app.GalleryContext; +import com.android.gallery3d.common.ApiHelper; import com.android.gallery3d.common.LongSparseArray; import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.BitmapPool; @@ -48,7 +49,9 @@ public class TileImageView extends GLView { private static final int UPLOAD_LIMIT = 1; private static final BitmapPool sTilePool = - new BitmapPool(BITMAP_SIZE, BITMAP_SIZE, 128); + ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER + ? new BitmapPool(BITMAP_SIZE, BITMAP_SIZE, 128) + : null; /* * This is the tile state in the CPU side. @@ -378,7 +381,7 @@ public class TileImageView extends GLView { } } setScreenNail(null); - sTilePool.clear(); + if (sTilePool != null) sTilePool.clear(); } public void prepareTextures() { @@ -487,7 +490,7 @@ public class TileImageView extends GLView { if (tile.mTileState == STATE_RECYCLING) { tile.mTileState = STATE_RECYCLED; if (tile.mDecodedTile != null) { - sTilePool.recycle(tile.mDecodedTile); + if (sTilePool != null) sTilePool.recycle(tile.mDecodedTile); tile.mDecodedTile = null; } mRecycledQueue.push(tile); @@ -515,7 +518,7 @@ public class TileImageView extends GLView { } tile.mTileState = STATE_RECYCLED; if (tile.mDecodedTile != null) { - sTilePool.recycle(tile.mDecodedTile); + if (sTilePool != null) sTilePool.recycle(tile.mDecodedTile); tile.mDecodedTile = null; } mRecycledQueue.push(tile); @@ -653,7 +656,7 @@ public class TileImageView extends GLView { @Override protected void onFreeBitmap(Bitmap bitmap) { - sTilePool.recycle(bitmap); + if (sTilePool != null) sTilePool.recycle(bitmap); } boolean decode() { diff --git a/src/com/android/gallery3d/ui/TileImageViewAdapter.java b/src/com/android/gallery3d/ui/TileImageViewAdapter.java index 0b4ac0375..4865e5c67 100644 --- a/src/com/android/gallery3d/ui/TileImageViewAdapter.java +++ b/src/com/android/gallery3d/ui/TileImageViewAdapter.java @@ -20,8 +20,10 @@ import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.graphics.BitmapRegionDecoder; +import android.graphics.Canvas; import android.graphics.Rect; +import com.android.gallery3d.common.ApiHelper; import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.BitmapPool; @@ -108,6 +110,11 @@ public class TileImageViewAdapter implements TileImageView.Model { @Override public Bitmap getTile(int level, int x, int y, int tileSize, int borderSize, BitmapPool pool) { + + if (!ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER) { + return getTileWithoutReusingBitmap(level, x, y, tileSize, borderSize); + } + int b = borderSize << level; int t = tileSize << level; @@ -158,6 +165,49 @@ public class TileImageViewAdapter implements TileImageView.Model { return bitmap; } + private Bitmap getTileWithoutReusingBitmap( + int level, int x, int y, int tileSize, int borderSize) { + int b = borderSize << level; + int t = tileSize << level; + Rect wantRegion = new Rect(x - b, y - b, x + t + b, y + t + b); + + BitmapRegionDecoder regionDecoder; + Rect overlapRegion; + + synchronized (this) { + regionDecoder = mRegionDecoder; + if (regionDecoder == null) return null; + overlapRegion = new Rect(0, 0, mImageWidth, mImageHeight); + Utils.assertTrue(overlapRegion.intersect(wantRegion)); + } + + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inPreferredConfig = Config.ARGB_8888; + options.inPreferQualityOverSpeed = true; + options.inSampleSize = (1 << level); + Bitmap bitmap = null; + + // In CropImage, we may call the decodeRegion() concurrently. + synchronized (regionDecoder) { + bitmap = regionDecoder.decodeRegion(overlapRegion, options); + } + + if (bitmap == null) { + Log.w(TAG, "fail in decoding region"); + } + + if (wantRegion.equals(overlapRegion)) return bitmap; + + int s = tileSize + 2 * borderSize; + Bitmap result = Bitmap.createBitmap(s, s, Config.ARGB_8888); + Canvas canvas = new Canvas(result); + canvas.drawBitmap(bitmap, + (overlapRegion.left - wantRegion.left) >> level, + (overlapRegion.top - wantRegion.top) >> level, null); + return result; + } + + @Override public ScreenNail getScreenNail() { return mScreenNail; |