Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapView.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapView.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapView.java |
index efe355a64fff3534e3c04dbe0e92f364d14989c5..00fb0d7b928dfa00dadcc26c433e6bf6fe569d9b 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapView.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapView.java |
@@ -9,6 +9,7 @@ import android.content.res.Resources; |
import android.graphics.Bitmap; |
import android.graphics.PorterDuff; |
import android.graphics.drawable.Drawable; |
+import android.support.annotation.IntDef; |
import android.support.annotation.Nullable; |
import android.support.graphics.drawable.VectorDrawableCompat; |
import android.util.AttributeSet; |
@@ -20,10 +21,13 @@ import android.widget.ImageView; |
import android.widget.TextView; |
import org.chromium.base.ApiCompatibilityUtils; |
+import org.chromium.base.VisibleForTesting; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.widget.selection.SelectableItemView; |
import org.chromium.chrome.browser.widget.selection.SelectionDelegate; |
+import java.lang.annotation.Retention; |
+import java.lang.annotation.RetentionPolicy; |
import java.util.List; |
/** |
@@ -36,6 +40,14 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { |
// The length of the fade in animation (in ms). |
private static final int IMAGE_FADE_IN_DURATION = 200; |
+ // The possible stages of loading an image. |
+ @IntDef({PENDING, LOADING, LOADED}) |
+ @Retention(RetentionPolicy.SOURCE) |
+ public @interface LoadingStage {} |
+ public static final int PENDING = 0; |
+ public static final int LOADING = 1; |
+ public static final int LOADED = 2; |
+ |
// Our context. |
private Context mContext; |
@@ -70,8 +82,9 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { |
// The label under the special tile. |
public TextView mSpecialTileLabel; |
- // Whether the image has been loaded already. |
- private boolean mImageLoaded; |
+ // The loading stage for this tile. |
+ @LoadingStage |
+ private int mLoadingStage = PENDING; |
// The amount to use for the border. |
private int mBorder; |
@@ -206,10 +219,10 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { |
setItem(bitmapDetails); |
if (isCameraTile() || isGalleryTile()) { |
initializeSpecialTile(mBitmapDetails); |
- mImageLoaded = true; |
+ mLoadingStage = LOADED; |
} else { |
setThumbnailBitmap(thumbnail); |
- mImageLoaded = !placeholder; |
+ mLoadingStage = placeholder ? LOADING : LOADED; |
} |
updateSelectionState(); |
@@ -259,8 +272,8 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { |
addPaddingToParent(mIconView, mBorder); |
} |
- boolean noImageWasLoaded = !mImageLoaded; |
- mImageLoaded = true; |
+ boolean noImageWasLoaded = mLoadingStage != LOADED; |
+ mLoadingStage = LOADED; |
updateSelectionState(); |
return noImageWasLoaded; |
@@ -338,11 +351,12 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { |
// The visibility of the unselected image is a little more complex because we don't want |
// to show it when nothing is selected and also not on a blank canvas. |
+ boolean imageLoaded = mLoadingStage == LOADED; |
mSelectedView.setVisibility(!special && checked ? View.VISIBLE : View.GONE); |
mUnselectedView.setVisibility( |
- !special && !checked && anySelection && mImageLoaded ? View.VISIBLE : View.GONE); |
+ !special && !checked && anySelection && imageLoaded ? View.VISIBLE : View.GONE); |
mScrim.setVisibility( |
- !special && !checked && anySelection && mImageLoaded ? View.VISIBLE : View.GONE); |
+ !special && !checked && anySelection && imageLoaded ? View.VISIBLE : View.GONE); |
} |
private boolean isGalleryTile() { |
@@ -356,4 +370,9 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { |
private boolean isPictureTile() { |
return mBitmapDetails.type() == PickerBitmap.PICTURE; |
} |
+ |
+ @VisibleForTesting |
+ public boolean getImageLoadingForTesting() { |
+ return mLoadingStage == LOADING; |
+ } |
} |