From 58e2a16d9237d2a5674a97062b5d614d8d397845 Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Wed, 3 Oct 2012 15:01:20 -0400 Subject: look harder for images to load. Bug: 7242346 Change-Id: I729286685d7cd19a68e9db5f428ff714f3d2775c --- src/com/android/dreams/phototable/PhotoSource.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/com/android/dreams/phototable') diff --git a/src/com/android/dreams/phototable/PhotoSource.java b/src/com/android/dreams/phototable/PhotoSource.java index 21c6646..62c0f4f 100644 --- a/src/com/android/dreams/phototable/PhotoSource.java +++ b/src/com/android/dreams/phototable/PhotoSource.java @@ -74,6 +74,7 @@ public abstract class PhotoSource { private final LinkedList mImageQueue; private final int mMaxQueueSize; private final float mMaxCropRatio; + private final int mBadImageSkipLimit; private final PhotoSource mFallbackSource; protected final Context mContext; @@ -97,6 +98,7 @@ public abstract class PhotoSource { mImageQueue = new LinkedList(); mMaxQueueSize = mResources.getInteger(R.integer.image_queue_size); mMaxCropRatio = mResources.getInteger(R.integer.max_crop_ratio) / 1000000f; + mBadImageSkipLimit = mResources.getInteger(R.integer.bad_image_skip_limit); mRNG = new Random(); mFallbackSource = fallbackSource; } @@ -111,18 +113,23 @@ public abstract class PhotoSource { public Bitmap next(BitmapFactory.Options options, int longSide, int shortSide) { log(TAG, "decoding a picasa resource to " + longSide + ", " + shortSide); Bitmap image = null; + int tries = 0; - if (mImageQueue.isEmpty()) { - fillQueue(); - } + while (image == null && tries < mBadImageSkipLimit) { + if (mImageQueue.isEmpty()) { + fillQueue(); + } + + if (!mImageQueue.isEmpty()) { + image = load(mImageQueue.poll(), options, longSide, shortSide); + } - if (!mImageQueue.isEmpty()) { - image = load(mImageQueue.poll(), options, longSide, shortSide); + tries++; } if (image == null && mFallbackSource != null) { image = load((ImageData) mFallbackSource.findImages(1).toArray()[0], - options, longSide, shortSide); + options, longSide, shortSide); } return image; -- cgit v1.2.3