Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. @Override
  2. public int getHeight() {
  3. return getKeyHeight() * 3;
  4. }
  5.  
  6. @Override
  7. public int getHeight() {
  8. return row1Height + row2Height + row3Height + row4Height + row5Height;
  9. }
  10.  
  11. public void changeKeyHeight(double height_modifier)
  12. {
  13. int height = 0;
  14. for(Keyboard.Key key : getKeys()) {
  15. key.height *= height_modifier;
  16. key.y *= height_modifier;
  17. height = key.height;
  18. }
  19. setKeyHeight(height);
  20. getNearestKeys(0, 0); //somehow adding this fixed a weird bug where bottom row keys could not be pressed if keyboard height is too tall.. from the Keyboard source code seems like calling this will recalculate some values used in keypress detection calculation
  21. }
  22.  
  23. @Override public void onStartInputView(EditorInfo attribute, boolean restarting) {
  24. super.onStartInputView(attribute, restarting);
  25.  
  26. // Change the key height here dynamically after getting your value from shared preference or something
  27. mCurKeyboard.changeKeyHeight(1.5);
  28.  
  29. // Apply the selected keyboard to the input view.
  30. mInputView.setKeyboard(mCurKeyboard);
  31. mInputView.closing();
  32.  
  33. final InputMethodSubtype subtype = mInputMethodManager.getCurrentInputMethodSubtype();
  34. mInputView.setSubtypeOnSpaceKey(subtype);
  35. }
  36.  
  37. private int convertDpToPx(int dp)
  38. {
  39. return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
  40. }
  41.  
  42. private void adjustKeyboardKeyHeight (MyKeyboard keyboard, int newKeyHeight) {
  43. int oldKeyHeight = keyboard.getKeyHeight();
  44. int verticalGap = keyboard.getVerticalGap();
  45. int rows = 0;
  46. for (Keyboard.Key key : keyboard.getKeys()) {
  47. key.height = newKeyHeight;
  48. int row = (key.y + verticalGap) / (oldKeyHeight + verticalGap);
  49. key.y = row * newKeyHeight + (row - 1) * verticalGap;
  50. rows = Math.max(rows, row + 1);
  51. }
  52. keyboard.setHeight(rows * newKeyHeight + (rows - 1) * verticalGap);
  53. }
  54.  
  55. private static class MyKeyboard extends Keyboard {
  56. private int height;
  57. MyKeyboard (Context context, int xmlLayoutResId) {
  58. super(context, xmlLayoutResId);
  59. height = super.getHeight();
  60. }
  61. @Override public int getKeyHeight() {
  62. return super.getKeyHeight();
  63. }
  64. @Override public int getVerticalGap() {
  65. return super.getVerticalGap();
  66. }
  67. public void setHeight (int newHeight) {
  68. height = newHeight;
  69. }
  70. @Override public int getHeight() {
  71. return height;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement