diff options
author | ztenghui <ztenghui@google.com> | 2013-09-05 15:47:58 -0700 |
---|---|---|
committer | ztenghui <ztenghui@google.com> | 2013-09-19 11:12:50 -0700 |
commit | 064d6000933354f7bf344a41e0caa7052401c903 (patch) | |
tree | f442349e15a415ad0af271960391175b1f5100d2 /src/com/android/camera/data | |
parent | a5682ab08e1d42fe272ec877929478b4adb769f5 (diff) | |
download | android_packages_apps_Snap-064d6000933354f7bf344a41e0caa7052401c903.tar.gz android_packages_apps_Snap-064d6000933354f7bf344a41e0caa7052401c903.tar.bz2 android_packages_apps_Snap-064d6000933354f7bf344a41e0caa7052401c903.zip |
Use contentObserver to refresh the data when dirty.
Handle another setDataSource exception.
Remove the old work around for refreshing after editing.
bug:10390298
Change-Id: I8777364b96c86eeaf5581a96163aab823cd4b438
Diffstat (limited to 'src/com/android/camera/data')
-rw-r--r-- | src/com/android/camera/data/LocalMediaData.java | 27 | ||||
-rw-r--r-- | src/com/android/camera/data/LocalMediaObserver.java | 47 |
2 files changed, 62 insertions, 12 deletions
diff --git a/src/com/android/camera/data/LocalMediaData.java b/src/com/android/camera/data/LocalMediaData.java index 573da45db..17ddbca42 100644 --- a/src/com/android/camera/data/LocalMediaData.java +++ b/src/com/android/camera/data/LocalMediaData.java @@ -495,7 +495,7 @@ public abstract class LocalMediaData implements LocalData { return null; } Bitmap b = BitmapFactory.decodeFile(mPath, opts); - if (mOrientation != 0) { + if (mOrientation != 0 && b != null) { if (isCancelled() || !isUsing()) { return null; } @@ -742,18 +742,21 @@ public abstract class LocalMediaData implements LocalData { return null; } MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setDataSource(mPath); - byte[] data = retriever.getEmbeddedPicture(); Bitmap bitmap = null; - if (isCancelled() || !isUsing()) { - retriever.release(); - return null; - } - if (data != null) { - bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); - } - if (bitmap == null) { - bitmap = retriever.getFrameAtTime(); + try { + retriever.setDataSource(mPath); + byte[] data = retriever.getEmbeddedPicture(); + if (!isCancelled() && isUsing()) { + if (data != null) { + bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); + } + if (bitmap == null) { + bitmap = retriever.getFrameAtTime(); + } + } + } catch (IllegalArgumentException e) { + Log.e(TAG, "MediaMetadataRetriever.setDataSource() fail:" + + e.getMessage()); } retriever.release(); return bitmap; diff --git a/src/com/android/camera/data/LocalMediaObserver.java b/src/com/android/camera/data/LocalMediaObserver.java new file mode 100644 index 000000000..4dd0f8897 --- /dev/null +++ b/src/com/android/camera/data/LocalMediaObserver.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.camera.data; + +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Handler; + +import com.android.camera.CameraActivity; + +/** + * Listening to the changes to the local image and video data. onChange will + * happen on the main thread. + */ +public class LocalMediaObserver extends ContentObserver { + + private final CameraActivity mActivity; + + public LocalMediaObserver(Handler handler, CameraActivity activity) { + super(handler); + mActivity = activity; + } + + @Override + public void onChange(boolean selfChange) { + this.onChange(selfChange, null); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + mActivity.setDirtyWhenPaused(); + } +} |