Ogengine pop-up software disk manual input text processing

Source: Internet
Author: User
  1. Import Android. content. context;

  2. Import Android. Text. editable;

  3. Import Android. Text. inputfilter;

  4. Import Android. Text. inputtype;

  5. Import Android. Text. textwatcher;

  6. Import Android. Text. method. passwordtransformationmethod;

  7. Import Android. View. keyevent;

  8. Import Android. View. view;

  9. Import Android. View. View. onkeylistener;

  10. Import Android. View. inputmethod. inputmethodmanager;

  11. Import Android. widget. edittext;


  12. Import com. Orange. UI. activity. gameactivity;


  13. Public class softinput {


  14. Private gameactivity;


  15. Private Static onsoftinputlistener;


  16. Private edittext;


  17. Public softinput (gameactivity activity,

  18. Onsoftinputlistener ){

  19. This. Activity = activity;

  20. Softinput. onsoftinputlistener = onsoftinputlistener;

  21. This. edittext = activity. getedittext ();

  22. This. edittext. setonkeylistener (onkeylistener1 );

  23. }


  24. Private onkeylistener onkeylistener1 = new onkeylistener (){


  25. @ Override

  26. Public Boolean onkey (view V, int keycode, keyevent event ){

  27. // Todo auto-generated method stub

  28. If (keycode = keyevent. keycode_back ){

  29. Edittext. setonkeylistener (onkeylistener2 );

  30. Return true;

  31. }

  32. Return false;

  33. }

  34. };

  35. Private onkeylistener onkeylistener2 = new onkeylistener (){


  36. @ Override

  37. Public Boolean onkey (view V, int keycode, keyevent event ){

  38. // Todo auto-generated method stub

  39. Return false;

  40. }

  41. };


  42. Public void seteditviewstyle (Boolean number, Boolean password,

  43. Int maxtextlength ){

  44. If (this. edittext! = NULL ){

  45. If (maxtextlength> 0 ){

  46. This. edittext

  47. . Setfilters (New inputfilter [] {New inputfilter. lengthfilter (

  48. Maxtextlength )});

  49. } Else {

  50. This. edittext. setfilters (New inputfilter [] {});

  51. }

  52. If (number ){

  53. This. edittext. setinputtype (inputtype. type_class_number );

  54. } Else {

  55. This. edittext. setinputtype (inputtype. type_class_text );

  56. }

  57. If (password ){

  58. This. edittext

  59. . Settransformationmethod (passwordtransformationmethod

  60. . Getinstance ());

  61. } Else {

  62. This. edittext. settransformationmethod (null );

  63. }

  64. }

  65. }


  66. Public void show (view parent, string hint, string text ){

  67. If (this. edittext! = NULL ){

  68. If (hint! = NULL ){

  69. This. edittext. sethint (hint );

  70. } Else {

  71. This. edittext. sethint ("");

  72. }

  73. If (text! = NULL ){

  74. This. edittext. settext (text );

  75. } Else {

  76. This. edittext. settext ("");

  77. }

  78. Editable editable = This. edittext. gettext ();

  79. If (editable! = NULL ){

  80. This. edittext. setselection (editable. tostring (). Length ());

  81. }

  82. This. edittext. removetextchangedlistener (mtextwatcher );

  83. This. edittext. addtextchangedlistener (mtextwatcher );


  84. Final inputmethodmanager M = (inputmethodmanager) This. Activity

  85. . Getsystemservice (context. input_method_service );

  86. M. showsoftinput (this. edittext, 0 );

  87. }

  88. }


  89. Private Static textwatcher mtextwatcher = new textwatcher (){


  90. @ Override

  91. Public void ontextchanged (charsequence S, int start, int before,

  92. Int count ){

  93. // Todo auto-generated method stub

  94. }


  95. @ Override

  96. Public void beforetextchanged (charsequence S, int start, int count,

  97. Int after ){

  98. // Todo auto-generated method stub


  99. }


  100. @ Override

  101. Public void aftertextchanged (editable s ){

  102. // Todo auto-generated method stub

  103. If (onsoftinputlistener! = NULL ){

  104. Onsoftinputlistener. ontextchanged (S. tostring ());

  105. }

  106. }

  107. };


  108. /**

  109. * The keyboard is displayed.

  110. *

  111. * @ Param Activity

  112. * Not explained

  113. * @ Param hint

  114. * If not, enter null.

  115. * @ Param text

  116. * If not, enter null.

  117. * @ Param number

  118. * Digit or not

  119. * @ Param Password

  120. * Password?

  121. * @ Param maxtextlength

  122. * Maximum length. If no limit is set, enter 0.

  123. * @ Param onsoftinputlistener

  124. * Response Interface

  125. */

  126. Public static void showsoftinput (gameactivity activity, string hint,

  127. String text, Boolean number, Boolean password, int maxtextlength,

  128. Onsoftinputlistener ){

  129. Softinput = new softinput (activity, onsoftinputlistener );

  130. Softinput. seteditviewstyle (number, password, maxtextlength );

  131. Softinput. Show (activity. getwindow (). getdecorview (), hint, text );

  132. }


  133. Public interface onsoftinputlistener {


  134. /**

  135. * The content of the edit box is changed.

  136. *

  137. * @ Param newcontent

  138. * New Content

  139. */

  140. Public void ontextchanged (string newcontent );


  141. }


  142. }


Copy code



The softinput. showsoftinput () method is called directly to bring up the software disk, and the onsoftinputlistener is called back to listen to the input results.

Http://www.eoeandroid.com/forum-863-1.html

Www.ogengine.com



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.