Bug 1388396: Add IconRequestBuilder.forActivityStream. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 11 Sep 2017 17:25:10 -0700
changeset 664260 46dadbeed206e7cf8666c1c6e97300a3f6c40c23
parent 664259 995262e4975a4ebd713cc81f29bc9e84ee2b8d9f
child 664261 b2d8fbf5692b6259176e18f7fc4d72c194210240
push id79654
push usermichael.l.comella@gmail.com
push dateWed, 13 Sep 2017 20:23:12 +0000
reviewerssebastian
bugs1388396
milestone57.0a1
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