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

Commit 0148e83e authored by Austin Kolander's avatar Austin Kolander Committed by android-build-merger
Browse files

Fixed thumbnail flashing bug in the inspector.

am: 04efd4af

Change-Id: I3552ab49d96cb9aa8bc32e33025d7150da9f3def
parents 1b3b3f93 04efd4af
Loading
Loading
Loading
Loading
+14 −15
Original line number Diff line number Diff line
@@ -17,11 +17,13 @@ package com.android.documentsui;

import static com.android.documentsui.base.Shared.VERBOSE;

import android.annotation.Nullable;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.CancellationSignal;
@@ -32,6 +34,7 @@ import android.view.View;
import android.widget.ImageView;
import com.android.documentsui.ProviderExecutor.Preemptable;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 *  Loads a Thumbnails asynchronously then animates from the mime icon to the thumbnail
@@ -54,34 +57,31 @@ public final class ThumbnailLoader extends AsyncTask<Uri, Void, Bitmap> implemen

    private final ImageView mIconThumb;
    private final Point mThumbSize;
    // A callback to apply animation to image views after the thumbnail is loaded.
    private final BiConsumer<View, View> mImageAnimator;
    private final Uri mUri;
    private final ImageView mIconMime;
    private final long mLastModified;
    private final Consumer<Bitmap> mCallback;
    private final boolean mAddToCache;
    private final CancellationSignal mSignal;

    /**
     * @param uri - to a thumbnail.
     * @param iconMime - ImageView for displaying a mime type.
     * @param iconThumb - ImageView to display the thumbnail.
     * @param thumbSize - size of the thumbnail.
     * @param lastModified - used for updating thumbnail caches.
     * @param animator - used to animate from the mime icon to the thumbnail.
     * @param addToCache - flag that determines if the loader saves the thumbnail to the cache.
     */
    public ThumbnailLoader(Uri uri, ImageView iconMime, ImageView iconThumb,
        Point thumbSize, long lastModified, BiConsumer<View, View> animator, boolean addToCache) {
    public ThumbnailLoader(Uri uri, ImageView iconThumb, Point thumbSize, long lastModified,
        Consumer<Bitmap> callback, boolean addToCache) {

        mUri = uri;
        mIconMime = iconMime;
        mIconThumb = iconThumb;
        mThumbSize = thumbSize;
        mImageAnimator = animator;
        mLastModified = lastModified;
        mCallback = callback;
        mAddToCache = addToCache;
        mSignal = new CancellationSignal();
        mIconThumb.setTag(this);

        if (VERBOSE) Log.v(TAG, "Starting icon loader task for " + mUri);
    }

@@ -125,10 +125,9 @@ public final class ThumbnailLoader extends AsyncTask<Uri, Void, Bitmap> implemen
    protected void onPostExecute(Bitmap result) {
        if (VERBOSE) Log.v(TAG, "Loader task for " + mUri + " completed");

            if (mIconThumb.getTag() == this && result != null) {
        if (mIconThumb.getTag() == this) {
            mIconThumb.setTag(null);
                mIconThumb.setImageBitmap(result);
                mImageAnimator.accept(mIconMime, mIconThumb);
            mCallback.accept(result);
        }
    }
}
 No newline at end of file
+13 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.documentsui.base.State;
import com.android.documentsui.base.State.ViewMode;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * A class to assist with loading and managing the Images (i.e. thumbnails and icons) associated
@@ -199,8 +200,18 @@ public class IconHelper {
                        (cachedThumbnail == null ? ThumbnailLoader.ANIM_FADE_IN :
                                ThumbnailLoader.ANIM_NO_OP);

                final ThumbnailLoader task = new ThumbnailLoader(uri, iconMime, iconThumb,
                    mCurrentSize, docLastModified, animator, true);
                Consumer<Bitmap> callback = new Consumer<Bitmap>() {
                    @Override
                    public void accept(Bitmap bitmap) {
                        if (result != null) {
                            iconThumb.setImageBitmap(bitmap);
                            animator.accept(iconMime, iconThumb);
                        }
                    }
                };

                final ThumbnailLoader task = new ThumbnailLoader(uri, iconThumb,
                    mCurrentSize, docLastModified, callback, true);

                ProviderExecutor.forAuthority(docAuthority).execute(task);
            }
+16 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.documentsui.inspector;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
@@ -93,13 +94,23 @@ public final class HeaderView extends RelativeLayout implements Consumer<Documen

    private void loadHeaderImage(DocumentInfo info) {

        // load the mime icon.
        Drawable d = mContext.getContentResolver().getTypeDrawable(info.mimeType);
        mMime.setImageDrawable(d);
        Consumer<Bitmap> callback = new Consumer<Bitmap>() {
            @Override
            public void accept(Bitmap bitmap) {
                if (bitmap != null) {
                    mThumbnail.setImageBitmap(bitmap);
                    ThumbnailLoader.ANIM_FADE_IN.accept(mMime, mThumbnail);
                } else {
                    Drawable mimeIcon = mContext.getContentResolver()
                            .getTypeDrawable(info.mimeType);
                    mMime.setImageDrawable(mimeIcon);
                }
            }
        };

        // load the thumbnail async.
        final ThumbnailLoader task = new ThumbnailLoader(info.derivedUri, mMime, mThumbnail,
            mImageDimensions, info.lastModified, ThumbnailLoader.ANIM_FADE_IN, false);
        final ThumbnailLoader task = new ThumbnailLoader(info.derivedUri, mThumbnail,
            mImageDimensions, info.lastModified, callback, false);
        task.executeOnExecutor(ProviderExecutor.forAuthority(info.derivedUri.getAuthority()),
            info.derivedUri);
    }