From b6c75a5e1a9dfc7753a451e97607510d37264374 Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Thu, 1 Nov 2012 12:57:36 -0400 Subject: don't reuse mOptions across threads. Bug: 7370134 Change-Id: If6e02c2095f5f70e4dd506e651efbbd5ad47fa07 --- src/com/android/dreams/phototable/PhotoCarousel.java | 14 +++++++++----- src/com/android/dreams/phototable/PhotoTable.java | 18 +++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/com/android/dreams/phototable/PhotoCarousel.java b/src/com/android/dreams/phototable/PhotoCarousel.java index 495e73c..70ba046 100644 --- a/src/com/android/dreams/phototable/PhotoCarousel.java +++ b/src/com/android/dreams/phototable/PhotoCarousel.java @@ -48,7 +48,6 @@ public class PhotoCarousel extends FrameLayout { private final PhotoSourcePlexor mPhotoSource; private final GestureDetector mGestureDetector; private final View[] mPanel; - private final BitmapFactory.Options mOptions; private final int mFlipDuration; private final int mDropPeriod; private final int mBitmapQueueLimit; @@ -100,8 +99,6 @@ public class PhotoCarousel extends FrameLayout { mDropPeriod = resources.getInteger(R.integer.carousel_drop_period); mBitmapQueueLimit = resources.getInteger(R.integer.num_images_to_preload); mFlipDuration = resources.getInteger(R.integer.flip_duration); - mOptions = new BitmapFactory.Options(); - mOptions.inTempStorage = new byte[32768]; mPhotoSource = new PhotoSourcePlexor(getContext(), getContext().getSharedPreferences(FlipperDreamSettings.PREFS_NAME, 0)); mBitmapStore = new HashMap(); @@ -130,6 +127,13 @@ public class PhotoCarousel extends FrameLayout { } private class PhotoLoadTask extends AsyncTask { + private final BitmapFactory.Options mOptions; + + public PhotoLoadTask () { + mOptions = new BitmapFactory.Options(); + mOptions.inTempStorage = new byte[32768]; + } + @Override public Bitmap doInBackground(Void... unused) { Bitmap decodedPhoto; @@ -180,8 +184,8 @@ public class PhotoCarousel extends FrameLayout { if (photo != null) { ImageView destination = getBackface(); Bitmap old = mBitmapStore.get(destination); - int width = mOptions.outWidth; - int height = mOptions.outHeight; + int width = photo.getWidth(); + int height = photo.getHeight(); int orientation = (width > height ? LANDSCAPE : PORTRAIT); destination.setImageBitmap(photo); diff --git a/src/com/android/dreams/phototable/PhotoTable.java b/src/com/android/dreams/phototable/PhotoTable.java index ddf2f58..50212c9 100644 --- a/src/com/android/dreams/phototable/PhotoTable.java +++ b/src/com/android/dreams/phototable/PhotoTable.java @@ -85,7 +85,6 @@ public class PhotoTable extends FrameLayout { private PhotoLaunchTask mPhotoLaunchTask; private boolean mStarted; private boolean mIsLandscape; - private BitmapFactory.Options mOptions; private int mLongSide; private int mShortSide; private int mWidth; @@ -114,8 +113,6 @@ public class PhotoTable extends FrameLayout { mDropInterpolator = new DecelerateInterpolator( (float) mResources.getInteger(R.integer.drop_deceleration_exponent)); mOnTable = new LinkedList(); - mOptions = new BitmapFactory.Options(); - mOptions.inTempStorage = new byte[32768]; mPhotoSource = new PhotoSourcePlexor(getContext(), getContext().getSharedPreferences(PhotoTableDreamSettings.PREFS_NAME, 0)); mLauncher = new Launcher(this); @@ -242,6 +239,13 @@ public class PhotoTable extends FrameLayout { } private class PhotoLaunchTask extends AsyncTask { + private final BitmapFactory.Options mOptions; + + public PhotoLaunchTask () { + mOptions = new BitmapFactory.Options(); + mOptions.inTempStorage = new byte[32768]; + } + @Override public View doInBackground(Void... unused) { log("load a new photo"); @@ -252,11 +256,11 @@ public class PhotoTable extends FrameLayout { View photo = inflater.inflate(R.layout.photo, null); ImageView image = (ImageView) photo; Drawable[] layers = new Drawable[2]; - Bitmap decodedPhoto = table.mPhotoSource.next(table.mOptions, + Bitmap decodedPhoto = table.mPhotoSource.next(mOptions, table.mLongSide, table.mShortSide); - int photoWidth = table.mOptions.outWidth; - int photoHeight = table.mOptions.outHeight; - if (table.mOptions.outWidth <= 0 || table.mOptions.outHeight <= 0) { + int photoWidth = mOptions.outWidth; + int photoHeight = mOptions.outHeight; + if (mOptions.outWidth <= 0 || mOptions.outHeight <= 0) { photo = null; } else { decodedPhoto.setHasMipMap(true); -- cgit v1.2.3