Skip to content
Snippets Groups Projects
Commit 3013200d authored by Jim Chen's avatar Jim Chen
Browse files

Bug 1258470 - 2. Move thumbnail code out of BitmapUtils; r=nalexander

Move the "thumbnail:" handler out of BitmapUtils and into
ThumbnailHelper and PromptListItem.

The patch adds two overloads of the getAndProcessThumbnailFor method in
ThumbnailHelper, which handle the tasks of getting a thumbnail for a
specific tab and calling a given BitmapLoader.

Because only PromptListItem makes use of the "thumbnail:" convention,
the actual handling of "thumbnail:" is moved to PromptListItem, which
calls ThumbnailHelper to get the thumbnail.
parent bdb35912
No related merge requests found
......@@ -78,6 +78,29 @@ public final class ThumbnailHelper {
mHeight = -1;
}
public void getAndProcessThumbnailFor(final int tabId, final BitmapUtils.BitmapLoader loader) {
final Tab tab = Tabs.getInstance().getTab(tabId);
if (tab != null) {
getAndProcessThumbnailFor(tab, loader);
}
}
public void getAndProcessThumbnailFor(final Tab tab, final BitmapUtils.BitmapLoader loader) {
BitmapUtils.runOnBitmapFoundOnUiThread(loader, tab.getThumbnail());
Tabs.registerOnTabsChangedListener(new Tabs.OnTabsChangedListener() {
@Override
public void onTabChanged(final Tab t, final Tabs.TabEvents msg, final String data) {
if (tab != t || msg != Tabs.TabEvents.THUMBNAIL) {
return;
}
Tabs.unregisterOnTabsChangedListener(this);
BitmapUtils.runOnBitmapFoundOnUiThread(loader, t.getThumbnail());
}
});
getAndProcessThumbnailFor(tab);
}
public void getAndProcessThumbnailFor(Tab tab) {
if (AboutPages.isAboutHome(tab.getURL()) || AboutPages.isAboutPrivateBrowsing(tab.getURL())) {
tab.updateThumbnail(null, CachePolicy.NO_STORE);
......
......@@ -3,6 +3,7 @@ package org.mozilla.gecko.prompts;
import org.mozilla.gecko.IntentHelper;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.ThumbnailHelper;
import org.mozilla.gecko.widget.GeckoActionProvider;
import org.json.JSONArray;
......@@ -57,12 +58,19 @@ public class PromptListItem {
final String iconStr = aObject.optString("icon");
if (iconStr != null) {
BitmapUtils.getDrawable(context, iconStr, new BitmapUtils.BitmapLoader() {
final BitmapUtils.BitmapLoader loader = new BitmapUtils.BitmapLoader() {
@Override
public void onBitmapFound(Drawable d) {
mIcon = d;
}
});
};
if (iconStr.startsWith("thumbnail:")) {
final int id = Integer.parseInt(iconStr.substring(10), 10);
ThumbnailHelper.getInstance().getAndProcessThumbnailFor(id, loader);
} else {
BitmapUtils.getDrawable(context, iconStr, loader);
}
}
}
......
......@@ -15,9 +15,6 @@ import org.mozilla.gecko.R;
import org.mozilla.gecko.util.GeckoJarReader;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UIAsyncTask;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.ThumbnailHelper;
import android.content.Context;
import android.content.res.Resources;
......@@ -47,7 +44,7 @@ public final class BitmapUtils {
public void onBitmapFound(Drawable d);
}
private static void runOnBitmapFoundOnUiThread(final BitmapLoader loader, final Drawable d) {
public static void runOnBitmapFoundOnUiThread(final BitmapLoader loader, final Drawable d) {
if (ThreadUtils.isOnUiThread()) {
loader.onBitmapFound(d);
return;
......@@ -80,11 +77,6 @@ public final class BitmapUtils {
return;
}
if (data.startsWith("thumbnail:")) {
getThumbnailDrawable(context, data, loader);
return;
}
if (data.startsWith("jar:") || data.startsWith("file://")) {
(new UIAsyncTask.WithoutParams<Drawable>(ThreadUtils.getBackgroundHandler()) {
@Override
......@@ -147,22 +139,6 @@ public final class BitmapUtils {
runOnBitmapFoundOnUiThread(loader, null);
}
public static void getThumbnailDrawable(final Context context, final String data, final BitmapLoader loader) {
int id = Integer.parseInt(data.substring(10), 10);
final Tab tab = Tabs.getInstance().getTab(id);
runOnBitmapFoundOnUiThread(loader, tab.getThumbnail());
Tabs.registerOnTabsChangedListener(new Tabs.OnTabsChangedListener() {
@Override
public void onTabChanged(Tab t, Tabs.TabEvents msg, String data) {
if (tab == t && msg == Tabs.TabEvents.THUMBNAIL) {
Tabs.unregisterOnTabsChangedListener(this);
runOnBitmapFoundOnUiThread(loader, t.getThumbnail());
}
}
});
ThumbnailHelper.getInstance().getAndProcessThumbnailFor(tab);
}
public static Bitmap decodeByteArray(byte[] bytes) {
return decodeByteArray(bytes, null);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment