Added Android boilerplate for CLIPBOARD_MANAGER
This still fails due to obviously running in the wrong thread. Looking for suggestions.
This commit is contained in:
parent
35680e6405
commit
30a22bfbbe
|
@ -26,8 +26,10 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Android/ClipboardImpl.hpp>
|
||||
#include <SFML/System/Android/Activity.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
#include <SFML/System/Lock.hpp>
|
||||
#include <jni.h>
|
||||
|
||||
namespace sf
|
||||
{
|
||||
|
@ -36,8 +38,81 @@ namespace priv
|
|||
////////////////////////////////////////////////////////////
|
||||
String ClipboardImpl::getString()
|
||||
{
|
||||
sf::err() << "Clipboard API not implemented for Android.\n";
|
||||
return String();
|
||||
String content;
|
||||
|
||||
ActivityStates* states = getActivity(NULL);
|
||||
Lock lock(states->mutex);
|
||||
|
||||
// Initializes JNI
|
||||
jint lResult;
|
||||
jint lFlags = 0;
|
||||
|
||||
JavaVM* lJavaVM = states->activity->vm;
|
||||
JNIEnv* lJNIEnv = states->activity->env;
|
||||
|
||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
||||
lJavaVMAttachArgs.name = "NativeThread";
|
||||
lJavaVMAttachArgs.group = NULL;
|
||||
|
||||
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
|
||||
|
||||
if (lResult == JNI_ERR)
|
||||
err() << "Failed to initialize JNI, couldn't switch the keyboard visibility" << std::endl;
|
||||
|
||||
// Retrieves NativeActivity
|
||||
jobject lNativeActivity = states->activity->clazz;
|
||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
|
||||
|
||||
// Retrieves Context.CLIPBOARD_SERVICE
|
||||
jclass ClassContext = lJNIEnv->FindClass("android/content/Context");
|
||||
jfieldID FieldCLIPBOARD_SERVICE = lJNIEnv->GetStaticFieldID(ClassContext,
|
||||
"CLIPBOARD_SERVICE", "Ljava/lang/String;");
|
||||
jobject CLIPBOARD_SERVICE = lJNIEnv->GetStaticObjectField(ClassContext,
|
||||
FieldCLIPBOARD_SERVICE);
|
||||
lJNIEnv->DeleteLocalRef(ClassContext);
|
||||
|
||||
// Runs getSystemService(Context.CLIPBOARD_SERVICE)
|
||||
jclass ClassInputMethodManager =
|
||||
lJNIEnv->FindClass("android/view/inputmethod/InputMethodManager");
|
||||
jmethodID MethodGetSystemService = lJNIEnv->GetMethodID(ClassNativeActivity,
|
||||
"getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
|
||||
jobject lInputMethodManager = lJNIEnv->CallObjectMethod(lNativeActivity,
|
||||
MethodGetSystemService, CLIPBOARD_SERVICE);
|
||||
lJNIEnv->DeleteLocalRef(CLIPBOARD_SERVICE);
|
||||
|
||||
/*if (visible)
|
||||
{
|
||||
// Runs lInputMethodManager.showSoftInput(...)
|
||||
jmethodID MethodShowSoftInput = lJNIEnv->GetMethodID(ClassInputMethodManager,
|
||||
"showSoftInput", "(Landroid/view/View;I)Z");
|
||||
jboolean lResult = lJNIEnv->CallBooleanMethod(lInputMethodManager,
|
||||
MethodShowSoftInput, lDecorView, lFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Runs lWindow.getViewToken()
|
||||
jclass ClassView = lJNIEnv->FindClass("android/view/View");
|
||||
jmethodID MethodGetWindowToken = lJNIEnv->GetMethodID(ClassView,
|
||||
"getWindowToken", "()Landroid/os/IBinder;");
|
||||
jobject lBinder = lJNIEnv->CallObjectMethod(lDecorView,
|
||||
MethodGetWindowToken);
|
||||
lJNIEnv->DeleteLocalRef(ClassView);
|
||||
|
||||
// lInputMethodManager.hideSoftInput(...)
|
||||
jmethodID MethodHideSoftInput = lJNIEnv->GetMethodID(ClassInputMethodManager,
|
||||
"hideSoftInputFromWindow", "(Landroid/os/IBinder;I)Z");
|
||||
jboolean lRes = lJNIEnv->CallBooleanMethod(lInputMethodManager,
|
||||
MethodHideSoftInput, lBinder, lFlags);
|
||||
lJNIEnv->DeleteLocalRef(lBinder);
|
||||
}*/
|
||||
lJNIEnv->DeleteLocalRef(ClassNativeActivity);
|
||||
lJNIEnv->DeleteLocalRef(ClassInputMethodManager);
|
||||
|
||||
// Finished with the JVM
|
||||
lJavaVM->DetachCurrentThread();
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue