summaryrefslogtreecommitdiffstats
path: root/native/glue
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2010-07-13 17:48:30 -0700
committerDianne Hackborn <hackbod@google.com>2010-07-13 18:36:46 -0700
commitd76b67c340d1564abf8d14d976fdaf83bf2b3320 (patch)
tree59c0fff396681a622480a84f4f9c74d188970a11 /native/glue
parentfd03582995e0fce963dd0fa0669e3211b74c0dd7 (diff)
downloadframeworks_base-d76b67c340d1564abf8d14d976fdaf83bf2b3320.zip
frameworks_base-d76b67c340d1564abf8d14d976fdaf83bf2b3320.tar.gz
frameworks_base-d76b67c340d1564abf8d14d976fdaf83bf2b3320.tar.bz2
IME events are now dispatched to native applications.
And also: - APIs to show and hide the IME, and control its interaction with the app. - APIs to tell the app when its window resizes and needs to be redrawn. - API to tell the app the content rectangle of its window (to layout around the IME or status bar). There is still a problem with IME interaction -- we need a way for the app to deliver events to the IME before it handles them, so that for example the back key will close the IME instead of finishing the app. Change-Id: I37b75fc2ec533750ef36ca3aedd2f0cc0b5813cd
Diffstat (limited to 'native/glue')
-rw-r--r--native/glue/threaded_app/threaded_app.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/native/glue/threaded_app/threaded_app.c b/native/glue/threaded_app/threaded_app.c
index 2411e93..452c735 100644
--- a/native/glue/threaded_app/threaded_app.c
+++ b/native/glue/threaded_app/threaded_app.c
@@ -18,6 +18,7 @@
#include <jni.h>
#include <errno.h>
+#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/resource.h>
@@ -75,6 +76,19 @@ int32_t android_app_exec_cmd(struct android_app* android_app, int8_t cmd) {
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
break;
+
+ case APP_CMD_WINDOW_REDRAW_NEEDED:
+ LOGI("APP_CMD_WINDOW_REDRAW_NEEDED\n");
+ pthread_mutex_lock(&android_app->mutex);
+ android_app->redrawNeeded = 0;
+ pthread_cond_broadcast(&android_app->cond);
+ pthread_mutex_unlock(&android_app->mutex);
+ break;
+
+ case APP_CMD_CONTENT_RECT_CHANGED:
+ LOGI("APP_CMD_CONTENT_RECT_CHANGED\n");
+ android_app->contentRect = android_app->pendingContentRect;
+ break;
case APP_CMD_DESTROY:
LOGI("APP_CMD_DESTROY\n");
@@ -133,6 +147,12 @@ static struct android_app* android_app_create(ANativeActivity* activity) {
}
android_app->msgread = msgpipe[0];
android_app->msgwrite = msgpipe[1];
+ int result = fcntl(android_app->msgread, F_SETFL, O_NONBLOCK);
+ if (result != 0) LOGW("Could not make message read pipe "
+ "non-blocking: %s", strerror(errno));
+ result = fcntl(android_app->msgwrite, F_SETFL, O_NONBLOCK);
+ if (result != 0) LOGW("Could not make message write pipe "
+ "non-blocking: %s", strerror(errno));
pthread_attr_t attr;
pthread_attr_init(&attr);
@@ -184,6 +204,23 @@ static void android_app_set_activity_state(struct android_app* android_app, int8
pthread_mutex_unlock(&android_app->mutex);
}
+static void android_app_wait_redraw(struct android_app* android_app) {
+ pthread_mutex_lock(&android_app->mutex);
+ android_app->redrawNeeded = 1;
+ android_app_write_cmd(android_app, APP_CMD_WINDOW_REDRAW_NEEDED);
+ while (android_app->redrawNeeded) {
+ pthread_cond_wait(&android_app->cond, &android_app->mutex);
+ }
+ pthread_mutex_unlock(&android_app->mutex);
+}
+
+static void android_app_set_content_rect(struct android_app* android_app, const ARect* rect) {
+ pthread_mutex_lock(&android_app->mutex);
+ android_app->pendingContentRect = *rect;
+ android_app_write_cmd(android_app, APP_CMD_CONTENT_RECT_CHANGED);
+ pthread_mutex_unlock(&android_app->mutex);
+}
+
static void android_app_free(struct android_app* android_app) {
pthread_mutex_lock(&android_app->mutex);
android_app_write_cmd(android_app, APP_CMD_DESTROY);
@@ -231,6 +268,8 @@ static void onStop(ANativeActivity* activity) {
static void onLowMemory(ANativeActivity* activity) {
LOGI("LowMemory: %p\n", activity);
+ android_app_write_cmd((struct android_app*)activity->instance,
+ APP_CMD_LOW_MEMORY);
}
static void onWindowFocusChanged(ANativeActivity* activity, int focused) {
@@ -244,6 +283,23 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind
android_app_set_window((struct android_app*)activity->instance, window);
}
+static void onNativeWindowResized(ANativeActivity* activity, ANativeWindow* window) {
+ LOGI("NativeWindowResized: %p -- %p\n", activity, window);
+ android_app_write_cmd((struct android_app*)activity->instance,
+ APP_CMD_WINDOW_RESIZED);
+}
+
+static void onNativeWindowRedrawNeeded(ANativeActivity* activity, ANativeWindow* window) {
+ LOGI("NativeWindowRedrawNeeded: %p -- %p\n", activity, window);
+ android_app_wait_redraw((struct android_app*)activity->instance);
+}
+
+static void onContentRectChanged(ANativeActivity* activity, const ARect* rect) {
+ LOGI("ContentRectChanged: %p -- (%d,%d)-(%d,%d)\n", activity, rect->left,
+ rect->top, rect->right, rect->bottom);
+ android_app_set_content_rect((struct android_app*)activity->instance, rect);
+}
+
static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* window) {
LOGI("NativeWindowDestroyed: %p -- %p\n", activity, window);
android_app_set_window((struct android_app*)activity->instance, NULL);
@@ -268,12 +324,15 @@ void ANativeActivity_onCreate(ANativeActivity* activity,
activity->callbacks->onSaveInstanceState = onSaveInstanceState;
activity->callbacks->onPause = onPause;
activity->callbacks->onStop = onStop;
- activity->callbacks->onLowMemory = onLowMemory;
activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
+ activity->callbacks->onNativeWindowResized = onNativeWindowResized;
+ activity->callbacks->onNativeWindowRedrawNeeded = onNativeWindowRedrawNeeded;
activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
activity->callbacks->onInputQueueCreated = onInputQueueCreated;
activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;
+ activity->callbacks->onContentRectChanged = onContentRectChanged;
+ activity->callbacks->onLowMemory = onLowMemory;
activity->instance = android_app_create(activity);
}