Skip to content

Commit 9233059

Browse files
committed
ANDROID: update handling for external modules
1 parent de18244 commit 9233059

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ end
162162

163163
sub do_setup()
164164
local frm
165+
local fontId = int(env("fontId"))
166+
local loadModules = int(env("loadModules"))
165167

166168
color colText, colBkGnd
167169
cls
@@ -185,7 +187,7 @@ sub do_setup()
185187
frm.inputs(0).x = char_w
186188
frm.inputs(1).type = "list"
187189
frm.inputs(1).value = "Inconsolata|Envy Code R|UbuntuMono"
188-
frm.inputs(1).selectedIndex = env("fontId")
190+
frm.inputs(1).selectedIndex = iff(fontId in [0,1,2], fontId, 0)
189191
frm.inputs(1).x = char_w * 1.5
190192
frm.inputs(1).y = char_h * 2.2
191193
frm.inputs(1).height = char_h * 3 + 4
@@ -213,14 +215,14 @@ sub do_setup()
213215
goto exitFunc
214216
endif
215217
wend
216-
local fontId = frm.inputs(1).selectedIndex
218+
fontId = frm.inputs(1).selectedIndex
217219

218220
cls
219221
at 0, char_h * 1
220222
rect x, y, w * 2, h + y * 2.5
221223
frm.inputs(0).label = "Extension modules:"
222224
frm.inputs(1).value = "Ignore|Load"
223-
frm.inputs(1).selectedIndex = env("loadModules")
225+
frm.inputs(1).selectedIndex = iff(loadModules == 1, 1, 0)
224226
frm = form(frm)
225227
while 1
226228
frm.doEvents()
@@ -230,7 +232,7 @@ sub do_setup()
230232
goto exitFunc
231233
endif
232234
wend
233-
local loadModules = frm.inputs(1).selectedIndex
235+
loadModules = frm.inputs(1).selectedIndex
234236

235237
color colText, colBkGnd
236238
cls
@@ -270,22 +272,17 @@ end
270272
sub server_info()
271273
local serverSocket = env("serverSocket")
272274
local ipAddr = env("IP_ADDR")
273-
local loadModules = env("loadModules")
274-
local hasText = false
275+
local loadModules = int(env("loadModules"))
275276

276277
if (len(serverSocket) > 0 && int(serverSocket) > 1023 && int(serverSocket) < 65536 && len(ipAddr)) then
277278
serverSocket = ipAddr + ":" + serverSocket
278279
print boldOff + "Web Service: " + boldOn + serverSocket
279280
print boldOff + "Access token: " + boldOn + env("serverToken")
280281
print boldOff;
281-
hasText = true
282282
fi
283-
if (int(loadModules) == 1) then
284-
print "Extension modules: " + boldOn + "Enabled"
285-
print boldOff;
286-
hasText = true
287-
endif
288-
if (hasText) then print
283+
284+
print "Extension modules: " + boldOn + iff(loadModules == 2, "Active", iff(loadModules == 1, "Enabled", "Disabled"))
285+
print boldOff
289286
end
290287

291288
func fileCmpFunc0(l, r)

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public class MainActivity extends NativeActivity {
115115
System.loadLibrary("smallbasic");
116116
}
117117

118+
public native long getActivity();
118119
public static native boolean libraryMode();
119120
public static native void onActivityPaused(boolean paused);
120121
public static native void onResize(int width, int height);
@@ -222,6 +223,16 @@ public boolean closeLibHandlers() {
222223
return removeLocationUpdates();
223224
}
224225

226+
public Class<?> findClass(String className) {
227+
try {
228+
Log.d(TAG, "findClass " + className);
229+
return Class.forName(className.replace("/", "."));
230+
}
231+
catch (ClassNotFoundException e) {
232+
throw new RuntimeException(e);
233+
}
234+
}
235+
225236
public byte[] getClipboardText() {
226237
final StringBuilder text = new StringBuilder();
227238
final Context context = this;
@@ -358,15 +369,16 @@ public int getWindowHeight() {
358369
}
359370

360371
public boolean loadModules() {
361-
Log.i(TAG, "loadModules");
372+
Log.i(TAG, "loadModules: " + getActivity() );
362373
boolean result;
363374
try {
364375
System.loadLibrary("ioio");
365-
Class.forName("net.sourceforge.smallbasic.ioio.IOIOLoader").newInstance();
366-
Log.i(TAG, "loadModules - success");
376+
Class<?> clazz = Class.forName("net.sourceforge.smallbasic.ioio.IOIOLoader");
377+
clazz.getDeclaredConstructor(Long.class).newInstance(getActivity());
378+
Log.d(TAG, "loadModules - success");
367379
result = true;
368380
} catch (Exception | UnsatisfiedLinkError e) {
369-
Log.i(TAG, "loadModules", e);
381+
Log.d(TAG, "loadModules", e);
370382
result = false;
371383
}
372384
return result;

src/platform/android/jni/runtime.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ extern "C" JNIEXPORT jboolean JNICALL Java_net_sourceforge_smallbasic_MainActivi
190190
#endif
191191
}
192192

193+
extern "C" JNIEXPORT jlong JNICALL Java_net_sourceforge_smallbasic_MainActivity_getActivity
194+
(JNIEnv *env, jobject instance) {
195+
return runtime->getActivity();
196+
}
197+
193198
void onContentRectChanged(ANativeActivity *activity, const ARect *rect) {
194199
logEntered();
195200
runtime->onResize(rect->right, rect->bottom);
@@ -555,14 +560,20 @@ void Runtime::loadConfig() {
555560
g_themeId = id;
556561
}
557562
}
563+
s = settings.get(LOAD_MODULES_KEY);
564+
if (s && s->toInteger() == 1) {
565+
if (getBoolean("loadModules")) {
566+
systemLog("Extension modules loaded\n");
567+
settings.put(LOAD_MODULES_KEY, "2");
568+
} else {
569+
systemLog("Loading extension modules failed\n");
570+
settings.put(LOAD_MODULES_KEY, "0");
571+
}
572+
}
558573
loadEnvConfig(settings, SERVER_SOCKET_KEY);
559574
loadEnvConfig(settings, SERVER_TOKEN_KEY);
560575
loadEnvConfig(settings, LOAD_MODULES_KEY);
561576
loadEnvConfig(settings, FONT_ID_KEY);
562-
s = settings.get(LOAD_MODULES_KEY);
563-
if (s && s->toInteger() == 1 && !getBoolean("loadModules")) {
564-
systemLog("loadModules failed");
565-
}
566577
}
567578
}
568579

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct Runtime : public System {
3636
void disableSensor();
3737
void enableCursor(bool enabled) {}
3838
bool enableSensor(int sensorType);
39+
jlong getActivity() { return (jlong)_app->activity->clazz; }
3940
bool getBoolean(const char *methodName);
4041
String getString(const char *methodName);
4142
String getStringBytes(const char *methodName);

src/ui/utils.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626

2727
#if defined(_ANDROID)
2828
#include <android/log.h>
29-
#define deviceLog(...) __android_log_print(ANDROID_LOG_INFO, \
30-
"smallbasic", __VA_ARGS__)
29+
#if defined(_DEBUG)
30+
#define deviceLog(...) __android_log_print(ANDROID_LOG_ERROR, "smallbasic", __VA_ARGS__)
31+
#else
32+
#define deviceLog(...) __android_log_print(ANDROID_LOG_INFO, "smallbasic", __VA_ARGS__)
33+
#endif
3134
#elif defined(_SDL) || defined(_FLTK) || defined(_EMCC)
3235
void appLog(const char *format, ...);
3336
#define deviceLog(...) appLog(__VA_ARGS__)
@@ -39,10 +42,8 @@
3942
#define trace(...)
4043
#endif
4144

42-
#define logEntered() trace("%s entered (%s %d)", \
43-
__FUNCTION__, __FILE__, __LINE__);
44-
#define logLeaving() trace("%s leaving (%s %d)", \
45-
__FUNCTION__, __FILE__, __LINE__);
45+
#define logEntered() trace("%s entered (%s %d)", __FUNCTION__, __FILE__, __LINE__);
46+
#define logLeaving() trace("%s leaving (%s %d)", __FUNCTION__, __FILE__, __LINE__);
4647

4748
#define C_LINKAGE_BEGIN extern "C" {
4849
#define C_LINKAGE_END }

0 commit comments

Comments
 (0)