From 6491bf9ef6c5ca845eb757231365e55a6aba0736 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 26 Jan 2016 11:41:32 +1000 Subject: [PATCH 1/2] ANDROID: fix pause and resume --- configure.ac | 2 +- debian/changelog | 5 +++++ ide/android/AndroidManifest.xml | 4 ++-- ide/android/assets/main.bas | 2 +- src/platform/android/jni/runtime.cpp | 20 +++++++++++--------- src/platform/android/jni/runtime.h | 2 ++ src/platform/sdl/display.cpp | 13 +++++++++---- src/ui/form.cpp | 18 +++++++++++++++++- 8 files changed, 48 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index ef0426fa..9f887cd6 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0 dnl Download the GNU Public License (GPL) from www.gnu.org dnl -AC_INIT([smallbasic], [0.12.2]) +AC_INIT([smallbasic], [0.12.3]) AC_CONFIG_SRCDIR([configure.ac]) AC_CANONICAL_TARGET diff --git a/debian/changelog b/debian/changelog index 6f1915d8..48e51c12 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,8 @@ +smallbasic (0.12.3) unstable; urgency=low + * Various - see web site + + -- Chris Warren-Smith Tue, 26 Jan 2016 09:45:25 +1000 + smallbasic (0.12.2) unstable; urgency=low * Various - see web site diff --git a/ide/android/AndroidManifest.xml b/ide/android/AndroidManifest.xml index 2500765e..266a066b 100644 --- a/ide/android/AndroidManifest.xml +++ b/ide/android/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="17" + android:versionName="0.12.3"> diff --git a/ide/android/assets/main.bas b/ide/android/assets/main.bas index 49efafef..bdecd9f4 100644 --- a/ide/android/assets/main.bas +++ b/ide/android/assets/main.bas @@ -55,7 +55,7 @@ sub do_about() print "(_ ._ _ _.|||_) /\ (_ |/ " print "__)| | |(_||||_)/--\__)|\_" print - print "Version 0.12.2" + print "Version 0.12.3" print print "Copyright (c) 2002-2015 Chris Warren-Smith" print "Copyright (c) 1999-2006 Nic Christopoulos" + chr(10) diff --git a/src/platform/android/jni/runtime.cpp b/src/platform/android/jni/runtime.cpp index 5d57c8d6..5f4002cf 100644 --- a/src/platform/android/jni/runtime.cpp +++ b/src/platform/android/jni/runtime.cpp @@ -81,17 +81,18 @@ void handleCommand(android_app *app, int32_t cmd) { trace("handleCommand = %d", cmd); switch (cmd) { case APP_CMD_INIT_WINDOW: - // thread is ready to start - runtime->construct(); - break; - case APP_CMD_TERM_WINDOW: - if (runtime) { - // thread is ending - runtime->setExit(true); + // thread is ready to start or resume + if (runtime->isInitial()) { + runtime->construct(); } break; + case APP_CMD_GAINED_FOCUS: + trace("gainedFocus"); + runtime->setFocus(true); + break; case APP_CMD_LOST_FOCUS: - // display menu or exit + trace("lostFocus"); + runtime->setFocus(false); break; } } @@ -150,6 +151,7 @@ void onContentRectChanged(ANativeActivity *activity, const ARect *rect) { Runtime::Runtime(android_app *app) : System(), _keypadActive(false), + _hasFocus(false), _graphics(NULL), _app(app), _eventQueue(NULL) { @@ -603,7 +605,7 @@ void Runtime::pause(int timeout) { void Runtime::pollEvents(bool blocking) { int events; android_poll_source *source; - ALooper_pollAll(blocking ? -1 : 0, NULL, &events, (void **)&source); + ALooper_pollAll(blocking || !_hasFocus ? -1 : 0, NULL, &events, (void **)&source); if (source != NULL) { source->process(_app, source); } diff --git a/src/platform/android/jni/runtime.h b/src/platform/android/jni/runtime.h index 1aff33b5..6af9bd5b 100644 --- a/src/platform/android/jni/runtime.h +++ b/src/platform/android/jni/runtime.h @@ -57,9 +57,11 @@ struct Runtime : public System { void runPath(const char *path); void setClipboardText(const char *text); char *getClipboardText(); + void setFocus(bool focus) { _hasFocus = focus; } private: bool _keypadActive; + bool _hasFocus; Graphics *_graphics; android_app *_app; Stack *_eventQueue; diff --git a/src/platform/sdl/display.cpp b/src/platform/sdl/display.cpp index 33f121ef..0375103a 100644 --- a/src/platform/sdl/display.cpp +++ b/src/platform/sdl/display.cpp @@ -111,21 +111,26 @@ bool Graphics::construct(const char *font, const char *boldFont) { logEntered(); int w, h; - bool result = false; + bool result = true; SDL_GetWindowSize(_window, &w, &h); SDL_Surface *surface = SDL_GetWindowSurface(_window); - if (surface->format->format != PIXELFORMAT) { + if (surface == NULL) { + fprintf(stderr, "SDL surface is null\n"); + result = false; + } else if (surface->format == NULL) { + fprintf(stderr, "SDL surface format is null\n"); + result = false; + } else if (surface->format->format != PIXELFORMAT) { deviceLog("Unexpected window surface format %d", surface->format->format); _surface = surface; } - if (loadFonts(font, boldFont)) { + if (result && loadFonts(font, boldFont)) { _screen = new Canvas(); if (_screen != NULL) { if (_surface == NULL) { _screen->setSurface(SDL_GetWindowSurface(_window), w, h); - result = true; } else { result = _screen->create(w, h); } diff --git a/src/ui/form.cpp b/src/ui/form.cpp index 773d1968..58b74bda 100644 --- a/src/ui/form.cpp +++ b/src/ui/form.cpp @@ -34,6 +34,22 @@ void set_focus(FormInput *focus) { } } +struct FormTextInput : public TextEditInput { + FormTextInput(const char *text, int chW, int chH, int x, int y, int w, int h): + TextEditInput(text, chW, chH, x, y, w, h) { + } + + void clicked(int x, int y, bool pressed) { + TextEditInput::clicked(x, y, pressed); + if (pressed && g_system->isRunning()) { + set_focus(this); + updateForm(form); + mode = m_selected; + g_system->getOutput()->setDirty(); + } + } +}; + // returns setBG when the program colours are default int FormInput::getBackground(int buttonColor) const { int result = _bg; @@ -241,7 +257,7 @@ FormInput *create_input(var_p_t v_field) { text = value->v.p.ptr; } if (h * 2 >= charHeight) { - widget = new TextEditInput(text, charWidth, charHeight, x, y, w, h); + widget = new FormTextInput(text, charWidth, charHeight, x, y, w, h); } else { widget = new FormLineInput(text, maxSize, false, x, y, w, h); } From 344d433120faf0c8c2289e11ff8d5717e1eba51b Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 30 Jan 2016 17:37:06 +1000 Subject: [PATCH 2/2] COMMON: add simple cache and history handling --- ide/android/assets/main.bas | 12 ++++-- src/ui/system.cpp | 76 +++++++++++++++++++++++++++---------- src/ui/system.h | 8 ++++ 3 files changed, 72 insertions(+), 24 deletions(-) diff --git a/ide/android/assets/main.bas b/ide/android/assets/main.bas index bdecd9f4..ab7c2f53 100644 --- a/ide/android/assets/main.bas +++ b/ide/android/assets/main.bas @@ -155,6 +155,12 @@ sub serverInfo() fi end +func fileCmpFunc(l, r) + local f1 = lower(l) + local f2 = lower(r) + fileCmpFunc = IFF(f1 == f2, 0, IFF(f1 > f2, 1, -1)) +end + sub listFiles(byref frm, path, byref basList, byref dirList) local fileList, ent, name, lastItem, bn, bn_back @@ -181,15 +187,15 @@ sub listFiles(byref frm, path, byref basList, byref dirList) for ent in fileList name = ent - if (isdir(path + name)) then + if (isdir(path + name) && left(name, 1) != ".") then dirList << name else if (lower(right(ent, 4)) == ".bas") then basList << name endif next ent - sort dirList - sort basList + sort dirList use fileCmpFunc(x,y) + sort basList use filecmpfunc(x,y) lastItem = len(dirList) - 1 diff --git a/src/ui/system.cpp b/src/ui/system.cpp index efa21c2b..d53b5437 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -47,6 +47,7 @@ #define MENU_COMPETION_2 (MENU_SIZE + 3) #define MENU_COMPETION_3 (MENU_SIZE + 4) #define MAX_COMPLETIONS 4 +#define MAX_CACHE 8 #define FONT_SCALE_INTERVAL 10 #define FONT_MIN 20 @@ -56,9 +57,23 @@ System *g_system; +void Cache::add(const char *key, const char *value) { + if (_size == _count) { + // overwrite at next index position + _head[_index]->empty(); + _head[_index]->append(key); + _head[_index + 1]->empty(); + _head[_index + 1]->append(value); + _index = (_index + 2) % _size; + } else { + Properties::put(key, value); + } +} + System::System() : _output(NULL), _state(kInitState), + _cache(MAX_CACHE), _lastEventTime(0), _eventTicks(0), _touchX(-1), @@ -406,27 +421,35 @@ void System::handleEvent(MAEvent &event) { char *System::loadResource(const char *fileName) { char *buffer = NULL; if (strstr(fileName, "://") != NULL) { - int handle = 1; - var_t *var_p = v_new(); - dev_file_t *f = dev_getfileptr(handle); - _output->setStatus("Loading..."); - _output->redraw(); - if (dev_fopen(handle, fileName, 0)) { - if (http_read(f, var_p) == 0) { - systemPrint("\nfailed to read %s\n", fileName); + String *cached = _cache.get(fileName); + if (cached != NULL) { + int len = cached->length(); + buffer = (char *)malloc(len + 1); + memcpy(buffer, cached->c_str(), len); + } else { + int handle = 1; + var_t *var_p = v_new(); + dev_file_t *f = dev_getfileptr(handle); + _output->setStatus("Loading..."); + _output->redraw(); + if (dev_fopen(handle, fileName, 0)) { + if (http_read(f, var_p) == 0) { + systemPrint("\nfailed to read %s\n", fileName); + } else { + int len = var_p->v.p.size; + buffer = (char *)malloc(len + 1); + memcpy(buffer, var_p->v.p.ptr, len); + buffer[len] = '\0'; + _cache.add(fileName, buffer); + } } else { - int len = var_p->v.p.size; - buffer = (char *)malloc(len + 1); - memcpy(buffer, var_p->v.p.ptr, len); - buffer[len] = '\0'; + systemPrint("\nfailed to open %s\n", fileName); } - } else { - systemPrint("\nfailed to open %s\n", fileName); + _output->setStatus(NULL); + dev_fclose(handle); + v_free(var_p); + free(var_p); } - _output->setStatus(NULL); - dev_fclose(handle); - v_free(var_p); - free(var_p); } return buffer; } @@ -612,14 +635,25 @@ void System::setBack() { _output->selectBackScreen(_userScreenId); _output->selectFrontScreen(_userScreenId); _userScreenId = -1; - } else { - // quit app when shell is active - setExit(_mainBas); + } + + // quit app when shell is active + setExit(_mainBas); + + // follow history when available and not exiting + if (!_mainBas) { + // remove the current item + _history.pop(); + if (_history.peek() != NULL) { + _loadPath.empty(); + _loadPath.append(_history.peek()); + } } } void System::setLoadBreak(const char *path) { _loadPath = path; + _history.push(new strlib::String(path)); _state = kBreakState; brun_break(); } diff --git a/src/ui/system.h b/src/ui/system.h index a0a12593..3bea273a 100755 --- a/src/ui/system.h +++ b/src/ui/system.h @@ -18,6 +18,12 @@ #include "platform/fltk/system.h" #else +struct Cache : public strlib::Properties { + Cache(int size) : Properties(size * 2), _index(0) {} + void add(const char *key, const char *value); + int _index; +}; + struct System { System(); virtual ~System(); @@ -107,8 +113,10 @@ struct System { kDoneState // thread has terminated } _state; + strlib::Stack _history; strlib::String _loadPath; strlib::String _activeFile; + Cache _cache; int _lastEventTime; int _eventTicks; int _touchX;