bug 928096 - UI for tab streaming, thumbnails in prompt r=mfinkle,wesj

This commit is contained in:
Brad Lassey 2014-03-31 21:59:41 -04:00
Родитель 6d112ec871
Коммит 81be981df4
4 изменённых файлов: 46 добавлений и 9 удалений

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

@ -15,6 +15,9 @@ 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;
@ -71,6 +74,11 @@ public final class BitmapUtils {
return;
}
if (data.startsWith("thumbnail:")) {
getThumbnailDrawable(context, data, loader);
return;
}
if (data.startsWith("jar:") || data.startsWith("file://")) {
(new UiAsyncTask<Void, Void, Drawable>(ThreadUtils.getBackgroundHandler()) {
@Override
@ -131,6 +139,21 @@ 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() {
public void onTabChanged(Tab t, Tabs.TabEvents msg, Object 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);
}

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

@ -53,12 +53,15 @@ public class PromptListItem {
isParent = aObject.optBoolean("isParent") || aObject.optBoolean("menu");
}
BitmapUtils.getDrawable(GeckoAppShell.getContext(), aObject.optString("icon"), new BitmapUtils.BitmapLoader() {
@Override
public void onBitmapFound(Drawable d) {
mIcon = d;
}
});
final String iconStr = aObject.optString("icon");
if (iconStr != null) {
BitmapUtils.getDrawable(GeckoAppShell.getContext(), iconStr, new BitmapUtils.BitmapLoader() {
@Override
public void onBitmapFound(Drawable d) {
mIcon = d;
}
});
}
}
public void setIntent(Intent i) {

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

@ -1,3 +1,9 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict"
const { classes: Cc, interfaces: Ci, manager: Cm, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/Services.jsm");
@ -38,7 +44,8 @@ TabSource.prototype = {
label = tab.browser.contentURI.spec;
else
label = tab.originalURI;
return { label: label }
return { label: label,
icon: "thumbnail:" + tab.id }
}));
let result = null;

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

@ -1,4 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict"
@ -36,7 +37,7 @@ function Prompt(aOptions) {
if ("hint" in aOptions && aOptions.hint != null)
this.msg.hint = aOptions.hint;
let idService = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
let idService = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
}
Prompt.prototype = {
@ -178,6 +179,9 @@ Prompt.prototype = {
obj.label = item.label;
if (item.icon)
obj.icon = item.icon;
if (item.disabled)
obj.disabled = true;