|
49 | 49 | import com.codename1.notifications.LocalNotification;
|
50 | 50 | import com.codename1.payment.Purchase;
|
51 | 51 | import com.codename1.system.CrashReport;
|
| 52 | +import com.codename1.ui.events.MessageEvent; |
52 | 53 | import com.codename1.ui.geom.Rectangle;
|
53 | 54 | import com.codename1.ui.plaf.UIManager;
|
54 | 55 | import com.codename1.ui.util.EventDispatcher;
|
@@ -90,6 +91,8 @@ public final class Display extends CN1Constants {
|
90 | 91 | boolean codenameOneExited;
|
91 | 92 | private boolean inNativeUI;
|
92 | 93 |
|
| 94 | + private EventDispatcher messageListeners; |
| 95 | + |
93 | 96 | /**
|
94 | 97 | * A common sound type that can be used with playBuiltinSound
|
95 | 98 | */
|
@@ -3203,7 +3206,62 @@ public void setAutoFoldVKBOnFormSwitch(boolean autoFoldVKBOnFormSwitch) {
|
3203 | 3206 | public int getCommandBehavior() {
|
3204 | 3207 | return impl.getCommandBehavior();
|
3205 | 3208 | }
|
3206 |
| - |
| 3209 | + |
| 3210 | + /** |
| 3211 | + * Posts a message to the native platform. Different platforms may handle messages posted this |
| 3212 | + * way differently. |
| 3213 | + * <p>The Javascript port will dispatch the message on the {@literal window} object |
| 3214 | + * as a custom DOM event named 'cn1outbox', with the event data containing a 'detail' key with the |
| 3215 | + * message, and a 'code' key with the code.</p> |
| 3216 | + * @param message The message. |
| 3217 | + * @since 7.0 |
| 3218 | + */ |
| 3219 | + public void postMessage(MessageEvent message) { |
| 3220 | + impl.postMessage(message); |
| 3221 | + } |
| 3222 | + |
| 3223 | + /** |
| 3224 | + * Adds a listener to receive messages from the native platform. This is one mechanism for the native |
| 3225 | + * platform to communicate with the Codename one app. |
| 3226 | + * |
| 3227 | + * <p>In the JavaScript port, listeners will be notified when DOM events named 'cn1inbox' are received on the |
| 3228 | + * window object. The event data 'detail' key will be the source of the message, and the 'code' key will be the |
| 3229 | + * source of the code. |
| 3230 | + * @param l The listener. |
| 3231 | + * @since 7.0 |
| 3232 | + */ |
| 3233 | + public void addMessageListener(ActionListener<MessageEvent> l) { |
| 3234 | + if (messageListeners == null) { |
| 3235 | + messageListeners = new EventDispatcher(); |
| 3236 | + } |
| 3237 | + messageListeners.addListener(l); |
| 3238 | + } |
| 3239 | + |
| 3240 | + /** |
| 3241 | + * Removes a listener from receiving messages from the native platform. |
| 3242 | + * |
| 3243 | + * @param l The listener. |
| 3244 | + * @since 7.0 |
| 3245 | + */ |
| 3246 | + public void removeMessageListener(ActionListener<MessageEvent> l) { |
| 3247 | + if (messageListeners != null) { |
| 3248 | + messageListeners.removeListener(l); |
| 3249 | + } |
| 3250 | + } |
| 3251 | + |
| 3252 | + /** |
| 3253 | + * Dispatches a message to all of the registered listeners. |
| 3254 | + * @param evt |
| 3255 | + * @see #addMessageListener(com.codename1.ui.events.ActionListener) |
| 3256 | + * @see #removeMessageListener(com.codename1.ui.events.ActionListener) |
| 3257 | + * @since 7.0 |
| 3258 | + */ |
| 3259 | + public void dispatchMessage(MessageEvent evt) { |
| 3260 | + if (messageListeners != null && messageListeners.hasListeners()) { |
| 3261 | + messageListeners.fireActionEvent(evt); |
| 3262 | + } |
| 3263 | + } |
| 3264 | + |
3207 | 3265 | /**
|
3208 | 3266 | * Indicates the way commands should be added to a form as one of the ocmmand constants defined
|
3209 | 3267 | * in this class
|
@@ -3803,7 +3861,7 @@ public boolean isGalleryTypeSupported(int type) {
|
3803 | 3861 | /**
|
3804 | 3862 | * Returns a 2-3 letter code representing the platform name for the platform override
|
3805 | 3863 | *
|
3806 |
| - * @return the name of the platform e.g. ios, rim, win, and, me |
| 3864 | + * @return the name of the platform e.g. ios, rim, win, and, me, HTML5 |
3807 | 3865 | */
|
3808 | 3866 | public String getPlatformName() {
|
3809 | 3867 | return impl.getPlatformName();
|
|
0 commit comments