/CircleIME/src/com/marvin/circleime/LatinKeyboard.java

http://eyes-free.googlecode.com/ · Java · 101 lines · 65 code · 13 blank · 23 comment · 6 complexity · cafb5a8bdc7a524c41aa75540199d6d7 MD5 · raw file

  1. /*
  2. * Copyright (C) 2008-2009 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.marvin.circleime;
  17. import android.content.Context;
  18. import android.content.res.Resources;
  19. import android.content.res.XmlResourceParser;
  20. import android.inputmethodservice.Keyboard;
  21. import android.inputmethodservice.Keyboard.Key;
  22. import android.inputmethodservice.Keyboard.Row;
  23. import android.view.inputmethod.EditorInfo;
  24. public class LatinKeyboard extends Keyboard {
  25. private Key mEnterKey;
  26. public LatinKeyboard(Context context, int xmlLayoutResId) {
  27. super(context, xmlLayoutResId);
  28. }
  29. public LatinKeyboard(Context context, int layoutTemplateResId, CharSequence characters,
  30. int columns, int horizontalPadding) {
  31. super(context, layoutTemplateResId, characters, columns, horizontalPadding);
  32. }
  33. @Override
  34. protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
  35. Key key = new LatinKey(res, parent, x, y, parser);
  36. if (key.codes[0] == 10) {
  37. mEnterKey = key;
  38. }
  39. return key;
  40. }
  41. /**
  42. * This looks at the ime options given by the current editor, to set the
  43. * appropriate label on the keyboard's enter key (if it has one).
  44. */
  45. void setImeOptions(Resources res, int options) {
  46. if (mEnterKey == null) {
  47. return;
  48. }
  49. switch (options & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
  50. case EditorInfo.IME_ACTION_GO:
  51. mEnterKey.iconPreview = null;
  52. mEnterKey.icon = null;
  53. mEnterKey.label = res.getText(R.string.label_go_key);
  54. break;
  55. case EditorInfo.IME_ACTION_NEXT:
  56. mEnterKey.iconPreview = null;
  57. mEnterKey.icon = null;
  58. mEnterKey.label = res.getText(R.string.label_next_key);
  59. break;
  60. case EditorInfo.IME_ACTION_SEARCH:
  61. mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
  62. mEnterKey.label = null;
  63. break;
  64. case EditorInfo.IME_ACTION_SEND:
  65. mEnterKey.iconPreview = null;
  66. mEnterKey.icon = null;
  67. mEnterKey.label = res.getText(R.string.label_send_key);
  68. break;
  69. default:
  70. mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_return);
  71. mEnterKey.label = null;
  72. break;
  73. }
  74. }
  75. static class LatinKey extends Keyboard.Key {
  76. public LatinKey(Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser) {
  77. super(res, parent, x, y, parser);
  78. }
  79. /**
  80. * Overriding this method so that we can reduce the target area for the
  81. * key that closes the keyboard.
  82. */
  83. @Override
  84. public boolean isInside(int x, int y) {
  85. return super.isInside(x, codes[0] == KEYCODE_CANCEL ? y - 10 : y);
  86. }
  87. }
  88. }