diff options
author | d34d <clark@cyngn.com> | 2015-03-18 15:12:58 -0700 |
---|---|---|
committer | d34d <clark@cyngn.com> | 2015-03-18 15:22:14 -0700 |
commit | 9824ba42179bc15e6cb810479ffeeeea583afd26 (patch) | |
tree | d1f89da1a4ec532a6ebd40682c4d5df330793b41 /src/com | |
parent | 0e62bfaf2f382f9219528d51351c163329012446 (diff) | |
download | packages_apps_ThemeChooser-9824ba42179bc15e6cb810479ffeeeea583afd26.tar.gz packages_apps_ThemeChooser-9824ba42179bc15e6cb810479ffeeeea583afd26.tar.bz2 packages_apps_ThemeChooser-9824ba42179bc15e6cb810479ffeeeea583afd26.zip |
BootAni: Recreate bitmap when reusing fails
If the inBitmap does not have enough bytes allocated to load in the
newly decoded frame an IllegalArgumentException will be thrown.
Instead of giving up here we can load in a new image instead.
If this fails then we log it and continue as normal.
Change-Id: Ibc11cde7aed9633552854a11a50924872a94fa53
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/cyngn/theme/widget/BootAniImageView.java | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/com/cyngn/theme/widget/BootAniImageView.java b/src/com/cyngn/theme/widget/BootAniImageView.java index 93d58c1..44363d6 100644 --- a/src/com/cyngn/theme/widget/BootAniImageView.java +++ b/src/com/cyngn/theme/widget/BootAniImageView.java @@ -20,6 +20,8 @@ import java.util.zip.ZipFile; public class BootAniImageView extends ImageView { private static final String TAG = BootAniImageView.class.getName(); + private static final boolean DEBUG = false; + private static final int MAX_BUFFERS = 2; private Bitmap[] mBuffers = new Bitmap[MAX_BUFFERS]; @@ -128,7 +130,26 @@ public class BootAniImageView extends ImageView { mBuffers[mWriteBufferIndex] = BitmapFactory.decodeStream(mBootAniZip.getInputStream(mBootAniZip.getEntry( part.frames.get(mCurrentFrame++))), null, opts); - } catch (Exception e) { + } catch (IllegalArgumentException iae) { + // In case we're here because the bitmap could not be re-used, try creating a new one + opts.inBitmap = null; + try { + if (DEBUG) { + Log.d(TAG, "Trying to load frame without reusing existing bitmap", iae); + } + if (mBuffers[mWriteBufferIndex] != null) { + // clean up our old bitmap + mBuffers[mWriteBufferIndex].recycle(); + mBuffers[mWriteBufferIndex] = null; + } + mBuffers[mWriteBufferIndex] = + BitmapFactory.decodeStream(mBootAniZip.getInputStream(mBootAniZip.getEntry( + part.frames.get(mCurrentFrame++))), null, opts); + } catch (Exception e) { + // Still failling? Let's log it and carry on. + Log.w(TAG, "Unable to get next frame", e); + } + } catch (IOException e) { Log.w(TAG, "Unable to get next frame", e); } mWriteBufferIndex = (mWriteBufferIndex + 1) % MAX_BUFFERS; |