#include <locale.h>
#include <pthread.h>
#include <unistd.h>
+#include <sys/prctl.h>
#include <android/configuration.h>
#include <android/looper.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "ecere-app", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "ecere-app", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "ecere-app", __VA_ARGS__))
-#ifdef _DEBUG
+#ifndef _DEBUG
#define LOGV(...) ((void)0)
#else
#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "ecere-app", __VA_ARGS__))
#endif
// *** NATIVE APP GLUE ********
-enum LooperID : byte { main = 1, input = 2, user = 3 };
+enum LooperID { main = 1, input = 2, user = 3 };
enum AppCommand : byte
{
error = 0, inputChanged, initWindow, termWindow, windowResized, windowRedrawNeeded,
AInputEvent* event = null;
if(AInputQueue_getEvent(inputQueue, &event) >= 0)
{
- int handled = 0;
+ //int handled = 0;
LOGV("New input event: type=%d\n", AInputEvent_getType(event));
if(AInputQueue_preDispatchEvent(inputQueue, event))
return;
- handled = onInputEvent(event);
+ /*handled = */onInputEvent(event);
//AInputQueue_finishEvent(inputQueue, event, handled);
}
else
void pre_exec_cmd(AppCommand cmd)
{
- PrintLn("pre_exec_cmd: ", (int)cmd);
+ //PrintLn("pre_exec_cmd: ", cmd);
switch(cmd)
{
case inputChanged:
void post_exec_cmd(AppCommand cmd)
{
- PrintLn("post_exec_cmd: ", (int)cmd);
+ //PrintLn("post_exec_cmd: ", cmd);
switch(cmd)
{
case termWindow:
savedStateSize = 0;
}
- void Create()
+ public void Create()
{
int msgpipe[2];
if(pipe(msgpipe))
static void onDestroy(ANativeActivity* activity)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("Destroy: %p\n", activity);
+ LOGI("Destroy: %p\n", activity);
app.cleanup();
app.Wait();
delete androidActivity;
delete __androidCurrentModule;
- LOGV("THE END.");
+ LOGI("THE END.");
}
static void onStart(ANativeActivity* activity)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("Start: %p\n", activity);
+ LOGI("Start: %p\n", activity);
app.set_activity_state(start);
}
static void onResume(ANativeActivity* activity)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("Resume: %p\n", activity);
+ LOGI("Resume: %p\n", activity);
app.set_activity_state(resume);
}
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
void* savedState = null;
- LOGV("SaveInstanceState: %p\n", activity);
+ LOGI("SaveInstanceState: %p\n", activity);
app.mutex.Wait();
app.stateSaved = false;
app.write_cmd(saveState);
static void onPause(ANativeActivity* activity)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("Pause: %p\n", activity);
+ LOGI("Pause: %p\n", activity);
app.set_activity_state(pause);
}
static void onStop(ANativeActivity* activity)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("Stop: %p\n", activity);
+ LOGI("Stop: %p\n", activity);
app.set_activity_state(stop);
}
static void onConfigurationChanged(ANativeActivity* activity)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("ConfigurationChanged: %p\n", activity);
+ LOGI("ConfigurationChanged: %p\n", activity);
app.write_cmd(configChanged);
}
static void onLowMemory(ANativeActivity* activity)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("LowMemory: %p\n", activity);
+ LOGI("LowMemory: %p\n", activity);
app.write_cmd(lowMemory);
}
static void onWindowFocusChanged(ANativeActivity* activity, int focused)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("WindowFocusChanged: %p -- %d\n", activity, focused);
+ LOGI("WindowFocusChanged: %p -- %d\n", activity, focused);
app.write_cmd(focused ? gainedFocus : lostFocus);
}
static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("NativeWindowCreated: %p -- %p\n", activity, window);
+ LOGI("NativeWindowCreated: %p -- %p\n", activity, window);
app.set_window(window);
}
static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* window)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("NativeWindowDestroyed: %p -- %p\n", activity, window);
+ LOGI("NativeWindowDestroyed: %p -- %p\n", activity, window);
app.set_window(null);
}
static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("InputQueueCreated: %p -- %p\n", activity, queue);
+ LOGI("InputQueueCreated: %p -- %p\n", activity, queue);
app.set_input(queue);
}
static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue)
{
AndroidAppGlue app = (AndroidAppGlue)activity->instance;
- LOGV("InputQueueDestroyed: %p -- %p\n", activity, queue);
+ LOGI("InputQueueDestroyed: %p -- %p\n", activity, queue);
app.inputQueue = null;
app.set_input(null);
}
__thisModule = null;
__androidCurrentModule = null;
- LOGV("Creating: %p\n", activity);
+ prctl(PR_SET_DUMPABLE, 1);
+
+ LOGI("Creating: %p\n", activity);
//(*activity->vm)->AttachCurrentThread(activity->vm, &env, 0);
clazz = (*env)->GetObjectClass(env, activity->clazz);
eModule_Load(__androidCurrentModule, "ecere", publicAccess);
+ /*
if(activity->internalDataPath) PrintLn("internalDataPath is ", activity->internalDataPath);
if(activity->externalDataPath) PrintLn("externalDataPath is ", activity->externalDataPath);
{
char tmp[256];
PrintLn("cwd is ", GetWorkingDir(tmp, sizeof(tmp)));
}
+ */
ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_FULLSCREEN|AWINDOW_FLAG_KEEP_SCREEN_ON, 0 );
app = AndroidActivity { activity = activity, moduleName = moduleName };
static int desktopW, desktopH;
static char * clipBoardData;
+static int mouseX, mouseY;
class AndroidInterface : Interface
{
bool ProcessInput(bool processAll)
{
bool eventAvailable = false;
- if(androidActivity.ident >= 0)
+
+ if(androidActivity.ident < 0)
+ androidActivity.ident = (LooperID)ALooper_pollAll(0, null, &androidActivity.events, (void**)&androidActivity.source);
+
+ if(gotInit && androidActivity.window)
+ {
+ int w = ANativeWindow_getWidth(androidActivity.window);
+ int h = ANativeWindow_getHeight(androidActivity.window);
+ if(desktopW != w || desktopH != h)
+ {
+ guiApp.SetDesktopPosition(0, 0, w, h, true);
+ desktopW = w;
+ desktopH = h;
+ guiApp.desktop.Update(null);
+ }
+ }
+
+ while(androidActivity.ident >= 0)
{
AndroidPollSource source = androidActivity.source;
- //PrintLn("androidActivity.ident >= 0");
- // Process this event.
- androidActivity.ident = 0;
+
androidActivity.source = null;
if(source)
source.process(source.userData);
}
}
*/
- // eventAvailable = true;
+
+ eventAvailable = true;
if(androidActivity.destroyRequested)
{
guiApp.desktop.Destroy(0);
eventAvailable = true;
+ androidActivity.ident = (LooperID)-1;
}
+ else if(processAll)
+ androidActivity.ident = (LooperID)ALooper_pollAll(0, null, &androidActivity.events, (void**)&androidActivity.source);
+ else
+ androidActivity.ident = (LooperID)-1;
}
-
- if(androidActivity.animating)
- guiApp.desktop.Update(null);
-
- if(!eventAvailable)
- return false;
- return true;
+ return eventAvailable;
}
void Wait()
{
- androidActivity.ident = (LooperID)ALooper_pollAll(androidActivity.animating ? 0 : -1, null, &androidActivity.events, (void**)&androidActivity.source);
+ androidActivity.ident = (LooperID)ALooper_pollAll((int)(1000/18.2f), null, &androidActivity.events, (void**)&androidActivity.source);
// guiApp.WaitEvent();
}
}
- char ** GraphicsDrivers(int * numDrivers)
+ const char ** GraphicsDrivers(int * numDrivers)
{
- static char *graphicsDrivers[] = { "OpenGL" };
+ static const char *graphicsDrivers[] = { "OpenGL" };
*numDrivers = sizeof(graphicsDrivers) / sizeof(char *);
- return (char **)graphicsDrivers;
+ return (const char **)graphicsDrivers;
}
void GetCurrentMode(bool * fullScreen, int * resolution, int * colorDepth, int * refreshRate)
// -- Window manipulation ---
- void SetRootWindowCaption(Window window, char * name)
+ void SetRootWindowCaption(Window window, const char * name)
{
}
void GetMousePosition(int *x, int *y)
{
- int rootWindow, childWindow;
- int mx, my;
- unsigned int state;
+ *x = mouseX;
+ *y = mouseY;
}
void SetMousePosition(int x, int y)
{
-
+ mouseX = x;
+ mouseY = y;
}
void SetMouseRange(Window window, Box box)
// -- Mouse cursor ---
- void SetMouseCursor(int cursor)
+ void SetMouseCursor(Window window, int cursor)
{
if(cursor == -1)
{
if(window && window.windowData)
{
}
- }
+ }
void ClearClipboard()
{
{
bool result = false;
if((clipBoard.text = new0 byte[size]))
- result = true;
+ result = true;
return result;
}
bool GetKeyState(Key key)
{
- int keyState = 0;
+ bool keyState = false;
return keyState;
}
void SetTimerResolution(uint hertz)
{
// timerDelay = hertz ? (1000000 / hertz) : MAXINT;
- }
+ }
bool SetIcon(Window window, BitmapResource resource)
{
static AndroidActivity androidActivity;
+default const char * AndroidInterface_GetLibLocation(Application a)
+{
+ static char loc[MAX_LOCATION];
+ // sprintf(loc, "/data/data/com.ecere.%s/lib/lib", a.argv[0]);
+ sprintf(loc, "/data/app/com.ecere.%s-1/lib/arm64/lib", a.argv[0]);
+ return loc;
+}
+
static bool gotInit;
default float AMotionEvent_getAxisValue(const AInputEvent* motion_event,
int32_t axis, size_t pointer_index);
+
+static define AMETA_META_ON = 0x00010000;
+static define AMETA_META_LEFT_ON = 0x00020000;
+static define AMETA_META_RIGHT_ON = 0x00040000;
+
static Key keyCodeTable[] =
{
0, //AKEYCODE_UNKNOWN = 0,
k9, //AKEYCODE_9 = 16,
keyPadStar, //AKEYCODE_STAR = 17,
Key { k3, shift = true }, //AKEYCODE_POUND = 18,
- wheelDown, //AKEYCODE_DPAD_UP = 19,
- wheelUp, //AKEYCODE_DPAD_DOWN = 20,
- wheelDown, //AKEYCODE_DPAD_LEFT = 21,
- wheelUp, //AKEYCODE_DPAD_RIGHT = 22,
+ up, //AKEYCODE_DPAD_UP = 19,
+ down, //AKEYCODE_DPAD_DOWN = 20,
+ left, //AKEYCODE_DPAD_LEFT = 21,
+ right, //AKEYCODE_DPAD_RIGHT = 22,
keyPad5, //AKEYCODE_DPAD_CENTER = 23,
0, //AKEYCODE_VOLUME_UP = 24,
0, //AKEYCODE_VOLUME_DOWN = 25,
z, //AKEYCODE_Z = 54,
comma, //AKEYCODE_COMMA = 55,
period, //AKEYCODE_PERIOD = 56,
- Key { left, alt = true }, //AKEYCODE_ALT_LEFT = 57,
- Key { right, alt = true }, //AKEYCODE_ALT_RIGHT = 58,
- Key { left, shift = true }, //AKEYCODE_SHIFT_LEFT = 59,
- Key { right, shift = true }, //AKEYCODE_SHIFT_RIGHT = 60,
+ leftAlt, //AKEYCODE_ALT_LEFT = 57,
+ rightAlt, //AKEYCODE_ALT_RIGHT = 58,
+ leftShift, //AKEYCODE_SHIFT_LEFT = 59,
+ rightShift, //AKEYCODE_SHIFT_RIGHT = 60,
tab, //AKEYCODE_TAB = 61,
space, //AKEYCODE_SPACE = 62,
0, //AKEYCODE_SYM = 63,
0, //AKEYCODE_EXPLORER = 64,
0, //AKEYCODE_ENVELOPE = 65,
enter, //AKEYCODE_ENTER = 66,
- del, //AKEYCODE_DEL = 67,
+ backSpace, //AKEYCODE_DEL = 67,
backQuote, //AKEYCODE_GRAVE = 68,
minus, //AKEYCODE_MINUS = 69,
plus, //AKEYCODE_EQUALS = 70,
quote, //AKEYCODE_APOSTROPHE = 75,
slash, //AKEYCODE_SLASH = 76,
Key { k2, shift = true }, //AKEYCODE_AT = 77,
- 0, //AKEYCODE_NUM = 78,
+ 0, //AKEYCODE_NUM = 78, // Interpreted as an Alt
0, //AKEYCODE_HEADSETHOOK = 79,
0, //AKEYCODE_FOCUS = 80, // *Camera* focus
keyPadPlus, //AKEYCODE_PLUS = 81,
0, //AKEYCODE_BUTTON_START = 108,
0, //AKEYCODE_BUTTON_SELECT = 109,
0, //AKEYCODE_BUTTON_MODE = 110,
+ escape, //AKEYCODE_BUTTON_ESCAPE = 111,
+ del, //AKEYCODE_BUTTON_ESCAPE = 112,
+ leftControl, // = 113
+ rightControl, // = 114
+ capsLock, // = 115
+ scrollLock, // = 116
+ 0, // = 117 KEYCODE_META_LEFT
+ 0, // = 118 KEYCODE_META_RIGHT
+ 0, // = 119 KEYCODE_FUNCTION
+ printScreen, // = 120 KEYCODE_SYSRQ
+ pauseBreak, // = 121
+ home, // = 122
+ end, // = 123
+ insert // = 124
};
+// Why don't we have this in the NDK :(
+// default int32_t AKeyEvent_getUnichar(const AInputEvent* key_event);
+
class AndroidActivity : AndroidAppGlue
{
AndroidPollSource source;
const ASensor* accelerometerSensor;
ASensorEventQueue* sensorEventQueue;
*/
- bool animating;
SavedState state;
int onInputEvent(AInputEvent* event)
if(type == AINPUT_EVENT_TYPE_MOTION)
{
uint actionAndIndex = AMotionEvent_getAction(event);
- uint source = AInputEvent_getSource(event);
+ //uint source = AInputEvent_getSource(event);
uint action = actionAndIndex & AMOTION_EVENT_ACTION_MASK;
- uint index = (actionAndIndex & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
- uint flags = AMotionEvent_getFlags(event);
+ //uint index = (actionAndIndex & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+ //uint flags = AMotionEvent_getFlags(event);
uint meta = AMotionEvent_getMetaState(event);
- uint edge = AMotionEvent_getEdgeFlags(event);
- int64 downTime = AMotionEvent_getDownTime(event); // nanotime
- int64 eventTime = AMotionEvent_getDownTime(event);
+ //uint edge = AMotionEvent_getEdgeFlags(event);
+ //int64 downTime = AMotionEvent_getDownTime(event); // nanotime
+ //int64 eventTime = AMotionEvent_getDownTime(event);
//float axis;
Modifiers keyFlags = 0;
int x = (int)AMotionEvent_getX(event, 0);
int y = (int)AMotionEvent_getY(event, 0);
+ bool shift = (meta & AMETA_SHIFT_ON) ? true : false;
+ bool alt = (meta & AMETA_ALT_ON) ? true : false;
+ //bool sym = (meta & AMETA_SYM_ON) ? true : false;
+
+ keyFlags.shift = shift;
+ keyFlags.alt = alt;
+
//PrintLn("Got a motion input event: ", action);
/*
if(action == 8) //AMOTION_EVENT_ACTION_SCROLL)
- axis = AMotionEvent_getAxisValue(event, 9, index); //AMOTION_EVENT_AXIS_VSCROLL);
+ axis = AMotionEvent_getAxisValue(event, 9, index); //AMOTION_EVENT_AXIS_VSCROLL);
*/
AInputQueue_finishEvent(inputQueue, event, 1);
break;
*/
case AMOTION_EVENT_ACTION_DOWN:
+ mouseX = x, mouseY = y;
window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown, x, y, &keyFlags, false, true);
break;
case AMOTION_EVENT_ACTION_UP:
+ mouseX = x, mouseY = y;
window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp, x, y, &keyFlags, false, true);
break;
case AMOTION_EVENT_ACTION_MOVE:
+ mouseX = x, mouseY = y;
window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &keyFlags, false, true);
break;
case AMOTION_EVENT_ACTION_CANCEL: break;
case AMOTION_EVENT_ACTION_POINTER_DOWN: break;
case AMOTION_EVENT_ACTION_POINTER_UP: break;
}
-
- animating = true;
return 1;
}
else if(type == AINPUT_EVENT_TYPE_KEY)
{
uint action = AKeyEvent_getAction(event);
- uint flags = AKeyEvent_getFlags(event);
+ //uint flags = AKeyEvent_getFlags(event);
uint keyCode = AKeyEvent_getKeyCode(event);
uint meta = AKeyEvent_getMetaState(event);
Key key = keyCodeTable[keyCode];
+ bool shift = (meta & AMETA_SHIFT_ON) ? true : false;
+ bool alt = (meta & AMETA_ALT_ON || meta & AMETA_ALT_LEFT_ON || meta & AMETA_ALT_RIGHT_ON) ? true : false;
+ //bool metaMeta = (meta & AMETA_META_ON || meta & AMETA_META_LEFT_ON || meta & AMETA_META_RIGHT_ON) ? true : false;
+ //bool sym = (meta & AMETA_SYM_ON) ? true : false;
+ //unichar ch = AKeyEvent_getUnichar(event);
+ unichar ch = 0;
+
+ key.shift = shift;
+ key.alt = alt;
AInputQueue_finishEvent(inputQueue, event, 1);
- //PrintLn("Got a key: action = ", action, ", flags = ", flags, ", keyCode = ", keyCode, ", meta = ", meta, ": key = ", (int)key);
+ // PrintLn("Got a key: action = ", action, ", flags = ", flags, ", keyCode = ", keyCode, ", meta = ", meta, ": key = ", (int)key);
if(key)
{
- if(action == AKEY_STATE_DOWN)
+ if(action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_MULTIPLE)
{
- window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit, key, 0);
+ /*if(key == wheelDown || key == wheelUp)
+ window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit, key, ch);
+ else*/
+ {
+ char c = Interface::TranslateKey(key.code, shift);
+ if(c > 0) ch = c;
+ window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, key, ch);
+ }
}
+ else if(action == AKEY_EVENT_ACTION_UP)
+ window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, ch);
}
return 1;
}
{
int w, h;
gotInit = true;
- PrintLn("onAppCmd: initWindow");
ANativeWindow_setBuffersGeometry(window, 0, 0, 0); //format);
w = ANativeWindow_getWidth(window);
h = ANativeWindow_getHeight(window);
}
break;
case termWindow:
- animating = false;
guiApp.desktop.UnloadGraphics(false);
break;
case gainedFocus:
- androidActivity.animating = true;
+ guiApp.desktop.Update(null);
guiApp.SetAppFocus(true);
/*
if(accelerometerSensor)
if(accelerometerSensor)
ASensorEventQueue_disableSensor(sensorEventQueue, accelerometerSensor);
*/
- animating = false;
guiApp.SetAppFocus(false);
guiApp.desktop.Update(null);
break;
+ case configChanged:
+ if(window)
+ guiApp.desktop.UpdateDisplay();
+ break;
}
}
{
Module app;
-
+
// Evolve the Application class into a GuiApplication
eInstance_Evolve((Instance *)&__androidCurrentModule, class(GuiApplication));
for(c = app.classes.first; c && !eClass_IsDerived(c, class(GuiApplication)); c = c.next);
if(!c) c = class(GuiApplication);
+ guiApp.lockMutex.Release(); // TOCHECK: Seems the evolve is losing our mutex lock here ?
+
// Evolve the Application into it
eInstance_Evolve((Instance *)&__androidCurrentModule, c);
guiApp = (GuiApplication)__androidCurrentModule;
{
- String skin = guiApp.skin;
+ const String skin = guiApp.skin;
*&guiApp.currentSkin = null;
guiApp.SelectSkin(skin);
}
+ guiApp.lockMutex.Wait();
+
// Call Main()
- __androidCurrentModule._vTbl[12](__androidCurrentModule);
+ ((void (*)(void *))(void *)__androidCurrentModule._vTbl[12])(__androidCurrentModule);
}
if(!destroyRequested)