From 7139335dcd84209285c028f5d83cb72bfbf1a966 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sun, 24 Jul 2011 16:35:54 -0700 Subject: [PATCH] Swap parenthesis-like character code on RTL keyboard Bug: 5047217 Change-Id: I1b88484825f5c035401cf083522bf95bbee30edb --- java/res/values/attrs.xml | 2 + java/res/xml-ar/kbd_symbols.xml | 27 ++++ java/res/xml-ar/kbd_symbols_shift.xml | 27 ++++ java/res/xml-iw/kbd_symbols.xml | 27 ++++ java/res/xml-iw/kbd_symbols_shift.xml | 27 ++++ .../{kbd_symbols.xml => kbd_rows_symbols.xml} | 4 +- ...s_shift.xml => kbd_rows_symbols_shift.xml} | 4 +- .../{kbd_symbols.xml => kbd_rows_symbols.xml} | 6 +- ...s_shift.xml => kbd_rows_symbols_shift.xml} | 6 +- java/res/xml/kbd_rows_symbols.xml | 130 ++++++++++++++++++ java/res/xml/kbd_rows_symbols_shift.xml | 125 +++++++++++++++++ java/res/xml/kbd_symbols.xml | 119 ++-------------- java/res/xml/kbd_symbols_shift.xml | 113 ++------------- .../com/android/inputmethod/keyboard/Key.java | 40 +++++- .../inputmethod/keyboard/Keyboard.java | 11 ++ .../inputmethod/keyboard/MiniKeyboard.java | 2 + .../keyboard/internal/KeyboardParser.java | 3 +- 17 files changed, 448 insertions(+), 225 deletions(-) create mode 100644 java/res/xml-ar/kbd_symbols.xml create mode 100644 java/res/xml-ar/kbd_symbols_shift.xml create mode 100644 java/res/xml-iw/kbd_symbols.xml create mode 100644 java/res/xml-iw/kbd_symbols_shift.xml rename java/res/xml-sw600dp/{kbd_symbols.xml => kbd_rows_symbols.xml} (99%) rename java/res/xml-sw600dp/{kbd_symbols_shift.xml => kbd_rows_symbols_shift.xml} (99%) rename java/res/xml-sw768dp/{kbd_symbols.xml => kbd_rows_symbols.xml} (98%) rename java/res/xml-sw768dp/{kbd_symbols_shift.xml => kbd_rows_symbols_shift.xml} (98%) create mode 100644 java/res/xml/kbd_rows_symbols.xml create mode 100644 java/res/xml/kbd_rows_symbols_shift.xml diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 4c3ea83ed..e503d98a4 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -150,6 +150,8 @@ + + diff --git a/java/res/xml-ar/kbd_symbols.xml b/java/res/xml-ar/kbd_symbols.xml new file mode 100644 index 000000000..9e5c255d0 --- /dev/null +++ b/java/res/xml-ar/kbd_symbols.xml @@ -0,0 +1,27 @@ + + + + + + diff --git a/java/res/xml-ar/kbd_symbols_shift.xml b/java/res/xml-ar/kbd_symbols_shift.xml new file mode 100644 index 000000000..934e6f849 --- /dev/null +++ b/java/res/xml-ar/kbd_symbols_shift.xml @@ -0,0 +1,27 @@ + + + + + + diff --git a/java/res/xml-iw/kbd_symbols.xml b/java/res/xml-iw/kbd_symbols.xml new file mode 100644 index 000000000..9e5c255d0 --- /dev/null +++ b/java/res/xml-iw/kbd_symbols.xml @@ -0,0 +1,27 @@ + + + + + + diff --git a/java/res/xml-iw/kbd_symbols_shift.xml b/java/res/xml-iw/kbd_symbols_shift.xml new file mode 100644 index 000000000..934e6f849 --- /dev/null +++ b/java/res/xml-iw/kbd_symbols_shift.xml @@ -0,0 +1,27 @@ + + + + + + diff --git a/java/res/xml-sw600dp/kbd_symbols.xml b/java/res/xml-sw600dp/kbd_rows_symbols.xml similarity index 99% rename from java/res/xml-sw600dp/kbd_symbols.xml rename to java/res/xml-sw600dp/kbd_rows_symbols.xml index fc89cd3c5..9982f4575 100644 --- a/java/res/xml-sw600dp/kbd_symbols.xml +++ b/java/res/xml-sw600dp/kbd_rows_symbols.xml @@ -18,7 +18,7 @@ */ --> - - + diff --git a/java/res/xml-sw600dp/kbd_symbols_shift.xml b/java/res/xml-sw600dp/kbd_rows_symbols_shift.xml similarity index 99% rename from java/res/xml-sw600dp/kbd_symbols_shift.xml rename to java/res/xml-sw600dp/kbd_rows_symbols_shift.xml index 99b78a435..ac4b93fa4 100644 --- a/java/res/xml-sw600dp/kbd_symbols_shift.xml +++ b/java/res/xml-sw600dp/kbd_rows_symbols_shift.xml @@ -18,7 +18,7 @@ */ --> - - + diff --git a/java/res/xml-sw768dp/kbd_symbols.xml b/java/res/xml-sw768dp/kbd_rows_symbols.xml similarity index 98% rename from java/res/xml-sw768dp/kbd_symbols.xml rename to java/res/xml-sw768dp/kbd_rows_symbols.xml index ba0715cd4..1d5bd9d15 100644 --- a/java/res/xml-sw768dp/kbd_symbols.xml +++ b/java/res/xml-sw768dp/kbd_rows_symbols.xml @@ -2,7 +2,7 @@ - - + diff --git a/java/res/xml-sw768dp/kbd_symbols_shift.xml b/java/res/xml-sw768dp/kbd_rows_symbols_shift.xml similarity index 98% rename from java/res/xml-sw768dp/kbd_symbols_shift.xml rename to java/res/xml-sw768dp/kbd_rows_symbols_shift.xml index 1ddd64be3..2219bdc92 100644 --- a/java/res/xml-sw768dp/kbd_symbols_shift.xml +++ b/java/res/xml-sw768dp/kbd_rows_symbols_shift.xml @@ -2,7 +2,7 @@ - - + diff --git a/java/res/xml/kbd_rows_symbols.xml b/java/res/xml/kbd_rows_symbols.xml new file mode 100644 index 000000000..a8eeb3b91 --- /dev/null +++ b/java/res/xml/kbd_rows_symbols.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml/kbd_rows_symbols_shift.xml b/java/res/xml/kbd_rows_symbols_shift.xml new file mode 100644 index 000000000..0706cbc78 --- /dev/null +++ b/java/res/xml/kbd_rows_symbols_shift.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols.xml b/java/res/xml/kbd_symbols.xml index 7bb8d0200..737f684a7 100644 --- a/java/res/xml/kbd_symbols.xml +++ b/java/res/xml/kbd_symbols.xml @@ -1,125 +1,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + latin:keyboardLayout="@xml/kbd_rows_symbols" /> diff --git a/java/res/xml/kbd_symbols_shift.xml b/java/res/xml/kbd_symbols_shift.xml index 61fbec2df..9c163d694 100644 --- a/java/res/xml/kbd_symbols_shift.xml +++ b/java/res/xml/kbd_symbols_shift.xml @@ -1,119 +1,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + latin:keyboardLayout="@xml/kbd_rows_symbols_shift" /> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 33ab511a5..8b8930a86 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -34,6 +34,8 @@ import com.android.inputmethod.keyboard.internal.Row; import com.android.inputmethod.latin.R; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; /** * Class for describing the position and characteristics of a single key in the keyboard. @@ -153,6 +155,38 @@ public class Key { android.R.attr.state_pressed }; + // RTL parenthesis character swapping map. + private static final Map sRtlParenthesisMap = new HashMap(); + + static { + addRtlParenthesisPair('(', ')'); + addRtlParenthesisPair('[', ']'); + addRtlParenthesisPair('{', '}'); + addRtlParenthesisPair('<', '>'); + // \u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // \u00bb: RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + addRtlParenthesisPair('\u00ab', '\u00bb'); + // \u2039: SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // \u203a: SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + addRtlParenthesisPair('\u2039', '\u203a'); + // \u2264: LESS-THAN OR EQUAL TO + // \u2265: GREATER-THAN OR EQUAL TO + addRtlParenthesisPair('\u2264', '\u2265'); + } + + private static void addRtlParenthesisPair(int left, int right) { + sRtlParenthesisMap.put(left, right); + sRtlParenthesisMap.put(right, left); + } + + private static int getRtlParenthesisCode(int code) { + if (sRtlParenthesisMap.containsKey(code)) { + return sRtlParenthesisMap.get(code); + } else { + return code; + } + } + /** * This constructor is being used only for key in popup mini keyboard. */ @@ -174,7 +208,8 @@ public class Key { final String popupSpecification = popupCharacter.toString(); mLabel = PopupCharactersParser.getLabel(popupSpecification); mOutputText = PopupCharactersParser.getOutputText(popupSpecification); - mCode = PopupCharactersParser.getCode(res, popupSpecification); + final int code = PopupCharactersParser.getCode(res, popupSpecification); + mCode = keyboard.isRtlKeyboard() ? getRtlParenthesisCode(code) : code; mIcon = keyboard.mIconsSet.getIcon(PopupCharactersParser.getIconId(popupSpecification)); // Horizontal gap is divided equally to both sides of the key. mX = x + mGap / 2; @@ -298,7 +333,8 @@ public class Key { final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code, Keyboard.CODE_UNSPECIFIED); if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) { - mCode = mLabel.charAt(0); + final int firstChar = mLabel.charAt(0); + mCode = mKeyboard.isRtlKeyboard() ? getRtlParenthesisCode(firstChar) : firstChar; } else if (code != Keyboard.CODE_UNSPECIFIED) { mCode = code; } else { diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index d4a23aa15..19847c5ec 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -110,6 +110,9 @@ public class Keyboard { /** Maximum column for popup keyboard */ private int mMaxPopupColumn; + /** True if Right-To-Left keyboard */ + private boolean mIsRtlKeyboard; + /** List of shift keys in this keyboard and its icons and state */ private final List mShiftKeys = new ArrayList(); private final HashMap mShiftedIcons = new HashMap(); @@ -257,6 +260,14 @@ public class Keyboard { mKeyboardHeight = height; } + public boolean isRtlKeyboard() { + return mIsRtlKeyboard; + } + + public void setRtlKeyboard(boolean isRtl) { + mIsRtlKeyboard = isRtl; + } + public int getPopupKeyboardResId() { return mPopupKeyboardResId; } diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java index 44f9f195c..95e32755e 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java @@ -34,6 +34,8 @@ public class MiniKeyboard extends Keyboard { // revert the above hacks and uncomment the following lines. //setHorizontalGap(parentKeyboard.getHorizontalGap()); //setVerticalGap(parentKeyboard.getVerticalGap()); + + setRtlKeyboard(parentKeyboard.isRtlKeyboard()); } public void setDefaultCoordX(int pos) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java index 6f7349915..8eae2bb42 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java @@ -222,8 +222,9 @@ public class KeyboardParser { final int height = Math.max( Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight); - keyboard.setKeyboardHeight(height); + keyboard.setRtlKeyboard(keyboardAttr.getBoolean( + R.styleable.Keyboard_isRtlKeyboard, false)); keyboard.setKeyWidth(getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_keyWidth, displayWidth, displayWidth / 10)); keyboard.setRowHeight(getDimensionOrFraction(keyboardAttr,