diff options
author | Chih-Chung Chang <chihchung@google.com> | 2009-04-14 18:00:10 +0800 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2009-04-15 14:53:17 +0800 |
commit | 2b82c4a17abfe926dc2942a6d1bf7982b006de6d (patch) | |
tree | 7a441c7356f13ed1e52b1633f955645ef2da9eb6 /src | |
parent | 14c3da178d14d461f93036b3c2471bc6471ae249 (diff) | |
download | LegacyCamera-2b82c4a17abfe926dc2942a6d1bf7982b006de6d.zip LegacyCamera-2b82c4a17abfe926dc2942a6d1bf7982b006de6d.tar.gz LegacyCamera-2b82c4a17abfe926dc2942a6d1bf7982b006de6d.tar.bz2 |
Clean verbose logging messages.
Extract UriImage to a separate file.
Diffstat (limited to 'src')
26 files changed, 340 insertions, 872 deletions
diff --git a/src/com/android/camera/BitmapManager.java b/src/com/android/camera/BitmapManager.java index 84eae54..7229162 100644 --- a/src/com/android/camera/BitmapManager.java +++ b/src/com/android/camera/BitmapManager.java @@ -19,7 +19,6 @@ package com.android.camera; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Rect; -import android.util.Config; import android.util.Log; import java.io.FileDescriptor; @@ -39,8 +38,7 @@ import java.util.WeakHashMap; */ public class BitmapManager { private static final String TAG = "BitmapManager"; - private static final boolean VERBOSE = - Config.LOGD && (false || Config.LOGV); + private static final boolean VERBOSE = false; private static enum State {RUNNING, CANCEL, WAIT} private static class ThreadStatus { public State state = State.WAIT; @@ -109,21 +107,11 @@ public class BitmapManager { Thread t = Thread.currentThread(); ThreadStatus status = getThreadStatus(t, true); - if (VERBOSE) { - Log.v(TAG, "lock... thread " + t + "(" + t.getId() + ")"); - } - while (mLocked) { try { - if (VERBOSE) { - Log.v(TAG, "waiting... thread " + t.getId()); - } wait(); // remove canceled thread if (status.state == State.CANCEL) { - if (VERBOSE) { - Log.v(TAG, "[" + t + "] someone cancels me!!"); - } return false; } } catch (InterruptedException ex) { @@ -131,9 +119,6 @@ public class BitmapManager { } } - if (VERBOSE) { - Log.v(TAG, "locked... thread " + t + "(" + t.getId() + ")"); - } status.state = State.RUNNING; mLocked = true; return true; @@ -144,9 +129,6 @@ public class BitmapManager { */ public synchronized void releaseResourceLock() { Thread t = Thread.currentThread(); - if (VERBOSE) { - Log.v(TAG, "unlocking... thread " + t + "(" + t.getId() + ")"); - } mLocked = false; notifyAll(); } @@ -157,10 +139,6 @@ public class BitmapManager { */ private synchronized void setDecodingOptions(Thread t, BitmapFactory.Options options) { - if (VERBOSE) { - Log.v(TAG, "setDecodingOptions for thread " + t.getId() - + ", options=" + options); - } getThreadStatus(t, true).options = options; } @@ -170,9 +148,6 @@ public class BitmapManager { } synchronized void removeDecodingOptions(Thread t) { - if (VERBOSE) { - Log.v(TAG, "removeDecodingOptions for thread " + t.getId()); - } ThreadStatus status = mThreadStatus.get(t); status.options = null; } @@ -190,31 +165,17 @@ public class BitmapManager { boolean result = (status.state == State.RUNNING) || (status.state != State.CANCEL && !mCheckResourceLock); - if (VERBOSE) { - Log.v(TAG, "canThread " + t + " allow to decode " - + result); - } return result; } public synchronized void allowThreadDecoding(Thread t) { - if (VERBOSE) { - Log.v(TAG, "allowThreadDecoding: " + t + "(" + t.getId() + ")"); - } getThreadStatus(t, true).state = State.WAIT; } public synchronized void cancelThreadDecoding(Thread t) { - if (VERBOSE) { - Log.v(TAG, "[Cancel Thread] cancelThreadDecode: " - + t + "(" + t.getId() + ")"); - } ThreadStatus status = getThreadStatus(t, true); status.state = State.CANCEL; if (status.options != null) { - if (VERBOSE) { - Log.v(TAG, "[Cancel Decoding] options: " + status.options); - } status.options.requestCancelDecode(); } @@ -227,16 +188,10 @@ public class BitmapManager { * bitmap decoding. */ public synchronized void cancelAllDecoding() { - if (VERBOSE) { - Log.v(TAG, ">>>>>>>> cancelAllDecoding <<<<<<<"); - } allowAllDecoding(false); for (ThreadStatus status : mThreadStatus.values()) { status.state = State.CANCEL; if (status.options != null) { - if (VERBOSE) { - Log.v(TAG, "cancelDecode: " + status.options); - } status.options.requestCancelDecode(); } } @@ -250,9 +205,6 @@ public class BitmapManager { } public synchronized void allowAllDecoding(boolean reset) { - if (VERBOSE) { - Log.v(TAG, ">>>>>>>> allowAllDecoding <<<<<<<"); - } mAllowDecoding = true; if (reset) { mThreadStatus.clear(); @@ -286,40 +238,23 @@ public class BitmapManager { BitmapFactory.Options options) { // Does the global switch turn on? if (!canDecode() || options.mCancel) { - if (VERBOSE) { - Log.v(TAG, "Not allowed to decode."); - } return null; } // Can current thread decode? Thread thread = Thread.currentThread(); if (!canThreadDecoding(thread)) { - if (VERBOSE) { - Log.v(TAG, "Thread " + thread + "(" + thread.getId() - + ") is not allowed to decode"); - } return null; } setDecodingOptions(thread, options); - if (VERBOSE) { - Log.v(TAG, "decodeFileDescriptor: " + options + ", cancel=" - + options.mCancel); - } - long t = System.currentTimeMillis(); Bitmap b = BitmapFactory.decodeFileDescriptor(fd, null, options); // In case legacy code cancel it in traditional way if (options.mCancel) { cancelThreadDecoding(thread); } - if (VERBOSE) { - Log.v(TAG, "decodeFileDescriptor done: options=" + options - + ", cancel=" + options.mCancel + ", it takes " - + (System.currentTimeMillis() - t) + " ms."); - } removeDecodingOptions(thread); return b; diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index d8f6e67..0138dfc 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -336,9 +336,6 @@ public class Camera extends Activity implements View.OnClickListener, private final class RawPictureCallback implements PictureCallback { public void onPictureTaken( byte [] rawData, android.hardware.Camera camera) { - if (Config.LOGV) { - Log.v(TAG, "got RawPictureCallback..."); - } mRawPictureCallbackTime = System.currentTimeMillis(); if (DEBUG_TIME_OPERATIONS) { Log.v(TAG, (mRawPictureCallbackTime - mShutterCallbackTime) @@ -360,9 +357,6 @@ public class Camera extends Activity implements View.OnClickListener, if (mPausing) { return; } - if (Config.LOGV) { - Log.v(TAG, "got JpegPictureCallback..."); - } if (DEBUG_TIME_OPERATIONS) { long mJpegPictureCallback = System.currentTimeMillis(); @@ -1413,9 +1407,6 @@ public class Camera extends Activity implements View.OnClickListener, watchDog.start(); - if (Config.LOGV) { - Log.v(TAG, "calling mCameraDevice.startPreview"); - } try { mCameraDevice.startPreview(); } catch (Throwable e) { diff --git a/src/com/android/camera/CropImage.java b/src/com/android/camera/CropImage.java index 2702e67..47902f1 100644 --- a/src/com/android/camera/CropImage.java +++ b/src/com/android/camera/CropImage.java @@ -106,15 +106,7 @@ public class CropImage extends Activity { try { Intent intent = getIntent(); Bundle extras = intent.getExtras(); - if (Config.LOGV) { - Log.v(TAG, "extras are " + extras); - } if (extras != null) { - for (String s : extras.keySet()) { - if (Config.LOGV) { - Log.v(TAG, "" + s + " >>> " + extras.get(s)); - } - } if (extras.getString("circleCrop") != null) { mCircleCrop = true; mAspectX = 1; @@ -151,9 +143,6 @@ public class CropImage extends Activity { // TODO when saving the resulting bitmap use the // decode/crop/encode api so we don't lose any resolution. mBitmap = mImage.thumbBitmap(); - if (Config.LOGV) { - Log.v(TAG, "thumbBitmap returned " + mBitmap); - } } } @@ -205,11 +194,6 @@ public class CropImage extends Activity { final Bitmap b = (mImage != null) ? mImage.fullSizeBitmap(500) : mBitmap; - if (Config.LOGV) { - Log.v(TAG, "back from fullSizeBitmap(500) " - + "with bitmap of size " + b.getWidth() - + " / " + b.getHeight()); - } mHandler.post(new Runnable() { public void run() { if (b != mBitmap && b != null) { @@ -234,9 +218,6 @@ public class CropImage extends Activity { mSaving = true; if (mCroppedImage == null) { if (mCrop == null) { - if (Config.LOGV) { - Log.v(TAG, "no cropped image..."); - } return; } @@ -336,9 +317,7 @@ public class CropImage extends Activity { outputStream); } } catch (IOException ex) { - if (Config.LOGV) { - Log.v(TAG, "got IOException " + ex); - } + } finally { if (outputStream != null) { try { @@ -371,9 +350,6 @@ public class CropImage extends Activity { x += 1; String candidate = directory.toString() + "/" + fileName + "-" + x + ".jpg"; - if (Config.LOGV) { - Log.v(TAG, "candidate is " + candidate); - } boolean exists = (new java.io.File(candidate)).exists(); if (!exists) { diff --git a/src/com/android/camera/ExifInterface.java b/src/com/android/camera/ExifInterface.java index 9c8d410..18a9040 100644 --- a/src/com/android/camera/ExifInterface.java +++ b/src/com/android/camera/ExifInterface.java @@ -110,9 +110,6 @@ public class ExifInterface { sb.append(val); } String s = sb.toString(); - if (android.util.Config.LOGV) { - android.util.Log.v("camera", "saving exif data: " + s); - } saveAttributesNative(mFilename, s); mSavedAttributes = true; } diff --git a/src/com/android/camera/GalleryPicker.java b/src/com/android/camera/GalleryPicker.java index 30e8b72..8a8d262 100644 --- a/src/com/android/camera/GalleryPicker.java +++ b/src/com/android/camera/GalleryPicker.java @@ -191,9 +191,6 @@ public class GalleryPicker extends Activity { // This is called when we receive media-related broadcast. private void onReceiveMediaBroadcast(Intent intent) { - if (Config.LOGV) { - Log.v(TAG, "onReceiveMediaBroadcast " + intent.getAction()); - } String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { // SD card available @@ -201,9 +198,6 @@ public class GalleryPicker extends Activity { // TODO also listen for the media scanner finished message } else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) { // SD card unavailable - if (Config.LOGV) { - Log.v(TAG, "sd card no longer available"); - } Toast.makeText(GalleryPicker.this, getResources().getString(R.string.wait), 5000); rebake(true, false); @@ -213,15 +207,8 @@ public class GalleryPicker extends Activity { rebake(false, true); } else if (action.equals( Intent.ACTION_MEDIA_SCANNER_FINISHED)) { - if (Config.LOGV) { - Log.v(TAG, "rebake because of " - + "ACTION_MEDIA_SCANNER_FINISHED"); - } rebake(false, false); } else if (action.equals(Intent.ACTION_MEDIA_EJECT)) { - if (Config.LOGV) { - Log.v(TAG, "rebake because of ACTION_MEDIA_EJECT"); - } rebake(true, false); } } @@ -400,10 +387,6 @@ public class GalleryPicker extends Activity { if (mWorkerThread != null) { try { mDone = true; - if (Config.LOGV) { - Log.v(TAG, "about to call join on thread " - + mWorkerThread.getId()); - } mWorkerThread.join(); } finally { mWorkerThread = null; diff --git a/src/com/android/camera/ImageGallery2.java b/src/com/android/camera/ImageGallery2.java index 5c1e8a7..e706027 100644 --- a/src/com/android/camera/ImageGallery2.java +++ b/src/com/android/camera/ImageGallery2.java @@ -96,7 +96,6 @@ public class ImageGallery2 extends Activity { @Override public void onCreate(Bundle icicle) { - if (Config.LOGV) Log.v(TAG, "onCreate"); super.onCreate(icicle); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -108,9 +107,6 @@ public class ImageGallery2 extends Activity { getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_gallery_title); - if (Config.LOGV) { - Log.v(TAG, "findView... " + findViewById(R.id.loading_indicator)); - } mGvs = (GridViewSpecial) findViewById(R.id.grid); mGvs.requestFocus(); @@ -361,7 +357,6 @@ public class ImageGallery2 extends Activity { /* pass through any extras that were passed in */ cropIntent.putExtras(myExtras); - if (Config.LOGV) Log.v(TAG, "startSubActivity " + cropIntent); startActivityForResult(cropIntent, CROP_MSG); } else { Intent result = new Intent(null, img.fullSizeImageUri()); @@ -379,10 +374,6 @@ public class ImageGallery2 extends Activity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (Config.LOGV) { - Log.v(TAG, "onActivityResult: " + requestCode - + "; resultCode is " + resultCode + "; data is " + data); - } switch (requestCode) { case MenuHelper.RESULT_COMMON_MENU_CROP: { if (resultCode == RESULT_OK) { @@ -400,7 +391,6 @@ public class ImageGallery2 extends Activity { break; } case CROP_MSG: { - if (Config.LOGV) Log.v(TAG, "onActivityResult " + data); if (resultCode == RESULT_OK) { setResult(resultCode, data); finish(); @@ -408,9 +398,6 @@ public class ImageGallery2 extends Activity { break; } case VIEW_MSG: { - if (Config.LOGV) { - Log.v(TAG, "got VIEW_MSG with " + data); - } IImage img = mAllImages.getImageForUri(data.getData()); launchCropperOrFinish(img); break; @@ -458,9 +445,6 @@ public class ImageGallery2 extends Activity { mAllImages = ImageManager.instance().emptyImageList(); } else { mAllImages = allImages(!unmounted); - if (Config.LOGV) { - Log.v(TAG, "mAllImages is now " + mAllImages); - } mGvs.init(mHandler); mGvs.start(); mGvs.requestLayout(); @@ -514,9 +498,6 @@ public class ImageGallery2 extends Activity { mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (Config.LOGV) { - Log.v(TAG, "onReceiveIntent " + intent.getAction()); - } String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { // SD card available @@ -524,7 +505,6 @@ public class ImageGallery2 extends Activity { // TODO also listen for the media scanner finished message } else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) { // SD card unavailable - if (Config.LOGV) Log.v(TAG, "sd card no longer available"); Toast.makeText(ImageGallery2.this, getResources().getString(R.string.wait), 5000); rebake(true, false); @@ -534,15 +514,8 @@ public class ImageGallery2 extends Activity { rebake(false, true); } else if (action.equals( Intent.ACTION_MEDIA_SCANNER_FINISHED)) { - if (Config.LOGV) { - Log.v(TAG, "rebake because of " - + "ACTION_MEDIA_SCANNER_FINISHED"); - } rebake(false, false); } else if (action.equals(Intent.ACTION_MEDIA_EJECT)) { - if (Config.LOGV) { - Log.v(TAG, "rebake because of ACTION_MEDIA_EJECT"); - } rebake(true, false); } } @@ -561,7 +534,6 @@ public class ImageGallery2 extends Activity { private void checkThumbnails() { final long startTime = System.currentTimeMillis(); - final long t1 = System.currentTimeMillis(); mThumbnailCheckThread = new BitmapThread(new Runnable() { public void run() { android.content.res.Resources resources = getResources(); @@ -603,6 +575,8 @@ public class ImageGallery2 extends Activity { } mGvs.postInvalidate(); + // If there is a new image done and it has been + // a second, update the progress. if (System.currentTimeMillis() - startTime > 1000) { mHandler.post(new Runnable() { @@ -628,11 +602,6 @@ public class ImageGallery2 extends Activity { View.GONE); } }); - long t2 = System.currentTimeMillis(); - if (Config.LOGV) { - Log.v(TAG, "check thumbnails thread finishing; took " - + (t2 - t1)); - } } }); @@ -702,9 +671,6 @@ public class ImageGallery2 extends Activity { Intent intent = getIntent(); if (intent != null) { String type = intent.resolveType(this); - if (Config.LOGV) { - Log.v(TAG, "allImages... type is " + type); - } TextView leftText = (TextView) findViewById(R.id.left_text); if (type != null) { if (type.equals("vnd.android.cursor.dir/image") @@ -747,11 +713,6 @@ public class ImageGallery2 extends Activity { mInclusion = ImageManager.INCLUDE_DRM_IMAGES; } } - if (Config.LOGV) { - Log.v(TAG, "computing images... mSortAscending is " - + mSortAscending + "; assumeMounted is " - + assumeMounted); - } Uri uri = getIntent().getData(); if (!assumeMounted) { mAllImages = ImageManager.instance().emptyImageList(); @@ -888,12 +849,6 @@ class GridViewSpecial extends View { private GestureDetector mGestureDetector; public void dump() { - if (Config.LOGV){ - Log.v(TAG, "mSizeChoice is " + mCellSizeChoices[mSizeChoice]); - Log.v(TAG, "mCurrentSpec.width / mCellHeight are " - + mCurrentSpec.mCellWidth + " / " - + mCurrentSpec.mCellHeight); - } mImageBlockManager.dump(); } @@ -1160,21 +1115,12 @@ class GridViewSpecial extends View { synchronized (ImageBlockManager.this) { StringBuilder line1 = new StringBuilder(); StringBuilder line2 = new StringBuilder(); - if (Config.LOGV) { - Log.v(TAG, ">>> mBlockCacheFirstBlockNumber: " - + mBlockCacheFirstBlockNumber + " " - + mBlockCacheStartOffset); - } for (int i = 0; i < mBlockCache.length; i++) { int index = (mBlockCacheStartOffset + i) % mBlockCache.length; ImageBlock block = mBlockCache[index]; block.dump(line1, line2); } - if (Config.LOGV){ - Log.v(TAG, line1.toString()); - Log.v(TAG, line2.toString()); - } } } @@ -1195,10 +1141,6 @@ class GridViewSpecial extends View { workCounter = mWorkCounter; } if (mDone) { - if (Config.LOGV) { - Log.v(TAG, "stopping the loader here " - + Thread.currentThread().getName()); - } if (mLoader != null) { mLoader.stop(); } @@ -1701,15 +1643,6 @@ class GridViewSpecial extends View { android.graphics.Rect dst = new android.graphics.Rect(xPos, yPos, xPos + w, yPos + h); - if (src.width() != dst.width() - || src.height() != dst.height()) { - if (Config.LOGV){ - Log.v(TAG, "nope... width doesn't match " - + src.width() + " " + dst.width()); - Log.v(TAG, "nope... height doesn't match " - + src.height() + " " + dst.height()); - } - } mCanvas.drawBitmap(b, src, dst, mPaint); } else { android.graphics.Rect src = @@ -1877,10 +1810,6 @@ class GridViewSpecial extends View { super.onDraw(canvas); if (false) { canvas.drawRect(0, 0, getWidth(), getHeight(), mGridViewPaint); - if (Config.LOGV) { - Log.v(TAG, "painting background w/h " + getWidth() - + " / " + getHeight()); - } return; } diff --git a/src/com/android/camera/ImageLoader.java b/src/com/android/camera/ImageLoader.java index 8d9be55..c17c7bc 100644 --- a/src/com/android/camera/ImageLoader.java +++ b/src/com/android/camera/ImageLoader.java @@ -49,14 +49,6 @@ public class ImageLoader { synchronized void clear(Uri uri) { } - public synchronized void dump() { - synchronized (mQueue) { - if (Config.LOGV) { - Log.v(TAG, "Loader queue length is " + mQueue.size()); - } - } - } - public interface LoadedCallback { public void run(Bitmap result); } @@ -104,10 +96,7 @@ public class ImageLoader { start(); } } - long t1 = System.currentTimeMillis(); - long t2, t3, t4; synchronized (mQueue) { - t2 = System.currentTimeMillis(); WorkItem w = new WorkItem(image, tag, imageLoadedRunnable, postBack); @@ -131,11 +120,7 @@ public class ImageLoader { if (false) { dumpQueue("+" + (postAtFront ? "F " : "B ") + tag + ": "); } - t3 = System.currentTimeMillis(); } - t4 = System.currentTimeMillis(); - // Log.v(TAG, "getBitmap breakdown: tot= " + (t4-t1) + "; " + "; " + - // (t4-t3) + "; " + (t3-t2) + "; " + (t2-t1)); return null; } @@ -145,9 +130,6 @@ public class ImageLoader { for (int i = 0; i < mQueue.size(); i++) { sb.append(mQueue.get(i).mTag + " "); } - if (Config.LOGV) { - Log.v(TAG, sb.toString()); - } } } @@ -190,10 +172,6 @@ public class ImageLoader { } private synchronized void start() { - if (Config.LOGV) { - Log.v(TAG, "ImageLoader.start() <<<<<<<<<<<<<<<<<<<<<<<<<<<<"); - } - synchronized (mDecodeThreads) { if (mDecodeThreads.size() > 0) { return; @@ -226,11 +204,6 @@ public class ImageLoader { dumpQueue("-" + workItem.mTag + ": "); } Bitmap b = workItem.mImage.miniThumbBitmap(); - if (b == null && Config.LOGV) { - Log.v(TAG, "unable to read thumbnail for " - + workItem.mImage - .fullSizeImageUri()); - } synchronized (mQueue) { mInProgress.remove(workItem); @@ -296,9 +269,6 @@ public class ImageLoader { dstY, targetWidth - dstX, targetHeight - dstY); - if (Config.LOGV) { - Log.v(TAG, "draw " + src.toString() + " ==> " + dst.toString()); - } c.drawBitmap(source, src, dst, null); return b2; } @@ -351,10 +321,6 @@ public class ImageLoader { } public void stop() { - if (Config.LOGV) { - Log.v(TAG, "ImageLoader.stop " + mDecodeThreads.size() + - " threads"); - } mDone = true; synchronized (mQueue) { mQueue.notifyAll(); diff --git a/src/com/android/camera/ImageManager.java b/src/com/android/camera/ImageManager.java index 378368b..412b36d 100755 --- a/src/com/android/camera/ImageManager.java +++ b/src/com/android/camera/ImageManager.java @@ -55,14 +55,7 @@ import java.util.HashMap; * in the media content provider. */ public class ImageManager { - // To enable verbose logging for this class, change false to true. The other - // logic ensures that this logging can be disabled by turned off DEBUG and - // lower, and that it can be enabled by "setprop log.tag.ImageManager - // VERBOSE" if desired. - // - // IMPORTANT: Never check in this file set to true! - private static final boolean VERBOSE = - Config.LOGD && (false || Config.LOGV); + private static final boolean VERBOSE = false; private static final String TAG = "ImageManager"; private static ImageManager sInstance = null; @@ -172,9 +165,6 @@ public class ImageManager { retVal = 0; } - if (VERBOSE) { - Log.v(TAG, "map orientation " + orientationInput + " to " + retVal); - } return retVal; } @@ -218,16 +208,7 @@ public class ImageManager { String path = parentFile.toString().toLowerCase(); String name = parentFile.getName(); - if (VERBOSE) { - Log.v(TAG, "addImage id is " + path.hashCode() + "; name " - + name + "; path is " + path); - } - if (location != null) { - if (VERBOSE) { - Log.v(TAG, "lat long " + location.getLatitude() + " / " - + location.getLongitude()); - } values.put(Images.Media.LATITUDE, location.getLatitude()); values.put(Images.Media.LONGITUDE, location.getLongitude()); } @@ -237,7 +218,6 @@ public class ImageManager { values.put(Images.Media.DATA, value); } - long t3 = System.currentTimeMillis(); Uri uri = cr.insert(sStorageURI, values); // The line above will create a filename that ends in .jpg @@ -290,10 +270,6 @@ public class ImageManager { @Override public boolean doCancelWork() { - if (VERBOSE) { - Log.v(TAG, "calling AddImageCancelable.cancel() " - + mSaveImageCancelable); - } if (mSaveImageCancelable != null) { mSaveImageCancelable.cancel(); } @@ -302,7 +278,6 @@ public class ImageManager { public Void get() { try { - long t1 = System.currentTimeMillis(); synchronized (this) { if (mCancel) { throw new CanceledException(); @@ -313,7 +288,6 @@ public class ImageManager { BaseImageList il = new ImageList(mCtx, mCr, sStorageURI, sThumbURI, SORT_ASCENDING, null); Image image = new Image(id, 0, mCr, il, il.getCount(), 0); - long t5 = System.currentTimeMillis(); String[] projection = new String[] { ImageColumns._ID, ImageColumns.MINI_THUMB_MAGIC, ImageColumns.DATA}; @@ -328,31 +302,15 @@ public class ImageManager { } if (mSaveImageCancelable.get()) { - long t6 = System.currentTimeMillis(); - if (VERBOSE) { - Log.v(TAG, "saveImageContents took " + (t6 - t5)); - Log.v(TAG, "updating new picture with id " + id); - } c.updateLong(1, id); c.commitUpdates(); c.close(); - long t7 = System.currentTimeMillis(); - if (VERBOSE) { - Log.v(TAG, "commit updates to save mini thumb took " - + (t7 - t6)); - } } else { c.close(); throw new CanceledException(); } } catch (CanceledException ex) { - if (VERBOSE) { - Log.v(TAG, "caught CanceledException"); - } if (mUri != null) { - if (VERBOSE) { - Log.v(TAG, "canceled... cleaning up this uri: " + mUri); - } mCr.delete(mUri, null, null); } acknowledgeCancel(); @@ -385,9 +343,6 @@ public class ImageManager { imageList = new SingleImageList(cr, uri); } else { String bucketId = uri.getQueryParameter("bucketId"); - if (VERBOSE) { - Log.v(TAG, "bucketId is " + bucketId); - } imageList = ImageManager.instance().allImages( ctx, cr, ImageManager.DataLocation.ALL, ImageManager.INCLUDE_IMAGES, sort, bucketId); @@ -458,12 +413,6 @@ public class ImageManager { public IImageList allImages( Context ctx, ContentResolver cr, DataLocation location, int inclusion, int sort, String bucketId, Uri specificImageUri) { - if (VERBOSE) { - Log.v(TAG, "allImages " + location + " " - + ((inclusion & INCLUDE_IMAGES) != 0) + " + v=" - + ((inclusion & INCLUDE_VIDEOS) != 0)); - } - if (cr == null) { return null; } else { @@ -473,12 +422,6 @@ public class ImageManager { if (true) { // use this code to merge videos and stills into the same list ArrayList<IImageList> l = new ArrayList<IImageList>(); - - if (VERBOSE) { - Log.v(TAG, "initializing ... haveSdCard == " + haveSdCard - + "; inclusion is " - + String.format("%x", inclusion)); - } if (specificImageUri != null) { try { if (specificImageUri.getScheme() @@ -583,14 +526,11 @@ public class ImageManager { } public static boolean hasStorage(boolean requireWriteAccess) { - //TODO: After fix the bug, add "if (VERBOSE)" before logging errors. String state = Environment.getExternalStorageState(); - Log.v(TAG, "storage state is " + state); if (Environment.MEDIA_MOUNTED.equals(state)) { if (requireWriteAccess) { boolean writable = checkFsWritable(); - Log.v(TAG, "storage writable is " + writable); return writable; } else { return true; @@ -630,9 +570,6 @@ public class ImageManager { cursor.close(); } - if (VERBOSE) { - Log.v(TAG, "isMediaScannerScanning returning " + result); - } return result; } diff --git a/src/com/android/camera/MenuHelper.java b/src/com/android/camera/MenuHelper.java index 9859ff7..dff3870 100644 --- a/src/com/android/camera/MenuHelper.java +++ b/src/com/android/camera/MenuHelper.java @@ -570,20 +570,12 @@ public class MenuHelper { } boolean readOnly = image.isReadonly(); boolean isDrm = image.isDrm(); - if (Config.LOGV) { - Log.v(TAG, "readOnly: " + readOnly + "; drm: " + isDrm); - } + for (MenuItem item : requiresWriteAccessItems) { - if (Config.LOGV) { - Log.v(TAG, "item is " + item.toString()); - } item.setVisible(!readOnly); item.setEnabled(!readOnly); } for (MenuItem item : requiresNoDrmAccessItems) { - if (Config.LOGV) { - Log.v(TAG, "item is " + item.toString()); - } item.setVisible(!isDrm); item.setEnabled(!isDrm); } diff --git a/src/com/android/camera/OnScreenHint.java b/src/com/android/camera/OnScreenHint.java index 3d8d145..7e26a92 100644 --- a/src/com/android/camera/OnScreenHint.java +++ b/src/com/android/camera/OnScreenHint.java @@ -87,9 +87,6 @@ public class OnScreenHint { if (mNextView == null) { throw new RuntimeException("setView must have been called"); } - if (LOCAL_LOGV) { - Log.v(TAG, "SHOW: " + this); - } mHandler.post(mShow); } @@ -97,9 +94,6 @@ public class OnScreenHint { * Close the view if it's showing. */ public void cancel() { - if (LOCAL_LOGV) { - Log.v(TAG, "HIDE: " + this); - } mHandler.post(mHide); } @@ -251,10 +245,6 @@ public class OnScreenHint { } private synchronized void handleShow() { - if (LOCAL_LOGV) { - Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView - + " mNextView=" + mNextView); - } if (mView != mNextView) { // remove the old view if necessary handleHide(); @@ -274,30 +264,18 @@ public class OnScreenHint { mParams.verticalMargin = mVerticalMargin; mParams.horizontalMargin = mHorizontalMargin; if (mView.getParent() != null) { - if (LOCAL_LOGV) { - Log.v(TAG, "REMOVE! " + mView + " in " + this); - } mWM.removeView(mView); } - if (LOCAL_LOGV) { - Log.v(TAG, "ADD! " + mView + " in " + this); - } mWM.addView(mView, mParams); } } private synchronized void handleHide() { - if (LOCAL_LOGV) { - Log.v(TAG, "HANDLE HIDE: " + this + " mView=" + mView); - } if (mView != null) { // note: checking parent() just to make sure the view has // been added... i have seen cases where we get here when // the view isn't yet added, so let's try not to crash. if (mView.getParent() != null) { - if (LOCAL_LOGV) { - Log.v(TAG, "REMOVE! " + mView + " in " + this); - } mWM.removeView(mView); } mView = null; diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java index c081d02..8b5498c 100644 --- a/src/com/android/camera/Util.java +++ b/src/com/android/camera/Util.java @@ -85,11 +85,6 @@ public class Util { 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; } diff --git a/src/com/android/camera/ViewImage.java b/src/com/android/camera/ViewImage.java index e3e98cb..7337836 100644 --- a/src/com/android/camera/ViewImage.java +++ b/src/com/android/camera/ViewImage.java @@ -647,6 +647,13 @@ public class ViewImage extends Activity implements View.OnClickListener { mShutterButton.setVisibility(View.GONE); findViewById(R.id.slideShowContainer).getRootView().requestLayout(); + + // The preferences we want to read: + // mUseShuffleOrder + // mSlideShowLoop + // mAnimationIndex + // mSlideShowInterval + mUseShuffleOrder = mPrefs.getBoolean( "pref_gallery_slideshow_shuffle_key", false); mSlideShowLoop = mPrefs.getBoolean( @@ -666,12 +673,6 @@ public class ViewImage extends Activity implements View.OnClickListener { mSlideShowInterval = 3000; } - if (Config.LOGV) { - Log.v(TAG, "read prefs... shuffle: " + mUseShuffleOrder); - Log.v(TAG, "read prefs... loop: " + mSlideShowLoop); - Log.v(TAG, "read prefs... animidx: " + mAnimationIndex); - Log.v(TAG, "read prefs... interval: " + mSlideShowInterval); - } if (mUseShuffleOrder) { generateShuffleOrder(); diff --git a/src/com/android/camera/Wallpaper.java b/src/com/android/camera/Wallpaper.java index 27c6779..9fe4fbf 100644 --- a/src/com/android/camera/Wallpaper.java +++ b/src/com/android/camera/Wallpaper.java @@ -195,11 +195,6 @@ public class Wallpaper extends Activity { + "Couldn't get bitmap for path " + mTempFilePath); } else { - if (android.util.Config.LOGV) { - Log.v(LOG_TAG, "bitmap size is " - + bitmap.getWidth() - + " / " + bitmap.getHeight()); - } mHandler.sendEmptyMessage(SHOW_PROGRESS); new SetWallpaperThread(bitmap, mHandler, this, tempFile).start(); diff --git a/src/com/android/camera/gallery/BaseImage.java b/src/com/android/camera/gallery/BaseImage.java index 8b521d9..cee1076 100644 --- a/src/com/android/camera/gallery/BaseImage.java +++ b/src/com/android/camera/gallery/BaseImage.java @@ -40,7 +40,6 @@ import java.util.HashMap; * the path to the actual image data. */ public abstract class BaseImage implements IImage { - private static final boolean VERBOSE = false; private static final String TAG = "BaseImage"; @@ -98,29 +97,15 @@ public abstract class BaseImage implements IImage { public Boolean get() { try { - long t1 = System.currentTimeMillis(); OutputStream delegate = mContentResolver.openOutputStream(mUri); synchronized (this) { checkCanceled(); mOutputStream = new ThreadSafeOutputStream(delegate); } - long t2 = System.currentTimeMillis(); if (mBitmap != null) { mBitmap.compress(compressionType(), 75, mOutputStream); } else { - long x1 = System.currentTimeMillis(); mOutputStream.write(mJpegData); - long x2 = System.currentTimeMillis(); - if (VERBOSE) { - Log.v(TAG, "done writing... " + mJpegData.length - + " bytes took " + (x2 - x1)); - } - } - long t3 = System.currentTimeMillis(); - if (VERBOSE) { - Log.v(TAG, String.format( - "CompressImageToFile.get took %d (%d, %d)", - (t3 - t1), (t2 - t1), (t3 - t2))); } return true; } catch (FileNotFoundException ex) { @@ -167,7 +152,6 @@ public abstract class BaseImage implements IImage { protected Bitmap fullSizeBitmap( int targetWidthHeight, boolean rotateAsNeeded) { Uri url = mContainer.contentUri(mId); - if (VERBOSE) Log.v(TAG, "getCreateBitmap for " + url); if (url == null) return null; Bitmap b = makeBitmap(targetWidthHeight, url); @@ -180,7 +164,6 @@ public abstract class BaseImage implements IImage { private class LoadBitmapCancelable extends BaseCancelable<Bitmap> { private ParcelFileDescriptor mPFD; private BitmapFactory.Options mOptions = new BitmapFactory.Options(); - private long mCancelInitiationTime; private int mTargetWidthHeight; public LoadBitmapCancelable( @@ -191,8 +174,6 @@ public abstract class BaseImage implements IImage { @Override public boolean doCancelWork() { - if (VERBOSE) Log.v(TAG, "requesting bitmap load cancel"); - mCancelInitiationTime = System.currentTimeMillis(); mOptions.requestCancelDecode(); return true; } @@ -201,12 +182,6 @@ public abstract class BaseImage implements IImage { try { Bitmap b = makeBitmap( mTargetWidthHeight, fullSizeImageUri(), mPFD, mOptions); - if (mCancelInitiationTime != 0 && VERBOSE) { - Log.v(TAG, "cancelation of bitmap load success==" - + (b == null ? "TRUE" : "FALSE") + " -- took " - + (System.currentTimeMillis() - - mCancelInitiationTime)); - } if (b != null) { b = Util.rotate(b, getDegreesRotated()); } @@ -372,10 +347,6 @@ public abstract class BaseImage implements IImage { } } - public long imageId() { - return mId; - } - /** * Make a bitmap from a given Uri. * @@ -405,10 +376,6 @@ public abstract class BaseImage implements IImage { if (dbMagic == 0 || dbMagic == id) { dbMagic = ((BaseImageList) getContainer()) .checkThumbnail(this, getCursor(), getRow()); - if (VERBOSE) { - Log.v(TAG, "after computing thumbnail dbMagic is " - + dbMagic); - } } synchronized (sMiniThumbData) { @@ -433,15 +400,12 @@ public abstract class BaseImage implements IImage { dbMagic); } if (data == null) { - if (VERBOSE) { - Log.v(TAG, "unable to get miniThumbBitmap," - + " data is null"); - } + // Unable to get mini-thumb data from file. } if (data != null) { Bitmap b = BitmapFactory.decodeByteArray(data, 0, data.length); - if (b == null && VERBOSE) { + if (b == null) { Log.v(TAG, "couldn't decode byte array, " + "length was " + data.length); } @@ -450,11 +414,7 @@ public abstract class BaseImage implements IImage { } return null; } catch (Throwable ex) { - if (VERBOSE) { - Log.e(TAG, "miniThumbBitmap got exception " + ex.toString()); - for (StackTraceElement s : ex.getStackTrace()) - Log.e(TAG, "... " + s.toString()); - } + Log.e(TAG, "miniThumbBitmap got exception", ex); return null; } } diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java index 18eef1d..c1141ab 100644 --- a/src/com/android/camera/gallery/BaseImageList.java +++ b/src/com/android/camera/gallery/BaseImageList.java @@ -133,7 +133,7 @@ public abstract class BaseImageList implements IImageList { thumbOut.close(); return thumb; } catch (Exception ex) { - if (VERBOSE) Log.d(TAG, "unable to store thumbnail: " + ex); + Log.e(TAG, "Unable to store thumbnail", ex); return thumb; } } @@ -228,11 +228,6 @@ public abstract class BaseImageList implements IImageList { // and is significantly faster. options.inSampleSize = Util.computeSampleSize(options, THUMBNAIL_TARGET_SIZE); - - if (VERBOSE) { - Log.v(TAG, "in createThumbnailFromExif using inSampleSize of " - + options.inSampleSize); - } options.inDither = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inJustDecodeBounds = false; @@ -378,46 +373,29 @@ public abstract class BaseImageList implements IImageList { "_id ASC"); int count = c.getCount(); - if (VERBOSE) { - Log.v(TAG, ">>>>>>>>>>> need to check " + c.getCount() + " rows"); - } c.close(); if (!ImageManager.hasStorage()) { - if (VERBOSE) { - Log.v(TAG, "bailing from the image checker thread " - + "-- no storage"); - } + Log.v(TAG, "bailing from the image checker thread -- no storage"); return; } c = getCursor(); - try { - if (VERBOSE) Log.v(TAG, "checkThumbnails found " + c.getCount()); - int current = 0; - for (int i = 0; i < c.getCount(); i++) { - try { - checkThumbnail(null, c, i); - } catch (IOException ex) { - Log.e(TAG, "!!!!! failed to check thumbnail..." - + " was the sd card removed? - " + ex.getMessage()); + int current = 0; + for (int i = 0; i < c.getCount(); i++) { + try { + checkThumbnail(null, c, i); + } catch (IOException ex) { + Log.e(TAG, "!!!!! failed to check thumbnail..." + + " was the sd card removed? - " + ex.getMessage()); + break; + } + if (cb != null) { + if (!cb.checking(current, totalThumbnails)) { break; } - if (cb != null) { - if (!cb.checking(current, totalThumbnails)) { - if (VERBOSE) { - Log.v(TAG, "got false from checking... break"); - } - break; - } - } - current += 1; - } - } finally { - if (VERBOSE) { - Log.v(TAG, "checkThumbnails existing after reaching count " - + c.getCount()); } + current += 1; } } @@ -459,18 +437,6 @@ public abstract class BaseImageList implements IImageList { mMiniThumbFile.deactivate(); } - public void dump(String msg) { - int count = getCount(); - if (VERBOSE) { - Log.v(TAG, "dump ImageList (count is " + count + ") " + msg); - } - for (int i = 0; i < count; i++) { - IImage img = getImageAt(i); - if (VERBOSE) Log.v(TAG, " " + i + ": " + img); - } - if (VERBOSE) Log.v(TAG, "end of dump container"); - } - public int getCount() { Cursor c = getCursor(); synchronized (c) { @@ -624,7 +590,6 @@ public abstract class BaseImageList implements IImageList { * we can get it back as needed * TODO: need to delete the thumbnails as well */ - dump("before delete"); IImage image = getImageAt(i); boolean moved; try { @@ -639,7 +604,6 @@ public abstract class BaseImageList implements IImageList { requery(); image.onRemove(); } - dump("after delete"); } } diff --git a/src/com/android/camera/gallery/IImage.java b/src/com/android/camera/gallery/IImage.java index aee46f0..263cb29 100644 --- a/src/com/android/camera/gallery/IImage.java +++ b/src/com/android/camera/gallery/IImage.java @@ -26,72 +26,55 @@ import java.io.InputStream; */ public interface IImage { - public abstract void commitChanges(); + /** Get the image list which contains this image. */ + public abstract IImageList getContainer(); - /** - * Get the bitmap for the full size image. - * @return the bitmap for the full size image. - */ + /** Get the bitmap for the full size image. */ public abstract Bitmap fullSizeBitmap(int targetWidthOrHeight); - /** - * - * @return an object which can be canceled while the bitmap is loading - */ + /** Get the cancelable object for the bitmap of the full size image. */ public abstract ICancelable<Bitmap> fullSizeBitmapCancelable( int targetWidthOrHeight); - /** - * Gets the input stream associated with a given full size image. - * This is used, for example, if one wants to email or upload - * the image. - * @return the InputStream associated with the image. - */ + /** Get the input stream associated with a given full size image. */ public abstract InputStream fullSizeImageData(); public abstract long fullSizeImageId(); public abstract Uri fullSizeImageUri(); - public abstract IImageList getContainer(); - public abstract long getDateTaken(); - public abstract String getMimeType(); - public abstract int getHeight(); + /** Get the path of the (full size) image data. */ + public abstract String getDataPath(); - /** - * Gets the name of the image. - * @return the name of the image. - */ + // Get/Set the title of the image + public abstract void setTitle(String name); public abstract String getTitle(); - public abstract String getDisplayName(); - - public abstract int getRow(); - + // Get metadata of the image + public abstract long getDateTaken(); + public abstract String getMimeType(); public abstract int getWidth(); + public abstract int getHeight(); + public abstract String getDisplayName(); - public abstract long imageId(); - + // Get property of the image public abstract boolean isReadonly(); - public abstract boolean isDrm(); + // Get the bitmap/uri of the medium thumbnail + public abstract Bitmap thumbBitmap(); + public abstract Uri thumbUri(); + + // Get the bitmap of the mini thumbnail. public abstract Bitmap miniThumbBitmap(); - public abstract void onRemove(); + // Get the row number for this image in the database table. + public abstract int getRow(); + // Rotate the image public abstract boolean rotateImageBy(int degrees); - /** - * Sets the title of the image. - */ - public abstract void setTitle(String name); - - /** - * Get the bitmap for the medium thumbnail. - * @return the bitmap for the medium thumbnail. - */ - public abstract Bitmap thumbBitmap(); - - public abstract Uri thumbUri(); + // This is called if the image is removed. + public abstract void onRemove(); - public abstract String getDataPath(); -}
\ No newline at end of file + // Commit the changes done to this image. + public abstract void commitChanges(); +} diff --git a/src/com/android/camera/gallery/IImageList.java b/src/com/android/camera/gallery/IImageList.java index 1414bb5..f9257e5 100644 --- a/src/com/android/camera/gallery/IImageList.java +++ b/src/com/android/camera/gallery/IImageList.java @@ -20,6 +20,26 @@ import android.net.Uri; import java.util.HashMap; +// +// ImageList and Image classes have one-to-one correspondence. +// The class hierarchy (* = abstract class): +// +// IImageList +// - BaseImageList (*) +// - VideoList +// - ImageList +// - DrmImageList +// - SingleImageList (contains UriImage) +// - ImageListUber +// +// IImage +// - BaseImage (*) +// - VideoObject +// - Image +// - DrmImage +// - UriImage +// + /** * The interface of all image collections used in gallery. */ @@ -81,4 +101,4 @@ public interface IImageList { * @param i the position */ public abstract void removeImageAt(int i); -}
\ No newline at end of file +} diff --git a/src/com/android/camera/gallery/Image.java b/src/com/android/camera/gallery/Image.java index 2ec100a..6ac0158 100644 --- a/src/com/android/camera/gallery/Image.java +++ b/src/com/android/camera/gallery/Image.java @@ -104,13 +104,9 @@ public class Image extends BaseImage implements IImage { if (mExifData == null) { mExifData = new HashMap<String, String>(); } + // If the key is already there, ignore it. if (!mExifData.containsKey(tag)) { mExifData.put(tag, value); - } else { - if (VERBOSE) { - Log.v(TAG, "addExifTag where the key already was there: " - + tag + " = " + value); - } } } @@ -192,7 +188,6 @@ public class Image extends BaseImage implements IImage { try { Bitmap thumbnail = null; - long t1 = System.currentTimeMillis(); Uri uri = mContainer.contentUri(mId); synchronized (this) { checkCanceled(); @@ -200,7 +195,6 @@ public class Image extends BaseImage implements IImage { compressImageToFile(mImage, mJpegData, uri); } - long t2 = System.currentTimeMillis(); if (!mCurrentCancelable.get()) return false; synchronized (this) { @@ -219,20 +213,10 @@ public class Image extends BaseImage implements IImage { thumbData = (new ExifInterface(filePath)).getThumbnail(); } - if (VERBOSE) { - Log.v(TAG, "for file " + filePath + " thumbData is " - + thumbData + "; length " - + (thumbData != null ? thumbData.length : -1)); - } if (thumbData != null) { thumbnail = BitmapFactory.decodeByteArray( thumbData, 0, thumbData.length); - if (VERBOSE) { - Log.v(TAG, "embedded thumbnail bitmap " - + thumbnail.getWidth() + "/" - + thumbnail.getHeight()); - } } if (thumbnail == null && mImage != null) { thumbnail = mImage; @@ -243,28 +227,20 @@ public class Image extends BaseImage implements IImage { } } - long t3 = System.currentTimeMillis(); mContainer.storeThumbnail( thumbnail, Image.this.fullSizeImageId()); - long t4 = System.currentTimeMillis(); checkCanceled(); - if (VERBOSE) Log.v(TAG, "rotating by " + mOrientation); + try { thumbnail = Util.rotate(thumbnail, mOrientation); saveMiniThumb(thumbnail); } catch (IOException e) { // Ignore if unable to save thumb. } - long t5 = System.currentTimeMillis(); checkCanceled(); - - if (VERBOSE) { - Log.v(TAG, String.format("Timing data %d %d %d %d", - t2 - t1, t3 - t2, t4 - t3, t5 - t4)); - } return true; } catch (CanceledException ex) { - if (VERBOSE) Log.v(TAG, "got canceled... need to cleanup"); + // Got canceled... need to cleanup. return false; } finally { /* @@ -366,10 +342,7 @@ public class Image extends BaseImage implements IImage { if (bitmap == null) { bitmap = fullSizeBitmap(ImageManager.THUMBNAIL_TARGET_SIZE, false); - if (VERBOSE) { - Log.v(TAG, "no thumbnail found... storing new one for " - + fullSizeImageId()); - } + // No thumbnail found... storing the new one. bitmap = mContainer.storeThumbnail(bitmap, fullSizeImageId()); } diff --git a/src/com/android/camera/gallery/ImageList.java b/src/com/android/camera/gallery/ImageList.java index 75ed900..ec2a85a 100644 --- a/src/com/android/camera/gallery/ImageList.java +++ b/src/com/android/camera/gallery/ImageList.java @@ -79,12 +79,6 @@ public class ImageList extends BaseImageList implements IImageList { Log.e(TAG, "unable to create image cursor for " + mBaseUri); throw new UnsupportedOperationException(); } - - if (VERBOSE) { - Log.v(TAG, "for " + mBaseUri.toString() + " got cursor " - + mCursor + " with length " - + (mCursor != null ? mCursor.getCount() : "-1")); - } } private static final String WHERE_CLAUSE = @@ -107,10 +101,6 @@ public class ImageList extends BaseImageList implements IImageList { Cursor c = Images.Media.query( mContentResolver, mBaseUri, BaseImageList.IMAGE_PROJECTION, whereClause(), whereClauseArgs(), sortOrder()); - if (VERBOSE) { - Log.v(TAG, "createCursor got cursor with count " - + (c == null ? -1 : c.getCount())); - } return c; } @@ -179,9 +169,7 @@ public class ImageList extends BaseImageList implements IImageList { options.inSampleSize = 1; if (targetWidthHeight != -1) { options.inJustDecodeBounds = true; - long t1 = System.currentTimeMillis(); BitmapManager.instance().decodeFileDescriptor(fd, null, options); - long t2 = System.currentTimeMillis(); if (options.mCancel || options.outWidth == -1 || options.outHeight == -1) { return null; @@ -193,18 +181,10 @@ public class ImageList extends BaseImageList implements IImageList { options.inDither = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; - long t1 = System.currentTimeMillis(); b = BitmapManager.instance() .decodeFileDescriptor(fd, null, options); - long t2 = System.currentTimeMillis(); - if (VERBOSE) { - Log.v(TAG, "A: got bitmap " + b + " with sampleSize " - + options.inSampleSize + " took " + (t2 - t1)); - } } catch (OutOfMemoryError ex) { - if (VERBOSE) { - Log.v(TAG, "got oom exception " + ex); - } + Log.e(TAG, "Got oom exception ", ex); return null; } finally { Util.closeSiliently(pfd); diff --git a/src/com/android/camera/gallery/ImageListUber.java b/src/com/android/camera/gallery/ImageListUber.java index 2f97b9f..c196de5 100644 --- a/src/com/android/camera/gallery/ImageListUber.java +++ b/src/com/android/camera/gallery/ImageListUber.java @@ -180,7 +180,6 @@ public class ImageListUber implements IImageList { } if (which == -1) { - if (VERBOSE) Log.v(TAG, "which is -1, returning null"); return null; } @@ -197,9 +196,6 @@ public class ImageListUber implements IImageList { } if (!done) { long newEntry = ((long) which << 32) | count; - if (VERBOSE) { - Log.v(TAG, "new entry is " + Long.toHexString(newEntry)); - } mSkipList.add(newEntry); } diff --git a/src/com/android/camera/gallery/MiniThumbFile.java b/src/com/android/camera/gallery/MiniThumbFile.java index 692dacf..8c2b970 100644 --- a/src/com/android/camera/gallery/MiniThumbFile.java +++ b/src/com/android/camera/gallery/MiniThumbFile.java @@ -140,7 +140,6 @@ class MiniThumbFile { if (r == null) return; long pos = id * BYTES_PER_MINTHUMB; - long t0 = System.currentTimeMillis(); synchronized (r) { try { if (data != null) { diff --git a/src/com/android/camera/gallery/SimpleBaseImage.java b/src/com/android/camera/gallery/SimpleBaseImage.java deleted file mode 100644 index 6de6329..0000000 --- a/src/com/android/camera/gallery/SimpleBaseImage.java +++ /dev/null @@ -1,98 +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.net.Uri; - -import java.io.InputStream; - -/** - * A simple version of <code>BaseImage</code>. - */ -public abstract class SimpleBaseImage implements IImage { - public void commitChanges() { - throw new UnsupportedOperationException(); - } - - public InputStream fullSizeImageData() { - throw new UnsupportedOperationException(); - } - - public long fullSizeImageId() { - return 0; - } - - public Uri fullSizeImageUri() { - throw new UnsupportedOperationException(); - } - - public IImageList getContainer() { - return null; - } - - public long getDateTaken() { - return 0; - } - - public String getMimeType() { - throw new UnsupportedOperationException(); - } - - public String getTitle() { - throw new UnsupportedOperationException(); - } - - public String getDisplayName() { - throw new UnsupportedOperationException(); - } - - public int getRow() { - throw new UnsupportedOperationException(); - } - - public int getHeight() { - return 0; - } - - public int getWidth() { - return 0; - } - - public boolean isReadonly() { - return true; - } - - public boolean isDrm() { - return false; - } - - public void onRemove() { - throw new UnsupportedOperationException(); - } - - public boolean rotateImageBy(int degrees) { - return false; - } - - public void setTitle(String name) { - throw new UnsupportedOperationException(); - } - - public Uri thumbUri() { - throw new UnsupportedOperationException(); - } -}
\ No newline at end of file diff --git a/src/com/android/camera/gallery/SingleImageList.java b/src/com/android/camera/gallery/SingleImageList.java index 099a01f..39d7d7b 100644 --- a/src/com/android/camera/gallery/SingleImageList.java +++ b/src/com/android/camera/gallery/SingleImageList.java @@ -23,14 +23,10 @@ import com.android.camera.Util; import android.content.ContentResolver; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.Matrix; import android.net.Uri; import android.os.ParcelFileDescriptor; import android.util.Log; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.InputStream; import java.util.HashMap; /** @@ -40,214 +36,12 @@ import java.util.HashMap; public class SingleImageList extends BaseImageList implements IImageList { private static final String TAG = "SingleImageList"; private static final boolean VERBOSE = false; - private static final int THUMBNAIL_TARGET_SIZE = 320; private IImage mSingleImage; - private class UriImage extends SimpleBaseImage { - - UriImage() { - } - - public String getDataPath() { - return mUri.getPath(); - } - - InputStream getInputStream() { - try { - if (mUri.getScheme().equals("file")) { - String path = mUri.getPath(); - if (VERBOSE) Log.v(TAG, "path is " + path); - return new java.io.FileInputStream(mUri.getPath()); - } else { - return mContentResolver.openInputStream(mUri); - } - } catch (FileNotFoundException ex) { - return null; - } - } - - ParcelFileDescriptor getPFD() { - try { - if (mUri.getScheme().equals("file")) { - String path = mUri.getPath(); - if (VERBOSE) Log.v(TAG, "path is " + path); - return ParcelFileDescriptor.open(new File(path), - ParcelFileDescriptor.MODE_READ_ONLY); - } else { - return mContentResolver.openFileDescriptor(mUri, "r"); - } - } catch (FileNotFoundException ex) { - return null; - } - } - - public Bitmap fullSizeBitmap(int targetWidthHeight) { - try { - ParcelFileDescriptor pfdInput = getPFD(); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapManager.instance().decodeFileDescriptor( - pfdInput.getFileDescriptor(), null, options); - - if (targetWidthHeight != -1) { - options.inSampleSize = - Util.computeSampleSize(options, targetWidthHeight); - } - - options.inJustDecodeBounds = false; - options.inDither = false; - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - - Bitmap b = BitmapManager.instance().decodeFileDescriptor( - pfdInput.getFileDescriptor(), null, options); - if (VERBOSE) { - Log.v(TAG, "B: got bitmap " + b + " with sampleSize " - + options.inSampleSize); - } - pfdInput.close(); - return b; - } catch (Exception ex) { - Log.e(TAG, "got exception decoding bitmap " + ex.toString()); - return null; - } - } - - final class LoadBitmapCancelable extends BaseCancelable<Bitmap> { - ParcelFileDescriptor mPfdInput; - BitmapFactory.Options mOptions = new BitmapFactory.Options(); - long mCancelInitiationTime; - int mTargetWidthOrHeight; - - public LoadBitmapCancelable( - ParcelFileDescriptor pfd, int targetWidthOrHeight) { - mPfdInput = pfd; - mTargetWidthOrHeight = targetWidthOrHeight; - } - - @Override - public boolean doCancelWork() { - if (VERBOSE) { - Log.v(TAG, "requesting bitmap load cancel"); - } - mCancelInitiationTime = System.currentTimeMillis(); - mOptions.requestCancelDecode(); - return true; - } - - public Bitmap get() { - try { - Bitmap b = makeBitmap(mTargetWidthOrHeight, - fullSizeImageUri(), mPfdInput, mOptions); - if (b == null && mCancelInitiationTime != 0) { - if (VERBOSE) { - Log.v(TAG, "cancel returned null bitmap -- took " - + (System.currentTimeMillis() - - mCancelInitiationTime)); - } - } - if (VERBOSE) Log.v(TAG, "b is " + b); - return b; - } catch (Exception ex) { - return null; - } finally { - acknowledgeCancel(); - } - } - } - - public ICancelable<Bitmap> fullSizeBitmapCancelable( - int targetWidthOrHeight) { - try { - ParcelFileDescriptor pfdInput = getPFD(); - if (pfdInput == null) return null; - if (VERBOSE) Log.v(TAG, "inputStream is " + pfdInput); - return new LoadBitmapCancelable(pfdInput, targetWidthOrHeight); - } catch (UnsupportedOperationException ex) { - return null; - } - } - - @Override - public Uri fullSizeImageUri() { - return mUri; - } - - @Override - public InputStream fullSizeImageData() { - return getInputStream(); - } - - public long imageId() { - return 0; - } - - public Bitmap miniThumbBitmap() { - return thumbBitmap(); - } - - @Override - public String getTitle() { - return mUri.toString(); - } - - @Override - public String getDisplayName() { - return getTitle(); - } - - public Bitmap thumbBitmap() { - Bitmap b = fullSizeBitmap(THUMBNAIL_TARGET_SIZE); - if (b != null) { - Matrix m = new Matrix(); - float scale = Math.min( - 1F, THUMBNAIL_TARGET_SIZE / (float) b.getWidth()); - m.setScale(scale, scale); - Bitmap scaledBitmap = Bitmap.createBitmap( - b, 0, 0, b.getWidth(), b.getHeight(), m, true); - return scaledBitmap; - } else { - return null; - } - } - - private BitmapFactory.Options snifBitmapOptions() { - ParcelFileDescriptor input = getPFD(); - if (input == null) return null; - try { - Uri uri = fullSizeImageUri(); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapManager.instance().decodeFileDescriptor( - input.getFileDescriptor(), null, options); - return options; - } finally { - Util.closeSiliently(input); - } - } - - @Override - public String getMimeType() { - BitmapFactory.Options options = snifBitmapOptions(); - return (options != null) ? options.outMimeType : ""; - } - - @Override - public int getHeight() { - BitmapFactory.Options options = snifBitmapOptions(); - return (options != null) ? options.outHeight : 0; - } - - @Override - public int getWidth() { - BitmapFactory.Options options = snifBitmapOptions(); - return (options != null) ? options.outWidth : 0; - } - } - public SingleImageList(ContentResolver cr, Uri uri) { super(null, cr, uri, ImageManager.SORT_ASCENDING, null); - mSingleImage = new UriImage(); + mSingleImage = new UriImage(this, cr, uri); } public HashMap<String, String> getBucketIds() { @@ -279,10 +73,6 @@ public class SingleImageList extends BaseImageList implements IImageList { return uri.equals(mUri) ? mSingleImage : null; } - public IImage getImageWithId(long id) { - throw new UnsupportedOperationException(); - } - @Override protected int indexOrientation() { return -1; @@ -346,12 +136,8 @@ public class SingleImageList extends BaseImageList implements IImageList { } b = BitmapManager.instance().decodeFileDescriptor( pfdInput.getFileDescriptor(), null, options); - if (VERBOSE) { - Log.v(TAG, "C: got bitmap " + b + " with sampleSize " - + options.inSampleSize); - } } catch (OutOfMemoryError ex) { - if (VERBOSE) Log.v(TAG, "got oom exception " + ex); + Log.e(TAG, "Got oom exception ", ex); return null; } finally { Util.closeSiliently(pfdInput); diff --git a/src/com/android/camera/gallery/UriImage.java b/src/com/android/camera/gallery/UriImage.java new file mode 100644 index 0000000..b7cb482 --- /dev/null +++ b/src/com/android/camera/gallery/UriImage.java @@ -0,0 +1,254 @@ +/* + * 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 com.android.camera.BitmapManager; +import com.android.camera.Util; + +import android.content.ContentResolver; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.net.Uri; +import android.os.ParcelFileDescriptor; +import android.util.Log; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStream; + +class UriImage implements IImage { + private static final String TAG = "UriImage"; + private static final int THUMBNAIL_TARGET_SIZE = 320; + private Uri mUri; + private BaseImageList mContainer; + private ContentResolver mContentResolver; + + UriImage(BaseImageList container, ContentResolver cr, Uri uri) { + mContainer = container; + mContentResolver = cr; + mUri = uri; + } + + public String getDataPath() { + return mUri.getPath(); + } + + InputStream getInputStream() { + try { + if (mUri.getScheme().equals("file")) { + String path = mUri.getPath(); + return new java.io.FileInputStream(mUri.getPath()); + } else { + return mContentResolver.openInputStream(mUri); + } + } catch (FileNotFoundException ex) { + return null; + } + } + + ParcelFileDescriptor getPFD() { + try { + if (mUri.getScheme().equals("file")) { + String path = mUri.getPath(); + return ParcelFileDescriptor.open(new File(path), + ParcelFileDescriptor.MODE_READ_ONLY); + } else { + return mContentResolver.openFileDescriptor(mUri, "r"); + } + } catch (FileNotFoundException ex) { + return null; + } + } + + public Bitmap fullSizeBitmap(int targetWidthHeight) { + try { + ParcelFileDescriptor pfdInput = getPFD(); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapManager.instance().decodeFileDescriptor( + pfdInput.getFileDescriptor(), null, options); + + if (targetWidthHeight != -1) { + options.inSampleSize = + Util.computeSampleSize(options, targetWidthHeight); + } + + options.inJustDecodeBounds = false; + options.inDither = false; + options.inPreferredConfig = Bitmap.Config.ARGB_8888; + + Bitmap b = BitmapManager.instance().decodeFileDescriptor( + pfdInput.getFileDescriptor(), null, options); + pfdInput.close(); + return b; + } catch (Exception ex) { + Log.e(TAG, "got exception decoding bitmap " + ex.toString()); + return null; + } + } + + final class LoadBitmapCancelable extends BaseCancelable<Bitmap> { + ParcelFileDescriptor mPfdInput; + BitmapFactory.Options mOptions = new BitmapFactory.Options(); + int mTargetWidthOrHeight; + + public LoadBitmapCancelable( + ParcelFileDescriptor pfd, int targetWidthOrHeight) { + mPfdInput = pfd; + mTargetWidthOrHeight = targetWidthOrHeight; + } + + @Override + public boolean doCancelWork() { + mOptions.requestCancelDecode(); + return true; + } + + public Bitmap get() { + try { + Bitmap b = mContainer.makeBitmap(mTargetWidthOrHeight, + fullSizeImageUri(), mPfdInput, mOptions); + return b; + } catch (Exception ex) { + return null; + } finally { + acknowledgeCancel(); + } + } + } + + public ICancelable<Bitmap> fullSizeBitmapCancelable( + int targetWidthOrHeight) { + try { + ParcelFileDescriptor pfdInput = getPFD(); + if (pfdInput == null) return null; + return new LoadBitmapCancelable(pfdInput, targetWidthOrHeight); + } catch (UnsupportedOperationException ex) { + return null; + } + } + + public Uri fullSizeImageUri() { + return mUri; + } + + public InputStream fullSizeImageData() { + return getInputStream(); + } + + public Bitmap miniThumbBitmap() { + return thumbBitmap(); + } + + public String getTitle() { + return mUri.toString(); + } + + public String getDisplayName() { + return getTitle(); + } + + public Bitmap thumbBitmap() { + Bitmap b = fullSizeBitmap(THUMBNAIL_TARGET_SIZE); + if (b != null) { + Matrix m = new Matrix(); + float scale = Math.min( + 1F, THUMBNAIL_TARGET_SIZE / (float) b.getWidth()); + m.setScale(scale, scale); + Bitmap scaledBitmap = Bitmap.createBitmap( + b, 0, 0, b.getWidth(), b.getHeight(), m, true); + return scaledBitmap; + } else { + return null; + } + } + + private BitmapFactory.Options snifBitmapOptions() { + ParcelFileDescriptor input = getPFD(); + if (input == null) return null; + try { + Uri uri = fullSizeImageUri(); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapManager.instance().decodeFileDescriptor( + input.getFileDescriptor(), null, options); + return options; + } finally { + Util.closeSiliently(input); + } + } + + public String getMimeType() { + BitmapFactory.Options options = snifBitmapOptions(); + return (options != null) ? options.outMimeType : ""; + } + + public int getHeight() { + BitmapFactory.Options options = snifBitmapOptions(); + return (options != null) ? options.outHeight : 0; + } + + public int getWidth() { + BitmapFactory.Options options = snifBitmapOptions(); + return (options != null) ? options.outWidth : 0; + } + + public void commitChanges() { + throw new UnsupportedOperationException(); + } + + public long fullSizeImageId() { + return 0; + } + + public IImageList getContainer() { + return mContainer; + } + + public long getDateTaken() { + return 0; + } + + public int getRow() { + throw new UnsupportedOperationException(); + } + + public boolean isReadonly() { + return true; + } + + public boolean isDrm() { + return false; + } + + public void onRemove() { + throw new UnsupportedOperationException(); + } + + public boolean rotateImageBy(int degrees) { + return false; + } + + public void setTitle(String name) { + throw new UnsupportedOperationException(); + } + + public Uri thumbUri() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/com/android/camera/gallery/VideoList.java b/src/com/android/camera/gallery/VideoList.java index 995fd65..aac054d 100644 --- a/src/com/android/camera/gallery/VideoList.java +++ b/src/com/android/camera/gallery/VideoList.java @@ -84,12 +84,6 @@ public class VideoList extends BaseImageList implements IImageList { throw new UnsupportedOperationException(); } - if (Config.LOGV) { - Log.v(TAG, "for " + mUri.toString() + " got cursor " + mCursor - + " with length " - + (mCursor != null ? mCursor.getCount() : -1)); - } - if (mCursor == null) { throw new UnsupportedOperationException(); } @@ -150,10 +144,6 @@ public class VideoList extends BaseImageList implements IImageList { Cursor c = Images.Media.query( mContentResolver, mBaseUri, sProjection, whereClause(), whereClauseArgs(), sortOrder()); - if (VERBOSE) { - Log.v(TAG, "createCursor got cursor with count " - + (c == null ? -1 : c.getCount())); - } return c; } @@ -220,15 +210,6 @@ public class VideoList extends BaseImageList implements IImageList { // int at = duration > 2000 ? 1000 : duration / 2; int at = 1000; thumbnail = mp.getFrameAt(at); - if (Config.LOGV) { - if (thumbnail != null) { - Log.v(TAG, "getFrameAt @ " + at + " returned " + thumbnail - + "; " + thumbnail.getWidth() + " " - + thumbnail.getHeight()); - } else { - Log.v(TAG, "getFrame @ " + at + " failed for " + uri); - } - } } catch (IOException ex) { // ignore } catch (IllegalArgumentException ex) { diff --git a/src/com/android/camera/gallery/VideoObject.java b/src/com/android/camera/gallery/VideoObject.java index d4ce04e..2129664 100644 --- a/src/com/android/camera/gallery/VideoObject.java +++ b/src/com/android/camera/gallery/VideoObject.java @@ -132,11 +132,6 @@ public class VideoObject extends BaseImage implements IImage { return 0; } - @Override - public long imageId() { - return mId; - } - public boolean isReadonly() { return false; } |