summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/WallpaperPickerActivity.java
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2013-10-16 18:23:56 -0700
committerMichael Jurka <mikejurka@google.com>2013-10-21 14:51:49 -0700
commit862f7e395004b00d871cbe507fd5f2a70c797ef7 (patch)
treec8372d4947e06cd8591bd590a2820c97c12ac76b /src/com/android/launcher3/WallpaperPickerActivity.java
parent4f98332b98bbe95cb0574e51ef1514bade9a5e76 (diff)
downloadandroid_packages_apps_Trebuchet-862f7e395004b00d871cbe507fd5f2a70c797ef7.tar.gz
android_packages_apps_Trebuchet-862f7e395004b00d871cbe507fd5f2a70c797ef7.tar.bz2
android_packages_apps_Trebuchet-862f7e395004b00d871cbe507fd5f2a70c797ef7.zip
Load images on a bg thread
Bug: 11134758 Change-Id: Ie789a2fcb2024832ac104cd9cdbc3602abee85ee
Diffstat (limited to 'src/com/android/launcher3/WallpaperPickerActivity.java')
-rw-r--r--src/com/android/launcher3/WallpaperPickerActivity.java55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java
index 2ad92181d..9c6ee6ec0 100644
--- a/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -42,6 +42,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LevelListDrawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
@@ -133,11 +134,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
}
@Override
public void onClick(WallpaperPickerActivity a) {
- CropView v = a.getCropView();
- int rotation = WallpaperCropActivity.getRotationFromExif(a, mUri);
- a.getDefaultWallpaperView().setVisibility(View.INVISIBLE);
- v.setTileSource(new BitmapRegionTileSource(a, mUri, 1024, rotation), null);
- v.setTouchEnabled(true);
+ a.setCropViewTileSource(
+ new BitmapRegionTileSource.UriBitmapSource(a, mUri, 1024), true, false);
}
@Override
public void onSave(final WallpaperPickerActivity a) {
@@ -175,9 +173,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
}
@Override
public void onClick(WallpaperPickerActivity a) {
- int rotation = WallpaperCropActivity.getRotationFromExif(mResources, mResId);
- BitmapRegionTileSource source = new BitmapRegionTileSource(
- mResources, a, mResId, 1024, rotation);
+ BitmapRegionTileSource.ResourceBitmapSource bitmapSource =
+ new BitmapRegionTileSource.ResourceBitmapSource(mResources, mResId, 1024);
+ bitmapSource.loadInBackground();
+ BitmapRegionTileSource source = new BitmapRegionTileSource(a, bitmapSource);
CropView v = a.getCropView();
a.getDefaultWallpaperView().setVisibility(View.INVISIBLE);
v.setTileSource(source, null);
@@ -528,6 +527,12 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
}
};
}
+ @Override
+ public void setCropViewTileSource(final BitmapRegionTileSource.BitmapSource bitmapSource,
+ final boolean touchEnabled, boolean moveToLeft) {
+ getDefaultWallpaperView().setVisibility(View.INVISIBLE);
+ super.setCropViewTileSource(bitmapSource, touchEnabled, moveToLeft);
+ }
private void initializeScrollForRtl() {
final HorizontalScrollView scroll =
@@ -687,26 +692,34 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
}
}
- private void addTemporaryWallpaperTile(Uri uri) {
+ private void addTemporaryWallpaperTile(final Uri uri) {
mTempWallpaperTiles.add(uri);
// Add a tile for the image picked from Gallery
FrameLayout pickedImageThumbnail = (FrameLayout) getLayoutInflater().
inflate(R.layout.wallpaper_picker_item, mWallpapersView, false);
setWallpaperItemPaddingToZero(pickedImageThumbnail);
+ mWallpapersView.addView(pickedImageThumbnail, 0);
// Load the thumbnail
- ImageView image = (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image);
- Point defaultSize = getDefaultThumbnailSize(this.getResources());
- int rotation = WallpaperCropActivity.getRotationFromExif(this, uri);
- Bitmap thumb = createThumbnail(defaultSize, this, uri, null, null, 0, rotation, false);
- if (thumb != null) {
- image.setImageBitmap(thumb);
- Drawable thumbDrawable = image.getDrawable();
- thumbDrawable.setDither(true);
- } else {
- Log.e(TAG, "Error loading thumbnail for uri=" + uri);
- }
- mWallpapersView.addView(pickedImageThumbnail, 0);
+ final ImageView image = (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image);
+ final Point defaultSize = getDefaultThumbnailSize(this.getResources());
+ final Context context = this;
+ new AsyncTask<Void, Bitmap, Bitmap>() {
+ protected Bitmap doInBackground(Void...args) {
+ int rotation = WallpaperCropActivity.getRotationFromExif(context, uri);
+ return createThumbnail(defaultSize, context, uri, null, null, 0, rotation, false);
+
+ }
+ protected void onPostExecute(Bitmap thumb) {
+ if (thumb != null) {
+ image.setImageBitmap(thumb);
+ Drawable thumbDrawable = image.getDrawable();
+ thumbDrawable.setDither(true);
+ } else {
+ Log.e(TAG, "Error loading thumbnail for uri=" + uri);
+ }
+ }
+ }.execute();
UriWallpaperInfo info = new UriWallpaperInfo(uri);
pickedImageThumbnail.setTag(info);