diff options
author | Roman Birg <roman@cyngn.com> | 2014-04-24 22:24:07 -0700 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2014-04-28 17:37:24 -0700 |
commit | 29c2da02bf48fbdba977bc774027e218487e1abe (patch) | |
tree | 092a27cf31a18ea7922dc81d0d523c33f350adfb /src/com/android/photos/BitmapRegionTileSource.java | |
parent | dcbd1c41eec21fca93eb95f769b8a9722e0379a6 (diff) | |
download | android_packages_apps_Trebuchet-29c2da02bf48fbdba977bc774027e218487e1abe.tar.gz android_packages_apps_Trebuchet-29c2da02bf48fbdba977bc774027e218487e1abe.tar.bz2 android_packages_apps_Trebuchet-29c2da02bf48fbdba977bc774027e218487e1abe.zip |
Trebuchet: add lockscreen wallpaper picker
Change-Id: Ic4f2589924a3c61b676db907f08108286dc45c29
Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src/com/android/photos/BitmapRegionTileSource.java')
-rw-r--r-- | src/com/android/photos/BitmapRegionTileSource.java | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/src/com/android/photos/BitmapRegionTileSource.java b/src/com/android/photos/BitmapRegionTileSource.java index 5f6401868..4d1a84ed7 100644 --- a/src/com/android/photos/BitmapRegionTileSource.java +++ b/src/com/android/photos/BitmapRegionTileSource.java @@ -18,6 +18,7 @@ package com.android.photos; import android.annotation.TargetApi; import android.content.Context; +import android.content.res.AssetManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; @@ -36,6 +37,7 @@ import com.android.gallery3d.glrenderer.BitmapTexture; import com.android.photos.views.TiledImageRenderer; import java.io.BufferedInputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -69,25 +71,38 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { private Canvas mCanvas; public BitmapRegionTileSource(Context context, String path, int previewSize, int rotation) { - this(null, context, path, null, 0, previewSize, rotation); + this(null, context, path, null, 0, previewSize, rotation, false); + } + + public BitmapRegionTileSource(Resources res, Context context, String path, int previewSize, int rotation, boolean assetPath) { + this(res, context, path, null, 0, previewSize, rotation, assetPath); } public BitmapRegionTileSource(Context context, Uri uri, int previewSize, int rotation) { - this(null, context, null, uri, 0, previewSize, rotation); + this(null, context, null, uri, 0, previewSize, rotation, false); } public BitmapRegionTileSource(Resources res, Context context, int resId, int previewSize, int rotation) { - this(res, context, null, null, resId, previewSize, rotation); + this(res, context, null, null, resId, previewSize, rotation, false); } private BitmapRegionTileSource(Resources res, - Context context, String path, Uri uri, int resId, int previewSize, int rotation) { + Context context, String path, Uri uri, int resId, int previewSize, int rotation, boolean assetPath) { mTileSize = TiledImageRenderer.suggestedTileSize(context); mRotation = rotation; try { - if (path != null) { + if (path != null && !assetPath) { mDecoder = BitmapRegionDecoder.newInstance(path, true); + } else if (path != null && res != null && assetPath) { + AssetManager am = res.getAssets(); + String[] pathImages = am.list(path); + if (pathImages == null || pathImages.length == 0) { + throw new IOException("did not find any images in path: " + path); + } + InputStream is = am.open(path + File.separator + pathImages[0]); + BufferedInputStream bis = new BufferedInputStream(is); + mDecoder = BitmapRegionDecoder.newInstance(bis, true); } else if (uri != null) { InputStream is = context.getContentResolver().openInputStream(uri); BufferedInputStream bis = new BufferedInputStream(is); @@ -111,7 +126,7 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { // Although this is the same size as the Bitmap that is likely already // loaded, the lifecycle is different and interactions are on a different // thread. Thus to simplify, this source will decode its own bitmap. - Bitmap preview = decodePreview(res, context, path, uri, resId, previewSize); + Bitmap preview = decodePreview(res, context, path, uri, resId, previewSize, assetPath); if (preview.getWidth() <= GL_SIZE_LIMIT && preview.getHeight() <= GL_SIZE_LIMIT) { mPreview = new BitmapTexture(preview); } else { @@ -216,13 +231,26 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { * than the targetSize, but it will always be less than 2x the targetSize */ private Bitmap decodePreview( - Resources res, Context context, String file, Uri uri, int resId, int targetSize) { + Resources res, Context context, String file, Uri uri, int resId, int targetSize, boolean assetPath) { float scale = (float) targetSize / Math.max(mWidth, mHeight); mOptions.inSampleSize = BitmapUtils.computeSampleSizeLarger(scale); mOptions.inJustDecodeBounds = false; Bitmap result = null; - if (file != null) { + if (file != null && res != null && assetPath) { + try { + AssetManager am = res.getAssets(); + String[] pathImages = am.list(file); + if (pathImages == null || pathImages.length == 0) { + throw new IOException("did not find any images in path: " + file); + } + InputStream is = am.open(file + File.separator + pathImages[0]); + BufferedInputStream bis = new BufferedInputStream(is); + result = BitmapFactory.decodeStream(bis, null, mOptions); + } catch (IOException e) { + Log.w("BitmapRegionTileSource", "getting preview failed", e); + } + } else if (file != null) { result = BitmapFactory.decodeFile(file, mOptions); } else if (uri != null) { try { |