Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. package com.gmail.eadomke1.java;
  2.  
  3. import android.inputmethodservice.InputMethodService;
  4. import android.inputmethodservice.Keyboard;
  5. import android.inputmethodservice.KeyboardView;
  6. import android.text.TextUtils;
  7. import android.view.KeyEvent;
  8. import android.view.View;
  9. import android.view.inputmethod.InputConnection;
  10.  
  11. import com.gmail.eadomke1.java.EnchantingKeyboard.R;
  12.  
  13. public class keyboard extends InputMethodService implements
  14. KeyboardView.OnKeyboardActionListener {
  15.  
  16. private KeyboardView keyboardView;
  17. private Keyboard keyboard;
  18.  
  19. private boolean caps = true;
  20.  
  21. @Override
  22. public View onCreateInputView() {
  23. keyboardView = (KeyboardView)
  24. getLayoutInflater().inflate(R.layout.keyboard, null);
  25. keyboard = new Keyboard(this, R.xml.qwerty);
  26. keyboardView.setKeyboard(keyboard);
  27. keyboardView.setOnKeyboardActionListener(this);
  28. return keyboardView;
  29. }
  30.  
  31. @Override
  32. public void onPress(int i) {
  33. }
  34.  
  35. @Override
  36. public void onRelease(int i) {
  37.  
  38. }
  39.  
  40.  
  41.  
  42. @Override
  43. public void onKey(int primaryCode, int[] keyCodes) {
  44. InputConnection inputConnection = getCurrentInputConnection();
  45. if (inputConnection != null) {
  46. switch(primaryCode) {
  47. case Keyboard.KEYCODE_DELETE :
  48. CharSequence selectedText = inputConnection.getSelectedText(0);
  49.  
  50. if (TextUtils.isEmpty(selectedText)) {
  51. inputConnection.deleteSurroundingText(1, 0);
  52. } else {
  53. inputConnection.commitText("", 1);
  54. }
  55. case Keyboard.KEYCODE_SHIFT:
  56. caps = !caps;
  57. keyboard.setShifted(caps);
  58. keyboardView.invalidateAllKeys();
  59. break;
  60. case Keyboard.KEYCODE_DONE:
  61. inputConnection.sendKeyEvent(new
  62. KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
  63.  
  64. break;
  65. default :
  66. char code = (char) primaryCode;
  67. if(Character.isLetter(code) && caps){
  68. code = Character.toUpperCase(code);
  69. }
  70. inputConnection.commitText(String.valueOf(code), 1);
  71.  
  72. }
  73. }
  74.  
  75. }
  76.  
  77.  
  78. @Override
  79. public void onText(CharSequence charSequence) {
  80.  
  81. }
  82.  
  83. @Override
  84. public void swipeLeft() {
  85.  
  86. }
  87.  
  88. @Override
  89. public void swipeRight() {
  90.  
  91. }
  92.  
  93. @Override
  94. public void swipeDown() {
  95.  
  96. }
  97.  
  98. @Override
  99. public void swipeUp() {
  100.  
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement