Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: tools/viewer/sk_app/android/surface_glue_android.cpp

Issue 1965013007: Use swipe gesture to switch between slides on Android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Revision Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/viewer/sk_app/android/surface_glue_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..acee839a30edfca2318eb534a84c5a7ea46eacad 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,11 @@ 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}
+});
+
void* pthread_main(void* arg);
SkiaAndroidApp::SkiaAndroidApp() {
@@ -90,7 +97,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 +111,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 +185,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
« no previous file with comments | « tools/viewer/sk_app/android/surface_glue_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698