Chromium Code Reviews| Index: tools/viewer/sk_app/android/surface_glue_android.cpp |
| diff --git a/tools/viewer/sk_app/android/surface_glue_android.cpp b/tools/viewer/sk_app/android/surface_glue_android.cpp |
| index b1d0029a108759588e21351f7fe868e078dc1151..fb2afb5637810fb7d80c65577f05a70c1c73ca21 100644 |
| --- a/tools/viewer/sk_app/android/surface_glue_android.cpp |
| +++ b/tools/viewer/sk_app/android/surface_glue_android.cpp |
| @@ -11,7 +11,9 @@ |
| #include <pthread.h> |
| #include <stdio.h> |
| #include <unistd.h> |
| +#include <unordered_map> |
| +#include <android/keycodes.h> |
| #include <android/looper.h> |
| #include <android/native_window_jni.h> |
| @@ -24,6 +26,9 @@ namespace sk_app { |
| static const int LOOPER_ID_MESSAGEPIPE = 1; |
| +static const std::unordered_map<int, Window::Key> ANDROID_TO_WINDOW_KEYMAP( |
| + {{AKEYCODE_SOFT_LEFT, Window::Key::kLeft}, {AKEYCODE_SOFT_RIGHT, Window::Key::kRight}}); |
|
djsollen
2016/05/11 19:05:25
order these with one per line so that they are eas
liyuqian
2016/05/11 19:11:24
Done.
|
| + |
| void* pthread_main(void* arg); |
| SkiaAndroidApp::SkiaAndroidApp() { |
| @@ -90,7 +95,6 @@ static int message_callback(int fd, int events, void* data) { |
| message.fNativeWindow); |
| int width = ANativeWindow_getWidth(skiaAndroidApp->fNativeWindow); |
| int height = ANativeWindow_getHeight(skiaAndroidApp->fNativeWindow); |
| - skiaAndroidApp->fWindow->onResize(width, height); |
| auto window_android = (Window_android*)skiaAndroidApp->fWindow; |
| window_android->setContentRect(0, 0, width, height); |
| skiaAndroidApp->paintIfNeeded(); |
| @@ -105,6 +109,14 @@ static int message_callback(int fd, int events, void* data) { |
| } |
| break; |
| } |
| + case kKeyPressed: { |
| + auto it = ANDROID_TO_WINDOW_KEYMAP.find(message.keycode); |
| + SkASSERT(it != ANDROID_TO_WINDOW_KEYMAP.end()); |
| + // No modifier is supported so far |
| + skiaAndroidApp->fWindow->onKey(it->second, Window::kDown_InputState, 0); |
| + skiaAndroidApp->fWindow->onKey(it->second, Window::kUp_InputState, 0); |
| + break; |
| + } |
| default: { |
| // do nothing |
| } |
| @@ -171,4 +183,14 @@ extern "C" JNIEXPORT void JNICALL Java_org_skia_viewer_ViewerActivity_onSurfaceD |
| skiaAndroidApp->postMessage(Message(kSurfaceDestroyed)); |
| } |
| +extern "C" JNIEXPORT void JNICALL Java_org_skia_viewer_ViewerActivity_onKeyPressed(JNIEnv* env, |
| + jobject activity, |
| + jlong handle, |
| + jint keycode) { |
| + auto skiaAndroidApp = (SkiaAndroidApp*)handle; |
| + Message message(kKeyPressed); |
| + message.keycode = keycode; |
| + skiaAndroidApp->postMessage(message); |
| +} |
| + |
| } // namespace sk_app |