summaryrefslogtreecommitdiffstats
path: root/samples/SoftKeyboard/src
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-02 22:54:20 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-02 22:54:20 -0800
commitb8747bc7b1082c273360f84f7cd0b4770613955a (patch)
tree08468596ec90adda61bf81d9c831316d096e6d2f /samples/SoftKeyboard/src
parent74a996a2c7251790ab3cc6a10358c31ad0fed828 (diff)
downloadandroid_development-b8747bc7b1082c273360f84f7cd0b4770613955a.tar.gz
android_development-b8747bc7b1082c273360f84f7cd0b4770613955a.tar.bz2
android_development-b8747bc7b1082c273360f84f7cd0b4770613955a.zip
auto import from //depot/cupcake/@137055
Diffstat (limited to 'samples/SoftKeyboard/src')
-rw-r--r--samples/SoftKeyboard/src/com/example/android/softkeyboard/LatinKeyboard.java49
-rw-r--r--samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java24
2 files changed, 68 insertions, 5 deletions
diff --git a/samples/SoftKeyboard/src/com/example/android/softkeyboard/LatinKeyboard.java b/samples/SoftKeyboard/src/com/example/android/softkeyboard/LatinKeyboard.java
index 944cefb3b..179844234 100644
--- a/samples/SoftKeyboard/src/com/example/android/softkeyboard/LatinKeyboard.java
+++ b/samples/SoftKeyboard/src/com/example/android/softkeyboard/LatinKeyboard.java
@@ -20,9 +20,14 @@ import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.inputmethodservice.Keyboard;
+import android.inputmethodservice.Keyboard.Key;
+import android.inputmethodservice.Keyboard.Row;
+import android.view.inputmethod.EditorInfo;
public class LatinKeyboard extends Keyboard {
+ private Key mEnterKey;
+
public LatinKeyboard(Context context, int xmlLayoutResId) {
super(context, xmlLayoutResId);
}
@@ -35,7 +40,49 @@ public class LatinKeyboard extends Keyboard {
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
XmlResourceParser parser) {
- return new LatinKey(res, parent, x, y, parser);
+ Key key = new LatinKey(res, parent, x, y, parser);
+ if (key.codes[0] == 10) {
+ mEnterKey = key;
+ }
+ return key;
+ }
+
+ /**
+ * This looks at the ime options given by the current editor, to set the
+ * appropriate label on the keyboard's enter key (if it has one).
+ */
+ void setImeOptions(Resources res, int options) {
+ if (mEnterKey == null) {
+ return;
+ }
+
+ switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
+ case EditorInfo.IME_ACTION_GO:
+ mEnterKey.iconPreview = null;
+ mEnterKey.icon = null;
+ mEnterKey.label = res.getText(R.string.label_go_key);
+ break;
+ case EditorInfo.IME_ACTION_NEXT:
+ mEnterKey.iconPreview = null;
+ mEnterKey.icon = null;
+ mEnterKey.label = res.getText(R.string.label_next_key);
+ break;
+ case EditorInfo.IME_ACTION_SEARCH:
+ mEnterKey.icon = res.getDrawable(
+ R.drawable.sym_keyboard_search);
+ mEnterKey.label = null;
+ break;
+ case EditorInfo.IME_ACTION_SEND:
+ mEnterKey.iconPreview = null;
+ mEnterKey.icon = null;
+ mEnterKey.label = res.getText(R.string.label_send_key);
+ break;
+ default:
+ mEnterKey.icon = res.getDrawable(
+ R.drawable.sym_keyboard_return);
+ mEnterKey.label = null;
+ break;
+ }
}
static class LatinKey extends Keyboard.Key {
diff --git a/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java b/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java
index 4df485318..656efdfb7 100644
--- a/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java
+++ b/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java
@@ -65,11 +65,11 @@ public class SoftKeyboard extends InputMethodService
private long mLastShiftTime;
private long mMetaState;
- private Keyboard mSymbolsKeyboard;
- private Keyboard mSymbolsShiftedKeyboard;
- private Keyboard mQwertyKeyboard;
+ private LatinKeyboard mSymbolsKeyboard;
+ private LatinKeyboard mSymbolsShiftedKeyboard;
+ private LatinKeyboard mQwertyKeyboard;
- private Keyboard mCurKeyboard;
+ private LatinKeyboard mCurKeyboard;
private String mWordSeparators;
@@ -208,6 +208,10 @@ public class SoftKeyboard extends InputMethodService
// keyboard with no special features.
mCurKeyboard = mQwertyKeyboard;
}
+
+ // Update the label on the enter key, depending on what the application
+ // says it will do.
+ mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions);
}
/**
@@ -504,6 +508,18 @@ public class SoftKeyboard extends InputMethodService
}
}
+ public void onText(CharSequence text) {
+ InputConnection ic = getCurrentInputConnection();
+ if (ic == null) return;
+ ic.beginBatchEdit();
+ if (mComposing.length() > 0) {
+ commitTyped(ic);
+ }
+ ic.commitText(text, 0);
+ ic.endBatchEdit();
+ updateShiftKeyState(getCurrentInputEditorInfo());
+ }
+
/**
* Update the list of available candidates from the current composing
* text. This will need to be filled in by however you are determining