aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java40
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java11
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboard.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java3
4 files changed, 53 insertions, 3 deletions
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<Integer, Integer> sRtlParenthesisMap = new HashMap<Integer, Integer>();
+
+ 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<Key> mShiftKeys = new ArrayList<Key>();
private final HashMap<Key, Drawable> mShiftedIcons = new HashMap<Key, Drawable>();
@@ -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,