зеркало из https://github.com/mozilla/gecko-dev.git
Bug 700913 - Add persistence and timeout features to Doorhangers. r=mfinkle
This commit is contained in:
Родитель
dc603e9fb1
Коммит
bdfb150259
|
@ -38,6 +38,8 @@
|
|||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -46,6 +48,9 @@ import android.widget.LinearLayout;
|
|||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class DoorHanger extends LinearLayout implements Button.OnClickListener {
|
||||
private Context mContext;
|
||||
private LinearLayout mChoicesLayout;
|
||||
|
@ -56,6 +61,9 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
|
|||
// value used to identify the notification
|
||||
private String mValue;
|
||||
|
||||
private int mPersistence = 0;
|
||||
private long mTimeout = 0;
|
||||
|
||||
public DoorHanger(Context aContext, String aValue) {
|
||||
super(aContext);
|
||||
|
||||
|
@ -124,4 +132,29 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
|
|||
public void setTab(Tab tab) {
|
||||
mTab = tab;
|
||||
}
|
||||
|
||||
public void setOptions(JSONObject options) {
|
||||
try {
|
||||
mPersistence = options.getInt("persistence");
|
||||
} catch (JSONException e) { }
|
||||
|
||||
try {
|
||||
mTimeout = options.getLong("timeout");
|
||||
} catch (JSONException e) { }
|
||||
}
|
||||
|
||||
// This method checks with persistence and timeout options to see if
|
||||
// it's okay to remove a doorhanger.
|
||||
public boolean shouldRemove() {
|
||||
if (mPersistence > 0) {
|
||||
mPersistence--;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (new Date().getTime() <= mTimeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ public class DoorHangerPopup extends PopupWindow {
|
|||
setContentView(layout);
|
||||
}
|
||||
|
||||
public void addDoorHanger(String message, String value, JSONArray buttons, Tab tab) {
|
||||
public void addDoorHanger(String message, String value, JSONArray buttons,
|
||||
Tab tab, JSONObject options) {
|
||||
Log.i("DoorHangerPopup", "Adding a DoorHanger to Tab: " + tab.getId());
|
||||
|
||||
// Replace the doorhanger if it already exists
|
||||
|
@ -95,6 +96,7 @@ public class DoorHangerPopup extends PopupWindow {
|
|||
Log.i("DoorHangerPopup", "JSON throws " + e);
|
||||
}
|
||||
}
|
||||
dh.setOptions(options);
|
||||
|
||||
dh.setTab(tab);
|
||||
tab.addDoorHanger(value, dh);
|
||||
|
|
|
@ -573,8 +573,6 @@ abstract public class GeckoApp
|
|||
tab.updateFavicon(null);
|
||||
tab.updateFaviconURL(null);
|
||||
tab.updateSecurityMode("unknown");
|
||||
|
||||
// TODO: check persistence and timeout options before removing doorhangers
|
||||
tab.removeAllDoorHangers();
|
||||
|
||||
mMainHandler.post(new Runnable() {
|
||||
|
@ -777,13 +775,15 @@ abstract public class GeckoApp
|
|||
final String value = geckoObject.getString("value");
|
||||
final JSONArray buttons = geckoObject.getJSONArray("buttons");
|
||||
final int tabId = geckoObject.getInt("tabID");
|
||||
final JSONObject options = geckoObject.getJSONObject("options");
|
||||
|
||||
Log.i(LOG_NAME, "DoorHanger received for tab " + tabId + ", msg:" + message);
|
||||
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Tab tab = Tabs.getInstance().getTab(tabId);
|
||||
mAppContext.mDoorHangerPopup.addDoorHanger(message, value, buttons, tab);
|
||||
mAppContext.mDoorHangerPopup.addDoorHanger(message, value, buttons,
|
||||
tab, options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -245,11 +245,16 @@ public class Tab {
|
|||
}
|
||||
|
||||
public void removeDoorHanger(String value) {
|
||||
mDoorHangers.remove(value);
|
||||
DoorHanger dh = mDoorHangers.get(value);
|
||||
// Check to see if we should remove a doorhanger before removing it
|
||||
if (dh.shouldRemove())
|
||||
mDoorHangers.remove(value);
|
||||
}
|
||||
|
||||
public void removeAllDoorHangers() {
|
||||
mDoorHangers = new HashMap<String, DoorHanger> ();
|
||||
for (String value : mDoorHangers.keySet()) {
|
||||
removeDoorHanger(value);
|
||||
}
|
||||
}
|
||||
|
||||
public DoorHanger getDoorHanger(String value) {
|
||||
|
|
|
@ -679,7 +679,16 @@ var NativeWindow = {
|
|||
_callbacksId: 0,
|
||||
_promptId: 0,
|
||||
|
||||
show: function(aMessage, aValue, aButtons, aTabID) {
|
||||
/**
|
||||
* @param aOptions
|
||||
* An options JavaScript object holding additional properties for the
|
||||
* notification. The following properties are currently supported:
|
||||
* persistence: An integer. The notification will not automatically
|
||||
* dismiss for this many page loads.
|
||||
* timeout: A time in milliseconds. The notification will not
|
||||
* automatically dismiss before this time.
|
||||
*/
|
||||
show: function(aMessage, aValue, aButtons, aTabID, aOptions) {
|
||||
aButtons.forEach((function(aButton) {
|
||||
this._callbacks[this._callbacksId] = { cb: aButton.callback, prompt: this._promptId };
|
||||
aButton.callback = this._callbacksId;
|
||||
|
@ -694,7 +703,8 @@ var NativeWindow = {
|
|||
value: aValue,
|
||||
buttons: aButtons,
|
||||
// use the current tab if none is provided
|
||||
tabID: aTabID || BrowserApp.selectedTab.id
|
||||
tabID: aTabID || BrowserApp.selectedTab.id,
|
||||
options: aOptions || {}
|
||||
}
|
||||
};
|
||||
sendMessageToJava(json);
|
||||
|
|
Загрузка…
Ссылка в новой задаче