diff options
author | ztenghui <ztenghui@google.com> | 2013-09-30 12:19:31 -0700 |
---|---|---|
committer | ztenghui <ztenghui@google.com> | 2013-09-30 16:14:55 -0700 |
commit | 4feabff8b87e1b71e8040dbcd6289a313bf9f593 (patch) | |
tree | c0b1c76660803bc5e8223527936651294981a871 /src | |
parent | c4aa7c0e3c9b6a15eca03ba7bdaaccf3ceb8c15d (diff) | |
download | android_packages_apps_Snap-4feabff8b87e1b71e8040dbcd6289a313bf9f593.tar.gz android_packages_apps_Snap-4feabff8b87e1b71e8040dbcd6289a313bf9f593.tar.bz2 android_packages_apps_Snap-4feabff8b87e1b71e8040dbcd6289a313bf9f593.zip |
Fix MediaStore correction code.
This reverts commit fb344efde20ffab903fae7c6e5a2e1c90b4ef085.
And this CL make sure we handle rotated image correctly and update the
MediaStore according to the bitmap size.
bug:10988273
Change-Id: I9acb60e0dd485292748bcc586801f76bc7a543dc
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/data/LocalMediaData.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/com/android/camera/data/LocalMediaData.java b/src/com/android/camera/data/LocalMediaData.java index ca29ad24b..9b61fc38d 100644 --- a/src/com/android/camera/data/LocalMediaData.java +++ b/src/com/android/camera/data/LocalMediaData.java @@ -505,6 +505,43 @@ public abstract class LocalMediaData implements LocalData { sampleSize = Math.max(heightRatio, widthRatio); } + // For correctness, we need to double check the size here. The + // good news is that decoding bounds take much less time than + // decoding samples like < 1%. + // TODO: better organize the decoding and sampling by using a + // image cache. + int decodedWidth = 0; + int decodedHeight = 0; + BitmapFactory.Options justBoundsOpts = new BitmapFactory.Options(); + justBoundsOpts.inJustDecodeBounds = true; + BitmapFactory.decodeFile(mPath, justBoundsOpts); + if (justBoundsOpts.outWidth > 0 && justBoundsOpts.outHeight > 0) { + decodedWidth = justBoundsOpts.outWidth; + decodedHeight = justBoundsOpts.outHeight; + } + + int viewWidth = decodedWidth; + int viewHeight = decodedHeight; + if (mOrientation == 90 || mOrientation == 270) { + viewWidth = decodedHeight; + viewHeight = decodedWidth; + } + + // If the width and height is valid and not matching the values + // from MediaStore, then update the MediaStore. This only + // happened when the MediaStore had been told a wrong data. + if (viewWidth > 0 && viewHeight > 0 && + (viewWidth != mWidth || viewHeight != mHeight)) { + ContentValues values = new ContentValues(); + values.put(Images.Media.WIDTH, decodedWidth); + values.put(Images.Media.HEIGHT, decodedHeight); + mResolver.update(getContentUri(), values, null, null); + mNeedsRefresh = true; + Log.w(TAG, "Uri " + getContentUri() + " has been updated with" + + " correct size!"); + return null; + } + BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = sampleSize; opts.inTempStorage = DECODE_TEMP_STORAGE; @@ -524,6 +561,13 @@ public abstract class LocalMediaData implements LocalData { return b; } + @Override + protected void onPostExecute(Bitmap bitmap) { + super.onPostExecute(bitmap); + if (mNeedsRefresh && mAdapter != null) { + mAdapter.refresh(mResolver, getContentUri()); + } + } } @Override |