зеркало из https://github.com/mozilla/gecko-dev.git
Bug 696282 - Implement native toast alert support [r=mfinkle]
This commit is contained in:
Родитель
cfc392bd83
Коммит
5c2f485b4c
|
@ -654,6 +654,10 @@ abstract public class GeckoApp
|
|||
return;
|
||||
}
|
||||
}
|
||||
} else if (event.equals("Toast:Show")) {
|
||||
final String msg = message.getString("message");
|
||||
final String duration = message.getString("duration");
|
||||
handleShowToast(msg, duration);
|
||||
} else if (event.equals("DOMContentLoaded")) {
|
||||
final int tabId = message.getInt("tabID");
|
||||
final String uri = message.getString("uri");
|
||||
|
@ -871,6 +875,19 @@ abstract public class GeckoApp
|
|||
});
|
||||
}
|
||||
|
||||
void handleShowToast(final String message, final String duration) {
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast toast;
|
||||
if (duration.equals("long"))
|
||||
toast = Toast.makeText(mAppContext, message, Toast.LENGTH_LONG);
|
||||
else
|
||||
toast = Toast.makeText(mAppContext, message, Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void handleContentLoaded(final int tabId, final String uri, final String title) {
|
||||
Tab tab = Tabs.getInstance().getTab(tabId);
|
||||
if (tab == null)
|
||||
|
@ -1113,6 +1130,7 @@ abstract public class GeckoApp
|
|||
GeckoAppShell.registerGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Preferences:Data", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
|
||||
|
||||
mConnectivityFilter = new IntentFilter();
|
||||
mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
|
@ -1310,6 +1328,7 @@ abstract public class GeckoApp
|
|||
GeckoAppShell.unregisterGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
|
|
@ -101,7 +101,6 @@ var BrowserApp = {
|
|||
type: "Gecko:Ready"
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
shutdown: function shutdown() {
|
||||
|
@ -288,7 +287,7 @@ var BrowserApp = {
|
|||
|
||||
for each (let prefName in json) {
|
||||
let pref = {
|
||||
name: prefName,
|
||||
name: prefName
|
||||
};
|
||||
|
||||
try {
|
||||
|
@ -340,7 +339,6 @@ var BrowserApp = {
|
|||
preferences: prefs
|
||||
}
|
||||
});
|
||||
|
||||
} catch (e) {}
|
||||
},
|
||||
|
||||
|
@ -412,11 +410,30 @@ var NativeWindow = {
|
|||
Services.obs.removeObserver(this, "Menu:Clicked");
|
||||
},
|
||||
|
||||
toast: {
|
||||
show: function(aMessage, aDuration) {
|
||||
sendMessageToJava({
|
||||
gecko: {
|
||||
type: "Toast:Show",
|
||||
message: aMessage,
|
||||
duration: aDuration
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
menu: {
|
||||
_callbacks: [],
|
||||
_menuId: 0,
|
||||
add: function(aName, aIcon, aCallback) {
|
||||
sendMessageToJava({ gecko: {type: "Menu:Add", name: aName, icon: aIcon, id: this._menuId }});
|
||||
sendMessageToJava({
|
||||
gecko: {
|
||||
type: "Menu:Add",
|
||||
name: aName,
|
||||
icon: aIcon,
|
||||
id: this._menuId
|
||||
}
|
||||
});
|
||||
this._callbacks[this._menuId] = aCallback;
|
||||
this._menuId++;
|
||||
return this._menuId - 1;
|
||||
|
|
Загрузка…
Ссылка в новой задаче