diff options
author | Owen Lin <> | 2009-04-14 02:02:51 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-14 02:02:51 -0700 |
commit | 937fc48b37fafe3ffc8f4b52bd9a171bbb4d3a37 (patch) | |
tree | 5e11cdcd63e1aef4e0502ea08e51226b227085e6 /src/com/android/camera/gallery | |
parent | 9d6fbf9660a0c3d289c539e0275272d31b0ef596 (diff) | |
download | LegacyCamera-937fc48b37fafe3ffc8f4b52bd9a171bbb4d3a37.zip LegacyCamera-937fc48b37fafe3ffc8f4b52bd9a171bbb4d3a37.tar.gz LegacyCamera-937fc48b37fafe3ffc8f4b52bd9a171bbb4d3a37.tar.bz2 |
AI 146099: 1. Use ICancelable<T> to replace several different interfaces, such as IGetBooleanCancelable.
2. Remove some warnings.
Automated import of CL 146099
Diffstat (limited to 'src/com/android/camera/gallery')
-rw-r--r-- | src/com/android/camera/gallery/BaseCancelable.java | 2 | ||||
-rw-r--r-- | src/com/android/camera/gallery/BaseImage.java | 14 | ||||
-rw-r--r-- | src/com/android/camera/gallery/BaseImageList.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/gallery/IAddImageCancelable.java | 10 | ||||
-rw-r--r-- | src/com/android/camera/gallery/ICancelable.java | 4 | ||||
-rw-r--r-- | src/com/android/camera/gallery/IGetBitmapCancelable.java | 27 | ||||
-rw-r--r-- | src/com/android/camera/gallery/IGetBooleanCancelable.java | 24 | ||||
-rw-r--r-- | src/com/android/camera/gallery/IImage.java | 2 | ||||
-rw-r--r-- | src/com/android/camera/gallery/Image.java | 19 | ||||
-rw-r--r-- | src/com/android/camera/gallery/ImageList.java | 1 | ||||
-rw-r--r-- | src/com/android/camera/gallery/ImageListUber.java | 1 | ||||
-rw-r--r-- | src/com/android/camera/gallery/MiniThumbFile.java | 9 | ||||
-rw-r--r-- | src/com/android/camera/gallery/SingleImageList.java | 9 | ||||
-rw-r--r-- | src/com/android/camera/gallery/Util.java | 216 | ||||
-rw-r--r-- | src/com/android/camera/gallery/VideoList.java | 5 | ||||
-rw-r--r-- | src/com/android/camera/gallery/VideoObject.java | 6 |
16 files changed, 39 insertions, 318 deletions
diff --git a/src/com/android/camera/gallery/BaseCancelable.java b/src/com/android/camera/gallery/BaseCancelable.java index dbc46cc..de23521 100644 --- a/src/com/android/camera/gallery/BaseCancelable.java +++ b/src/com/android/camera/gallery/BaseCancelable.java @@ -20,7 +20,7 @@ package com.android.camera.gallery; /** * A base class for the interface <code>ICancelable</code>. */ -public abstract class BaseCancelable implements ICancelable { +public abstract class BaseCancelable<T> implements ICancelable<T> { protected boolean mCancel = false; protected boolean mFinished = false; diff --git a/src/com/android/camera/gallery/BaseImage.java b/src/com/android/camera/gallery/BaseImage.java index f11cc26..8b521d9 100644 --- a/src/com/android/camera/gallery/BaseImage.java +++ b/src/com/android/camera/gallery/BaseImage.java @@ -17,6 +17,7 @@ package com.android.camera.gallery; import com.android.camera.BitmapManager; +import com.android.camera.Util; import android.content.ContentResolver; import android.database.Cursor; @@ -27,7 +28,6 @@ import android.os.ParcelFileDescriptor; import android.provider.MediaStore.Images; import android.util.Log; - import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -74,8 +74,7 @@ public abstract class BaseImage implements IImage { } } - private class CompressImageToFile extends BaseCancelable - implements IGetBooleanCancelable { + private class CompressImageToFile extends BaseCancelable<Boolean> { private ThreadSafeOutputStream mOutputStream = null; private Bitmap mBitmap; @@ -97,7 +96,7 @@ public abstract class BaseImage implements IImage { return false; } - public boolean get() { + public Boolean get() { try { long t1 = System.currentTimeMillis(); OutputStream delegate = mContentResolver.openOutputStream(mUri); @@ -145,7 +144,7 @@ public abstract class BaseImage implements IImage { * @param uri where to store the bitmap * @return true if we succeeded */ - protected IGetBooleanCancelable compressImageToFile( + protected ICancelable<Boolean> compressImageToFile( Bitmap bitmap, byte [] jpegData, Uri uri) { return new CompressImageToFile(bitmap, jpegData, uri); } @@ -178,8 +177,7 @@ public abstract class BaseImage implements IImage { return b; } - private class LoadBitmapCancelable extends BaseCancelable - implements IGetBitmapCancelable { + private class LoadBitmapCancelable extends BaseCancelable<Bitmap> { private ParcelFileDescriptor mPFD; private BitmapFactory.Options mOptions = new BitmapFactory.Options(); private long mCancelInitiationTime; @@ -224,7 +222,7 @@ public abstract class BaseImage implements IImage { } - public IGetBitmapCancelable fullSizeBitmapCancelable( + public ICancelable<Bitmap> fullSizeBitmapCancelable( int targetWidthHeight) { try { ParcelFileDescriptor pfdInput = mContentResolver diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java index 49b43d3..18eef1d 100644 --- a/src/com/android/camera/gallery/BaseImageList.java +++ b/src/com/android/camera/gallery/BaseImageList.java @@ -17,6 +17,9 @@ package com.android.camera.gallery; import com.android.camera.BitmapManager; +import com.android.camera.ExifInterface; +import com.android.camera.ImageManager; +import com.android.camera.Util; import android.content.ContentResolver; import android.content.ContentUris; @@ -34,9 +37,6 @@ import android.provider.MediaStore.Images.Thumbnails; import android.provider.MediaStore.MediaColumns; import android.util.Log; -import com.android.camera.ExifInterface; -import com.android.camera.ImageManager; - import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; @@ -284,7 +284,7 @@ public abstract class BaseImageList implements IImageList { if (BitmapManager.instance().acquireResourceLock() == false) { return -1; } - + try { if (existingImage == null) { // if we don't have an Image object then get the id and magic diff --git a/src/com/android/camera/gallery/IAddImageCancelable.java b/src/com/android/camera/gallery/IAddImageCancelable.java deleted file mode 100644 index 30a6880..0000000 --- a/src/com/android/camera/gallery/IAddImageCancelable.java +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2009 Google Inc. All Rights Reserved. - -package com.android.camera.gallery; - -/** - * Cancelable interface for add image task. - */ -public interface IAddImageCancelable extends ICancelable { - public void get(); -}
\ No newline at end of file diff --git a/src/com/android/camera/gallery/ICancelable.java b/src/com/android/camera/gallery/ICancelable.java index ca02e79..9c9e1bf 100644 --- a/src/com/android/camera/gallery/ICancelable.java +++ b/src/com/android/camera/gallery/ICancelable.java @@ -19,7 +19,7 @@ package com.android.camera.gallery; /** * The interface for all the tasks that could be canceled. */ -public interface ICancelable { +public interface ICancelable<T> { /* * call cancel() when the unit of work in progress needs to be * canceled. This should return true if it was possible to @@ -27,4 +27,6 @@ public interface ICancelable { * may still be able to cleanup and simulate cancelation. */ public boolean cancel(); + + public T get(); }
\ No newline at end of file diff --git a/src/com/android/camera/gallery/IGetBitmapCancelable.java b/src/com/android/camera/gallery/IGetBitmapCancelable.java deleted file mode 100644 index 32f8b91..0000000 --- a/src/com/android/camera/gallery/IGetBitmapCancelable.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2009 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.gallery; - -import android.graphics.Bitmap; - -/** - * An <code>ICancelable</code> interface which will return a bitmap. - */ -public interface IGetBitmapCancelable extends ICancelable { - // returns the bitmap or null if there was an error or we were canceled - public Bitmap get(); -}
\ No newline at end of file diff --git a/src/com/android/camera/gallery/IGetBooleanCancelable.java b/src/com/android/camera/gallery/IGetBooleanCancelable.java deleted file mode 100644 index c85f223..0000000 --- a/src/com/android/camera/gallery/IGetBooleanCancelable.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2009 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.gallery; - -/** - * An <code>ICancelable</code> interface which will return a boolean value. - */ -public interface IGetBooleanCancelable extends ICancelable { - public boolean get(); -}
\ No newline at end of file diff --git a/src/com/android/camera/gallery/IImage.java b/src/com/android/camera/gallery/IImage.java index c91fb7f..aee46f0 100644 --- a/src/com/android/camera/gallery/IImage.java +++ b/src/com/android/camera/gallery/IImage.java @@ -38,7 +38,7 @@ public interface IImage { * * @return an object which can be canceled while the bitmap is loading */ - public abstract IGetBitmapCancelable fullSizeBitmapCancelable( + public abstract ICancelable<Bitmap> fullSizeBitmapCancelable( int targetWidthOrHeight); /** diff --git a/src/com/android/camera/gallery/Image.java b/src/com/android/camera/gallery/Image.java index c1a0a13..2ec100a 100644 --- a/src/com/android/camera/gallery/Image.java +++ b/src/com/android/camera/gallery/Image.java @@ -17,6 +17,9 @@ package com.android.camera.gallery; import com.android.camera.BitmapManager; +import com.android.camera.ExifInterface; +import com.android.camera.ImageManager; +import com.android.camera.Util; import android.content.ContentResolver; import android.content.ContentUris; @@ -28,9 +31,6 @@ import android.os.ParcelFileDescriptor; import android.provider.MediaStore.Images.Thumbnails; import android.util.Log; -import com.android.camera.ExifInterface; -import com.android.camera.ImageManager; - import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; @@ -165,13 +165,12 @@ public class Image extends BaseImage implements IImage { mExifData.put(tag, value); } - private class SaveImageContentsCancelable extends BaseCancelable - implements IGetBooleanCancelable { + private class SaveImageContentsCancelable extends BaseCancelable<Boolean> { private Bitmap mImage; private byte [] mJpegData; private int mOrientation; private Cursor mCursor; - IGetBooleanCancelable mCurrentCancelable = null; + ICancelable<Boolean> mCurrentCancelable = null; SaveImageContentsCancelable(Bitmap image, byte[] jpegData, int orientation, Cursor cursor) { @@ -189,7 +188,7 @@ public class Image extends BaseImage implements IImage { return true; } - public boolean get() { + public Boolean get() { try { Bitmap thumbnail = null; @@ -198,7 +197,7 @@ public class Image extends BaseImage implements IImage { synchronized (this) { checkCanceled(); mCurrentCancelable = - compressImageToFile(mImage, mJpegData, uri); + compressImageToFile(mImage, mJpegData, uri); } long t2 = System.currentTimeMillis(); @@ -277,7 +276,7 @@ public class Image extends BaseImage implements IImage { } } - public IGetBooleanCancelable saveImageContents(Bitmap image, + public ICancelable<Boolean> saveImageContents(Bitmap image, byte [] jpegData, int orientation, boolean newFile, Cursor cursor) { return new SaveImageContentsCancelable( image, jpegData, orientation, cursor); @@ -385,7 +384,7 @@ public class Image extends BaseImage implements IImage { private Bitmap decodeCurrentImage(Cursor c) { Uri thumbUri = ContentUris.withAppendedId( mContainer.mThumbUri, - c.getLong(((ImageList) mContainer).INDEX_THUMB_ID)); + c.getLong(ImageList.INDEX_THUMB_ID)); ParcelFileDescriptor pfdInput; Bitmap bitmap = null; try { diff --git a/src/com/android/camera/gallery/ImageList.java b/src/com/android/camera/gallery/ImageList.java index 2f638b5..75ed900 100644 --- a/src/com/android/camera/gallery/ImageList.java +++ b/src/com/android/camera/gallery/ImageList.java @@ -18,6 +18,7 @@ package com.android.camera.gallery; import com.android.camera.BitmapManager; import com.android.camera.ImageManager; +import com.android.camera.Util; import android.content.ContentResolver; import android.content.Context; diff --git a/src/com/android/camera/gallery/ImageListUber.java b/src/com/android/camera/gallery/ImageListUber.java index 0f24aef..2f97b9f 100644 --- a/src/com/android/camera/gallery/ImageListUber.java +++ b/src/com/android/camera/gallery/ImageListUber.java @@ -19,7 +19,6 @@ package com.android.camera.gallery; import com.android.camera.ImageManager; import android.net.Uri; -import android.os.Handler; import android.util.Log; import java.util.ArrayList; diff --git a/src/com/android/camera/gallery/MiniThumbFile.java b/src/com/android/camera/gallery/MiniThumbFile.java index e2c825c..692dacf 100644 --- a/src/com/android/camera/gallery/MiniThumbFile.java +++ b/src/com/android/camera/gallery/MiniThumbFile.java @@ -16,8 +16,10 @@ package com.android.camera.gallery; +import com.android.camera.Util; + import android.graphics.Bitmap; -import android.net.Uri; +import android.net.Uri; import android.os.Environment; import android.util.Log; @@ -40,10 +42,9 @@ class MiniThumbFile { private static final int MINI_THUMB_DATA_FILE_VERSION = 3; public static final int BYTES_PER_MINTHUMB = 10000; private static final int HEADER_SIZE = 1 + 8 + 4; - private static final byte [] sMiniThumbData = new byte[BYTES_PER_MINTHUMB]; private Uri mUri; - private RandomAccessFile mMiniThumbFile; - + private RandomAccessFile mMiniThumbFile; + private String randomAccessFilePath(int version) { String directoryName = Environment.getExternalStorageDirectory().toString() diff --git a/src/com/android/camera/gallery/SingleImageList.java b/src/com/android/camera/gallery/SingleImageList.java index 6fe7241..099a01f 100644 --- a/src/com/android/camera/gallery/SingleImageList.java +++ b/src/com/android/camera/gallery/SingleImageList.java @@ -17,6 +17,8 @@ package com.android.camera.gallery; import com.android.camera.BitmapManager; +import com.android.camera.ImageManager; +import com.android.camera.Util; import android.content.ContentResolver; import android.graphics.Bitmap; @@ -26,8 +28,6 @@ import android.net.Uri; import android.os.ParcelFileDescriptor; import android.util.Log; -import com.android.camera.ImageManager; - import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; @@ -113,8 +113,7 @@ public class SingleImageList extends BaseImageList implements IImageList { } } - final class LoadBitmapCancelable extends BaseCancelable - implements IGetBitmapCancelable { + final class LoadBitmapCancelable extends BaseCancelable<Bitmap> { ParcelFileDescriptor mPfdInput; BitmapFactory.Options mOptions = new BitmapFactory.Options(); long mCancelInitiationTime; @@ -157,7 +156,7 @@ public class SingleImageList extends BaseImageList implements IImageList { } } - public IGetBitmapCancelable fullSizeBitmapCancelable( + public ICancelable<Bitmap> fullSizeBitmapCancelable( int targetWidthOrHeight) { try { ParcelFileDescriptor pfdInput = getPFD(); diff --git a/src/com/android/camera/gallery/Util.java b/src/com/android/camera/gallery/Util.java deleted file mode 100644 index 04998ef..0000000 --- a/src/com/android/camera/gallery/Util.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (C) 2009 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.gallery; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.media.MediaMetadataRetriever; -import android.os.ParcelFileDescriptor; -import android.util.Log; - -import com.android.camera.ImageLoader; -import com.android.camera.ImageManager; - -import java.io.ByteArrayOutputStream; -import java.io.Closeable; - -/** - * Collection of utility functions used in this package. - */ -public class Util { - private static final boolean VERBOSE = false; - private static final String TAG = "db.Util"; - - private Util() { - } - - // Rotates the bitmap by the specified degree. - // If a new bitmap is created, the original bitmap is recycled. - public static Bitmap rotate(Bitmap b, int degrees) { - if (degrees != 0 && b != null) { - Matrix m = new Matrix(); - m.setRotate(degrees, - (float) b.getWidth() / 2, (float) b.getHeight() / 2); - try { - Bitmap b2 = Bitmap.createBitmap( - b, 0, 0, b.getWidth(), b.getHeight(), m, true); - if (b != b2) { - b.recycle(); - b = b2; - } - } catch (OutOfMemoryError ex) { - // We have no memory to rotate. Return the original bitmap. - } - } - return b; - } - - /* - * Compute the sample size as a function of the image size and the target. - * Scale the image down so that both the width and height are just above the - * target. If this means that one of the dimension goes from above the - * target to below the target (e.g. given a width of 480 and an image width - * of 600 but sample size of 2 -- i.e. new width 300 -- bump the sample size - * down by 1. - */ - public static int computeSampleSize( - BitmapFactory.Options options, int target) { - int w = options.outWidth; - int h = options.outHeight; - - int candidateW = w / target; - int candidateH = h / target; - int candidate = Math.max(candidateW, candidateH); - - if (candidate == 0) return 1; - - if (candidate > 1) { - if ((w > target) && (w / candidate) < target) candidate -= 1; - } - - if (candidate > 1) { - if ((h > target) && (h / candidate) < target) candidate -= 1; - } - - if (VERBOSE) { - Log.v(TAG, "for w/h " + w + "/" + h + " returning " + candidate - + "(" + (w / candidate) + " / " + (h / candidate)); - } - - return candidate; - } - - /** - * Creates a centered bitmap of the desired size. Recycles the input. - * @param source - */ - public static Bitmap extractMiniThumb( - Bitmap source, int width, int height) { - return Util.extractMiniThumb(source, width, height, true); - } - - public static Bitmap extractMiniThumb( - Bitmap source, int width, int height, boolean recycle) { - if (source == null) { - return null; - } - - float scale; - if (source.getWidth() < source.getHeight()) { - scale = width / (float) source.getWidth(); - } else { - scale = height / (float) source.getHeight(); - } - Matrix matrix = new Matrix(); - matrix.setScale(scale, scale); - Bitmap miniThumbnail = ImageLoader.transform(matrix, source, - width, height, false); - - if (recycle && miniThumbnail != source) { - source.recycle(); - } - return miniThumbnail; - } - - /** - * Creates a byte[] for a given bitmap of the desired size. Recycles the - * input bitmap. - */ - public static byte[] miniThumbData(Bitmap source) { - if (source == null) return null; - - Bitmap miniThumbnail = extractMiniThumb( - source, ImageManager.MINI_THUMB_TARGET_SIZE, - ImageManager.MINI_THUMB_TARGET_SIZE); - - ByteArrayOutputStream miniOutStream = new ByteArrayOutputStream(); - miniThumbnail.compress(Bitmap.CompressFormat.JPEG, 75, miniOutStream); - miniThumbnail.recycle(); - - try { - miniOutStream.close(); - byte [] data = miniOutStream.toByteArray(); - return data; - } catch (java.io.IOException ex) { - Log.e(TAG, "got exception ex " + ex); - } - return null; - } - - /** - * @return true if the mimetype is a video mimetype. - */ - public static boolean isVideoMimeType(String mimeType) { - return mimeType.startsWith("video/"); - } - - /** - * Create a video thumbnail for a video. May return null if the video is - * corrupt. - * - * @param filePath - */ - public static Bitmap createVideoThumbnail(String filePath) { - Bitmap bitmap = null; - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - try { - retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY); - retriever.setDataSource(filePath); - bitmap = retriever.captureFrame(); - } catch (IllegalArgumentException ex) { - // Assume this is a corrupt video file - } catch (RuntimeException ex) { - // Assume this is a corrupt video file. - } finally { - try { - retriever.release(); - } catch (RuntimeException ex) { - // Ignore failures while cleaning up. - } - } - return bitmap; - } - - public static int indexOf(String [] array, String s) { - for (int i = 0; i < array.length; i++) { - if (array[i].equals(s)) { - return i; - } - } - return -1; - } - - public static void closeSiliently(Closeable c) { - if (c == null) return; - try { - c.close(); - } catch (Throwable t) { - // do nothing - } - } - - public static void closeSiliently(ParcelFileDescriptor c) { - if (c == null) return; - try { - c.close(); - } catch (Throwable t) { - // do nothing - } - } - -} diff --git a/src/com/android/camera/gallery/VideoList.java b/src/com/android/camera/gallery/VideoList.java index 3f67113..995fd65 100644 --- a/src/com/android/camera/gallery/VideoList.java +++ b/src/com/android/camera/gallery/VideoList.java @@ -16,7 +16,8 @@ package com.android.camera.gallery; -import static com.android.camera.gallery.BaseImageList.MINITHUMB_IS_NULL; +import com.android.camera.ImageManager; +import com.android.camera.Util; import android.content.ContentResolver; import android.content.Context; @@ -33,8 +34,6 @@ import android.provider.MediaStore.Video.VideoColumns; import android.util.Config; import android.util.Log; -import com.android.camera.ImageManager; - import java.io.IOException; import java.util.HashMap; diff --git a/src/com/android/camera/gallery/VideoObject.java b/src/com/android/camera/gallery/VideoObject.java index cd75e61..d4ce04e 100644 --- a/src/com/android/camera/gallery/VideoObject.java +++ b/src/com/android/camera/gallery/VideoObject.java @@ -16,12 +16,12 @@ package com.android.camera.gallery; +import com.android.camera.ImageManager; + import android.content.ContentResolver; import android.database.Cursor; import android.graphics.Bitmap; -import com.android.camera.ImageManager; - import java.io.IOException; import java.io.InputStream; @@ -78,7 +78,7 @@ public class VideoObject extends BaseImage implements IImage { } @Override - public IGetBitmapCancelable fullSizeBitmapCancelable( + public ICancelable<Bitmap> fullSizeBitmapCancelable( int targetWidthHeight) { return null; } |