Bug 1158282 - Handle the default favicon as any other favicon. r=margaret

This removes the complications of handling the "default favicon" as a special
case simplifying the code into two branches - no favicon (i.e. blank) and a
custom favicon.  Under the hood, the Android framework probably does a similar
amount of work (e.g. opening & scaling the bitmap) so I doubt this is less
efficient.

This solves the custom search engine icons changing on FaviconView reuse
(i.e. scrolling) and the incorrect scaling of the default favicon in the
search engine bar.

I attempted to solve the issue while keeping the default favicon as a special
case and it caused a lot of hard to follow code branches so it wasn't worth it.
This special casing is also why this bug existed in the first place!

One caveat to the handle-the-default-as-any-other-approach is mentioned in
the code comments (see FaviconView.showDefaultFavicon).

--HG--
extra : rebase_source : b155ca835cc2d9b9c0b1ce85bbf6e4dc7eb548ef
This commit is contained in:
Michael Comella 2015-05-21 14:03:16 -07:00
Родитель 36c46ebfad
Коммит e064b0c599
1 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -11,6 +11,7 @@ import org.mozilla.gecko.favicons.Favicons;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
@ -22,6 +23,8 @@ import android.widget.ImageView;
* selected is the dominant colour of the provided Favicon.
*/
public class FaviconView extends ImageView {
private static String DEFAULT_FAVICON_KEY = FaviconView.class.getSimpleName() + "DefaultFavicon";
private Bitmap mIconBitmap;
// Reference to the unscaled bitmap, if any, to prevent repeated assignments of the same bitmap
@ -214,8 +217,13 @@ public class FaviconView extends ImageView {
}
public void showDefaultFavicon() {
setImageResource(R.drawable.favicon_globe);
mDominantColor = 0;
// We handle the default favicon as any other favicon to avoid the complications of special
// casing it. This means that if we provide assets that require the default favicon to be
// scaled up to fit in the container, a box with the dominant color will be used. We can
// deal with that later if it becomes relevant.
final Bitmap defaultFaviconBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.favicon_globe);
updateAndScaleImage(defaultFaviconBitmap, DEFAULT_FAVICON_KEY);
}
private void showNoImage() {