The default bug view has changed. See this FAQ.

Implement native toast alert support

VERIFIED FIXED

Status

()

Firefox for Android
General
P3
normal
VERIFIED FIXED
6 years ago
5 years ago

People

(Reporter: fabrice, Assigned: Julien Vermet | JulienDev)

Tracking

unspecified
All
Android
Points:
---

Firefox Tracking Flags

(firefox11 fixed, fennec11+)

Details

(Whiteboard: [QA+])

Attachments

(1 attachment, 1 obsolete attachment)

(Reporter)

Description

6 years ago
We used to have two alert types:

- actionable ones, that map to Status Bar Notifications (http://developer.android.com/guide/topics/ui/notifiers/notifications.html)
- simple toasters, that map to Toast Notifications (http://developer.android.com/guide/topics/ui/notifiers/toasts.html)
We already support Status Bar notifications. We also have a "toaster" alertsservice, but it's XUL. Lets switch it over to use native toast by passing a JSON message from the JS component to the Java UI.
Summary: Implement nsIAlertsService → Implement native toaster nsIAlertsService
Whiteboard: [QA+]

Updated

6 years ago
Assignee: nobody → wjohnston
Priority: -- → P3

Updated

6 years ago
Blocks: 697078
(Reporter)

Updated

6 years ago
Assignee: wjohnston → ju.vermet
(Assignee)

Comment 2

6 years ago
Created attachment 569539 [details] [diff] [review]
Patch v1

This is a first implementation with two parameters :
- A JSONObject called "message" just contain a string called "content"
- A boolean to set the duration. If true, long, if false, short
Awesome. Thanks Julien.

I think you're digging at this a bit already, but what we'll probably want is a method like this, except maybe taking a String and a Bool.

Then we'll register a message listener, similar to the ones in embedding/android/GeckoApp.java (look for "registerGeckoEventListener", and note we'll also want to unregister the listener at close) that watches for "Toast" messages coming from Javascript. I think we should try to contain all the JSON conversions to that method.

So in the listener, we'll look at the JSON we get, pull out the message text and the "length" boolean (I think for the sake readability, we might be better making this a string with values "long" or "short"?), and then fire them over to the real "showToast" method.

Thanks again. Ask away if any of that doesn't make sense.
(Reporter)

Comment 4

6 years ago
Thanks for the patch Julien - let's build on top of this.

We want to call this from JS. It used to be an XPCOM component but let's start by just adding this to the NativeWindow object in browser.js around http://hg.mozilla.org/projects/birch/file/1f61c869b696/mobile/chrome/content/browser.js#l406 :
NativeWindow.toaster.show(aMessage, aLong)

Message type will be Toaster:Show, and this message must then be handled in Gecko.app:

registration: http://hg.mozilla.org/projects/birch/file/1f61c869b696/embedding/android/GeckoApp.java#l1087

handling : http://hg.mozilla.org/projects/birch/file/1f61c869b696/embedding/android/GeckoApp.java#l618

unregistration: http://hg.mozilla.org/projects/birch/file/1f61c869b696/embedding/android/GeckoApp.java#l1284
(Assignee)

Comment 5

6 years ago
Created attachment 569581 [details] [diff] [review]
Patch v2

As suggested by wesj, I used a string to set the toast duration and the JSON conversion is now done in "handleMessage". If the duration is "long", a long toast is shown. If anything else is defined, a short toast is shown.

A toast can be shown by calling the JS function "NativeWindow.toaster.show("myToast", "long");"
Attachment #569539 - Attachment is obsolete: true
Comment on attachment 569581 [details] [diff] [review]
Patch v2

Very nice Julien!

This looks exactly like what we want. I'm going to do a few things to the patch before I land it:
1. Switch to  4-space indents, no Tabs
2. Use | } else if (...) { | format
3. Change the "length" param to "duration" - since that is what Android calls it

Thanks a lot for the patch
Attachment #569581 - Flags: review+
https://hg.mozilla.org/projects/birch/rev/41404c189adc

I also tweak:
* "Toaster" -> "Toast" since Android calls it that too.
* Some other spacing issues _not_ in the patch itself (just OCD)
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Summary: Implement native toaster nsIAlertsService → Implement native toast alert support

Comment 8

5 years ago
Saving a page as PDF two alerts appeared: Status Bar Notification and Toast Notification. Marking this as verified fixed. 

Build: Mozilla /5.0 (Android;Linux armv7l;rv:11.0a1) Gecko/20111128 Firefox/11.0a1 Fennec/11.0a1
Device: LG Optimus 2X (Android 2.2)
Status: RESOLVED → VERIFIED
tracking-fennec: --- → 11+
status-firefox11: --- → fixed
You need to log in before you can comment on or make changes to this bug.