Browse Source

Fix null issues with bitmap

master
Anthony Restaino 9 years ago
parent
commit
ff3d94635a
  1. 27
      app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java

27
app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java

@ -16,16 +16,16 @@ import acr.browser.lightning.utils.Utils;
*/ */
class LightningViewTitle { class LightningViewTitle {
private static Bitmap DEFAULT_ICON = null; @Nullable private static Bitmap DEFAULT_ICON;
@NonNull private final Bitmap mDefault;
@NonNull private Bitmap mFavicon; @NonNull private Bitmap mFavicon;
@NonNull private String mTitle; @NonNull private String mTitle;
public LightningViewTitle(@NonNull Context context, boolean darkTheme) { public LightningViewTitle(@NonNull Context context, boolean darkTheme) {
if (DEFAULT_ICON == null) { DEFAULT_ICON = getDefault(context, darkTheme);
DEFAULT_ICON = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme); mDefault = DEFAULT_ICON;
} mFavicon = mDefault;
mFavicon = DEFAULT_ICON;
mTitle = context.getString(R.string.action_new_tab); mTitle = context.getString(R.string.action_new_tab);
} }
@ -37,12 +37,27 @@ class LightningViewTitle {
*/ */
public void setFavicon(@Nullable Bitmap favicon) { public void setFavicon(@Nullable Bitmap favicon) {
if (favicon == null) { if (favicon == null) {
mFavicon = DEFAULT_ICON; mFavicon = mDefault;
} else { } else {
mFavicon = Utils.padFavicon(favicon); mFavicon = Utils.padFavicon(favicon);
} }
} }
/**
* Helper method to initialize the DEFAULT_ICON variable.
*
* @param context the context needed to initialize the Bitmap.
* @param darkTheme whether the icon should be themed dark or not.
* @return a not null icon.
*/
@NonNull
private static Bitmap getDefault(@NonNull Context context, boolean darkTheme) {
if (DEFAULT_ICON == null) {
DEFAULT_ICON = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
}
return DEFAULT_ICON;
}
/** /**
* Set the current title to a new title. * Set the current title to a new title.
* Must not be null. * Must not be null.

Loading…
Cancel
Save