From 626ecbfca04e95bcb42390827112b2d7de1c903f Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Wed, 7 Mar 2018 23:01:50 +0000 Subject: Android: specific event for Android. Use Fl::add_system_handler() and Fl::event(), for example: FL_ANDROID_EVENT_LOW_MEMORY git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12720 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Enumerations.H | 24 ++++++++++++++++++++++ .../app/src/main/cpp/HelloAndroid.cxx | 8 ++++++++ src/drivers/Android/Fl_Android_Screen_Driver.cxx | 13 +++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/FL/Enumerations.H b/FL/Enumerations.H index 2a1908f8e..d97298073 100644 --- a/FL/Enumerations.H +++ b/FL/Enumerations.H @@ -406,6 +406,30 @@ enum Fl_Event { // events FL_ZOOM_GESTURE = 26 // DEV NOTE: Keep this list in sync with FL/names.h + +#ifdef __ANDROID__ + // These events are specific to the Android OS driver system. They can + // be read by adding a callback via Fl::add_system_handler() and reading Fl::event() + // Dont's change the order of these enums! See Fl_Android_Application.H . + , FL_ANDROID_EVENTS = 0x00010000, + FL_ANDROID_EVENT_INPUT_CHANGED, + FL_ANDROID_EVENT_INIT_WINDOW, + FL_ANDROID_EVENT_TERM_WINDOW, + FL_ANDROID_EVENT_WINDOW_RESIZED, + FL_ANDROID_EVENT_WINDOW_REDRAW_NEEDED, + FL_ANDROID_EVENT_CONTENT_RECT_CHANGED, + FL_ANDROID_EVENT_GAINED_FOCUS, + FL_ANDROID_EVENT_LOST_FOCUS, + FL_ANDROID_EVENT_CONFIG_CHANGED, + FL_ANDROID_EVENT_LOW_MEMORY, + FL_ANDROID_EVENT_START, + FL_ANDROID_EVENT_RESUME, + FL_ANDROID_EVENT_SAVE_STATE, + FL_ANDROID_EVENT_PAUSE, + FL_ANDROID_EVENT_STOP, + FL_ANDROID_EVENT_DESTROY +#endif + }; /** \name When Conditions */ diff --git a/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx b/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx index 3c99fb148..911683944 100644 --- a/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx +++ b/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx @@ -15,6 +15,7 @@ * */ +#include #include #include #include @@ -22,8 +23,15 @@ Fl_Window *win; Fl_Button *btn; +int h(void*, void*) +{ + Fl_Android_Application::log_w("App global even %p", Fl::event()); + return 0; +} + int main(int argc, char **argv) { + Fl::add_system_handler(h, 0); win = new Fl_Window(10, 10, 600, 400, "Hallo"); btn = new Fl_Button(190, 200, 280, 35, "Hello, Android!"); btn->color(FL_LIGHT2); diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.cxx b/src/drivers/Android/Fl_Android_Screen_Driver.cxx index 9156d8c83..be2c94248 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Screen_Driver.cxx @@ -59,11 +59,22 @@ Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() return new Fl_Android_Screen_Driver(); } + +extern int fl_send_system_handlers(void *e); + int Fl_Android_Screen_Driver::handle_app_command() { + // get the command int8_t cmd = Fl_Android_Application::read_cmd(); + + // setup the Android glue and prepare all settings for calling into FLTK Fl_Android_Application::pre_exec_cmd(cmd); - // TODO: call Fl::handle() with event parametrs set + + // call all registered FLTK system handlers + Fl::e_number = ((uint32_t)cmd-APP_CMD_INPUT_CHANGED) + FL_ANDROID_EVENT_INPUT_CHANGED; + fl_send_system_handlers(0L); + + // fixup and finalize application wide command handling Fl_Android_Application::post_exec_cmd(cmd); return 1; } -- cgit v1.2.3