From 8eb2e34d5b2def57c9548f88e37e5c9e5a0bea59 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Fri, 22 Jan 2010 13:57:20 -0800 Subject: [PATCH] Enable language switching with long-press of space bar. This is a temporary solution until slide-on-space is implemented. --- .../android/inputmethod/latin/LatinIME.java | 2 +- .../inputmethod/latin/LatinKeyboard.java | 57 ++++++++++--------- .../inputmethod/latin/LatinKeyboardView.java | 5 ++ 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/com/android/inputmethod/latin/LatinIME.java b/src/com/android/inputmethod/latin/LatinIME.java index 762f292f6..a71f3d867 100644 --- a/src/com/android/inputmethod/latin/LatinIME.java +++ b/src/com/android/inputmethod/latin/LatinIME.java @@ -893,7 +893,7 @@ public class LatinIME extends InputMethodService case LatinKeyboardView.KEYCODE_OPTIONS: showOptionsMenu(); break; - case LatinKeyboardView.KEYCODE_F1: + case LatinKeyboardView.KEYCODE_NEXT_LANGUAGE: toggleLanguage(false); break; case LatinKeyboardView.KEYCODE_SHIFT_LONGPRESS: diff --git a/src/com/android/inputmethod/latin/LatinKeyboard.java b/src/com/android/inputmethod/latin/LatinKeyboard.java index 05913122f..f5748f415 100644 --- a/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -42,7 +42,7 @@ public class LatinKeyboard extends Keyboard { private Key mEnterKey; private Key mF1Key; private Key mSpaceKey; - private Locale mLocale; + /* package */ Locale mLocale; private Resources mRes; private int mMode; @@ -227,17 +227,40 @@ public class LatinKeyboard extends Keyboard { } private void setF1Key() { - if (mF1Key == null) return; // No function key on this keyboard + // TODO +// else { +// mSpaceKey.icon = mRes.getDrawable(R.drawable.sym_keyboard_space); +// switch (mMode) { +// case KeyboardSwitcher.KEYBOARDMODE_NORMAL: +// case KeyboardSwitcher.KEYBOARDMODE_IM: +// mF1Key.label = ","; +// mF1Key.codes = new int[] { ',' }; +// mF1Key.icon = null; +// mF1Key.iconPreview = null; +// break; +// case KeyboardSwitcher.KEYBOARDMODE_EMAIL: +// case KeyboardSwitcher.KEYBOARDMODE_URL: +// mF1Key.label = mRes.getString(R.string.popular_domain_0); +// mF1Key.codes = new int[] { '.' }; +// mF1Key.text = mF1Key.label; +// mF1Key.icon = null; +// mF1Key.iconPreview = null; +// mF1Key.popupResId = R.xml.popup_domains; +// break; +// } +// } + } + + private void updateSpaceBarForLocale() { if (mLocale != null) { // Create the graphic for spacebar - mF1Key.label = null; - mF1Key.icon = mRes.getDrawable(R.drawable.sym_keyboard_globe); Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(buffer); canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR); Paint paint = new Paint(); paint.setAntiAlias(true); + // TODO: Make the text size a customizable attribute paint.setTextSize(22); paint.setTextAlign(Align.CENTER); // Draw a drop shadow for the text @@ -250,36 +273,18 @@ public class LatinKeyboard extends Keyboard { mSpaceIcon.setBounds(x, y, x + mSpaceIcon.getIntrinsicWidth(), y + mSpaceIcon.getIntrinsicHeight()); mSpaceIcon.draw(canvas); - mSpaceKey.icon = new BitmapDrawable(mRes, buffer); + mSpaceKey.icon = new BitmapDrawable(mRes, buffer); + mSpaceKey.repeatable = false; } else { mSpaceKey.icon = mRes.getDrawable(R.drawable.sym_keyboard_space); - switch (mMode) { - case KeyboardSwitcher.KEYBOARDMODE_NORMAL: - case KeyboardSwitcher.KEYBOARDMODE_IM: - mF1Key.label = ","; - mF1Key.codes = new int[] { ',' }; - mF1Key.icon = null; - mF1Key.iconPreview = null; - break; - case KeyboardSwitcher.KEYBOARDMODE_EMAIL: - case KeyboardSwitcher.KEYBOARDMODE_URL: - mF1Key.label = mRes.getString(R.string.popular_domain_0); - mF1Key.codes = new int[] { '.' }; - mF1Key.text = mF1Key.label; - mF1Key.icon = null; - mF1Key.iconPreview = null; - mF1Key.popupResId = R.xml.popup_domains; - break; - } + mSpaceKey.repeatable = true; } } public void setLanguage(Locale locale) { if (mLocale != null && mLocale.equals(locale)) return; mLocale = locale; - setF1Key(); - if (mF1Key != null) { - } + updateSpaceBarForLocale(); } static class LatinKey extends Keyboard.Key { diff --git a/src/com/android/inputmethod/latin/LatinKeyboardView.java b/src/com/android/inputmethod/latin/LatinKeyboardView.java index ea9ccf0b6..a88c1818c 100644 --- a/src/com/android/inputmethod/latin/LatinKeyboardView.java +++ b/src/com/android/inputmethod/latin/LatinKeyboardView.java @@ -37,6 +37,8 @@ public class LatinKeyboardView extends KeyboardView { static final int KEYCODE_SHIFT_LONGPRESS = -101; static final int KEYCODE_VOICE = -102; static final int KEYCODE_F1 = -103; + static final int KEYCODE_NEXT_LANGUAGE = -104; + private Keyboard mPhoneKeyboard; public LatinKeyboardView(Context context, AttributeSet attrs) { @@ -64,6 +66,9 @@ public class LatinKeyboardView extends KeyboardView { // Long pressing on 0 in phone number keypad gives you a '+'. getOnKeyboardActionListener().onKey('+', null); return true; + } else if (key.codes[0] == ' ' && ((LatinKeyboard)getKeyboard()).mLocale != null) { + getOnKeyboardActionListener().onKey(KEYCODE_NEXT_LANGUAGE, null); + return true; } else { return super.onLongPress(key); }