Skip to content

Commit 17543b0

Browse files
committed
Marshal diagnostics and legacy snapshot UI updates onto MIDP event thread
1 parent e2686de commit 17543b0

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

‎src/com/netormium/client/ui/BrowserCanvas.java‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,18 @@ public void run() {
300300
report.append("Configuration: ").append(config == null ? "Unknown" : config).append("\\n");
301301
report.append("Profiles: ").append(profile == null ? "Unknown" : profile).append("\\n");
302302
report.append("Gateway: ").append(gateway).append("\\n");
303-
Alert alert = new Alert("Diagnostics", report.toString(), null,
304-
gateway.indexOf("OK") >= 0 ? AlertType.INFO : AlertType.WARNING);
305-
alert.setTimeout(Alert.FOREVER);
306-
Display.getDisplay(midlet).setCurrent(alert, BrowserCanvas.this);
307-
status = "Diagnostics complete";
308-
repaint();
303+
final String diagnosticText = report.toString();
304+
final boolean healthy = gateway.indexOf("OK") >= 0;
305+
Display.getDisplay(midlet).callSerially(new Runnable() {
306+
public void run() {
307+
Alert alert = new Alert("Diagnostics", diagnosticText, null,
308+
healthy ? AlertType.INFO : AlertType.WARNING);
309+
alert.setTimeout(Alert.FOREVER);
310+
Display.getDisplay(midlet).setCurrent(alert, BrowserCanvas.this);
311+
status = "Diagnostics complete";
312+
repaint();
313+
}
314+
});
309315
}
310316
}).start();
311317
}
@@ -778,17 +784,24 @@ private void reloadSnapshot() {
778784
repaint();
779785
new Thread(new Runnable() {
780786
public void run() {
781-
byte[] png = snapshotLoader.load(url, width, height, offset);
782-
if (token != requestToken || png == null) return;
783-
try {
784-
// Release the previous full viewport image before decoding its replacement.
785-
pageImage = null;
786-
pageImage = Image.createImage(png, 0, png.length);
787-
status = "Visual page";
788-
} catch (Exception e) {
789-
status = "Snapshot failed";
790-
}
791-
repaint();
787+
final byte[] png = snapshotLoader.load(url, width, height, offset);
788+
if (token != requestToken) return;
789+
postUi(token, null, new Runnable() {
790+
public void run() {
791+
if (png == null) {
792+
status = "Snapshot failed - check gateway";
793+
} else {
794+
try {
795+
pageImage = null;
796+
pageImage = Image.createImage(png, 0, png.length);
797+
status = "Visual page";
798+
} catch (Exception e) {
799+
status = "Snapshot failed";
800+
}
801+
}
802+
repaint();
803+
}
804+
});
792805
}
793806
}).start();
794807
}

0 commit comments

Comments
 (0)