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

Commit 1d2e6e77 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Only load thumbnail if supported by provider."

parents a3b8908d 961f1ec8
Loading
Loading
Loading
Loading
+35 −20
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import com.android.documentsui.inspector.InspectorController.HeaderDisplay;

import java.util.function.Consumer;

import javax.annotation.Nullable;

/**
 * Organizes and displays the title and thumbnail for a given document
 */
@@ -77,14 +79,35 @@ public final class HeaderView extends RelativeLayout implements HeaderDisplay {
        mTitle.setText(displayName);
    }

    private void loadHeaderImage(DocumentInfo info) {
    private void loadHeaderImage(DocumentInfo doc) {
        if (!doc.isThumbnailSupported()) {
            showImage(doc, null);
        } else {
            Consumer<Bitmap> callback = new Consumer<Bitmap>() {
                @Override
                public void accept(Bitmap thumbnail) {
                    showImage(doc, thumbnail);
                }
            };
            // load the thumbnail async.
            final ThumbnailLoader task = new ThumbnailLoader(doc.derivedUri, mThumbnail,
                    mImageDimensions, doc.lastModified, callback, false);
            task.executeOnExecutor(ProviderExecutor.forAuthority(doc.derivedUri.getAuthority()),
                    doc.derivedUri);
        }
    }

    /**
     * Shows the supplied image, falling back to a mimetype icon if the image is null.
     */
    private void showImage(DocumentInfo info, @Nullable Bitmap thumbnail) {
        if (thumbnail != null) {
            mThumbnail.resetPaddingToInitialValues();
            mThumbnail.setScaleType(ScaleType.CENTER_CROP);
            mThumbnail.setImageBitmap(thumbnail);
        } else {
            mThumbnail.setPadding(0, 0, 0, mTitle.getHeight());

            Drawable mimeIcon =
                    mContext.getContentResolver().getTypeDrawable(info.mimeType);
            mThumbnail.setScaleType(ScaleType.FIT_CENTER);
@@ -92,12 +115,4 @@ public final class HeaderView extends RelativeLayout implements HeaderDisplay {
        }
        mThumbnail.animate().alpha(1.0f).start();
    }
        };

        // load the thumbnail async.
        final ThumbnailLoader task = new ThumbnailLoader(info.derivedUri, mThumbnail,
                mImageDimensions, info.lastModified, callback, false);
        task.executeOnExecutor(ProviderExecutor.forAuthority(info.derivedUri.getAuthority()),
                info.derivedUri);
    }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public class PagingProvider extends TestRootProvider {
            String parentDocumentId, String[] projection, Bundle queryArgs)
            throws FileNotFoundException {

        // TODO: Content notification.
        queryArgs = queryArgs != null ? queryArgs : Bundle.EMPTY;

        MatrixCursor c = createDocCursor(projection);
        Bundle extras = c.getExtras();