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 958b7876b8baa674aec32cc89c684d8f7db0edda..daf26a3852ed2c6275816f4756829dc2d06a0567 100644 |
--- a/tools/viewer/sk_app/android/surface_glue_android.cpp |
+++ b/tools/viewer/sk_app/android/surface_glue_android.cpp |
@@ -46,6 +46,7 @@ SkiaAndroidApp::SkiaAndroidApp(JNIEnv* env, jobject androidApp) { |
fAndroidApp = env->NewGlobalRef(androidApp); |
jclass cls = env->GetObjectClass(fAndroidApp); |
fSetTitleMethodID = env->GetMethodID(cls, "setTitle", "(Ljava/lang/String;)V"); |
+ fSetStateMethodID = env->GetMethodID(cls, "setState", "(Ljava/lang/String;)V"); |
fNativeWindow = nullptr; |
pthread_create(&fThread, nullptr, pthread_main, this); |
} |
@@ -70,6 +71,12 @@ void SkiaAndroidApp::setTitle(const char* title) const { |
fPThreadEnv->DeleteLocalRef(titleString); |
} |
+void SkiaAndroidApp::setUIState(const Json::Value& state) const { |
+ jstring jstr = fPThreadEnv->NewStringUTF(state.toStyledString().c_str()); |
+ fPThreadEnv->CallVoidMethod(fAndroidApp, fSetStateMethodID, jstr); |
+ fPThreadEnv->DeleteLocalRef(jstr); |
+} |
+ |
void SkiaAndroidApp::postMessage(const Message& message) const { |
SkDEBUGCODE(auto writeSize =) write(fPipes[1], &message, sizeof(message)); |
SkASSERT(writeSize == sizeof(message)); |
@@ -139,6 +146,12 @@ int SkiaAndroidApp::message_callback(int fd, int events, void* data) { |
message.fTouchY); |
break; |
} |
+ case kUIStateChanged: { |
+ skiaAndroidApp->fWindow->onUIStateChanged(*message.stateName, *message.stateValue); |
+ delete message.stateName; |
+ delete message.stateValue; |
+ break; |
+ } |
default: { |
// do nothing |
} |
@@ -229,4 +242,17 @@ extern "C" JNIEXPORT void JNICALL Java_org_skia_viewer_ViewerActivity_onTouched( |
skiaAndroidApp->postMessage(message); |
} |
+extern "C" JNIEXPORT void JNICALL Java_org_skia_viewer_ViewerActivity_onUIStateChanged( |
+ JNIEnv* env, jobject activity, jlong handle, jstring stateName, jstring stateValue) { |
+ auto skiaAndroidApp = (SkiaAndroidApp*)handle; |
+ Message message(kUIStateChanged); |
+ const char* nameChars = env->GetStringUTFChars(stateName, nullptr); |
+ const char* valueChars = env->GetStringUTFChars(stateValue, nullptr); |
+ message.stateName = new SkString(nameChars); |
+ message.stateValue = new SkString(valueChars); |
+ skiaAndroidApp->postMessage(message); |
+ env->ReleaseStringUTFChars(stateName, nameChars); |
+ env->ReleaseStringUTFChars(stateValue, valueChars); |
+} |
+ |
} // namespace sk_app |