aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-04-10 03:07:57 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-04-10 03:07:57 +0000
commit996a1fb8159c8d5507d87e23f5577ca34d03451b (patch)
tree353cb45ae683a91486dc4266c97e8aa55b52189a
parent79acbaaad802f885fd58bf05fde88ab496fe99ea (diff)
parent5c532a6de0f207c1d42c3ef5578b82f46c8641d1 (diff)
downloadvolley-android11-tests-release.tar.gz
Snap for 5452753 from 5c532a6de0f207c1d42c3ef5578b82f46c8641d1 to rvc-releaseandroid-vts-11.0_r9android-vts-11.0_r8android-vts-11.0_r7android-vts-11.0_r6android-vts-11.0_r5android-vts-11.0_r4android-vts-11.0_r3android-vts-11.0_r2android-vts-11.0_r16android-vts-11.0_r15android-vts-11.0_r14android-vts-11.0_r13android-vts-11.0_r12android-vts-11.0_r11android-vts-11.0_r10android-vts-11.0_r1android-security-11.0.0_r76android-security-11.0.0_r75android-security-11.0.0_r74android-security-11.0.0_r73android-security-11.0.0_r72android-security-11.0.0_r71android-security-11.0.0_r70android-security-11.0.0_r69android-security-11.0.0_r68android-security-11.0.0_r67android-security-11.0.0_r66android-security-11.0.0_r65android-security-11.0.0_r64android-security-11.0.0_r63android-security-11.0.0_r62android-security-11.0.0_r61android-security-11.0.0_r60android-security-11.0.0_r59android-security-11.0.0_r58android-security-11.0.0_r57android-security-11.0.0_r56android-security-11.0.0_r55android-security-11.0.0_r54android-security-11.0.0_r53android-security-11.0.0_r52android-security-11.0.0_r51android-security-11.0.0_r50android-security-11.0.0_r49android-security-11.0.0_r1android-platform-11.0.0_r9android-platform-11.0.0_r8android-platform-11.0.0_r7android-platform-11.0.0_r6android-platform-11.0.0_r5android-platform-11.0.0_r40android-platform-11.0.0_r4android-platform-11.0.0_r39android-platform-11.0.0_r38android-platform-11.0.0_r37android-platform-11.0.0_r36android-platform-11.0.0_r35android-platform-11.0.0_r34android-platform-11.0.0_r33android-platform-11.0.0_r32android-platform-11.0.0_r31android-platform-11.0.0_r30android-platform-11.0.0_r3android-platform-11.0.0_r29android-platform-11.0.0_r28android-platform-11.0.0_r27android-platform-11.0.0_r26android-platform-11.0.0_r25android-platform-11.0.0_r24android-platform-11.0.0_r23android-platform-11.0.0_r22android-platform-11.0.0_r21android-platform-11.0.0_r20android-platform-11.0.0_r2android-platform-11.0.0_r19android-platform-11.0.0_r18android-platform-11.0.0_r17android-platform-11.0.0_r16android-platform-11.0.0_r15android-platform-11.0.0_r14android-platform-11.0.0_r13android-platform-11.0.0_r12android-platform-11.0.0_r11android-platform-11.0.0_r10android-platform-11.0.0_r1android-cts-11.0_r9android-cts-11.0_r8android-cts-11.0_r7android-cts-11.0_r6android-cts-11.0_r5android-cts-11.0_r4android-cts-11.0_r3android-cts-11.0_r2android-cts-11.0_r16android-cts-11.0_r15android-cts-11.0_r14android-cts-11.0_r13android-cts-11.0_r12android-cts-11.0_r11android-cts-11.0_r10android-cts-11.0_r1android-11.0.0_r6android-11.0.0_r5android-11.0.0_r4android-11.0.0_r3android-11.0.0_r25android-11.0.0_r2android-11.0.0_r17android-11.0.0_r1android11-tests-releaseandroid11-security-releaseandroid11-s1-releaseandroid11-releaseandroid11-platform-releaseandroid11-gsi
Change-Id: Iaca3ea2231a6f5d9bf2e4f31b27eb317232c2af5
-rw-r--r--build.gradle19
-rw-r--r--src/main/java/com/android/volley/toolbox/NetworkImageView.java71
-rw-r--r--src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java3
3 files changed, 82 insertions, 11 deletions
diff --git a/build.gradle b/build.gradle
index 1765a3a..828a192 100644
--- a/build.gradle
+++ b/build.gradle
@@ -14,6 +14,8 @@
// include(":volley")
// project(':volley').buildFileName = 'rules.gradle'
+import net.ltgt.gradle.errorprone.CheckSeverity
+
buildscript {
repositories {
jcenter()
@@ -26,7 +28,9 @@ buildscript {
plugins {
id "com.github.sherter.google-java-format" version "0.6"
- id "net.ltgt.errorprone" version "0.0.13"
+ // NOTE: 0.7 or newer will require upgrading to a newer Android gradle plugin:
+ // https://github.com/tbroyer/gradle-errorprone-plugin/commit/65b1026ebeae1b7ed8c28578c7f6eea512c16bea
+ id "net.ltgt.errorprone" version "0.6.1"
}
googleJavaFormat {
@@ -41,6 +45,15 @@ repositories {
google()
}
+dependencies {
+ // NOTE: Updating ErrorProne introduces new checks that may cause the build to fail. Pin to a
+ // specific version to control these updates.
+ errorprone("com.google.errorprone:error_prone_core:2.3.2")
+ // ErrorProne requires a JDK 9 compiler, so pull one in as a dependency since we use Java 8:
+ // https://github.com/tbroyer/gradle-errorprone-plugin#jdk-8-support
+ errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
+}
+
group = 'com.android.volley'
version = '1.2.0-SNAPSHOT'
@@ -55,7 +68,9 @@ android {
}
tasks.withType(JavaCompile) {
- options.compilerArgs << "-Xep:ParameterComment:ERROR"
+ options.errorprone {
+ check("ParameterComment", CheckSeverity.ERROR)
+ }
}
apply from: 'rules.gradle'
diff --git a/src/main/java/com/android/volley/toolbox/NetworkImageView.java b/src/main/java/com/android/volley/toolbox/NetworkImageView.java
index 53affc3..a24b3e2 100644
--- a/src/main/java/com/android/volley/toolbox/NetworkImageView.java
+++ b/src/main/java/com/android/volley/toolbox/NetworkImageView.java
@@ -15,6 +15,7 @@ package com.android.volley.toolbox;
import android.content.Context;
import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ViewGroup.LayoutParams;
@@ -32,25 +33,37 @@ public class NetworkImageView extends ImageView {
/**
* Resource ID of the image to be used as a placeholder until the network image is loaded. Won't
- * be set at the same time as mDefaultImageBitmap.
+ * be set at the same time as mDefaultImageDrawable or mDefaultImageBitmap.
*/
private int mDefaultImageId;
/**
+ * Drawable of the image to be used as a placeholder until the network image is loaded. Won't be
+ * set at the same time as mDefaultImageId or mDefaultImageBitmap.
+ */
+ @Nullable private Drawable mDefaultImageDrawable;
+
+ /**
* Bitmap of the image to be used as a placeholder until the network image is loaded. Won't be
- * set at the same time as mDefaultImageId.
+ * set at the same time as mDefaultImageId or mDefaultImageDrawable.
*/
- @Nullable Bitmap mDefaultImageBitmap;
+ @Nullable private Bitmap mDefaultImageBitmap;
/**
* Resource ID of the image to be used if the network response fails. Won't be set at the same
- * time as mErrorImageBitmap.
+ * time as mErrorImageDrawable or mErrorImageBitmap.
*/
private int mErrorImageId;
/**
* Bitmap of the image to be used if the network response fails. Won't be set at the same time
- * as mErrorImageId.
+ * as mErrorImageId or mErrorImageBitmap.
+ */
+ @Nullable private Drawable mErrorImageDrawable;
+
+ /**
+ * Bitmap of the image to be used if the network response fails. Won't be set at the same time
+ * as mErrorImageId or mErrorImageDrawable.
*/
@Nullable private Bitmap mErrorImageBitmap;
@@ -100,21 +113,38 @@ public class NetworkImageView extends ImageView {
* Sets the default image resource ID to be used for this view until the attempt to load it
* completes.
*
- * <p>This will clear anything set by {@link NetworkImageView#setDefaultImageBitmap}.
+ * <p>This will clear anything set by {@link NetworkImageView#setDefaultImageBitmap} or {@link
+ * NetworkImageView#setDefaultImageDrawable}.
*/
public void setDefaultImageResId(int defaultImage) {
mDefaultImageBitmap = null;
+ mDefaultImageDrawable = null;
mDefaultImageId = defaultImage;
}
/**
+ * Sets the default image drawable to be used for this view until the attempt to load it
+ * completes.
+ *
+ * <p>This will clear anything set by {@link NetworkImageView#setDefaultImageResId} or {@link
+ * NetworkImageView#setDefaultImageBitmap}.
+ */
+ public void setDefaultImageDrawable(@Nullable Drawable defaultImageDrawable) {
+ mDefaultImageId = 0;
+ mDefaultImageBitmap = null;
+ mDefaultImageDrawable = defaultImageDrawable;
+ }
+
+ /**
* Sets the default image bitmap to be used for this view until the attempt to load it
* completes.
*
- * <p>This will clear anything set by {@link NetworkImageView#setDefaultImageResId}.
+ * <p>This will clear anything set by {@link NetworkImageView#setDefaultImageResId} or {@link
+ * NetworkImageView#setDefaultImageDrawable}.
*/
public void setDefaultImageBitmap(Bitmap defaultImage) {
mDefaultImageId = 0;
+ mDefaultImageDrawable = null;
mDefaultImageBitmap = defaultImage;
}
@@ -122,21 +152,38 @@ public class NetworkImageView extends ImageView {
* Sets the error image resource ID to be used for this view in the event that the image
* requested fails to load.
*
- * <p>This will clear anything set by {@link NetworkImageView#setErrorImageBitmap}.
+ * <p>This will clear anything set by {@link NetworkImageView#setErrorImageBitmap} or {@link
+ * NetworkImageView#setErrorImageDrawable}.
*/
public void setErrorImageResId(int errorImage) {
mErrorImageBitmap = null;
+ mErrorImageDrawable = null;
mErrorImageId = errorImage;
}
/**
+ * Sets the error image drawable to be used for this view in the event that the image requested
+ * fails to load.
+ *
+ * <p>This will clear anything set by {@link NetworkImageView#setErrorImageResId} or {@link
+ * NetworkImageView#setDefaultImageBitmap}.
+ */
+ public void setErrorImageDrawable(@Nullable Drawable errorImageDrawable) {
+ mErrorImageId = 0;
+ mErrorImageBitmap = null;
+ mErrorImageDrawable = errorImageDrawable;
+ }
+
+ /**
* Sets the error image bitmap to be used for this view in the event that the image requested
* fails to load.
*
- * <p>This will clear anything set by {@link NetworkImageView#setErrorImageResId}.
+ * <p>This will clear anything set by {@link NetworkImageView#setErrorImageResId} or {@link
+ * NetworkImageView#setDefaultImageDrawable}.
*/
public void setErrorImageBitmap(Bitmap errorImage) {
mErrorImageId = 0;
+ mErrorImageDrawable = null;
mErrorImageBitmap = errorImage;
}
@@ -202,6 +249,8 @@ public class NetworkImageView extends ImageView {
public void onErrorResponse(VolleyError error) {
if (mErrorImageId != 0) {
setImageResource(mErrorImageId);
+ } else if (mErrorImageDrawable != null) {
+ setImageDrawable(mErrorImageDrawable);
} else if (mErrorImageBitmap != null) {
setImageBitmap(mErrorImageBitmap);
}
@@ -232,6 +281,8 @@ public class NetworkImageView extends ImageView {
setImageBitmap(response.getBitmap());
} else if (mDefaultImageId != 0) {
setImageResource(mDefaultImageId);
+ } else if (mDefaultImageDrawable != null) {
+ setImageDrawable(mDefaultImageDrawable);
} else if (mDefaultImageBitmap != null) {
setImageBitmap(mDefaultImageBitmap);
}
@@ -245,6 +296,8 @@ public class NetworkImageView extends ImageView {
private void setDefaultImageOrNull() {
if (mDefaultImageId != 0) {
setImageResource(mDefaultImageId);
+ } else if (mDefaultImageDrawable != null) {
+ setImageDrawable(mDefaultImageDrawable);
} else if (mDefaultImageBitmap != null) {
setImageBitmap(mDefaultImageBitmap);
} else {
diff --git a/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java b/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
index 7705a8f..fd2073e 100644
--- a/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
+++ b/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotNull;
import android.content.Context;
import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView.ScaleType;
@@ -90,8 +91,10 @@ public class NetworkImageViewTest {
assertNotNull(
NetworkImageView.class.getMethod("setImageUrl", String.class, ImageLoader.class));
+ assertNotNull(NetworkImageView.class.getMethod("setDefaultImageDrawable", Drawable.class));
assertNotNull(NetworkImageView.class.getMethod("setDefaultImageBitmap", Bitmap.class));
assertNotNull(NetworkImageView.class.getMethod("setDefaultImageResId", int.class));
+ assertNotNull(NetworkImageView.class.getMethod("setErrorImageDrawable", Drawable.class));
assertNotNull(NetworkImageView.class.getMethod("setErrorImageBitmap", Bitmap.class));
assertNotNull(NetworkImageView.class.getMethod("setErrorImageResId", int.class));
}