PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/kakeyboard/src/org/herrlado/android/kakeyboard/LatinKeyboard.java

http://kakeyboard.googlecode.com/
Java | 107 lines | 69 code | 15 blank | 23 comment | 6 complexity | 7e60c1395318d923a971e3d9fb2b4f54 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 org.herrlado.android.kakeyboard;
  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. private String icon;
  27. public LatinKeyboard(Context context, int xmlLayoutResId) {
  28. super(context, xmlLayoutResId);
  29. }
  30. public LatinKeyboard(Context context, int layoutTemplateResId,
  31. CharSequence characters, int columns, int horizontalPadding) {
  32. super(context, layoutTemplateResId, characters, columns, horizontalPadding);
  33. }
  34. @Override
  35. protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
  36. XmlResourceParser parser) {
  37. Key key = new LatinKey(res, parent, x, y, parser);
  38. if (key.codes[0] == 10) {
  39. mEnterKey = key;
  40. }
  41. return key;
  42. }
  43. /**
  44. * This looks at the ime options given by the current editor, to set the
  45. * appropriate label on the keyboard's enter key (if it has one).
  46. */
  47. void setImeOptions(Resources res, int options) {
  48. if (mEnterKey == null) {
  49. return;
  50. }
  51. switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
  52. case EditorInfo.IME_ACTION_GO:
  53. mEnterKey.iconPreview = null;
  54. mEnterKey.icon = null;
  55. mEnterKey.label = res.getText(R.string.label_go_key);
  56. break;
  57. case EditorInfo.IME_ACTION_NEXT:
  58. mEnterKey.iconPreview = null;
  59. mEnterKey.icon = null;
  60. mEnterKey.label = res.getText(R.string.label_next_key);
  61. break;
  62. case EditorInfo.IME_ACTION_SEARCH:
  63. mEnterKey.icon = res.getDrawable(
  64. R.drawable.sym_keyboard_search);
  65. mEnterKey.label = null;
  66. break;
  67. case EditorInfo.IME_ACTION_SEND:
  68. mEnterKey.iconPreview = null;
  69. mEnterKey.icon = null;
  70. mEnterKey.label = res.getText(R.string.label_send_key);
  71. break;
  72. default:
  73. mEnterKey.icon = res.getDrawable(
  74. R.drawable.sym_keyboard_return);
  75. mEnterKey.label = null;
  76. break;
  77. }
  78. }
  79. static class LatinKey extends Keyboard.Key {
  80. public LatinKey(Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser) {
  81. super(res, parent, x, y, parser);
  82. }
  83. /**
  84. * Overriding this method so that we can reduce the target area for the key that
  85. * closes the keyboard.
  86. */
  87. @Override
  88. public boolean isInside(int x, int y) {
  89. return super.isInside(x, codes[0] == KEYCODE_CANCEL ? y - 10 : y);
  90. }
  91. }
  92. }