Skip to content

Commit 85aa416

Browse files
committed
UI: experimental keypad to replace android keypad
1 parent fc1d8b7 commit 85aa416

File tree

12 files changed

+162
-105
lines changed

12 files changed

+162
-105
lines changed

src/platform/android/jni/editor.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
#include "common/device.h"
1414
#include "ui/keypad.h"
1515

16-
extern Runtime *runtime;
17-
1816
void showHelpLineInput(TextEditHelpWidget *helpWidget, int width = 35) {
1917
helpWidget->showPopup(width, 1);
2018
}
2119

22-
void System::editSource(strlib::String loadPath, bool restoreOnExit) {
20+
void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
2321
logEntered();
2422

2523
strlib::String fileName;
@@ -60,19 +58,25 @@ void System::editSource(strlib::String loadPath, bool restoreOnExit) {
6058
_output->clearScreen();
6159
_output->addInput(editWidget);
6260
_output->addInput(helpWidget);
63-
_output->addInput(new KeypadInput(false, false, charWidth, charHeight));
61+
62+
if (_keypad != nullptr) {
63+
_output->addInput(_keypad);
64+
} else {
65+
_keypad = new KeypadInput(false, false, charWidth, charHeight);
66+
_output->addInput(_keypad);
67+
}
6468

6569
// to layout inputs
6670
_output->resize(w, h);
6771

6872
if (gsb_last_line && isBreak()) {
6973
String msg = "Break at line: ";
7074
msg.append(gsb_last_line);
71-
runtime->alert(msg);
75+
alert(msg);
7276
} else if (gsb_last_error && !isBack()) {
7377
// program stopped with an error
7478
editWidget->setCursorRow(gsb_last_line + editWidget->getSelectionRow() - 1);
75-
runtime->alert(gsb_last_errmsg);
79+
alert(gsb_last_errmsg);
7680
}
7781

7882
bool showStatus = !editWidget->getScroll();
@@ -89,11 +93,6 @@ void System::editSource(strlib::String loadPath, bool restoreOnExit) {
8993
_output->setStatus(editWidget->isDirty() ? dirtyFile : cleanFile);
9094
_output->redraw();
9195
showStatus = true;
92-
} else if (widget == helpWidget && helpWidget->searchMode()) {
93-
// end searching
94-
widget = editWidget;
95-
helpWidget->hide();
96-
helpWidget->cancelMode();
9796
}
9897
break;
9998
case EVENT_TYPE_POINTER_RELEASED:
@@ -149,9 +148,18 @@ void System::editSource(strlib::String loadPath, bool restoreOnExit) {
149148
}
150149
break;
151150
case SB_KEY_CTRL('f'):
152-
widget = helpWidget;
153-
helpWidget->createSearch(false);
154-
showHelpLineInput(helpWidget);
151+
if (widget == helpWidget && helpWidget->searchMode()) {
152+
// end searching
153+
widget = editWidget;
154+
helpWidget->hide();
155+
helpWidget->cancelMode();
156+
showStatus = false;
157+
} else {
158+
widget = helpWidget;
159+
helpWidget->createSearch(false);
160+
showHelpLineInput(helpWidget);
161+
showStatus = true;
162+
}
155163
break;
156164
case SB_KEY_CTRL('s'):
157165
saveFile(editWidget, loadPath);
@@ -222,13 +230,17 @@ void System::editSource(strlib::String loadPath, bool restoreOnExit) {
222230
if (!_output->removeInput(editWidget)) {
223231
trace("Failed to remove editor input");
224232
}
233+
if (!_output->removeInput(_keypad)) {
234+
trace("Failed to remove keypad input");
235+
}
225236
_editor = editWidget;
226237
_editor->setFocus(false);
227238
} else {
228239
_editor = nullptr;
240+
_keypad = nullptr;
229241
}
230242

231-
// deletes editWidget unless it has been removed
243+
// deletes editWidget and _keypad unless it has been removed
232244
_output->removeInputs();
233245
if (!isClosing() && restoreOnExit) {
234246
_output->selectScreen(prevScreenId);

src/platform/android/jni/runtime.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ Runtime::Runtime(android_app *app) :
219219
_graphics(nullptr),
220220
_app(app),
221221
_eventQueue(nullptr),
222-
_sensorEventQueue(nullptr) {
222+
_sensorEventQueue(nullptr),
223+
_keypad(nullptr) {
223224
_app->userData = nullptr;
224225
_app->onAppCmd = handleCommand;
225226
_app->onInputEvent = handleInput;
@@ -240,10 +241,12 @@ Runtime::~Runtime() {
240241
delete _output;
241242
delete _eventQueue;
242243
delete _graphics;
244+
delete _keypad;
243245
runtime = nullptr;
244246
_output = nullptr;
245247
_eventQueue = nullptr;
246248
_graphics = nullptr;
249+
_keypad = nullptr;
247250
pthread_mutex_destroy(&_mutex);
248251
disableSensor();
249252
}
@@ -770,7 +773,7 @@ void Runtime::handleKeyEvent(MAEvent &event) {
770773
break;
771774
}
772775
}
773-
} else if (event.nativeKey < 127 && event.nativeKey != event.key) {
776+
} else if (event.nativeKey != 0 && event.nativeKey < 127 && event.nativeKey != event.key) {
774777
// avoid translating keys send from onUnicodeChar
775778
event.key = getUnicodeChar(event.nativeKey, event.key);
776779
}
@@ -853,7 +856,9 @@ MAEvent Runtime::processEvents(int waitFlag) {
853856
case 1:
854857
// wait for an event
855858
_output->flush(true);
856-
pollEvents(true);
859+
if (!hasEvent()) {
860+
pollEvents(true);
861+
}
857862
break;
858863
case 2:
859864
_output->flush(false);

src/platform/android/jni/runtime.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "config.h"
1313
#include "ui/system.h"
14+
#include "ui/keypad.h"
1415
#include "platform/android/jni/display.h"
1516
#include "platform/android/jni/audio.h"
1617

@@ -68,7 +69,7 @@ struct Runtime : public System {
6869
void share(const char *path) override { setString("share", path); }
6970
void showCursor(CursorType cursorType) override {}
7071
void showKeypad(bool show);
71-
void onPaused(bool paused) { if (_graphics != NULL) _graphics->onPaused(paused); }
72+
void onPaused(bool paused) { if (_graphics != nullptr) _graphics->onPaused(paused); }
7273
void onResize(int w, int h);
7374
void onRunCompleted() override;
7475
void onUnicodeChar(int ch);
@@ -83,6 +84,8 @@ struct Runtime : public System {
8384
int getFontId();
8485

8586
private:
87+
void editSource(String loadPath, bool restoreOnExit) override;
88+
8689
bool _keypadActive;
8790
bool _hasFocus;
8891
Graphics *_graphics;
@@ -94,6 +97,7 @@ struct Runtime : public System {
9497
const ASensor * _sensors[MAX_SENSORS]{};
9598
ASensorEventQueue *_sensorEventQueue;
9699
Audio _audio;
100+
KeypadInput *_keypad;
97101
};
98102

99103
#endif

0 commit comments

Comments
 (0)