packages/apps/Trebuchet
Révision | 273db439991b7230f1adbf4502bc5f1ce01b211c (tree) |
---|---|
l'heure | 2017-05-27 07:16:14 |
Auteur | Tony Wickham <twickham@goog...> |
Commiter | Arne Coucheron |
Handle OutOfMemoryException gracefully in WallpaperCropActivity.
Now instead of crashing, it says "Couldn't load image."
Bug: 25326319
Change-Id: I6918b7b34e0a9b40036b1405fc449c10c2e1d40a
@@ -159,6 +159,7 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { | ||
159 | 159 | public enum State { NOT_LOADED, LOADED, ERROR_LOADING }; |
160 | 160 | private State mState = State.NOT_LOADED; |
161 | 161 | |
162 | + /** Returns whether loading was successful. */ | |
162 | 163 | public boolean loadInBackground(InBitmapProvider bitmapProvider) { |
163 | 164 | ExifInterface ei = new ExifInterface(); |
164 | 165 | if (readExif(ei)) { |
@@ -193,7 +194,7 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { | ||
193 | 194 | try { |
194 | 195 | mPreview = loadPreviewBitmap(opts); |
195 | 196 | } catch (IllegalArgumentException e) { |
196 | - Log.d(TAG, "Unable to reusage bitmap", e); | |
197 | + Log.d(TAG, "Unable to reuse bitmap", e); | |
197 | 198 | opts.inBitmap = null; |
198 | 199 | mPreview = null; |
199 | 200 | } |
@@ -202,6 +203,10 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { | ||
202 | 203 | if (mPreview == null) { |
203 | 204 | mPreview = loadPreviewBitmap(opts); |
204 | 205 | } |
206 | + if (mPreview == null) { | |
207 | + mState = State.ERROR_LOADING; | |
208 | + return false; | |
209 | + } | |
205 | 210 | |
206 | 211 | // Verify that the bitmap can be used on GL surface |
207 | 212 | try { |
@@ -212,7 +217,7 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { | ||
212 | 217 | Log.d(TAG, "Image cannot be rendered on a GL surface", e); |
213 | 218 | mState = State.ERROR_LOADING; |
214 | 219 | } |
215 | - return true; | |
220 | + return mState == State.LOADED; | |
216 | 221 | } |
217 | 222 | } |
218 | 223 |
@@ -310,7 +315,7 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { | ||
310 | 315 | Bitmap b = BitmapFactory.decodeStream(is, null, options); |
311 | 316 | Utils.closeSilently(is); |
312 | 317 | return b; |
313 | - } catch (FileNotFoundException e) { | |
318 | + } catch (FileNotFoundException | OutOfMemoryError e) { | |
314 | 319 | Log.e("BitmapRegionTileSource", "Failed to load URI " + mUri, e); |
315 | 320 | return null; |
316 | 321 | } |
@@ -412,7 +417,8 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { | ||
412 | 417 | "Failed to create preview of apropriate size! " |
413 | 418 | + " in: %dx%d, out: %dx%d", |
414 | 419 | mWidth, mHeight, |
415 | - preview.getWidth(), preview.getHeight())); | |
420 | + preview == null ? -1 : preview.getWidth(), | |
421 | + preview == null ? -1 : preview.getHeight())); | |
416 | 422 | } |
417 | 423 | } |
418 | 424 | } |