Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ JAVA_INT getSafeTop() {
BOOL firstTime = YES;
BOOL retinaBug;
float scaleValue = 1;

static void updateDisplayMetricsFromView(UIView *view) {
if (view == nil) {
return;
}
displayWidth = (int)(view.bounds.size.width * scaleValue);
displayHeight = (int)(view.bounds.size.height * scaleValue);
}
BOOL forceSlideUpField;


Expand Down Expand Up @@ -1435,10 +1443,6 @@ void vibrateDevice() {
* Signature: ()I
*/
int Java_com_codename1_impl_ios_IOSImplementation_getDisplayWidthImpl() {
//if(displayWidth <= 0) {
displayWidth = [CodenameOne_GLViewController instance].view.bounds.size.width * scaleValue;
//}
//CN1Log(@"Display width %i", displayWidth);
return displayWidth;
}

Expand All @@ -1450,10 +1454,6 @@ int Java_com_codename1_impl_ios_IOSImplementation_getDisplayWidthImpl() {
int
Java_com_codename1_impl_ios_IOSImplementation_getDisplayHeightImpl() {
//GET_DIPLAY_HEIGHT_MARKER

//if(displayHeight <= 0) {
displayHeight = [CodenameOne_GLViewController instance].view.bounds.size.height * scaleValue;
//}
return displayHeight;
}

Expand Down Expand Up @@ -1895,6 +1895,7 @@ - (void)viewDidLoad {
[self.view addSubview:self.adView];
[self.adView loadAd];
[super viewDidLoad];
updateDisplayMetricsFromView(self.view);
//replaceViewDidLoad
[self initGoogleConnect];
}
Expand All @@ -1906,6 +1907,7 @@ - (UIViewController *)viewControllerForPresentingModalView {
#else
- (void)viewDidLoad {
[super viewDidLoad];
updateDisplayMetricsFromView(self.view);
//replaceViewDidLoad
[self initGoogleConnect];
}
Expand Down Expand Up @@ -1995,8 +1997,8 @@ -(void)updateCanvas:(BOOL)animated {
// details, so it is possible that the size change event still needs to be sent
// even if the display width already matches the value we're given here.
[[self eaglView] updateFrameBufferSize:(int)self.view.bounds.size.width h:(int)self.view.bounds.size.height];
updateDisplayMetricsFromView(self.view);
displayWidth = currentWidth;
displayHeight = (int)self.view.bounds.size.height * scaleValue;
screenSizeChanged(displayWidth, displayHeight);
//}

Expand Down Expand Up @@ -4029,5 +4031,3 @@ - (UIViewController *) documentInteractionControllerViewControllerForPreview: (U


@end


Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.codenameone.examples.hellocodenameone.tests;

import com.codename1.ui.Display;
import com.codename1.ui.plaf.UIManager;

public class BackgroundThreadUiAccessTest extends BaseTest {
@Override
public boolean runTest() {
Thread worker = new Thread(() -> {
try {
Display display = Display.getInstance();
int width = display.getDisplayWidth();
int pixels = display.convertToPixels(10, true);
UIManager manager = UIManager.getInstance();
if (width <= 0 || pixels <= 0 || manager == null) {
fail("Unexpected display metrics: width=" + width + " pixels=" + pixels);
return;
}
done();
} catch (Throwable t) {
fail("Background UI access test failed: " + t);
}
}, "cn1-ui-access-bg");
worker.start();
return true;
}

@Override
public boolean shouldTakeScreenshot() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.codenameone.examples.hellocodenameone.tests;

import com.codename1.ui.CN;

public class BytecodeTranslatorRegressionTest extends BaseTest {
private interface Mapper {
String apply(String input);

default String decorate(String input) {
return "<" + input + ">";
}

default Mapper andThen(Mapper next) {
return value -> next.apply(this.apply(value));
}

static String suffix(String input, String suffix) {
return input + suffix;
}
}

private interface Factory {
Prefixer create(String prefix);
}

private interface Combiner {
String combine(String left, String right);
}

private static final class Prefixer {
private final String prefix;

private Prefixer(String prefix) {
this.prefix = prefix;
}

private String applyPrefix(String input) {
return prefix + input;
}
}

@Override
public boolean runTest() {
Thread worker = new Thread(() -> {
try {
String[] inputs = {"alpha", "beta", "gamma"};
Factory factory = Prefixer::new;
Prefixer prefixer = factory.create("pre-");
Prefixer otherPrefixer = factory.create("other-");
Mapper upper = String::toUpperCase;
Mapper prefixed = prefixer::applyPrefix;
Mapper otherPrefixed = otherPrefixer::applyPrefix;
Mapper reversed = new Mapper() {
@Override
public String apply(String input) {
return new StringBuilder(input).reverse().toString();
}
};
Mapper pipeline = upper.andThen(reversed).andThen(otherPrefixed);
Combiner combiner = BytecodeTranslatorRegressionTest::join;
String suffix = "-suffix";
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 250; i++) {
for (String input : inputs) {
builder.append(combine(input, prefixed, pipeline, suffix, combiner));
builder.append('|');
}
}
String sample = combine("alpha", prefixed, pipeline, suffix, combiner);
String expected = "<pre-alpha>-suffix|<other-AHPLA>-suffix";
if (!expected.equals(sample)) {
fail("Unexpected output: " + sample);
return;
}
if (builder.length() == 0) {
fail("No output generated.");
return;
}
CN.callSerially(this::done);
} catch (Throwable t) {
fail("Regression test failed: " + t);
}
}, "cn1-bytecode-regression");
worker.start();
return true;
}

@Override
public boolean shouldTakeScreenshot() {
return false;
}

private static String combine(String input, Mapper first, Mapper second, String suffix, Combiner combiner) {
String left = Mapper.suffix(first.decorate(first.apply(input)), suffix);
String right = Mapper.suffix(second.decorate(second.apply(input)), suffix);
return combiner.combine(left, right);
}

private static String join(String left, String right) {
return left + "|" + right;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public final class Cn1ssDeviceRunner extends DeviceRunner {
new MediaPlaybackScreenshotTest(),
new OrientationLockScreenshotTest(),
new InPlaceEditViewTest(),
new BytecodeTranslatorRegressionTest(),
new BackgroundThreadUiAccessTest(),
new AccessibilityTest()));

public static void addTest(BaseTest test) {
Expand Down
Loading