diff options
Diffstat (limited to 'src/com/android/gallery3d/ingest/ui/MtpImageView.java')
-rw-r--r-- | src/com/android/gallery3d/ingest/ui/MtpImageView.java | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/src/com/android/gallery3d/ingest/ui/MtpImageView.java b/src/com/android/gallery3d/ingest/ui/MtpImageView.java index 67414c6c4..80c105126 100644 --- a/src/com/android/gallery3d/ingest/ui/MtpImageView.java +++ b/src/com/android/gallery3d/ingest/ui/MtpImageView.java @@ -17,7 +17,9 @@ package com.android.gallery3d.ingest.ui; import android.content.Context; +import android.graphics.Canvas; import android.graphics.Matrix; +import android.graphics.drawable.Drawable; import android.mtp.MtpDevice; import android.mtp.MtpObjectInfo; import android.os.Handler; @@ -27,12 +29,17 @@ import android.os.Message; import android.util.AttributeSet; import android.widget.ImageView; +import com.android.gallery3d.R; +import com.android.gallery3d.ingest.MtpDeviceIndex; import com.android.gallery3d.ingest.data.BitmapWithMetadata; import com.android.gallery3d.ingest.data.MtpBitmapFetch; import java.lang.ref.WeakReference; public class MtpImageView extends ImageView { + // We will use the thumbnail for images larger than this threshold + private static final int MAX_FULLSIZE_PREVIEW_SIZE = 8388608; // 8 megabytes + private int mObjectHandle; private int mGeneration; @@ -42,6 +49,8 @@ public class MtpImageView extends ImageView { private MtpObjectInfo mFetchObjectInfo; private MtpDevice mFetchDevice; private Object mFetchResult; + private Drawable mOverlayIcon; + private boolean mShowOverlayIcon; private static final FetchImageHandler sFetchHandler = FetchImageHandler.createOnNewThread(); private static final ShowImageHandler sFetchCompleteHandler = new ShowImageHandler(); @@ -78,6 +87,11 @@ public class MtpImageView extends ImageView { showPlaceholder(); mGeneration = gen; mObjectHandle = handle; + mShowOverlayIcon = MtpDeviceIndex.SUPPORTED_VIDEO_FORMATS.contains(object.getFormat()); + if (mShowOverlayIcon && mOverlayIcon == null) { + mOverlayIcon = getResources().getDrawable(R.drawable.ic_control_play); + updateOverlayIconBounds(); + } synchronized (mFetchLock) { mFetchObjectInfo = object; mFetchDevice = device; @@ -89,7 +103,12 @@ public class MtpImageView extends ImageView { } protected Object fetchMtpImageDataFromDevice(MtpDevice device, MtpObjectInfo info) { - return MtpBitmapFetch.getFullsize(device, info); + if (info.getCompressedSize() <= MAX_FULLSIZE_PREVIEW_SIZE + && MtpDeviceIndex.SUPPORTED_IMAGE_FORMATS.contains(info.getFormat())) { + return MtpBitmapFetch.getFullsize(device, info); + } else { + return new BitmapWithMetadata(MtpBitmapFetch.getThumbnail(device, info), 0); + } } private float mLastBitmapWidth; @@ -134,12 +153,46 @@ public class MtpImageView extends ImageView { setImageMatrix(mDrawMatrix); } + private static final int OVERLAY_ICON_SIZE_DENOMINATOR = 4; + + private void updateOverlayIconBounds() { + int iheight = mOverlayIcon.getIntrinsicHeight(); + int iwidth = mOverlayIcon.getIntrinsicWidth(); + int vheight = getHeight(); + int vwidth = getWidth(); + float scale_height = ((float) vheight) / (iheight * OVERLAY_ICON_SIZE_DENOMINATOR); + float scale_width = ((float) vwidth) / (iwidth * OVERLAY_ICON_SIZE_DENOMINATOR); + if (scale_height >= 1f && scale_width >= 1f) { + mOverlayIcon.setBounds((vwidth - iwidth) / 2, + (vheight - iheight) / 2, + (vwidth + iwidth) / 2, + (vheight + iheight) / 2); + } else { + float scale = Math.min(scale_height, scale_width); + mOverlayIcon.setBounds((int) (vwidth - scale * iwidth) / 2, + (int) (vheight - scale * iheight) / 2, + (int) (vwidth + scale * iwidth) / 2, + (int) (vheight + scale * iheight) / 2); + } + } + @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed && getScaleType() == ScaleType.MATRIX) { updateDrawMatrix(); } + if (mShowOverlayIcon && changed && mOverlayIcon != null) { + updateOverlayIconBounds(); + } + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (mShowOverlayIcon && mOverlayIcon != null) { + mOverlayIcon.draw(canvas); + } } protected void onMtpImageDataFetchedFromDevice(Object result) { |