Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
shai-almog committed Mar 15, 2024
2 parents 3d12027 + cf4a235 commit 7819ca9
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 61 deletions.
47 changes: 43 additions & 4 deletions CodenameOne/src/com/codename1/io/rest/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.codename1.properties.PropertyBusinessObject;
import com.codename1.ui.CN;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.util.EventDispatcher;
import com.codename1.util.Base64;
import com.codename1.util.Callback;
import com.codename1.util.FailureCallback;
Expand Down Expand Up @@ -87,6 +86,8 @@ public class RequestBuilder {
private Boolean postParameters;
private Byte priority;
private boolean insecure;
private Boolean useBoolean;
private Boolean useLongs;

RequestBuilder(String method, String url) {
this.method = method;
Expand All @@ -110,6 +111,29 @@ public RequestBuilder insecure(boolean insecure) {
return this;
}

/**
* Indicates if JSON should treat boolean values as Boolean. This values is set implicitly to true when reading property business objects
*
* @param useBoolean true to return Boolean objects in JSON Maps
* @return this request builder
*/
public RequestBuilder useBoolean(boolean useBoolean) {
this.useBoolean = useBoolean;
return this;
}

/**
* Indicates if JSON should treat non-decimal numeric values as Long. If not set, uses the current default
* from the static value in JSONParser.isUseLongs
*
* @param useLongs true to return Long objects in JSON Maps
* @return this request builder
*/
public RequestBuilder useLongs(boolean useLongs) {
this.useLongs = useLongs;
return this;
}

/**
* Sets the caching mode for this request, see {@link com.codename1.io.ConnectionRequest#getCacheMode()}
* @param cache the cache mode
Expand Down Expand Up @@ -584,6 +608,7 @@ public void actionPerformed(NetworkEvent evt) {
* @return returns the Connection Request object so it can be killed if necessary
*/
public ConnectionRequest fetchAsProperties(final OnComplete<Response<PropertyBusinessObject>> callback, final Class type) {
useBoolean(true);
final Connection request = createRequest(true);
request.addResponseListener(new ActionListener<NetworkEvent>() {
@Override
Expand Down Expand Up @@ -702,6 +727,7 @@ public Response<Map> getAsJsonMap() {
* @return Response Object
*/
public Response<PropertyBusinessObject> getAsProperties(Class type) {
useBoolean(true);
ConnectionRequest request = createRequest(true);
fetched = true;
CN.addToQueueAndWait(request);
Expand All @@ -725,6 +751,7 @@ public Response<PropertyBusinessObject> getAsProperties(Class type) {
* @return returns the Connection Request object so it can be killed if necessary
*/
public ConnectionRequest fetchAsPropertyList(final OnComplete<Response<List<PropertyBusinessObject>>> callback, final Class type, final String root) {
useBoolean(true);
final Connection request = createRequest(true);
request.addResponseListener(new ActionListener<NetworkEvent>() {
@Override
Expand Down Expand Up @@ -777,6 +804,7 @@ public ConnectionRequest fetchAsPropertyList(final OnComplete<Response<List<Prop
* @return Response Object
*/
public Response<List<PropertyBusinessObject>> getAsPropertyList(Class type, String root) {
useBoolean(true);
ConnectionRequest request = createRequest(true);
fetched = true;
CN.addToQueueAndWait(request);
Expand Down Expand Up @@ -847,14 +875,14 @@ protected void readUnzipedResponse(InputStream input) throws IOException {
return;
}
if(jsonErrorCallback != null) {
JSONParser jp = new JSONParser();
JSONParser jp = createJSONParser();
errorObject = jp.parseJSON(new InputStreamReader(input, "UTF-8"));
errorHandler = jsonErrorCallback;
return;
}
if(propertyErrorCallback != null) {
try {
JSONParser jp = new JSONParser();
JSONParser jp = createJSONParser();
Map m = jp.parseJSON(new InputStreamReader(input, "UTF-8"));
PropertyBusinessObject pb = (PropertyBusinessObject)errorHandlerPropertyType.newInstance();
pb.getPropertyIndex().populateFromMap(m);
Expand All @@ -871,7 +899,7 @@ protected void readUnzipedResponse(InputStream input) throws IOException {
return;
}
if(parseJSON) {
JSONParser parser = new JSONParser();
JSONParser parser = createJSONParser();
json = parser.parseJSON(new InputStreamReader(input, "UTF-8"));
if(hasResponseListeners() && !isKilled()) {
fireResponseListener(new NetworkEvent(this, json));
Expand All @@ -890,6 +918,17 @@ protected void postResponse() {

}

private JSONParser createJSONParser() {
JSONParser jp = new JSONParser();
if (useBoolean != null) {
jp.setUseBooleanInstance(useBoolean);
}
if (useLongs != null) {
jp.setUseLongsInstance(useLongs);
}
return jp;
}

private Connection createRequest(boolean parseJson) {
Connection req = new Connection(parseJson);
for (String key : pathParams.keySet()) {
Expand Down
12 changes: 6 additions & 6 deletions CodenameOne/src/com/codename1/properties/PropertyIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ public <X extends PropertyBusinessObject> List<X> loadJSONList(String name) {
public <X extends PropertyBusinessObject> List<X> loadJSONList(InputStream stream)
throws IOException {
JSONParser jp = new JSONParser();
JSONParser.setUseBoolean(true);
JSONParser.setUseLongs(true);
jp.setUseBooleanInstance(true);
jp.setUseLongsInstance(true);
List<X> response = new ArrayList<X>();
Map<String, Object> result = jp.parseJSON(new InputStreamReader(stream, "UTF-8"));
List<Map> entries = (List<Map>)result.get("root");
Expand Down Expand Up @@ -735,8 +735,8 @@ public void fromJSON(String jsonString) {
try {
StringReader r = new StringReader(jsonString);
JSONParser jp = new JSONParser();
JSONParser.setUseBoolean(true);
JSONParser.setUseLongs(true);
jp.setUseBooleanInstance(true);
jp.setUseLongsInstance(true);
populateFromMap(jp.parseJSON(r), parent.getClass());
} catch(IOException err) {
Log.e(err);
Expand Down Expand Up @@ -774,8 +774,8 @@ public void loadJSON(String name) {
*/
public void loadJSON(InputStream stream) throws IOException {
JSONParser jp = new JSONParser();
JSONParser.setUseBoolean(true);
JSONParser.setUseLongs(true);
jp.setUseBooleanInstance(true);
jp.setUseLongsInstance(true);
populateFromMap(jp.parseJSON(new InputStreamReader(stream, "UTF-8")), parent.getClass());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7982,10 +7982,29 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == REQUEST_SELECT_FILE || requestCode == FILECHOOSER_RESULTCODE) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (requestCode == REQUEST_SELECT_FILE) {
if (uploadMessage == null) {
return;
if (uploadMessage == null) return;
Uri[] results = null;

// Check that the response is a good one
if (resultCode == Activity.RESULT_OK) {
if (intent != null) {
// If there is not data, then we may have taken a photo
String dataString = intent.getDataString();
ClipData clipData = intent.getClipData();

if (clipData != null) {
results = new Uri[clipData.getItemCount()];
for (int i = 0; i < clipData.getItemCount(); i++) {
ClipData.Item item = clipData.getItemAt(i);
results[i] = item.getUri();
}
} else if (dataString != null) {
results = new Uri[]{Uri.parse(dataString)};
}
}
}
uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));

uploadMessage.onReceiveValue(results);
uploadMessage = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,16 @@ public boolean onKeyUpDown(boolean down, int keyCode, KeyEvent event) {
case KeyEvent.KEYCODE_SYM:
return false;
case KeyEvent.KEYCODE_ENTER:
if (down) {
Display.getInstance().keyPressed(keyCode);
} else {
Display.getInstance().keyReleased(keyCode);
if(Display.getInstance().getProperty("sendEnterKey", "false").equals("true")) {
if (down) {
Display.getInstance().keyPressed(keyCode);
} else {
Display.getInstance().keyReleased(keyCode);
}
return false;
}
return false;
break;

default:
}

Expand Down
31 changes: 31 additions & 0 deletions Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ int nextPowerOf2(int val) {
BOOL CN1_blockPaste=NO;
BOOL CN1_blockCut=NO;
BOOL CN1_blockCopy=NO;
JAVA_INT safeLeft = 0;
JAVA_INT safeRight = 0;
JAVA_INT safeTop = 0;
JAVA_INT safeBottom = 0;

JAVA_INT getSafeLeft() {
return safeLeft;
}

JAVA_INT getSafeRight() {
return safeRight;
}

JAVA_INT getSafeBottom() {
return safeBottom;
}

JAVA_INT getSafeTop() {
return safeTop;
}

UIView *editingComponent;

Expand Down Expand Up @@ -2644,6 +2664,17 @@ -(void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coor
#endif
}

- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
safeLeft = (JAVA_INT)self.view.window.safeAreaInsets.left * scaleValue;
safeRight = (JAVA_INT)self.view.window.safeAreaInsets.right * scaleValue;
safeTop = (JAVA_INT)self.view.window.safeAreaInsets.top * scaleValue;
safeBottom = (JAVA_INT)self.view.window.safeAreaInsets.bottom * scaleValue;

lockDrawing = NO;
repaintUI();
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

[[self eaglView] updateFrameBufferSize:(int)self.view.bounds.size.width h:(int)self.view.bounds.size.height];
Expand Down
37 changes: 9 additions & 28 deletions Ports/iOSPort/nativeSources/IOSNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ JAVA_OBJECT fromNSString(NSString* str)

extern int Java_com_codename1_impl_ios_IOSImplementation_getDisplayHeightImpl();

extern JAVA_INT getSafeTop();
extern JAVA_INT getSafeLeft();
extern JAVA_INT getSafeBottom();
extern JAVA_INT getSafeRight();

extern void Java_com_codename1_impl_ios_IOSImplementation_flushBufferImpl
(void* peer, int x, int y, int width, int height);

Expand Down Expand Up @@ -8284,43 +8289,19 @@ 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;
if(window != nil) {
return (JAVA_INT)(window.safeAreaInsets.left * scaleValue);
}
}
return 0;
return getSafeLeft();
}

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;
if(window != nil) {
return (JAVA_INT)(window.safeAreaInsets.top * scaleValue);
}
}
return 0;
return getSafeTop();
}

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;
if(window != nil) {
return (JAVA_INT)(window.safeAreaInsets.right * scaleValue);
}
}
return 0;
return getSafeRight();
}

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;
if(window != nil) {
return (JAVA_INT)(window.safeAreaInsets.bottom * scaleValue);
}
}
return 0;
return getSafeBottom();
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplayWidth___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ public class AndroidGradleBuilder extends Executor {
private String gradle8DistributionUrl = "https://services.gradle.org/distributions/gradle-8.1-bin.zip";
public boolean PREFER_MANAGED_GRADLE=true;

private boolean useGradle8 = false;
private boolean useGradle8 = true;

// Flag to indicate whether we should strip kotlin from user classes
// Necessary for using gradle 8 because kotlin seems to be included by default,
// so we get duplicate class errors.
private boolean stripKotlinFromUserClasses = true;

private boolean extendAppCompatActivity = false;

Expand Down Expand Up @@ -474,9 +479,11 @@ private static String escape(String str, String chars) {
@Override
public boolean build(File sourceZip, final BuildRequest request) throws BuildException {
boolean facebookSupported = request.getArg("facebook.appId", null) != null;
newFirebaseMessaging = request.getArg("android.newFirebaseMessaging", "false").equals("true");
newFirebaseMessaging = request.getArg("android.newFirebaseMessaging", "true").equals("true");
useGradle8 = request.getArg("android.useGradle8", ""+(useGradle8 || newFirebaseMessaging || facebookSupported)).equals("true");
extendAppCompatActivity = request.getArg("android.extendAppCompatActivity", "false").equals("true");
// When using gradle 8 we need to strip kotlin files from user classes otherwise we get duplicate class errors
stripKotlinFromUserClasses = useGradle8;
useJava8SourceLevel = request.getArg("android.java8", ""+useJava8SourceLevel).equals("true");
if (useGradle8) {
getGradleJavaHome(); // will throw build exception if JAVA17_HOME is not set
Expand Down Expand Up @@ -976,6 +983,9 @@ public boolean build(File sourceZip, final BuildRequest request) throws BuildExc
} catch (Exception ex) {
throw new BuildException("Failed to extract source zip "+sourceZip, ex);
}
if (stripKotlinFromUserClasses) {
stripKotlin(dummyClassesDir);
}

File appDir = buildToolsVersionInt >= 27 ?
new File(srcDir.getParentFile(), "app") :
Expand Down Expand Up @@ -1320,19 +1330,7 @@ public void usesClassMethod(String cls, String method) {
if (!request.getArg("android.xgradle", "").contains("apply plugin: 'com.google.gms.google-services'")) {
request.putArgument("android.xgradle", request.getArg("android.xgradle", "") + "\napply plugin: 'com.google.gms.google-services'\n");
}
if (!request.getArg("gradleDependencies", "").contains("com.google.firebase:firebase-core")) {
debug("Adding firebase core to gradle dependencies.");
debug("Play services version: " + request.getArg("var.android.playServicesVersion", ""));
debug("gradleDependencies before: "+request.getArg("gradleDependencies", ""));

request.putArgument(
"gradleDependencies",
request.getArg("gradleDependencies", "") +
"\n"+compile+" \"com.google.firebase:firebase-core:" +
request.getArg("android.firebaseCoreVersion", playServicesVersion) + "\"\n"
);
debug("gradleDependencies after: "+request.getArg("gradleDependencies", ""));
}
if (!request.getArg("gradleDependencies", "").contains("com.google.firebase:firebase-messaging")) {
request.putArgument(
"gradleDependencies",
Expand Down Expand Up @@ -4445,4 +4443,19 @@ private void initPlayServiceVersions(BuildRequest request) {
}
}
}

private void stripKotlin(File dummyClassesDir) {
String[] skipDirectories = new String[] {
"org" + File.separator + "jetbrains" + File.separator + "annotations",
"org" + File.separator + "intellij" + File.separator + "lang" + File.separator + "annotations",
"kotlin"
};
for (String path : skipDirectories) {
File directory = new File(dummyClassesDir, path);
if (directory.isDirectory()) {
log("Deleting directory " + directory);
delTree(directory, true);
}
}
}
}
Loading

0 comments on commit 7819ca9

Please sign in to comment.