Skip to content

Commit b54aac3

Browse files
committed
UI: Fix RGB handling with IMAGE
1 parent c8eb696 commit b54aac3

File tree

21 files changed

+267
-206
lines changed

21 files changed

+267
-206
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2021-06-12 (12.22)
2+
UI: Fix potential memory leak using IMAGE
3+
UI: Fix RGB handling with IMAGE
4+
ANDROID: restore home directory when resuming from run
5+
ANDROID: removed samsung keypad warning
6+
17
2021-06-06 (12.22)
28
UI: implemented image.draw(), fix image.save in andoid #115
39

src/platform/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
applicationId 'net.sourceforge.smallbasic'
1010
minSdkVersion 16
1111
targetSdkVersion 30
12-
versionCode 45
12+
versionCode 46
1313
versionName "12.22"
1414
resConfigs "en"
1515
}

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
import android.view.inputmethod.InputMethodManager;
3939
import android.widget.Toast;
4040

41+
import androidx.annotation.NonNull;
42+
import androidx.core.app.ActivityCompat;
43+
import androidx.core.content.ContextCompat;
44+
import androidx.core.content.FileProvider;
45+
4146
import java.io.BufferedOutputStream;
4247
import java.io.BufferedReader;
4348
import java.io.BufferedWriter;
@@ -63,8 +68,6 @@
6368
import java.net.Socket;
6469
import java.net.SocketException;
6570
import java.net.URLDecoder;
66-
import java.nio.file.Files;
67-
import java.nio.file.Path;
6871
import java.util.Date;
6972
import java.util.Enumeration;
7073
import java.util.HashMap;
@@ -78,10 +81,6 @@
7881
import java.util.concurrent.Semaphore;
7982
import java.util.zip.GZIPInputStream;
8083

81-
import androidx.annotation.NonNull;
82-
import androidx.core.app.ActivityCompat;
83-
import androidx.core.content.ContextCompat;
84-
import androidx.core.content.FileProvider;
8584
import dalvik.system.BaseDexClassLoader;
8685

8786
/**
@@ -471,7 +470,8 @@ public boolean removeLocationUpdates() {
471470
if (_locationAdapter != null) {
472471
LocationManager locationService = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
473472
if (locationService != null) {
474-
locationService.removeUpdates(_locationAdapter);
473+
// requires coarse location permission
474+
//locationService.removeUpdates(_locationAdapter);
475475
_locationAdapter = null;
476476
result = true;
477477
}
@@ -603,14 +603,7 @@ public void run() {
603603
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
604604
if (imm != null) {
605605
if (show) {
606-
String id = Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
607-
if (id != null && id.toLowerCase().contains("samsung")) {
608-
imm.showInputMethodPicker();
609-
String message = getResources().getString(R.string.samsung_keyboard);
610-
Toast.makeText(activity, message, Toast.LENGTH_LONG).show();
611-
} else {
612-
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
613-
}
606+
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
614607
} else {
615608
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
616609
}

src/platform/android/jni/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LOCAL_PATH := $(JNI_PATH)
1515
include $(CLEAR_VARS)
1616
LOCAL_MODULE := smallbasic
1717
LOCAL_CFLAGS := -DHAVE_CONFIG_H=1 -DLODEPNG_NO_COMPILE_CPP \
18-
-DPIXELFORMAT_RGBA8888 -Wno-unknown-pragmas
18+
-DPIXELFORMAT_ARGB8888 -Wno-unknown-pragmas
1919
LOCAL_C_INCLUDES := $(SB_HOME) $(SB_HOME)/src \
2020
$(FREETYPE_HOME)/freetype/include/freetype2 \
2121
$(FREETYPE_HOME)/freetype/include/freetype2/freetype

src/platform/android/jni/display.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ bool Graphics::construct(int fontId) {
145145
if (_screen && _screen->create(_w, _h)) {
146146
_drawTarget = _screen;
147147
maSetColor(DEFAULT_BACKGROUND);
148-
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM);
148+
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, PIXELFORMAT);
149149
result = true;
150150
} else {
151151
trace("Failed to create canvas");
@@ -163,9 +163,9 @@ void Graphics::redraw() {
163163
if (!locked) {
164164
trace("Unable to lock window buffer");
165165
} else {
166-
if (buffer.format != AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) {
166+
if (buffer.format != PIXELFORMAT) {
167167
ANativeWindow_unlockAndPost(_app->window);
168-
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM);
168+
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, PIXELFORMAT);
169169
locked = ANativeWindow_lock(_app->window, &buffer, nullptr) == 0;
170170
trace("Restore format %d", locked);
171171
}

src/platform/android/jni/runtime.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,7 @@ void Runtime::loadConfig() {
516516
_output->setFontSize(fontSize);
517517
_initialFontSize = _output->getFontSize();
518518

519-
const char *storage = getenv("EXTERNAL_DIR");
520-
if (!storage) {
521-
storage = getenv("INTERNAL_DIR");
522-
}
523-
if (storage) {
524-
setenv("HOME_DIR", storage, 1);
525-
chdir(storage);
526-
}
519+
onRunCompleted();
527520
if (loadSettings(settings)) {
528521
String *s = settings.get(FONT_SCALE_KEY);
529522
if (s) {
@@ -534,11 +527,6 @@ void Runtime::loadConfig() {
534527
_output->setFontSize(fontSize);
535528
}
536529
}
537-
s = settings.get(PATH_KEY);
538-
if (s) {
539-
trace("path = %s", s->c_str());
540-
chdir(s->c_str());
541-
}
542530
s = settings.get(MUTE_AUDIO_KEY);
543531
if (s && s->toInteger() == 1) {
544532
opt_mute_audio = 1;
@@ -896,6 +884,17 @@ void Runtime::onResize(int width, int height) {
896884
}
897885
}
898886

887+
void Runtime::onRunCompleted() {
888+
const char *storage = getenv("EXTERNAL_DIR");
889+
if (!storage) {
890+
storage = getenv("INTERNAL_DIR");
891+
}
892+
if (storage) {
893+
setenv("HOME_DIR", storage, 1);
894+
chdir(storage);
895+
}
896+
}
897+
899898
void Runtime::onUnicodeChar(int ch) {
900899
auto *maEvent = new MAEvent();
901900
maEvent->type = EVENT_TYPE_KEY_PRESSED;

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ struct Runtime : public System {
6161
void runShell();
6262
char *loadResource(const char *fileName);
6363
void optionsBox(StringList *items);
64-
void restoreWindowRect() {}
6564
void saveWindowRect() {}
6665
void setWindowSize(int width, int height) {};
6766
void setWindowTitle(const char *title) {}
@@ -70,6 +69,7 @@ struct Runtime : public System {
7069
void showKeypad(bool show);
7170
void onPaused(bool paused) { if (_graphics != NULL) _graphics->onPaused(paused); }
7271
void onResize(int w, int h);
72+
void onRunCompleted();
7373
void onUnicodeChar(int ch);
7474
void loadConfig();
7575
void loadEnvConfig(Properties<String *> &settings, const char *key);

src/platform/console/image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Copyright(C) 2002-2018 Chris Warren-Smith.
99

1010
#define LODEPNG_NO_COMPILE_CPP
11-
#define PIXELFORMAT_RGBA8888
11+
#define PIXELFORMAT_ARGB8888
1212
#define IMG_WIDTH "width"
1313
#define IMG_HEIGHT "height"
1414
#define IMG_NAME "name"

src/platform/fltk/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ AM_CPPFLAGS = \
1010
-DPACKAGE_PREFIX=\""$(prefix)"\" \
1111
-DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \
1212
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
13+
-DPIXELFORMAT_ARGB8888=1 \
1314
@PACKAGE_CFLAGS@ @FLTK_CXXFLAGS@
1415

1516
EXTRA_DIST = \

src/platform/fltk/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Runtime : public System {
2525
void enableCursor(bool enabled);
2626
int handle(int event);
2727
void optionsBox(StringList *items);
28-
void restoreWindowRect() {}
28+
void onRunCompleted() {}
2929
void saveWindowRect() {}
3030
MAEvent processEvents(int waitFlag);
3131
bool run(const char *bas) { return execute(bas); }

0 commit comments

Comments
 (0)