-
Import Android. content. context;
-
Import Android. Text. editable;
-
Import Android. Text. inputfilter;
-
Import Android. Text. inputtype;
-
Import Android. Text. textwatcher;
-
Import Android. Text. method. passwordtransformationmethod;
-
Import Android. View. keyevent;
-
Import Android. View. view;
-
Import Android. View. View. onkeylistener;
-
Import Android. View. inputmethod. inputmethodmanager;
-
Import Android. widget. edittext;
-
-
Import com. Orange. UI. activity. gameactivity;
-
-
Public class softinput {
-
-
Private gameactivity;
-
-
Private Static onsoftinputlistener;
-
-
Private edittext;
-
-
Public softinput (gameactivity activity,
-
Onsoftinputlistener ){
-
This. Activity = activity;
-
Softinput. onsoftinputlistener = onsoftinputlistener;
-
This. edittext = activity. getedittext ();
-
This. edittext. setonkeylistener (onkeylistener1 );
-
}
-
-
Private onkeylistener onkeylistener1 = new onkeylistener (){
-
-
@ Override
-
Public Boolean onkey (view V, int keycode, keyevent event ){
-
// Todo auto-generated method stub
-
If (keycode = keyevent. keycode_back ){
-
Edittext. setonkeylistener (onkeylistener2 );
-
Return true;
-
}
-
Return false;
-
}
-
};
-
Private onkeylistener onkeylistener2 = new onkeylistener (){
-
-
@ Override
-
Public Boolean onkey (view V, int keycode, keyevent event ){
-
// Todo auto-generated method stub
-
Return false;
-
}
-
};
-
-
Public void seteditviewstyle (Boolean number, Boolean password,
-
Int maxtextlength ){
-
If (this. edittext! = NULL ){
-
If (maxtextlength> 0 ){
-
This. edittext
-
. Setfilters (New inputfilter [] {New inputfilter. lengthfilter (
-
Maxtextlength )});
-
} Else {
-
This. edittext. setfilters (New inputfilter [] {});
-
}
-
If (number ){
-
This. edittext. setinputtype (inputtype. type_class_number );
-
} Else {
-
This. edittext. setinputtype (inputtype. type_class_text );
-
}
-
If (password ){
-
This. edittext
-
. Settransformationmethod (passwordtransformationmethod
-
. Getinstance ());
-
} Else {
-
This. edittext. settransformationmethod (null );
-
}
-
}
-
}
-
-
Public void show (view parent, string hint, string text ){
-
If (this. edittext! = NULL ){
-
If (hint! = NULL ){
-
This. edittext. sethint (hint );
-
} Else {
-
This. edittext. sethint ("");
-
}
-
If (text! = NULL ){
-
This. edittext. settext (text );
-
} Else {
-
This. edittext. settext ("");
-
}
-
Editable editable = This. edittext. gettext ();
-
If (editable! = NULL ){
-
This. edittext. setselection (editable. tostring (). Length ());
-
}
-
This. edittext. removetextchangedlistener (mtextwatcher );
-
This. edittext. addtextchangedlistener (mtextwatcher );
-
-
Final inputmethodmanager M = (inputmethodmanager) This. Activity
-
. Getsystemservice (context. input_method_service );
-
M. showsoftinput (this. edittext, 0 );
-
}
-
}
-
-
Private Static textwatcher mtextwatcher = new textwatcher (){
-
-
@ Override
-
Public void ontextchanged (charsequence S, int start, int before,
-
Int count ){
-
// Todo auto-generated method stub
-
}
-
-
@ Override
-
Public void beforetextchanged (charsequence S, int start, int count,
-
Int after ){
-
// Todo auto-generated method stub
-
-
}
-
-
@ Override
-
Public void aftertextchanged (editable s ){
-
// Todo auto-generated method stub
-
If (onsoftinputlistener! = NULL ){
-
Onsoftinputlistener. ontextchanged (S. tostring ());
-
}
-
}
-
};
-
-
/**
-
* The keyboard is displayed.
-
*
-
* @ Param Activity
-
* Not explained
-
* @ Param hint
-
* If not, enter null.
-
* @ Param text
-
* If not, enter null.
-
* @ Param number
-
* Digit or not
-
* @ Param Password
-
* Password?
-
* @ Param maxtextlength
-
* Maximum length. If no limit is set, enter 0.
-
* @ Param onsoftinputlistener
-
* Response Interface
-
*/
-
Public static void showsoftinput (gameactivity activity, string hint,
-
String text, Boolean number, Boolean password, int maxtextlength,
-
Onsoftinputlistener ){
-
Softinput = new softinput (activity, onsoftinputlistener );
-
Softinput. seteditviewstyle (number, password, maxtextlength );
-
Softinput. Show (activity. getwindow (). getdecorview (), hint, text );
-
}
-
-
Public interface onsoftinputlistener {
-
-
/**
-
* The content of the edit box is changed.
-
*
-
* @ Param newcontent
-
* New Content
-
*/
-
Public void ontextchanged (string newcontent );
-
-
}
-
-
}
-