java - Android (NDK) openSoftInput in landscape mode -
i'm porting framework android ndk. , have use on screen keyboard once in while. opening , closing keyboard works far..
but have problem focus of keyboard in landscape mode (portrait mode works fine) - part of screen colored red still reacting on touch input if there no keyboard on it, 1 uncolored row of keyboard works expected , greenish part on keyboard not receive touch input.
i have tested usual android app well. same result (code see @ end of question).
i'm opening keyboard when klicking on "press me!" button , close softkey. code called open/close:
//adapted https://groups.google.com/d/msg/android-ndk/tk3g00wlkhk/tjqucoae_asj void androidcore::openonscreenkeyboard(bool open){ // attaches current thread jvm. jint lresult; jint lflags = 0; javavm* javavm = view->native_activity->vm; jnienv* jnienv; bool attached = false; if(javavm->getenv((void**)&jnienv, jni_version_1_6) ==jni_edetached){ javavmattachargs attachargs; attachargs.version = jni_version_1_6; attachargs.name = "nativethread"; attachargs.group = null; jint result = javavm->attachcurrentthread(&jnienv, &attachargs); if(result == jni_err){ return; } attached = true; } // retrieves context.input_method_service. jclass classcontext = jnienv->findclass("android/content/context"); jfieldid fieldinput_method_service = jnienv->getstaticfieldid(classcontext, "input_method_service", "ljava/lang/string;"); jobject input_method_service = jnienv->getstaticobjectfield(classcontext, fieldinput_method_service); jclass classnativeactivity = jnienv->findclass("android/app/nativeactivity"); jobject lnativeactivity = view->native_activity->clazz; // runs getsystemservice(context.input_method_service). jclass classinputmethodmanager = jnienv->findclass("android/view/inputmethod/inputmethodmanager"); jmethodid methodgetsystemservice = jnienv->getmethodid(classnativeactivity, "getsystemservice", "(ljava/lang/string;)ljava/lang/object;"); jobject linputmethodmanager = jnienv->callobjectmethod(lnativeactivity, methodgetsystemservice, input_method_service); // runs getwindow().getdecorview(). jmethodid methodgetwindow = jnienv->getmethodid(classnativeactivity, "getwindow", "()landroid/view/window;"); jobject lwindow = jnienv->callobjectmethod(lnativeactivity, methodgetwindow); jclass classwindow = jnienv->findclass("android/view/window"); jmethodid methodgetdecorview = jnienv->getmethodid(classwindow, "getdecorview", "()landroid/view/view;"); jobject ldecorview = jnienv->callobjectmethod(lwindow, methodgetdecorview); // runs lwindow.getviewtoken() jclass classview = jnienv->findclass("android/view/view"); jmethodid methodgetwindowtoken = jnienv->getmethodid(classview, "getwindowtoken", "()landroid/os/ibinder;"); jobject lbinder = jnienv->callobjectmethod(ldecorview, methodgetwindowtoken); if (open) { // runs linputmethodmanager.showsoftinput(...). jmethodid methodshowsoftinput = jnienv->getmethodid(classinputmethodmanager, "showsoftinput", "(landroid/view/view;i)z"); jboolean lresult = jnienv->callbooleanmethod(linputmethodmanager, methodshowsoftinput, ldecorview, lflags); } else { // linputmethodmanager.hidesoftinput(...). jmethodid methodhidesoftinput = jnienv->getmethodid(classinputmethodmanager, "hidesoftinputfromwindow", "(landroid/os/ibinder;i)z"); jboolean lres = jnienv->callbooleanmethod(linputmethodmanager, methodhidesoftinput, lbinder, lflags); } // finished jvm. javavm->detachcurrentthread(); }
java code similiar problem:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button = (button) findviewbyid(r.id.button); button.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { inputmethodmanager keyboard = (inputmethodmanager)getsystemservice(context.input_method_service); keyboard.showsoftinput(getwindow().getdecorview(), 0); //same showsoftinput(button, 0); } }); }
so can imagine, why focus problem happens? , can me fixing problem?
thanks!
Comments
Post a Comment