Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c101881b authored by Raj Yengisetty's avatar Raj Yengisetty Committed by Gerrit Code Review
Browse files

WallpaperCropper: run addTemporaryWallpaperTile in an AsyncTask

Repro:
 - Select "Pick image"
 - Pick an image from DocumentsUI (e.g. Drive)
 - Observe: WallpaperCropper hangs on UI for a while as it's
 creating a bitmap thumbnail

Change-Id: I9072b58f877b09a70ce8138403830fdc39c8dbee
parent fac54217
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
        android:visibility="invisible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_centerInParent="true"
        android:indeterminate="true"
        android:indeterminateOnly="true"
        android:background="@android:color/transparent" />
+53 −26
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import com.android.photos.BitmapRegionTileSource;

import java.io.File;
@@ -618,25 +619,48 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
        }
    }

    private void addTemporaryWallpaperTile(Uri uri) {
    private void addTemporaryWallpaperTile(final Uri uri) {
        // Load the thumbnail
        new AsyncTask<Void, Void, Bitmap>() {
            FrameLayout pickedImageThumbnail;
            ProgressBar progressBar;

            @Override
            protected void onPreExecute() {
                mTempWallpaperTiles.add(uri);
                // Add a tile for the image picked from Gallery
        FrameLayout pickedImageThumbnail = (FrameLayout) getLayoutInflater().
                pickedImageThumbnail = (FrameLayout) getLayoutInflater().
                        inflate(R.layout.wallpaper_picker_item, mWallpapersView, false);
                setWallpaperItemPaddingToZero(pickedImageThumbnail);

        // Load the thumbnail
        ImageView image = (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image);
        Point defaultSize = Utilities.getDefaultThumbnailSize(this.getResources());
        int rotation = WallpaperCropActivity.getRotationFromExif(this, uri);
        Bitmap thumb = createThumbnail(defaultSize, this, uri, null, null, 0, rotation, false);
                progressBar = (ProgressBar) findViewById(R.id.loading);
                progressBar.setVisibility(View.VISIBLE);
            }

            @Override
            protected Bitmap doInBackground(Void... params) {
                Point defaultSize = Utilities.getDefaultThumbnailSize(
                        WallpaperPickerActivity.this.getResources());
                int rotation = WallpaperCropActivity.getRotationFromExif(
                        WallpaperPickerActivity.this, uri);
                Bitmap thumb = createThumbnail(defaultSize, WallpaperPickerActivity.this,
                        uri, null, null, 0, rotation, false);
                if (thumb == null) {
                    Log.e(TAG, "Error loading thumbnail for uri=" + uri);
                }
                return thumb;
            }

            @Override
            protected void onPostExecute(Bitmap thumb) {
                if (thumb != null) {
                    ImageView image =
                            (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image);
                    image.setImageBitmap(thumb);
                    Drawable thumbDrawable = image.getDrawable();
                    thumbDrawable.setDither(true);
        } else {
            Log.e(TAG, "Error loading thumbnail for uri=" + uri);
                }

                mWallpapersView.addView(pickedImageThumbnail, 0);

                UriWallpaperInfo info = new UriWallpaperInfo(uri);
@@ -646,6 +670,9 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
                updateTileIndices();
                pickedImageThumbnail.setOnClickListener(mThumbnailOnClickListener);
                mThumbnailOnClickListener.onClick(pickedImageThumbnail);
                progressBar.setVisibility(View.INVISIBLE);
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {