KeyboardIME.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package me.yoqi.android.safekeyboard.service;
  2. import android.content.Context;
  3. import android.inputmethodservice.InputMethodService;
  4. import android.os.PowerManager;
  5. import android.view.View;
  6. import android.view.inputmethod.EditorInfo;
  7. import android.widget.TextView;
  8. import me.yoqi.android.safekeyboard.R;
  9. /**
  10. * 自定义键盘服务
  11. *
  12. * @author liuyuqi.gov@msn.cn
  13. * @date 3/16/2021
  14. */
  15. public class KeyboardIME extends InputMethodService {
  16. private static final String TAG = "KeyboardIME";
  17. private TextView mTextViewMessage;
  18. private PowerManager.WakeLock mWakeLock;
  19. Context mContext;
  20. private void screenLock() {
  21. if (mWakeLock != null && !mWakeLock.isHeld()) { //设置10分钟后锁屏
  22. mWakeLock.acquire(10 * 60 * 1000L /*10 minutes*/);
  23. return;
  24. }
  25. mWakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "everettjf:remoboard");
  26. if (mWakeLock != null) {
  27. mWakeLock.acquire(10 * 60 * 1000L /*10 minutes*/);
  28. }
  29. }
  30. private void screenUnlock() {
  31. if (mWakeLock != null) {
  32. mWakeLock.release();
  33. mWakeLock = null;
  34. }
  35. }
  36. /**
  37. * 设置相应控件的事件,如软键盘按钮单击事件
  38. *
  39. * @return 返回建立的布局文件对应的View对象
  40. */
  41. @Override
  42. public View onCreateInputView() {
  43. mContext = this;
  44. return getLayoutInflater().inflate(R.layout.keyboard_key_board_popu, null);
  45. }
  46. @Override
  47. public void onStartInputView(EditorInfo info, boolean restarting) {
  48. super.onStartInputView(info, restarting);
  49. }
  50. @Override
  51. public void onStartInput(EditorInfo attribute, boolean restarting) {
  52. super.onStartInput(attribute, restarting);
  53. }
  54. @Override
  55. public void onFinishInput() {
  56. super.onFinishInput();
  57. screenUnlock();
  58. }
  59. @Override
  60. public boolean onEvaluateFullscreenMode() {
  61. return super.onEvaluateFullscreenMode();
  62. }
  63. @Override
  64. public void updateInputViewShown() {
  65. super.updateInputViewShown();
  66. if (isInputViewShown()) {
  67. screenLock();
  68. }
  69. }
  70. }