Skip to content

Commit d78a762

Browse files
committed
ANDROID: add build setting for library-mode
1 parent fed7b5d commit d78a762

File tree

7 files changed

+54
-10
lines changed

7 files changed

+54
-10
lines changed

configure.ac

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ function buildSDL() {
234234
}
235235

236236
function buildAndroid() {
237-
TARGET="Building for Android."
238-
239237
defaultConditionals
240238

239+
AC_MSG_CHECKING([if library mode is enabled])
240+
AC_ARG_WITH(library,
241+
[ --with-library Build the android as a library default=no],
242+
[with_library=$with_library],
243+
[with_library=no])
244+
AC_MSG_RESULT([$with_library])
241245
AC_DEFINE(_UnixOS, 1, [Building under Unix like systems.])
242246
AC_DEFINE(_ANDROID, 1, [Defined for Android build.])
243247
AC_DEFINE(IMPL_DEV_READ, 1, [Implement dev_read()])
@@ -248,7 +252,13 @@ function buildAndroid() {
248252

249253
TEST_DIR="src/platform/android"
250254
AC_SUBST(TEST_DIR)
251-
(cd src/platform/android/webui && npm run build)
255+
if test $with_library = no; then
256+
(cd src/platform/android/webui && npm run build)
257+
TARGET="Building for Android."
258+
else
259+
TARGET="Building for Android library."
260+
AC_DEFINE(_ANDROID_LIBRARY, 1, [android library build enabled])
261+
fi
252262
}
253263

254264
function buildConsole() {

src/common/screen.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,18 @@ void osd_line(int x1, int y1, int x2, int y2);
304304
//
305305
void dev_rect(int x1, int y1, int x2, int y2, int fill) {
306306
int c1, c2, in1, in2;
307+
308+
if (x2 < x1) {
309+
int x11 = x1;
310+
x1 = x2;
311+
x2 = x11;
312+
}
313+
if (y2 < y1) {
314+
int y11 = y1;
315+
y1 = y2;
316+
y2 = y11;
317+
}
318+
307319
int px1 = x1;
308320
int py1 = y1;
309321
int px2 = x2;
@@ -409,6 +421,9 @@ void dev_window(int x1, int y1, int x2, int y2) {
409421
}
410422
}
411423

424+
//
425+
// set screen width and height
426+
//
412427
void dev_resize(int width, int height) {
413428
if (dev_Vx2 == dev_Vdx && dev_Vx2 == os_graf_mx - 1) {
414429
// viewport width is full-screen
@@ -432,6 +447,9 @@ void dev_resize(int width, int height) {
432447
setsysvar_int(SYSVAR_YMAX, height - 1);
433448
}
434449

450+
//
451+
// remap x/y to world coordinates
452+
//
435453
void dev_map_point(int *x, int *y) {
436454
*x = W2X(*x);
437455
*y = W2Y(*y);

src/platform/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
<!-- Permissions -->
6868
<uses-permission android:name="android.permission.INTERNET" />
6969
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
70+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
71+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
7072
<uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION" />
7173
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
7274
</manifest>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public class MainActivity extends NativeActivity {
112112
System.loadLibrary("smallbasic");
113113
}
114114

115+
public static native boolean libraryMode();
115116
public static native void onActivityPaused(boolean paused);
116117
public static native void onResize(int width, int height);
117118
public static native void onUnicodeChar(int ch);
@@ -640,10 +641,12 @@ public void speak(final byte[] textBytes) {
640641
@Override
641642
protected void onCreate(Bundle savedInstanceState) {
642643
super.onCreate(savedInstanceState);
643-
processIntent();
644-
processSettings();
645644
String homeFolder = setupStorageEnvironment();
646-
installSamples(homeFolder);
645+
if (!libraryMode()) {
646+
processIntent();
647+
processSettings();
648+
installSamples(homeFolder);
649+
}
647650
}
648651

649652
@Override

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:7.2.1'
8+
classpath 'com.android.tools.build:gradle:7.2.2'
99
}
1010
}
1111

src/platform/android/jni/runtime.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of SmallBASIC
22
//
3-
// Copyright(C) 2001-2016 Chris Warren-Smith.
3+
// Copyright(C) 2001-2022 Chris Warren-Smith.
44
//
55
// This program is distributed under the terms of the GPL v2.0 or later
66
// Download the GNU Public License (GPL) from www.gnu.org
@@ -132,6 +132,7 @@ int get_sensor_events(int fd, int events, void *data) {
132132
return 1;
133133
}
134134

135+
// callbacks from MainActivity.java
135136
extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_onActivityPaused
136137
(JNIEnv *env, jclass jclazz, jboolean paused) {
137138
if (runtime != nullptr && !runtime->isClosing() && runtime->isActive() && os_graphics) {
@@ -140,7 +141,6 @@ extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_o
140141
}
141142
}
142143

143-
// callback from MainActivity.java
144144
extern "C" JNIEXPORT jboolean JNICALL Java_net_sourceforge_smallbasic_MainActivity_optionSelected
145145
(JNIEnv *env, jclass jclazz, jint index) {
146146
auto *maEvent = new MAEvent();
@@ -180,6 +180,15 @@ extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_o
180180
}
181181
}
182182

183+
extern "C" JNIEXPORT jboolean JNICALL Java_net_sourceforge_smallbasic_MainActivity_libraryMode
184+
(JNIEnv *env, jclass jclazz) {
185+
#if defined(_ANDROID_LIBRARY)
186+
return true;
187+
#else
188+
return false;
189+
#endif
190+
}
191+
183192
void onContentRectChanged(ANativeActivity *activity, const ARect *rect) {
184193
logEntered();
185194
runtime->onResize(rect->right, rect->bottom);

src/ui/system.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of SmallBASIC
22
//
3-
// Copyright(C) 2001-2019 Chris Warren-Smith.
3+
// Copyright(C) 2001-2022 Chris Warren-Smith.
44
//
55
// This program is distributed under the terms of the GPL v2.0 or later
66
// Download the GNU Public License (GPL) from www.gnu.org
@@ -1122,9 +1122,11 @@ void System::showMenu() {
11221122
_systemMenu[index++] = MENU_ZOOM_UP;
11231123
_systemMenu[index++] = MENU_ZOOM_DN;
11241124
#endif
1125+
#if !defined(_ANDROID_LIBRARY)
11251126
sprintf(buffer, MENU_STR_EDITOR, opt_ide == IDE_NONE ? MENU_STR_OFF : MENU_STR_ON);
11261127
items->add(new String(buffer));
11271128
_systemMenu[index++] = MENU_EDITMODE;
1129+
#endif
11281130
sprintf(buffer, MENU_STR_THEME, themeName());
11291131
items->add(new String(buffer));
11301132
_systemMenu[index++] = MENU_THEME;

0 commit comments

Comments
 (0)