Skip to content

Commit 3fb8b66

Browse files
author
Chris Warren-Smith
committed
ANDROID: implemented support for editing with the system keypad
1 parent c13e7b1 commit 3fb8b66

9 files changed

Lines changed: 61 additions & 17 deletions

File tree

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2025-09-11 (12.31)
2+
ANDROID: Implemented support for editing with the system keypad
3+
4+
2025-08-31 (12.30)
5+
ANDROID: Implemented a replacement editor keypad
6+
ANDROID: Implemented editor find command
7+
ANDROID: Updated editor help
8+
19
2025-04-26 (12.29)
210
ANDROID: minor fix for PEN(3)
311

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [12.30])
10+
AC_INIT([smallbasic], [12.31])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

src/platform/android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId 'net.sourceforge.smallbasic'
1010
minSdkVersion 21
1111
targetSdkVersion 36
12-
versionCode 83
13-
versionName '12.30'
12+
versionCode 84
13+
versionName '12.31'
1414
resourceConfigurations += ['en']
1515
}
1616

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,8 @@ protected Response getFile(String remoteHost, String path, boolean asset) throws
12261226
String name = "webui/" + path;
12271227
long length = getFileLength(name);
12281228
log("Opened " + name + " " + length + " bytes");
1229-
String contentType = path.endsWith("js") ? "text/javascript" : "text/html";
1229+
String contentType = path.endsWith("js") ? "text/javascript" :
1230+
path.endsWith("css") ? "text/css": "text/html";
12301231
result = new Response(getAssets().open(name), length, contentType);
12311232
if ("index.html".equals(path) && isHostNotPermitted(remoteHost)) {
12321233
requestHostPermission(remoteHost);

src/platform/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:8.12.1'
8+
classpath 'com.android.tools.build:gradle:8.13.0'
99
}
1010
}
1111

src/platform/android/jni/editor.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct StatusMessage {
102102
out->setStatus(message);
103103
}
104104

105-
private:
105+
private:
106106
bool _dirty;
107107
bool _find;
108108
int _scroll;
@@ -126,7 +126,6 @@ void showHelp(TextEditHelpWidget *helpWidget) {
126126
void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
127127
logEntered();
128128

129-
showKeypad(false);
130129
int w = _output->getWidth();
131130
int h = _output->getHeight();
132131
int charWidth = _output->getCharWidth();
@@ -153,11 +152,16 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
153152
_output->addInput(editWidget);
154153
_output->addInput(helpWidget);
155154

156-
if (_keypad != nullptr) {
157-
_output->addInput(_keypad);
155+
if (opt_ide == IDE_EXTERNAL) {
156+
showKeypad(true);
158157
} else {
159-
_keypad = new KeypadInput(w, false, false, charWidth, charHeight);
160-
_output->addInput(_keypad);
158+
showKeypad(false);
159+
if (_keypad != nullptr) {
160+
_output->addInput(_keypad);
161+
} else {
162+
_keypad = new KeypadInput(w, false, false, charWidth, charHeight);
163+
_output->addInput(_keypad);
164+
}
161165
}
162166

163167
statusMessage.update(editWidget, _output);
@@ -207,6 +211,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
207211
} else {
208212
widget = helpWidget;
209213
showHelp(helpWidget);
214+
showKeypad(false);
210215
}
211216
break;
212217
case SB_KEY_F(9):
@@ -258,6 +263,9 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
258263
}
259264

260265
if ((exitHelp || isBack()) && widget == helpWidget) {
266+
if (opt_ide == IDE_EXTERNAL) {
267+
showKeypad(true);
268+
}
261269
widget = editWidget;
262270
helpWidget->hide();
263271
editWidget->setFocus(true);
@@ -293,6 +301,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
293301
if (!_output->removeInput(_keypad)) {
294302
trace("Failed to remove keypad input");
295303
}
304+
showKeypad(false);
296305
_editor = editWidget;
297306
_editor->setFocus(false);
298307
} else {

src/platform/web/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ MHD_Response *serve_file(const char *path) {
156156
int fd = open(path, O_RDONLY | O_BINARY);
157157
if (!fstat(fd, &stbuf)) {
158158
response = MHD_create_response_from_fd(stbuf.st_size, fd);
159+
160+
// add the content-type headers for browsing
161+
unsigned len = strlen(path);
162+
if (len > 4 && strcmp(path + len - 4, ".css") == 0) {
163+
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/css");
164+
} else if (len > 3 && strcmp(path + len - 3, ".js") == 0) {
165+
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, "application/javascript");
166+
}
159167
} else {
160168
response = nullptr;
161169
}

src/ui/system.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#define MENU_STR_SELECT MK_MENU("Select All", "^a")
8484
#define MENU_STR_OFF "OFF"
8585
#define MENU_STR_ON "ON"
86+
#define MENU_STR_EXT "SYSTEM"
8687
#define MENU_STR_AUDIO " Audio [%s] "
8788
#define MENU_STR_EDITOR " Editor [%s] "
8889
#define MENU_STR_THEME " Theme [%s] "
@@ -414,7 +415,8 @@ void System::handleMenu(MAEvent &event) {
414415
}
415416
break;
416417
case MENU_EDITMODE:
417-
opt_ide = (opt_ide == IDE_NONE ? IDE_INTERNAL : IDE_NONE);
418+
opt_ide = (opt_ide == IDE_NONE ? IDE_INTERNAL :
419+
opt_ide == IDE_INTERNAL ? IDE_EXTERNAL : IDE_NONE);
418420
break;
419421
case MENU_THEME:
420422
g_themeId = (g_themeId + 1) % NUM_THEMES;
@@ -1072,7 +1074,9 @@ void System::showMenu() {
10721074
items->add(new String(MENU_STR_DEBUG));
10731075
items->add(new String(MENU_STR_OUTPUT));
10741076
#elif defined(_ANDROID)
1075-
items->add(new String(MENU_STR_FIND));
1077+
if (opt_ide == IDE_INTERNAL) {
1078+
items->add(new String(MENU_STR_FIND));
1079+
}
10761080
#endif
10771081
items->add(new String(MENU_STR_HELP));
10781082
for (int i = 0; i < completions; i++) {
@@ -1090,7 +1094,9 @@ void System::showMenu() {
10901094
_systemMenu[index++] = MENU_DEBUG;
10911095
_systemMenu[index++] = MENU_OUTPUT;
10921096
#elif defined(_ANDROID)
1093-
_systemMenu[index++] = MENU_FIND;
1097+
if (opt_ide == IDE_INTERNAL) {
1098+
_systemMenu[index++] = MENU_FIND;
1099+
}
10941100
#endif
10951101
_systemMenu[index++] = MENU_HELP;
10961102
} else if (isRunning()) {
@@ -1107,9 +1113,11 @@ void System::showMenu() {
11071113
items->add(new String(MENU_STR_BACK));
11081114
_systemMenu[index++] = MENU_BACK;
11091115
#else
1110-
if (!isEditing()) {
1116+
if (!isEditing() || opt_ide == IDE_EXTERNAL) {
11111117
items->add(new String(MENU_STR_KEYPAD));
11121118
_systemMenu[index++] = MENU_KEYPAD;
1119+
}
1120+
if (!isEditing()) {
11131121
bool controlMode = get_focus_edit()->getControlMode();
11141122
sprintf(buffer, MENU_STR_CONTROL, (controlMode ? MENU_STR_ON : MENU_STR_OFF));
11151123
items->add(new String(buffer));
@@ -1141,7 +1149,17 @@ void System::showMenu() {
11411149
_systemMenu[index++] = MENU_ZOOM_DN;
11421150
#endif
11431151
#if !defined(_ANDROID_LIBRARY)
1144-
sprintf(buffer, MENU_STR_EDITOR, opt_ide == IDE_NONE ? MENU_STR_OFF : MENU_STR_ON);
1152+
switch (opt_ide) {
1153+
case IDE_NONE:
1154+
sprintf(buffer, MENU_STR_EDITOR, MENU_STR_OFF);
1155+
break;
1156+
case IDE_INTERNAL:
1157+
sprintf(buffer, MENU_STR_EDITOR, MENU_STR_ON);
1158+
break;
1159+
case IDE_EXTERNAL:
1160+
sprintf(buffer, MENU_STR_EDITOR, MENU_STR_EXT);
1161+
break;
1162+
}
11451163
items->add(new String(buffer));
11461164
_systemMenu[index++] = MENU_EDITMODE;
11471165
#endif

src/ui/system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct System {
8181
uint32_t getModifiedTime() const;
8282
void handleEvent(MAEvent &event);
8383
void handleMenu(MAEvent &event);
84-
bool isEditEnabled() const {return opt_ide == IDE_INTERNAL || isScratchLoad();}
84+
bool isEditEnabled() const {return opt_ide == IDE_INTERNAL || opt_ide == IDE_EXTERNAL || isScratchLoad();}
8585
bool isEditReady() const {return !isRestart() && isEditEnabled() && !isNetworkLoad();}
8686
bool isNetworkLoad() const {return _loadPath.indexOf("://", 1) != -1;}
8787
bool isScratchLoad() const {return _loadPath.indexOf("scratch", 0) != -1;}

0 commit comments

Comments
 (0)