Skip to content

Commit 6491bf9

Browse files
committed
ANDROID: fix pause and resume
1 parent 11f49fb commit 6491bf9

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
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.12.2])
10+
AC_INIT([smallbasic], [0.12.3])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
smallbasic (0.12.3) unstable; urgency=low
2+
* Various - see web site
3+
4+
-- Chris Warren-Smith <cwarrensmith@gmail.com> Tue, 26 Jan 2016 09:45:25 +1000
5+
16
smallbasic (0.12.2) unstable; urgency=low
27
* Various - see web site
38

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="16"
6-
android:versionName="0.12.1">
5+
android:versionCode="17"
6+
android:versionName="0.12.3">
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
@@ -55,7 +55,7 @@ sub do_about()
5555
print "(_ ._ _ _.|||_) /\ (_ |/ "
5656
print "__)| | |(_||||_)/--\__)|\_"
5757
print
58-
print "Version 0.12.2"
58+
print "Version 0.12.3"
5959
print
6060
print "Copyright (c) 2002-2015 Chris Warren-Smith"
6161
print "Copyright (c) 1999-2006 Nic Christopoulos" + chr(10)

src/platform/android/jni/runtime.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ void handleCommand(android_app *app, int32_t cmd) {
8181
trace("handleCommand = %d", cmd);
8282
switch (cmd) {
8383
case APP_CMD_INIT_WINDOW:
84-
// thread is ready to start
85-
runtime->construct();
86-
break;
87-
case APP_CMD_TERM_WINDOW:
88-
if (runtime) {
89-
// thread is ending
90-
runtime->setExit(true);
84+
// thread is ready to start or resume
85+
if (runtime->isInitial()) {
86+
runtime->construct();
9187
}
9288
break;
89+
case APP_CMD_GAINED_FOCUS:
90+
trace("gainedFocus");
91+
runtime->setFocus(true);
92+
break;
9393
case APP_CMD_LOST_FOCUS:
94-
// display menu or exit
94+
trace("lostFocus");
95+
runtime->setFocus(false);
9596
break;
9697
}
9798
}
@@ -150,6 +151,7 @@ void onContentRectChanged(ANativeActivity *activity, const ARect *rect) {
150151
Runtime::Runtime(android_app *app) :
151152
System(),
152153
_keypadActive(false),
154+
_hasFocus(false),
153155
_graphics(NULL),
154156
_app(app),
155157
_eventQueue(NULL) {
@@ -603,7 +605,7 @@ void Runtime::pause(int timeout) {
603605
void Runtime::pollEvents(bool blocking) {
604606
int events;
605607
android_poll_source *source;
606-
ALooper_pollAll(blocking ? -1 : 0, NULL, &events, (void **)&source);
608+
ALooper_pollAll(blocking || !_hasFocus ? -1 : 0, NULL, &events, (void **)&source);
607609
if (source != NULL) {
608610
source->process(_app, source);
609611
}

src/platform/android/jni/runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ struct Runtime : public System {
5757
void runPath(const char *path);
5858
void setClipboardText(const char *text);
5959
char *getClipboardText();
60+
void setFocus(bool focus) { _hasFocus = focus; }
6061

6162
private:
6263
bool _keypadActive;
64+
bool _hasFocus;
6365
Graphics *_graphics;
6466
android_app *_app;
6567
Stack<MAEvent *> *_eventQueue;

src/platform/sdl/display.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,26 @@ bool Graphics::construct(const char *font, const char *boldFont) {
111111
logEntered();
112112

113113
int w, h;
114-
bool result = false;
114+
bool result = true;
115115
SDL_GetWindowSize(_window, &w, &h);
116116

117117
SDL_Surface *surface = SDL_GetWindowSurface(_window);
118-
if (surface->format->format != PIXELFORMAT) {
118+
if (surface == NULL) {
119+
fprintf(stderr, "SDL surface is null\n");
120+
result = false;
121+
} else if (surface->format == NULL) {
122+
fprintf(stderr, "SDL surface format is null\n");
123+
result = false;
124+
} else if (surface->format->format != PIXELFORMAT) {
119125
deviceLog("Unexpected window surface format %d", surface->format->format);
120126
_surface = surface;
121127
}
122128

123-
if (loadFonts(font, boldFont)) {
129+
if (result && loadFonts(font, boldFont)) {
124130
_screen = new Canvas();
125131
if (_screen != NULL) {
126132
if (_surface == NULL) {
127133
_screen->setSurface(SDL_GetWindowSurface(_window), w, h);
128-
result = true;
129134
} else {
130135
result = _screen->create(w, h);
131136
}

src/ui/form.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ void set_focus(FormInput *focus) {
3434
}
3535
}
3636

37+
struct FormTextInput : public TextEditInput {
38+
FormTextInput(const char *text, int chW, int chH, int x, int y, int w, int h):
39+
TextEditInput(text, chW, chH, x, y, w, h) {
40+
}
41+
42+
void clicked(int x, int y, bool pressed) {
43+
TextEditInput::clicked(x, y, pressed);
44+
if (pressed && g_system->isRunning()) {
45+
set_focus(this);
46+
updateForm(form);
47+
mode = m_selected;
48+
g_system->getOutput()->setDirty();
49+
}
50+
}
51+
};
52+
3753
// returns setBG when the program colours are default
3854
int FormInput::getBackground(int buttonColor) const {
3955
int result = _bg;
@@ -241,7 +257,7 @@ FormInput *create_input(var_p_t v_field) {
241257
text = value->v.p.ptr;
242258
}
243259
if (h * 2 >= charHeight) {
244-
widget = new TextEditInput(text, charWidth, charHeight, x, y, w, h);
260+
widget = new FormTextInput(text, charWidth, charHeight, x, y, w, h);
245261
} else {
246262
widget = new FormLineInput(text, maxSize, false, x, y, w, h);
247263
}

0 commit comments

Comments
 (0)