Bug 1388396: Add IconRequestBuilder.forActivityStream. r=sebastian
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 11 Sep 2017 17:25:10 -0700
changeset 430241 a5f78f2e5bfd84b220a6b886f0feb48c478f9d17
parent 430240 ada7d6900274686aca0b3500b3242c736caa9f49
child 430242 b79ec53305633fe444abfe4b0d7d64de276309bb
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1388396
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1388396: Add IconRequestBuilder.forActivityStream. r=sebastian MozReview-Commit-ID: HwCjdyB7o7q
mobile/android/base/java/org/mozilla/gecko/icons/IconRequest.java
mobile/android/base/java/org/mozilla/gecko/icons/IconRequestBuilder.java
--- 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