Skip to content

Commit bbd7a71

Browse files
committed
ANDROID: allow specified loading of extension modules
1 parent f7ecd77 commit bbd7a71

File tree

4 files changed

+71
-41
lines changed

4 files changed

+71
-41
lines changed

src/platform/android/app/src/main/assets/main.bas

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ sub do_about()
152152
print "This program is free software; you can use it ";
153153
print "redistribute it and/or modify it under the terms of the ";
154154
print "GNU General Public License version 2 as published by ";
155-
print "the Free Software Foundation." + chr(10)
155+
print "the Free Software Foundation."
156156
print
157157
color colText
158158
server_info()
@@ -163,6 +163,60 @@ end
163163
sub do_setup()
164164
local frm
165165

166+
color colText, colBkGnd
167+
cls
168+
at 0, char_h * 6.5
169+
print "Envy Code R:"
170+
print " http://damieng.com/envy-code-r"
171+
print "Inconsolata:"
172+
print " Copyright 2006 The Inconsolata Project"
173+
print " http://scripts.sil.org/OFL"
174+
print "Ubuntu:"
175+
print " https://ubuntu.com/legal/font-licence"
176+
at 0, char_h * 1
177+
local w = char_w * 14.5
178+
local h = char_h * 4.5
179+
local x = char_w / 2
180+
local y = char_h / 2
181+
rect x, y, w * 2, h + y * 2.5
182+
dim frm.inputs(3)
183+
frm.inputs(0).type = "label"
184+
frm.inputs(0).label = "Select display font:"
185+
frm.inputs(0).x = char_w
186+
frm.inputs(1).type = "list"
187+
frm.inputs(1).value = "Inconsolata|Envy Code R|UbuntuMono"
188+
frm.inputs(1).selectedIndex = env("fontId")
189+
frm.inputs(1).x = char_w * 1.5
190+
frm.inputs(1).y = char_h * 2.2
191+
frm.inputs(1).height = char_h * 3 + 4
192+
frm.inputs(1).width = char_w * 12
193+
frm.inputs(2).type = "button"
194+
frm.inputs(2).backgroundColor = colBkGnd
195+
frm.inputs(2).color = colText
196+
frm.inputs(2).label = "OK"
197+
frm.inputs(2).value = "OK"
198+
frm.inputs(2).x = -(char_w * 8)
199+
frm.inputs(2).y = -(char_h)
200+
frm = form(frm)
201+
while 1
202+
frm.doEvents()
203+
if (frm.value == "OK") then exit loop
204+
wend
205+
env("fontId=" + frm.inputs(1).selectedIndex)
206+
207+
cls
208+
at 0, char_h * 1
209+
rect x, y, w * 2, h + y * 2.5
210+
frm.inputs(0).label = "Extension modules:"
211+
frm.inputs(1).value = "Ignore|Load"
212+
frm.inputs(1).selectedIndex = env("loadModules")
213+
frm = form(frm)
214+
while 1
215+
frm.doEvents()
216+
if (frm.value == "OK") then exit loop
217+
wend
218+
env("loadModules=" + frm.inputs(1).selectedIndex)
219+
166220
color colText, colBkGnd
167221
cls
168222
print boldOn + "Setup web service port number."
@@ -188,30 +242,6 @@ sub do_setup()
188242
env("serverToken=" + token)
189243
endif
190244

191-
color colText, colBkGnd
192-
cls
193-
print "Web service port number: " + env("serverSocket")
194-
print
195-
print boldOn + "Select display font."
196-
print boldOff
197-
print "Envy Code R:"
198-
print " http://damieng.com/envy-code-r"
199-
print "Inconsolata:"
200-
print " Copyright 2006 The Inconsolata Project"
201-
print " http://scripts.sil.org/OFL"
202-
print "Ubuntu:"
203-
print " https://ubuntu.com/legal/font-licence"
204-
print
205-
dim frm.inputs(1)
206-
frm.inputs(0).type="list"
207-
frm.inputs(0).value="Inconsolata|Envy Code R|UbuntuMono"
208-
frm.inputs(0).selectedIndex=env("fontId")
209-
frm.inputs(0).height=TXTH("Q")*3+4
210-
frm.inputs(0).width=TXTW("Q")*12
211-
frm = form(frm)
212-
frm.doEvents()
213-
env("fontId=" + frm.inputs(0).selectedIndex)
214-
215245
local msg = "You must restart SmallBASIC for this change to take effect."
216246
wnd.alert(msg, "Restart required")
217247
clear_screen()
@@ -220,13 +250,18 @@ end
220250
sub server_info()
221251
local serverSocket = env("serverSocket")
222252
local ipAddr = env("IP_ADDR")
253+
local loadModules = env("loadModules")
223254

224255
if (len(serverSocket) > 0 && int(serverSocket) > 1023 && int(serverSocket) < 65536 && len(ipAddr)) then
225256
serverSocket = ipAddr + ":" + serverSocket
226257
print boldOff + "Web Service: " + boldOn + serverSocket
227258
print boldOff + "Access token: " + boldOn + env("serverToken")
228-
print boldOff
259+
print boldOff;
229260
fi
261+
if (int(loadModules) == 1) then
262+
print "Extension modules: " + boldOn + "Enabled"
263+
print boldOff;
264+
endif
230265
end
231266

232267
func fileCmpFunc0(l, r)

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import androidx.core.content.ContextCompat;
4343
import androidx.core.content.FileProvider;
4444

45-
import net.sourceforge.smallbasic.ioio.IOIOUtility;
46-
4745
import java.io.BufferedReader;
4846
import java.io.BufferedWriter;
4947
import java.io.ByteArrayInputStream;
@@ -364,9 +362,9 @@ public boolean loadModules() {
364362
boolean result;
365363
try {
366364
System.loadLibrary("ioio");
367-
IOIOUtility.init();
365+
Class.forName("net.sourceforge.smallbasic.ioio.IOIOLoader").newInstance();
368366
result = true;
369-
} catch (SecurityException | UnsatisfiedLinkError e) {
367+
} catch (Exception | UnsatisfiedLinkError e) {
370368
Log.i(TAG, "loadModules", e);
371369
result = false;
372370
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package net.sourceforge.smallbasic.ioio;
22

3-
public class IOIOUtility {
4-
private IOIOUtility() {
5-
// no access
6-
}
7-
3+
public class IOIOLoader {
84
public static native void init();
9-
5+
static {
6+
init();
7+
}
108
}

src/platform/android/jni/runtime.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,13 @@ void Runtime::loadConfig() {
557557
}
558558
loadEnvConfig(settings, SERVER_SOCKET_KEY);
559559
loadEnvConfig(settings, SERVER_TOKEN_KEY);
560+
loadEnvConfig(settings, LOAD_MODULES_KEY);
560561
loadEnvConfig(settings, FONT_ID_KEY);
561-
562562
s = settings.get(LOAD_MODULES_KEY);
563-
if (s && s->toInteger() == 1) {
564-
trace("calling loadModules");
565-
getBoolean("loadModules");
563+
if (s && s->toInteger() == 1 && !getBoolean("loadModules")) {
564+
systemLog("loadModules failed");
566565
}
567566
}
568-
569567
}
570568

571569
bool Runtime::loadSettings(Properties<String *> &settings) {
@@ -618,6 +616,7 @@ void Runtime::saveConfig() {
618616
char *env = environ[i];
619617
if (strstr(env, SERVER_SOCKET_KEY) != nullptr ||
620618
strstr(env, SERVER_TOKEN_KEY) != nullptr ||
619+
strstr(env, LOAD_MODULES_KEY) != nullptr ||
621620
strstr(env, FONT_ID_KEY) != nullptr) {
622621
fprintf(fp, "%s\n", env);
623622
}

0 commit comments

Comments
 (0)