Skip to content

Commit bdd843d

Browse files
authoredMay 21, 2020
Merge pull request #30 from codenameone/master
Update
2 parents bb0497d + de5c6cb commit bdd843d

File tree

12 files changed

+391
-28
lines changed

12 files changed

+391
-28
lines changed
 

‎CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.codename1.ui.animations.Transition;
5959
import com.codename1.ui.events.ActionEvent;
6060
import com.codename1.ui.events.ActionListener;
61+
import com.codename1.ui.events.MessageEvent;
6162
import com.codename1.ui.geom.Dimension;
6263
import com.codename1.ui.geom.Rectangle;
6364
import com.codename1.ui.geom.Shape;
@@ -8432,5 +8433,14 @@ public void onCanInstallOnHomescreen(Runnable r) {
84328433
public boolean supportsNativeTextAreaVerticalAlignment() {
84338434
return false;
84348435
}
8436+
8437+
/**
8438+
* Posts a message to the native platform.
8439+
* @param message The message.
8440+
* @since 7.0
8441+
*/
8442+
public void postMessage(MessageEvent message) {
8443+
8444+
}
84358445

84368446
}

‎CodenameOne/src/com/codename1/ui/CN.java

+48-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.codename1.io.Storage;
3232
import com.codename1.messaging.Message;
3333
import com.codename1.ui.events.ActionListener;
34+
import com.codename1.ui.events.MessageEvent;
3435
import com.codename1.ui.geom.Rectangle;
3536
import com.codename1.util.RunnableWithResultSync;
3637
import java.io.IOException;
@@ -760,7 +761,7 @@ public static void openGallery(ActionListener response, int type){
760761
/**
761762
* Returns a 2-3 letter code representing the platform name for the platform override
762763
*
763-
* @return the name of the platform e.g. ios, rim, win, and, me
764+
* @return the name of the platform e.g. ios, rim, win, and, me, HTML5
764765
*/
765766
public static String getPlatformName() {
766767
return Display.impl.getPlatformName();
@@ -1455,5 +1456,51 @@ public static void onCanInstallOnHomescreen(Runnable r) {
14551456
public static Image captureScreen() {
14561457
return Display.impl.captureScreen();
14571458
}
1459+
1460+
/**
1461+
* Adds a listener to receive messages from the native platform. This is a mechanism to communicate
1462+
* between the app and the native platform. Currently the Javascript port is the only port to use
1463+
* this mechanism.
1464+
*
1465+
* <p>In the Javascript port, javascript can send messages to the CN1 app by calling
1466+
*
1467+
* {@code
1468+
* window.dispatchEvent(new CustomEvent('cn1inbox', {detail:'The message', code: SOMEINTEGER}));
1469+
* }
1470+
*
1471+
* @param l The listener.
1472+
* @since 7.0
1473+
*/
1474+
public static void addMessageListener(ActionListener<MessageEvent> l) {
1475+
Display.INSTANCE.addMessageListener(l);
1476+
}
1477+
1478+
/**
1479+
* Removes a listener from receiving messages from the native platform. This is a mechanism to communicate
1480+
* between the app and the native platform. Currently the Javascript port is the only port to use
1481+
* this mechanism.
1482+
* @param l The listener.
1483+
* @since 7.0
1484+
*/
1485+
public static void removeMessageListener(ActionListener<MessageEvent> l) {
1486+
Display.INSTANCE.removeMessageListener(l);
1487+
}
1488+
1489+
/**
1490+
* Posts a message to the native platform. This is a mechanism to communicate
1491+
* between the app and the native platform. Currently the Javascript port is the only port to use
1492+
* this mechanism.
1493+
*
1494+
* <p>In the Javascript port these messages can be received in Javascript by adding an event listener
1495+
* for 'cn1outbox' events to the 'window' object. The message is contained in the event data "detail" key. And the
1496+
* code in the 'code' key.</p>
1497+
* @param message The message to send to the native platform.
1498+
* @since 7.0
1499+
*/
1500+
public static void postMessage(MessageEvent message) {
1501+
Display.INSTANCE.postMessage(message);
1502+
}
1503+
1504+
14581505

14591506
}

‎CodenameOne/src/com/codename1/ui/Display.java

+60-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.codename1.notifications.LocalNotification;
5050
import com.codename1.payment.Purchase;
5151
import com.codename1.system.CrashReport;
52+
import com.codename1.ui.events.MessageEvent;
5253
import com.codename1.ui.geom.Rectangle;
5354
import com.codename1.ui.plaf.UIManager;
5455
import com.codename1.ui.util.EventDispatcher;
@@ -90,6 +91,8 @@ public final class Display extends CN1Constants {
9091
boolean codenameOneExited;
9192
private boolean inNativeUI;
9293

94+
private EventDispatcher messageListeners;
95+
9396
/**
9497
* A common sound type that can be used with playBuiltinSound
9598
*/
@@ -3203,7 +3206,62 @@ public void setAutoFoldVKBOnFormSwitch(boolean autoFoldVKBOnFormSwitch) {
32033206
public int getCommandBehavior() {
32043207
return impl.getCommandBehavior();
32053208
}
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+
32073265
/**
32083266
* Indicates the way commands should be added to a form as one of the ocmmand constants defined
32093267
* in this class
@@ -3803,7 +3861,7 @@ public boolean isGalleryTypeSupported(int type) {
38033861
/**
38043862
* Returns a 2-3 letter code representing the platform name for the platform override
38053863
*
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
38073865
*/
38083866
public String getPlatformName() {
38093867
return impl.getPlatformName();

‎CodenameOne/src/com/codename1/ui/SwipeableContainer.java

+33
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class SwipeableContainer extends Container {
4444
private Container bottomLeftWrapper;
4545
private Container bottomRightWrapper;
4646
private Container topWrapper;
47+
private SwipeableContainer previouslyOpenSwípeable;
4748

4849
private boolean open = false;
4950
private boolean openedToRight = false;
@@ -56,6 +57,7 @@ public class SwipeableContainer extends Container {
5657
private int initialY = -1;
5758
private int topX = -1;
5859
private boolean waitForRelease;
60+
private SwipeableContainer previouslyOpened;
5961

6062
private final EventDispatcher dispatcher = new EventDispatcher();
6163
/**
@@ -382,6 +384,9 @@ public void actionPerformed(ActionEvent evt) {
382384
}
383385

384386
if (initialX != -1) {
387+
if (getPreviouslyOpened() != null && getPreviouslyOpened() != SwipeableContainer.this && getPreviouslyOpened().isOpen()) {
388+
getPreviouslyOpened().close();
389+
}
385390
int diff = x - initialX;
386391
int val = 0;
387392
if(!isOpen()){
@@ -442,5 +447,33 @@ public void actionPerformed(ActionEvent evt) {
442447
}
443448
}
444449
}
450+
451+
/**
452+
* returns a previously opened SwipeableContainer that should be
453+
* automatically closed when starting to open this one. Called as soon as
454+
* this Swipeable starts opening. One approach is to override this method to
455+
* return a previously opened SwipeableContainer Can be overridden to return
456+
* a SwipeableContainer stored outside this container.
457+
*
458+
* @return an already open SwipeableContainer that will be closed when
459+
* opening this one, or null if none
460+
*/
461+
public SwipeableContainer getPreviouslyOpened() {
462+
return previouslyOpened;
463+
}
464+
465+
/**
466+
* set a previously open SwipeableContainer, it will be closed as soon as
467+
* the user starts swiping this one. Be aware that with a long list of
468+
* Swipeable containers it may be a better approach to store the previously
469+
* opened outside the list and simply override getPreviouslyOpened to return
470+
* it
471+
*
472+
* @param previouslyOpened an already open SwipeableContainer that will be
473+
* closed if this one is opened
474+
*/
475+
public void setPreviouslyOpened(SwipeableContainer previouslyOpened) {
476+
this.previouslyOpened = previouslyOpened;
477+
}
445478

446479
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.codename1.ui.events;
7+
import com.codename1.ui.Display;
8+
9+
/**
10+
* Encapsulates an event that either originates outside the App (e.g. from the webpage that
11+
* contains the app if it is published using the Javascript port); or whose destination is
12+
* outside the app.
13+
*
14+
* @author shannah
15+
* @since 7.0
16+
* @see Display#postMessage(com.codename1.ui.events.MessageEvent)
17+
* @see Display#dispatchMessage(com.codename1.ui.events.MessageEvent)
18+
* @see Display#addMessageListener(com.codename1.ui.events.ActionListener)
19+
* @see Display#removeMessageListener(com.codename1.ui.events.ActionListener)
20+
*/
21+
public class MessageEvent extends ActionEvent {
22+
private final String message;
23+
private final int code;
24+
25+
/**
26+
* Creates a new message.
27+
* @param source The source of the message.
28+
* @param message The message content.
29+
* @param code A code for the message.
30+
*/
31+
public MessageEvent(Object source, String message, int code) {
32+
super(source);
33+
this.message = message;
34+
this.code = code;
35+
}
36+
37+
/**
38+
* Gets the message content.
39+
* @return The message
40+
*/
41+
public String getMessage() {
42+
return message;
43+
}
44+
45+
/**
46+
* Gets the message code.
47+
* @return
48+
*/
49+
public int getCode() {
50+
return code;
51+
}
52+
}

‎Ports/iOSPort/nativeSources/DrawPath.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ -(void)execute
5959

6060
if ( width < 0 ) width = -width;
6161
if ( height < 0 ) height = -height;
62-
62+
if (width == 0 || height == 0) {
63+
return;
64+
}
6365
GLfloat vertexes[] = {
6466
(GLfloat)x, (GLfloat)y,
6567
(GLfloat)(x+width), (GLfloat)y,

‎Ports/iOSPort/nativeSources/IOSNative.m

+7-11
Original file line numberDiff line numberDiff line change
@@ -7669,23 +7669,18 @@ JAVA_LONG com_codename1_impl_ios_IOSNative_nativePathRendererCreateTexture___lon
76697669

76707670
if ( width < 0 ) width = -width;
76717671
if ( height < 0 ) height = -height;
7672-
7672+
if (width == 0 || height == 0) {
7673+
POOL_END();
7674+
return;
7675+
}
76737676
AlphaConsumer *ac = malloc(sizeof(AlphaConsumer));
76747677
ac->originX = x;
76757678
ac->originY = y;
76767679
ac->width = width;
76777680
ac->height = height;
7678-
7679-
7680-
//CN1Log(@"AC Width %d", ac.width);
7681-
7682-
//jbyte maskArray[ac.width*ac.height];
7681+
76837682
jbyte* maskArray = malloc(sizeof(jbyte)*ac->width*ac->height);
7684-
7685-
//CN1Log(@"Mask width %d height %d",
7686-
// ac.width,
7687-
// ac.height
7688-
// );
7683+
76897684
ac->alphas = maskArray;
76907685
Renderer_produceAlphas(renderer, ac);
76917686

@@ -7742,6 +7737,7 @@ JAVA_LONG com_codename1_impl_ios_IOSNative_nativePathRendererCreateTexture___lon
77427737
}
77437738

77447739

7740+
77457741
float clamp_float_to_int(float val){
77467742
JAVA_FLOAT absVal = abs(val);
77477743
JAVA_INT absIntVal = round(absVal);

0 commit comments

Comments
 (0)
Please sign in to comment.