Skip to content

Commit e29bd4b

Browse files
committed
ANDROID: prevent display when paused
1 parent 9ffcbd9 commit e29bd4b

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public class MainActivity extends NativeActivity {
102102
System.loadLibrary("smallbasic");
103103
}
104104

105+
public static native void onActivityPaused(boolean paused);
105106
public static native void onResize(int width, int height);
106107
public static native void onUnicodeChar(int ch);
107108
public static native boolean optionSelected(int index);
@@ -600,6 +601,18 @@ protected void onCreate(Bundle savedInstanceState) {
600601
checkFilePermission();
601602
}
602603

604+
@Override
605+
protected void onPause() {
606+
super.onPause();
607+
onActivityPaused(true);
608+
}
609+
610+
@Override
611+
protected void onResume() {
612+
super.onResume();
613+
onActivityPaused(false);
614+
}
615+
603616
@Override
604617
protected void onStop() {
605618
super.onStop();

src/platform/android/jni/display.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ Graphics::Graphics(android_app *app) : ui::Graphics(),
118118
_fontBufferB(NULL),
119119
_app(app),
120120
_w(0),
121-
_h(0) {
121+
_h(0),
122+
_paused(false) {
122123
}
123124

124125
Graphics::~Graphics() {
@@ -154,7 +155,7 @@ bool Graphics::construct(int fontId) {
154155
}
155156

156157
void Graphics::redraw() {
157-
if (_app->window != NULL) {
158+
if (_app->window != NULL && !_paused) {
158159
ANativeWindow_Buffer buffer;
159160
if (ANativeWindow_lock(_app->window, &buffer, NULL) < 0) {
160161
trace("Unable to lock window buffer");

src/platform/android/jni/display.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct Graphics : ui::Graphics {
2525
bool construct(int fontId);
2626
void redraw();
2727
void resize();
28+
void onPaused(bool paused) { _paused=paused; }
2829
void setSize(int w, int h) { _w = w; _h = h; }
2930

3031
private:
@@ -35,6 +36,7 @@ struct Graphics : ui::Graphics {
3536
FT_Byte *_fontBufferB;
3637
android_app *_app;
3738
int _w, _h;
39+
bool _paused;
3840
};
3941

4042
#endif

src/platform/android/jni/runtime.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ int get_sensor_events(int fd, int events, void *data) {
130130
return 1;
131131
}
132132

133+
extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_onActivityPaused
134+
(JNIEnv *env, jclass jclazz, jboolean paused) {
135+
if (runtime != NULL && !runtime->isClosing() && runtime->isActive() && os_graphics) {
136+
trace("paused=%d", paused);
137+
runtime->onPaused(paused);
138+
}
139+
}
140+
133141
// callback from MainActivity.java
134142
extern "C" JNIEXPORT jboolean JNICALL Java_net_sourceforge_smallbasic_MainActivity_optionSelected
135143
(JNIEnv *env, jclass jclazz, jint index) {

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct Runtime : public System {
6666
void share(const char *path) { setString("share", path); }
6767
void showCursor(CursorType cursorType) {}
6868
void showKeypad(bool show);
69+
void onPaused(bool paused) { if (_graphics != NULL) _graphics->onPaused(paused); }
6970
void onResize(int w, int h);
7071
void onUnicodeChar(int ch);
7172
void loadConfig();

0 commit comments

Comments
 (0)