i have java code displays numeric soft keyboard in android:
public class mainactivity extends activity { edittext ed1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); ed1 = (edittext) findviewbyid(r.id.edittext1); ed1.setinputtype(inputtype.type_class_number); } }
my activity_main.xml file:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="numberkeypad.inputmethod.mainactivity" > <edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:ems="10" > </edittext>
the output is: numeric soft keyboard
i want display same keyboard using ndk jni call , no edittext. have implemented default keyboard in way using following link:
how show soft keyboard on native activity
but facing lot of trouble using same methodology numeric keyboard. great..thanks!
could not find way directly, had override oncreateinputconnection method of view class, , make jni call function using overridden method.
public class numbersview extends view { public numbersview(context context) { super(context); } @override public inputconnection oncreateinputconnection(editorinfo outattrs) { inputconnection inputconnection = super.oncreateinputconnection(outattrs); switch(systemkeyboardtype){ case inputtype.type_class_phone: outattrs.inputtype |= inputtype.type_class_phone; break; case inputtype.type_class_text: outattrs.inputtype |= inputtype.type_class_text; break; case inputtype.type_class_number: outattrs.inputtype |= inputtype.type_class_number; break; case inputtype.type_class_datetime: outattrs.inputtype |= inputtype.type_class_datetime; break; default: outattrs.inputtype |= inputtype.type_class_text; break; } return inputconnection; } } **/ @override protected void oncreate(bundle savedinstancestate) { calculatedevicedpi(); super.oncreate(savedinstancestate); myview = new numbersview(getapplicationcontext()); addcontentview(myview,new viewgroup.layoutparams( viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content)); myview.setfocusable(true); myview.setfocusableintouchmode(true); //myview.requestfocus(); mcontext = this; } public void displaysystemkeyboard(string keyboardtype){ if(keyboardtype.equals("text")) { systemkeyboardtype = inputtype.type_class_text; } else if(keyboardtype.equals("phone")) { systemkeyboardtype = inputtype.type_class_phone; } else if(keyboardtype.equals("number")) { systemkeyboardtype = inputtype.type_class_number; } else if(keyboardtype.equals("datetime")) { systemkeyboardtype = inputtype.type_class_datetime; } else { systemkeyboardtype = inputtype.type_class_datetime; } context ctx = getapplicationcontext(); inputmethodmanager mgr = (inputmethodmanager) ctx.getsystemservice(context.input_method_service); myview.requestfocus(); // trigger if no physical keyboard open mgr.restartinput(myview); mgr.showsoftinput(myview, 0); } public void hidesystemkeyboard(){ context ctx = getapplicationcontext(); view myview = this.getwindow().getdecorview(); inputmethodmanager mgr = (inputmethodmanager) ctx.getsystemservice(context.input_method_service); mgr.hidesoftinputfromwindow(myview.getwindowtoken(), 0); }
and made jni call function:
if(pshow){ jmethodid showsyskeys = ljnienv->getmethodid(lclassdeviceapi,"displaysystemkeyboard","(ljava/lang/string;)v"); if(showsyskeys == null){ logi("displaysystemkeyboard::couldn't void displaysystemkeyboard method"); return; } jstring keyboardtype = ljnienv->newstringutf(keyboardtype.c_str()); if(!keyboardtype) { logi( "failed alloc param string in java." ); return; }; ljnienv->callvoidmethod(lobjdeviceapi,showsyskeys, keyboardtype); } else{ jmethodid hidesyskeys = ljnienv->getmethodid(lclassdeviceapi,"hidesystemkeyboard","()v"); if(hidesyskeys == null){ logi("hidesystemkeyboard::couldn't void hidesystemkeyboard method"); return; } ljnienv->callvoidmethod(lobjdeviceapi,hidesyskeys); } ljavavm->detachcurrentthread();
Comments
Post a Comment