Skip to content

Commit 2d2dc08

Browse files
committed
ANDROID: fix android v4.4 crash
1 parent 7781588 commit 2d2dc08

File tree

9 files changed

+54
-19
lines changed

9 files changed

+54
-19
lines changed

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], [0.11.7])
10+
AC_INIT([smallbasic], [0.11.8])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

ide/android/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="net.sourceforge.smallbasic"
44
android:installLocation="preferExternal"
5-
android:versionCode="9"
6-
android:versionName="0.11.7">
5+
android:versionCode="10"
6+
android:versionName="0.11.8">
77
<!-- This is the platform API where NativeActivity was introduced. -->
88
<uses-sdk android:minSdkVersion="9" />
99

ide/android/assets/main.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sub about()
3030
print "(_ ._ _ _.|||_) /\ (_ |/ "
3131
print "__)| | |(_||||_)/--\__)|\_"
3232
print
33-
print "Version 0.11.7"
33+
print "Version 0.11.8"
3434
print
3535
print "Copyright (c) 2002-2014 Chris Warren-Smith"
3636
print "Copyright (c) 2000-2006 Nic Christopoulos" + chr(10)

src/platform/android/jni/runtime.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ String Runtime::getString(const char *methodName) {
214214
_app->activity->vm->AttachCurrentThread(&env, NULL);
215215
jclass clazz = env->GetObjectClass(_app->activity->clazz);
216216
jmethodID methodId = env->GetMethodID(clazz, methodName, "()Ljava/lang/String;");
217-
jstring startupBasObj = (jstring) env->CallObjectMethod(_app->activity->clazz, methodId);
218-
const char *startupBas = env->GetStringUTFChars(startupBasObj, JNI_FALSE);
219-
String result = startupBas;
220-
env->ReleaseStringUTFChars(startupBasObj, startupBas);
217+
jstring resultObj = (jstring) env->CallObjectMethod(_app->activity->clazz, methodId);
218+
const char *resultStr = env->GetStringUTFChars(resultObj, JNI_FALSE);
219+
String result = resultStr;
220+
env->ReleaseStringUTFChars(resultObj, resultStr);
221221
env->DeleteLocalRef(clazz);
222222
_app->activity->vm->DetachCurrentThread();
223223
return result;
@@ -471,7 +471,7 @@ void Runtime::optionsBox(StringList *items) {
471471
}
472472
jclass clazz = env->GetObjectClass(_app->activity->clazz);
473473
jmethodID methodId = env->GetMethodID(clazz, "optionsBox", "([Ljava/lang/String;)V");
474-
env->CallObjectMethod(_app->activity->clazz, methodId, array);
474+
env->CallVoidMethod(_app->activity->clazz, methodId, array);
475475

476476
for (int i = 0; i < items->size(); i++) {
477477
env->DeleteLocalRef(env->GetObjectArrayElement(array, i));
@@ -562,7 +562,7 @@ void Runtime::showKeypad(bool show) {
562562
_app->activity->vm->AttachCurrentThread(&env, NULL);
563563
jclass clazz = env->GetObjectClass(_app->activity->clazz);
564564
jmethodID methodId = env->GetMethodID(clazz, "showKeypad", "(Z)V");
565-
env->CallObjectMethod(_app->activity->clazz, methodId, show);
565+
env->CallVoidMethod(_app->activity->clazz, methodId, show);
566566
env->DeleteLocalRef(clazz);
567567
_app->activity->vm->DetachCurrentThread();
568568
}
@@ -577,7 +577,7 @@ void Runtime::showAlert(const char *title, const char *message) {
577577
jclass clazz = env->GetObjectClass(_app->activity->clazz);
578578
jmethodID method = env->GetMethodID(clazz, "showAlert",
579579
"(Ljava/lang/String;Ljava/lang/String;)V");
580-
env->CallObjectMethod(_app->activity->clazz, method, titleString, messageString);
580+
env->CallVoidMethod(_app->activity->clazz, method, titleString, messageString);
581581

582582
env->DeleteLocalRef(clazz);
583583
env->DeleteLocalRef(messageString);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public boolean getSoundPlaying() {
105105
}
106106

107107
public String getStartupBas() {
108-
return this._startupBas;
108+
return this._startupBas == null ? "" : this._startupBas;
109109
}
110110

111111
public int getUnicodeChar(int keyCode, int metaState) {

src/platform/common/graphics.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ Font::~Font() {
7878
Graphics::Graphics() :
7979
_screen(NULL),
8080
_drawTarget(NULL),
81-
_font(NULL) {
81+
_font(NULL),
82+
_w(0),
83+
_h(0) {
8284
graphics = this;
8385
}
8486

src/platform/common/system.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ char *System::loadResource(const char *fileName) {
251251
char *System::readSource(const char *fileName) {
252252
char *buffer = loadResource(fileName);
253253
if (!buffer) {
254-
int h = open(comp_file_name, O_BINARY | O_RDONLY, 0644);
254+
int h = open(fileName, O_BINARY | O_RDONLY, 0644);
255255
if (h != -1) {
256256
int len = lseek(h, 0, SEEK_END);
257257
lseek(h, 0, SEEK_SET);
258258
buffer = (char *)tmp_alloc(len + 1);
259-
read(h, buffer, len);
259+
len = read(h, buffer, len);
260260
buffer[len] = '\0';
261261
close(h);
262262
}

src/platform/sdl/keymap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static int keymap[] = {
2626
SDLK_KP_MINUS, SB_KEY_KP_MINUS,
2727
SDLK_KP_PLUS, SB_KEY_KP_PLUS,
2828
SDLK_KP_EQUALS, '=',
29-
SDLK_BACKSPACE, SB_KEY_BACKSPACE,
29+
SDLK_BACKSPACE, MAK_CLEAR,
3030
SDLK_DELETE, SB_KEY_DELETE,
3131
SDLK_UP, SB_KEY_UP,
3232
SDLK_DOWN, SB_KEY_DN,

src/platform/sdl/runtime.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ void Runtime::runPath(const char *path) {
134134

135135
void Runtime::handleKeyEvent(MAEvent &event) {
136136
if (isRunning()) {
137+
trace("key=%d scanCode=%d", event.key, event.nativeKey);
137138
int key = event.key;
138139
for (int i = 0; keymap[i] != 0; i += 2) {
139140
if (keymap[i] == key) {
140141
if (keymap[i + 1] != -1) {
141142
dev_pushkey(keymap[i + 1]);
143+
event.key = keymap[i + 1];
142144
}
143145
key = -1;
144146
break;
@@ -172,13 +174,17 @@ void Runtime::pollEvents(bool blocking) {
172174
runtime->setExit(true);
173175
break;
174176
case SDL_KEYDOWN:
175-
if ((ev.key.keysym.sym == SDLK_c && (ev.key.keysym.mod & KMOD_CTRL))) {
177+
if (ev.key.keysym.sym == SDLK_c && (ev.key.keysym.mod & KMOD_CTRL)) {
176178
runtime->setExit(true);
179+
} else if (ev.key.keysym.sym == SDLK_HOME && (ev.key.keysym.mod & KMOD_CTRL)) {
180+
showMenu();
181+
} else if (ev.key.keysym.sym == SDLK_BACKSPACE && (ev.key.keysym.mod & KMOD_CTRL)) {
182+
setBack();
177183
} else {
178184
maEvent = new MAEvent();
179185
maEvent->type = EVENT_TYPE_KEY_PRESSED;
180-
maEvent->nativeKey = (ev.key.keysym.scancode & 0xFF);
181186
maEvent->key = ev.key.keysym.sym;
187+
maEvent->nativeKey = ev.key.keysym.scancode;
182188
}
183189
break;
184190
case SDL_MOUSEBUTTONDOWN:
@@ -272,6 +278,33 @@ void Runtime::onResize(int width, int height) {
272278
}
273279
}
274280

281+
void Runtime::optionsBox(StringList *items) {
282+
SDL_MessageBoxButtonData buttons[items->size()];
283+
int index = 0;
284+
List_each(String *, it, *items) {
285+
char *str = (char *)(* it)->c_str();
286+
buttons[index].text = str;
287+
buttons[index].buttonid = index;
288+
buttons[index].flags = 0;
289+
index++;
290+
}
291+
292+
SDL_MessageBoxData data;
293+
data.window = _window;
294+
data.title = "SmallBASIC";
295+
data.message = "Menu";
296+
data.flags = SDL_MESSAGEBOX_INFORMATION;
297+
data.numbuttons = items->size();
298+
data.buttons = buttons;
299+
300+
int buttonid;
301+
SDL_ShowMessageBox(&data, &buttonid);
302+
MAEvent *maEvent = new MAEvent();
303+
maEvent->type = EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED;
304+
maEvent->optionsBoxButtonIndex = buttonid;
305+
pushEvent(maEvent);
306+
}
307+
275308
//
276309
// form_ui implementation
277310
//
@@ -280,7 +313,7 @@ AnsiWidget *form_ui::getOutput() {
280313
}
281314

282315
void form_ui::optionsBox(StringList *items) {
283-
// TODO: see fltk
316+
runtime->optionsBox(items);
284317
}
285318

286319
//

0 commit comments

Comments
 (0)