Skip to content

Commit

Permalink
Merge branch 'codenameone:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasH99 authored Jan 6, 2024
2 parents fa8ccf8 + 45d06ee commit 6970f3f
Show file tree
Hide file tree
Showing 28 changed files with 1,542 additions and 59 deletions.
16 changes: 11 additions & 5 deletions CodenameOne/src/com/codename1/io/Socket.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @author Shai Almog
*/
public class Socket {
public class Socket {
private Socket() {}

/**
Expand Down Expand Up @@ -74,7 +74,9 @@ public void run() {
Object connection = Util.getImplementation().connectSocket(host, port, sc.getConnectTimeout());
if(connection != null) {
sc.setConnected(true);
sc.connectionEstablished(new SocketInputStream(connection, sc), new SocketOutputStream(connection, sc));
sc.input = new SocketInputStream(connection, sc);
sc.output = new SocketOutputStream(connection, sc);
sc.connectionEstablished(sc.input, sc.output);
} else {
sc.setConnected(false);
if(connection == null) {
Expand Down Expand Up @@ -107,8 +109,9 @@ public void run() {
connection[0] = Util.getImplementation().connectSocket(host, port, sc.getConnectTimeout());
if(connection[0] != null) {
sc.setConnected(true);
sc.connectionEstablished(new SocketInputStream(connection[0], sc),
new SocketOutputStream(connection[0], sc));
sc.input = new SocketInputStream(connection[0], sc);
sc.output = new SocketOutputStream(connection[0], sc);
sc.connectionEstablished(sc.input, sc.output);
} else {
sc.setConnected(false);
if(connection[0] == null) {
Expand All @@ -133,6 +136,7 @@ public void close() throws IOException {
if(Util.getImplementation().isSocketConnected(connection[0])) {
Util.getImplementation().disconnectSocket(connection[0]);
}
connection[0] = null;
}
};
}
Expand All @@ -158,7 +162,9 @@ public void run() {
sc.setConnected(true);
Display.getInstance().startThread(new Runnable() {
public void run() {
sc.connectionEstablished(new SocketInputStream(connection, sc), new SocketOutputStream(connection, sc));
sc.input = new SocketInputStream(connection, sc);
sc.output = new SocketOutputStream(connection, sc);
sc.connectionEstablished(sc.input, sc.output);
sc.setConnected(false);
}
}, "Connection " + port).start();
Expand Down
7 changes: 7 additions & 0 deletions CodenameOne/src/com/codename1/io/SocketConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
* @author Shai Almog
*/
public abstract class SocketConnection {
/**
* Keeping member field so the GC won't collect these objects before the socket itself is collected.
* This can cause a problem since there's native reliance on these objects.
*/
InputStream input;
OutputStream output;

private int connectTimeout;
private boolean connected;

Expand Down
40 changes: 37 additions & 3 deletions CodenameOne/src/com/codename1/ui/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -4662,11 +4662,42 @@ private double distance(int[] x, int[] y) {
protected void pinchReleased(int x, int y) {

}


/**
* Invoked by subclasses interested in handling pinch to do their own actions based on the position of the two fingers, if true is returned
* other drag events will not be broadcast
*
* @param x the pointer x coordinate
* @param y the pointer y coordinate
* @return false by default, true if pinch is handled
*/
protected boolean pinch(int[] x, int[] y) {
return false;
}

private boolean pinchBlocksDragAndDrop;

/**
* If a component supports pinch as well as drag and drop the two may conflict (if one finger is placed a bit before the other, the drag
* timer will be initiated and may trigger drag even if the second finger has been placed before).
* Setting setPinchBlocksDragAndDrop to true will prevent drag from triggering.
* @param block if true will prevent drag and drop to trigger if two fingers are placed to pinch before the drag is initiated
*/
public void setPinchBlocksDragAndDrop(boolean block) {
pinchBlocksDragAndDrop = block;
}

/**
* returns true if pinch will block drag and drop
*/
public boolean isPinchBlocksDragAndDrop() {
return pinchBlocksDragAndDrop;
}

/**
* If this Component is focused, the pointer dragged event
* will call this method
*
*
* @param x the pointer x coordinate
* @param y the pointer y coordinate
*/
Expand All @@ -4679,8 +4710,11 @@ public void pointerDragged(int[] x, int[] y) {
pinchDistance = currentDis;
}
double scale = currentDis / pinchDistance;
if (pinch((float)scale)) {
boolean pinchXY = pinch(x, y); // ensure that both pinch(scale) and pinch(x,y) are called
if (pinch((float) scale) || pinchXY) {
inPinch = true;
if (pinchBlocksDragAndDrop)
dragActivated = false;
return;
}
} else {
Expand Down
34 changes: 33 additions & 1 deletion CodenameOne/src/com/codename1/ui/Toolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.events.ScrollListener;
import com.codename1.ui.geom.Rectangle;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.layouts.FlowLayout;
Expand Down Expand Up @@ -227,7 +228,6 @@ public Toolbar() {
&& UIManager.getInstance().getComponentStyle("Title").getAlignment() == CENTER) {
setTitleCentered(true);
}
//setSafeArea(true);
}

/**
Expand Down Expand Up @@ -2238,6 +2238,7 @@ protected List createOverflowCommandList(Vector commands) {
protected void initTitleBarStatus() {
Form f = getComponentForm();
if (f != null && !f.shouldPaintStatusBar()) {
setSafeArea(true);
return;
}
if (getUIManager().isThemeConstant("paintsTitleBarBool", false)) {
Expand All @@ -2249,11 +2250,42 @@ protected void initTitleBarStatus() {
} else {
bar.setUIID("StatusBar");
}
reallocateVerticalPaddingAndMarginsToTop(bar);
bar.setSafeArea(true);
addComponent(BorderLayout.NORTH, bar);
}
} else {
setSafeArea(true);
}
}

/**
* Reallocates vertical padding and margins to be all on top, so that bottom padding/margin
* is zero, but the total padding/margin is the same.
*
* This is helpful for the status bar so that, when the padding is adjusted by the safeArea
* we don't end up with extra padding at the bottom of the component, which would increase
* the height of the status bar.
* @param cmp
*/
private void reallocateVerticalPaddingAndMarginsToTop(Component cmp) {
Style allStyles = cmp.getAllStyles();
Style style = cmp.getStyle();
int topPadding = style.getPaddingTop();
int topMargin = style.getMarginTop();
int bottomPadding = style.getPaddingBottom();
int bottomMargin = style.getMarginBottom();
allStyles.setPaddingUnitTop(Style.UNIT_TYPE_PIXELS);
allStyles.setMarginUnitTop(Style.UNIT_TYPE_PIXELS);
allStyles.setPaddingUnitBottom(Style.UNIT_TYPE_PIXELS);
allStyles.setMarginUnitBottom(Style.UNIT_TYPE_PIXELS);
allStyles.setPaddingTop(topPadding + bottomPadding);
allStyles.setMarginTop(topMargin + bottomMargin);
allStyles.setPaddingBottom(0);
allStyles.setMarginBottom(0);
}


private void checkIfInitialized() {
if (!initialized) {
throw new IllegalStateException("Need to call "
Expand Down
48 changes: 48 additions & 0 deletions CodenameOne/src/com/codename1/ui/plaf/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,12 @@ private void initPaddingUnits() {
* @since 7.0
*/
public void setPaddingUnitLeft(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setPaddingUnitLeft(unit);
}
return;
}
initPaddingUnits();
paddingUnit[Component.LEFT] = unit;
}
Expand All @@ -1820,6 +1826,12 @@ public void setPaddingUnitLeft(byte unit) {
* @since 7.0
*/
public void setPaddingUnitRight(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setPaddingUnitRight(unit);
}
return;
}
initPaddingUnits();
paddingUnit[Component.RIGHT] = unit;
}
Expand All @@ -1831,6 +1843,12 @@ public void setPaddingUnitRight(byte unit) {
* @since 7.0
*/
public void setPaddingUnitTop(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setPaddingUnitTop(unit);
}
return;
}
initPaddingUnits();
paddingUnit[Component.TOP] = unit;
}
Expand All @@ -1842,6 +1860,12 @@ public void setPaddingUnitTop(byte unit) {
* @since 7.0
*/
public void setPaddingUnitBottom(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setPaddingUnitBottom(unit);
}
return;
}
initPaddingUnits();
paddingUnit[Component.BOTTOM] = unit;
}
Expand Down Expand Up @@ -3027,6 +3051,12 @@ private void initMarginUnits() {
* @since 7.0
*/
public void setMarginUnitLeft(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setMarginUnitLeft(unit);
}
return;
}
initMarginUnits();
marginUnit[Component.LEFT] = unit;
}
Expand All @@ -3038,6 +3068,12 @@ public void setMarginUnitLeft(byte unit) {
* @since 7.0
*/
public void setMarginUnitRight(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setMarginUnitRight(unit);
}
return;
}
initMarginUnits();
marginUnit[Component.RIGHT] = unit;
}
Expand All @@ -3049,6 +3085,12 @@ public void setMarginUnitRight(byte unit) {
* @since 7.0
*/
public void setMarginUnitTop(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setMarginUnitTop(unit);
}
return;
}
initMarginUnits();
marginUnit[Component.TOP] = unit;
}
Expand All @@ -3060,6 +3102,12 @@ public void setMarginUnitTop(byte unit) {
* @since 7.0
*/
public void setMarginUnitBottom(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setMarginUnitBottom(unit);
}
return;
}
initMarginUnits();
marginUnit[Component.BOTTOM] = unit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5241,7 +5241,7 @@ public void clearNativeCookies() {
}
private static CookieManager cookieManager;
private static CookieManager getCookieManager() {
if (android.os.Build.VERSION.SDK_INT >= 21) {
if (android.os.Build.VERSION.SDK_INT > 28) {
return CookieManager.getInstance();
}
if (cookieManager == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,11 @@ public boolean onKeyUpDown(boolean down, int keyCode, KeyEvent event) {
case KeyEvent.KEYCODE_ALT_LEFT:
case KeyEvent.KEYCODE_ALT_RIGHT:
case KeyEvent.KEYCODE_SYM:
return false;
case KeyEvent.KEYCODE_ENTER:
return false;
Display.getInstance().keyPressed(keyCode);
Display.getInstance().keyReleased(keyCode);
break;
default:
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ public void run() {
* @param show Show the keyboard if true, hide it otherwise
*/
private void showVirtualKeyboard(boolean show) {
show = Boolean.parseBoolean(Display.getInstance().getProperty("showVkb", "" + show));
Log.i(TAG, "showVirtualKeyboard show=" + show);

boolean result = false;
if (show) {
// If we're in landscape, Android will not show the soft
Expand Down
28 changes: 16 additions & 12 deletions Ports/iOSPort/nativeSources/IOSNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -8286,37 +8286,41 @@ JAVA_BOOLEAN com_codename1_impl_ios_IOSNative_nativeIsAlphaMaskSupportedGlobal__
JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetLeft___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
if (@available(iOS 11.0, *)) {
UIWindow *window = UIApplication.sharedApplication.keyWindow;
return (JAVA_INT)(window.safeAreaInsets.left * scaleValue);
} else {
return 0;
if(window != nil) {
return (JAVA_INT)(window.safeAreaInsets.left * scaleValue);
}
}
return 0;
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetTop___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
if (@available(iOS 11.0, *)) {
UIWindow *window = UIApplication.sharedApplication.keyWindow;
return (JAVA_INT)(window.safeAreaInsets.top * scaleValue);
} else {
return 0;
if(window != nil) {
return (JAVA_INT)(window.safeAreaInsets.top * scaleValue);
}
}
return 0;
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetRight___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
if (@available(iOS 11.0, *)) {
UIWindow *window = UIApplication.sharedApplication.keyWindow;
return (JAVA_INT)(window.safeAreaInsets.right * scaleValue);
} else {
return 0;
if(window != nil) {
return (JAVA_INT)(window.safeAreaInsets.right * scaleValue);
}
}
return 0;
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetBottom___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
if (@available(iOS 11.0, *)) {
UIWindow *window = UIApplication.sharedApplication.keyWindow;
return (JAVA_INT)(window.safeAreaInsets.bottom * scaleValue);
} else {
return 0;
if(window != nil) {
return (JAVA_INT)(window.safeAreaInsets.bottom * scaleValue);
}
}
return 0;
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplayWidth___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
Expand Down
Loading

0 comments on commit 6970f3f

Please sign in to comment.