Bug 1388396: Add IconRequestBuilder.forActivityStream. r=sebastian
☠☠ backed out by 540b7549aaa8 ☠ ☠
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 11 Sep 2017 17:25:10 -0700
changeset 429935 8756322ebb4a1ea6086ff0104d4abb4fd0100894
parent 429934 0aff84a0a8af1d23f1cd8f9abd810f82874731cd
child 429936 77f982a2f17ba33e49f56ee87dfff5be7ced8fb5
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