Bug 1388396: Add IconRequestBuilder.forActivityStream. r=sebastian
MozReview-Commit-ID: HwCjdyB7o7q
--- a/mobile/android/base/java/org/mozilla/gecko/icons/IconRequest.java
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/IconRequest.java
@@ -24,29 +24,31 @@ public class IconRequest {
/* package-private */ String pageUrl;
/* package-private */ boolean privileged;
/* package-private */ TreeSet<IconDescriptor> icons;
/* package-private */ boolean skipNetwork;
/* package-private */ boolean backgroundThread;
/* package-private */ boolean skipDisk;
/* package-private */ boolean skipMemory;
/* package-private */ int targetSize;
+ /* package-private */ int minimumSizePxAfterScaling;
/* package-private */ boolean prepareOnly;
private IconCallback callback;
/* package-private */ IconRequest(Context context) {
this.context = context.getApplicationContext();
this.icons = new TreeSet<>(new IconDescriptorComparator());
// Setting some sensible defaults.
this.privileged = false;
this.skipMemory = false;
this.skipDisk = false;
this.skipNetwork = false;
this.targetSize = context.getResources().getDimensionPixelSize(R.dimen.favicon_bg);
+ this.minimumSizePxAfterScaling = 0;
this.prepareOnly = false;
}
/**
* Execute this request and try to load an icon. Once an icon has been loaded successfully the
* callback will be executed.
*
* The returned Future can be used to cancel the job.
@@ -100,16 +102,27 @@ public class IconRequest {
/**
* Get the required target size of the icon.
*/
public int getTargetSize() {
return targetSize;
}
/**
+ * Gets the minimum size the icon can be before we substitute a generated icon.
+ *
+ * N.B. the minimum size is compared to the icon *after* scaling: consider using
+ * {@link org.mozilla.gecko.icons.processing.ResizingProcessor#MAX_SCALE_FACTOR}
+ * when setting this value.
+ */
+ public int getMinimumSizePxAfterScaling() {
+ return minimumSizePxAfterScaling;
+ }
+
+ /**
* Should a loader access the network to load this icon?
*/
public boolean shouldSkipNetwork() {
return skipNetwork;
}
/**
* Should a loader access the disk to load this icon?
--- a/mobile/android/base/java/org/mozilla/gecko/icons/IconRequestBuilder.java
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/IconRequestBuilder.java
@@ -8,16 +8,17 @@ package org.mozilla.gecko.icons;
import android.content.Context;
import android.support.annotation.CheckResult;
import org.mozilla.gecko.GeckoAppShell;
import java.util.TreeSet;
import ch.boye.httpclientandroidlib.util.TextUtils;
+import org.mozilla.gecko.icons.processing.ResizingProcessor;
/**
* Builder for creating a request to load an icon.
*/
public class IconRequestBuilder {
private final IconRequest internal;
/* package-private */ IconRequestBuilder(Context context) {
@@ -101,16 +102,26 @@ public class IconRequestBuilder {
* preferred Android launcher icon size.
*/
public IconRequestBuilder forLauncherIcon() {
internal.targetSize = GeckoAppShell.getPreferredIconSize();
return this;
}
/**
+ * The icon will be used in Activity Stream: a minimum size for the icon will be set.
+ */
+ public IconRequestBuilder forActivityStream() {
+ // This value was set anecdotally: 16px icons scaled up both look blurry and
+ // don't fill the space well. 32px icons look good enough.
+ internal.minimumSizePxAfterScaling = 32 * ResizingProcessor.MAX_SCALE_FACTOR;
+ return this;
+ }
+
+ /**
* Execute the callback on the background thread. By default the callback is always executed on
* the UI thread in order to add the loaded icon to a view easily.
*/
@CheckResult
public IconRequestBuilder executeCallbackOnBackgroundThread() {
internal.backgroundThread = true;
return this;
}
@@ -138,16 +149,17 @@ public class IconRequestBuilder {
request.pageUrl = internal.pageUrl;
request.privileged = internal.privileged;
request.icons = new TreeSet<>(internal.icons);
request.skipNetwork = internal.skipNetwork;
request.backgroundThread = internal.backgroundThread;
request.skipDisk = internal.skipDisk;
request.skipMemory = internal.skipMemory;
request.targetSize = internal.targetSize;
+ request.minimumSizePxAfterScaling = internal.minimumSizePxAfterScaling;
request.prepareOnly = internal.prepareOnly;
return request;
}
/**
* This is a no-op method.
*
* All builder methods are annotated with @CheckResult to denote that the