Keep track of TextEditor focus in Alert transitions.

When transitioning from a Canvas Screen to an Alert Screen, keep track
of which TextEditor has focus. When returning to the Canvas Screen,
focus the TextEditor. This helps us match app expectations with regard
to keyboard visibility.
This commit is contained in:
Tim Abraldes 2014-12-04 17:18:53 -08:00
Родитель 2448fc8f95
Коммит 5bee769f28
2 изменённых файлов: 48 добавлений и 6 удалений

Просмотреть файл

@ -1943,6 +1943,7 @@ public class Display {
*
* @param da The <code>Displayable</code> object whose LF to make current
*/
private DisplayableLF lastNonAlertScreen;
void callScreenChange(Displayable da) {
// Assert (da != null)
@ -1972,6 +1973,16 @@ public class Display {
oldCurrent.lSetDisplay(null);
}
if (oldCurrent instanceof CanvasLF) {
if (newCurrent instanceof AlertLF) {
lastNonAlertScreen = oldCurrent;
unfocusTextEditorForAlert();
} else {
lastNonAlertScreen = null;
unfocusTextEditorForScreenChange();
}
}
// Pre-grant the new current with access to this Display
// because its uCallShow() needs to call functions like
// Display.playAlertSound and setVerticallScroll(), etc.
@ -2033,6 +2044,12 @@ public class Display {
current = newCurrent;
transitionCurrent = null;
if (oldCurrent instanceof AlertLF &&
newCurrent instanceof CanvasLF &&
lastNonAlertScreen == newCurrent) {
refocusTextEditorAfterAlert();
}
if (!hasForegroundCopy) {
return;
}
@ -2499,6 +2516,10 @@ public class Display {
* ************* private methods
*/
private native void unfocusTextEditorForScreenChange();
private native void unfocusTextEditorForAlert();
private native void refocusTextEditorAfterAlert();
/**
* Control the drawing of the trusted <code>MIDlet<code> icon in native.
*

Просмотреть файл

@ -893,7 +893,6 @@
this.textEditorId = ++textEditorId;
this.textEditor = TextEditorProvider.createEditor(constraints);
this.visible = false;
this.focused = false;
this.backgroundColor = 0xFFFFFFFF | 0; // opaque white
this.foregroundColor = 0xFF000000 | 0; // opaque black
this.textEditor.setStyle("border", "none");
@ -946,6 +945,26 @@
this.textEditor.setParent(null);
});
var currentlyFocusedTextEditor;
Native.create("javax/microedition/lcdui/Display.unfocusTextEditorForScreenChange.()V", function() {
if (currentlyFocusedTextEditor) {
currentlyFocusedTextEditor.blur();
currentlyFocusedTextEditor = null;
}
});
Native.create("javax/microedition/lcdui/Display.unfocusTextEditorForAlert.()V", function() {
if (currentlyFocusedTextEditor) {
currentlyFocusedTextEditor.blur();
}
});
Native.create("javax/microedition/lcdui/Display.refocusTextEditorAfterAlert.()V", function() {
if (currentlyFocusedTextEditor) {
currentlyFocusedTextEditor.focus();
}
});
Native.create("com/nokia/mid/ui/CanvasItem.setSize.(II)V", function(width, height) {
this.textEditor.setStyle("width", width + "px");
this.textEditor.setStyle("height", height + "px");
@ -993,17 +1012,19 @@
return this.textEditor.getConstraints();
});
Native.create("com/nokia/mid/ui/TextEditor.setFocus.(Z)V", function(focused) {
if (focused && !this.focused) {
Native.create("com/nokia/mid/ui/TextEditor.setFocus.(Z)V", function(shouldFocus) {
if (shouldFocus && (currentlyFocusedTextEditor != this.textEditor)) {
this.textEditor.focus();
} else if (!focused && this.focused) {
currentlyFocusedTextEditor = this.textEditor;
} else if (!shouldFocus && (currentlyFocusedTextEditor == this.textEditor)) {
this.textEditor.blur();
currentlyFocusedTextEditor = null;
}
this.focused = focused;
this.focused = shouldFocus;
});
Native.create("com/nokia/mid/ui/TextEditor.hasFocus.()Z", function() {
return this.focused;
return (this.textEditor == currentlyFocusedTextEditor);
});
Native.create("com/nokia/mid/ui/TextEditor.setCaret.(I)V", function(index) {