aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/res/xml-sw600dp/key_greek_semicolon.xml29
-rw-r--r--java/res/xml-sw600dp/rows_greek.xml2
-rw-r--r--java/res/xml/key_greek_semicolon.xml42
-rw-r--r--java/res/xml/rowkeys_greek1.xml18
-rw-r--r--java/res/xml/rows_greek.xml2
-rw-r--r--native/jni/src/suggest/core/dictionary/dictionary.cpp6
-rw-r--r--native/jni/src/suggest/core/dictionary/dictionary.h3
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp14
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp12
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/AlphabetShifted.java11
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java6
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/Symbols.java157
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java42
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java8
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java107
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java51
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java51
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java6
18 files changed, 290 insertions, 277 deletions
diff --git a/java/res/xml-sw600dp/key_greek_semicolon.xml b/java/res/xml-sw600dp/key_greek_semicolon.xml
deleted file mode 100644
index 9e2c1fad0..000000000
--- a/java/res/xml-sw600dp/key_greek_semicolon.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2012, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
- xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
- <Key
- latin:keySpec=";"
- latin:keyHintLabel=":"
- latin:moreKeys=":"
- latin:keyStyle="hasShiftedLetterHintStyle" />
-</merge>
diff --git a/java/res/xml-sw600dp/rows_greek.xml b/java/res/xml-sw600dp/rows_greek.xml
index 066dc47fb..60ee478d8 100644
--- a/java/res/xml-sw600dp/rows_greek.xml
+++ b/java/res/xml-sw600dp/rows_greek.xml
@@ -27,8 +27,6 @@
latin:keyWidth="9.0%p"
>
<include
- latin:keyboardLayout="@xml/key_greek_semicolon" />
- <include
latin:keyboardLayout="@xml/rowkeys_greek1" />
<Key
latin:keyStyle="deleteKeyStyle"
diff --git a/java/res/xml/key_greek_semicolon.xml b/java/res/xml/key_greek_semicolon.xml
deleted file mode 100644
index 9001e4dfb..000000000
--- a/java/res/xml/key_greek_semicolon.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2012, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
- xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
- <switch>
- <case
- latin:keyboardLayoutSetElement="alphabetManualShifted|alphabetShiftLockShifted"
- >
- <Key
- latin:keySpec=":"
- latin:keyHintLabel="1"
- latin:moreKeys=";"
- latin:additionalMoreKeys="1" />
- </case>
- <default>
- <Key
- latin:keySpec=";"
- latin:keyHintLabel="1"
- latin:moreKeys=":"
- latin:additionalMoreKeys="1" />
- </default>
- </switch>
-</merge>
diff --git a/java/res/xml/rowkeys_greek1.xml b/java/res/xml/rowkeys_greek1.xml
index 5080dc843..c5033d029 100644
--- a/java/res/xml/rowkeys_greek1.xml
+++ b/java/res/xml/rowkeys_greek1.xml
@@ -21,6 +21,24 @@
<merge
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
>
+ <switch>
+ <case
+ latin:keyboardLayoutSetElement="alphabetManualShifted|alphabetShiftLockShifted"
+ >
+ <Key
+ latin:keySpec=":"
+ latin:keyHintLabel="1"
+ latin:moreKeys=";"
+ latin:additionalMoreKeys="1" />
+ </case>
+ <default>
+ <Key
+ latin:keySpec=";"
+ latin:keyHintLabel="1"
+ latin:moreKeys=":"
+ latin:additionalMoreKeys="1" />
+ </default>
+ </switch>
<!-- TODO: Should find a way to compound Greek dialytika tonos and other Greek letters. -->
<!--
<switch>
diff --git a/java/res/xml/rows_greek.xml b/java/res/xml/rows_greek.xml
index ca6d24005..e00b927a0 100644
--- a/java/res/xml/rows_greek.xml
+++ b/java/res/xml/rows_greek.xml
@@ -27,8 +27,6 @@
latin:keyWidth="10%p"
>
<include
- latin:keyboardLayout="@xml/key_greek_semicolon" />
- <include
latin:keyboardLayout="@xml/rowkeys_greek1" />
</Row>
<Row
diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp
index ffa96e167..c26e3aad6 100644
--- a/native/jni/src/suggest/core/dictionary/dictionary.cpp
+++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp
@@ -37,7 +37,7 @@ const int Dictionary::HEADER_ATTRIBUTE_BUFFER_SIZE = 32;
Dictionary::Dictionary(JNIEnv *env, DictionaryStructureWithBufferPolicy::StructurePolicyPtr
dictionaryStructureWithBufferPolicy)
: mDictionaryStructureWithBufferPolicy(std::move(dictionaryStructureWithBufferPolicy)),
- mBigramDictionary(new BigramDictionary(mDictionaryStructureWithBufferPolicy.get())),
+ mBigramDictionary(mDictionaryStructureWithBufferPolicy.get()),
mGestureSuggest(new Suggest(GestureSuggestPolicyFactory::getGestureSuggestPolicy())),
mTypingSuggest(new Suggest(TypingSuggestPolicyFactory::getTypingSuggestPolicy())) {
logDictionaryInfo(env);
@@ -78,7 +78,7 @@ void Dictionary::getPredictions(const int *word, int length,
SuggestionResults *const outSuggestionResults) const {
TimeKeeper::setCurrentTime();
if (length <= 0) return;
- mBigramDictionary->getPredictions(word, length, outSuggestionResults);
+ mBigramDictionary.getPredictions(word, length, outSuggestionResults);
}
int Dictionary::getProbability(const int *word, int length) const {
@@ -94,7 +94,7 @@ int Dictionary::getProbability(const int *word, int length) const {
int Dictionary::getBigramProbability(const int *word0, int length0, const int *word1,
int length1) const {
TimeKeeper::setCurrentTime();
- return mBigramDictionary->getBigramProbability(word0, length0, word1, length1);
+ return mBigramDictionary.getBigramProbability(word0, length0, word1, length1);
}
void Dictionary::addUnigramWord(const int *const word, const int length, const int probability,
diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h
index 2dea9fff8..ce032fceb 100644
--- a/native/jni/src/suggest/core/dictionary/dictionary.h
+++ b/native/jni/src/suggest/core/dictionary/dictionary.h
@@ -109,14 +109,13 @@ class Dictionary {
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary);
- typedef std::unique_ptr<BigramDictionary> BigramDictionaryPtr;
typedef std::unique_ptr<SuggestInterface> SuggestInterfacePtr;
static const int HEADER_ATTRIBUTE_BUFFER_SIZE;
const DictionaryStructureWithBufferPolicy::StructurePolicyPtr
mDictionaryStructureWithBufferPolicy;
- const BigramDictionaryPtr mBigramDictionary;
+ const BigramDictionary mBigramDictionary;
const SuggestInterfacePtr mGestureSuggest;
const SuggestInterfacePtr mTypingSuggest;
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
index 84a6ccf33..4e795f82c 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
@@ -349,13 +349,14 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin
// Skip the entry if the entry has been deleted. This never happens for ver2 dicts.
if (bigramsIt.getBigramPos() != NOT_A_DICT_POS) {
int word1Probability = NOT_A_PROBABILITY;
- int word1CodePointCount = getCodePointsAndProbabilityAndReturnCodePointCount(
+ const int word1CodePointCount = getCodePointsAndProbabilityAndReturnCodePointCount(
bigramsIt.getBigramPos(), MAX_WORD_LENGTH, bigramWord1CodePoints,
&word1Probability);
- std::vector<int> word1(bigramWord1CodePoints,
+ const std::vector<int> word1(bigramWord1CodePoints,
bigramWord1CodePoints + word1CodePointCount);
- bigrams.push_back(WordProperty::BigramProperty(&word1, bigramsIt.getProbability(),
- NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */));
+ const int probability = getProbability(word1Probability, bigramsIt.getProbability());
+ bigrams.emplace_back(&word1, probability,
+ NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */);
}
}
// Fetch shortcut information.
@@ -371,12 +372,11 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin
hasNext = ShortcutListReadingUtils::hasNext(shortcutFlags);
const int shortcutTargetLength = ShortcutListReadingUtils::readShortcutTarget(
mDictRoot, MAX_WORD_LENGTH, shortcutTargetCodePoints, &shortcutPos);
- std::vector<int> shortcutTarget(shortcutTargetCodePoints,
+ const std::vector<int> shortcutTarget(shortcutTargetCodePoints,
shortcutTargetCodePoints + shortcutTargetLength);
const int shortcutProbability =
ShortcutListReadingUtils::getProbabilityFromFlags(shortcutFlags);
- shortcuts.push_back(
- WordProperty::ShortcutProperty(&shortcutTarget, shortcutProbability));
+ shortcuts.emplace_back(&shortcutTarget, shortcutProbability);
}
}
return WordProperty(&codePointVector, ptNodeParams.isNotAWord(),
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
index 1a38a27ff..107ddab2c 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
@@ -382,16 +382,16 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code
const int codePointCount = getCodePointsAndProbabilityAndReturnCodePointCount(
word1TerminalPtNodePos, MAX_WORD_LENGTH, bigramWord1CodePoints,
&word1Probability);
- std::vector<int> word1(bigramWord1CodePoints,
+ const std::vector<int> word1(bigramWord1CodePoints,
bigramWord1CodePoints + codePointCount);
const HistoricalInfo *const historicalInfo = bigramEntry.getHistoricalInfo();
const int probability = bigramEntry.hasHistoricalInfo() ?
ForgettingCurveUtils::decodeProbability(
bigramEntry.getHistoricalInfo(), mHeaderPolicy) :
- bigramEntry.getProbability();
- bigrams.push_back(WordProperty::BigramProperty(&word1, probability,
+ getProbability(word1Probability, bigramEntry.getProbability());
+ bigrams.emplace_back(&word1, probability,
historicalInfo->getTimeStamp(), historicalInfo->getLevel(),
- historicalInfo->getCount()));
+ historicalInfo->getCount());
}
}
// Fetch shortcut information.
@@ -407,8 +407,8 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code
int shortcutProbability = NOT_A_PROBABILITY;
shortcutDictContent->getShortcutEntryAndAdvancePosition(MAX_WORD_LENGTH, shortcutTarget,
&shortcutTargetLength, &shortcutProbability, &hasNext, &shortcutPos);
- std::vector<int> target(shortcutTarget, shortcutTarget + shortcutTargetLength);
- shortcuts.push_back(WordProperty::ShortcutProperty(&target, shortcutProbability));
+ const std::vector<int> target(shortcutTarget, shortcutTarget + shortcutTargetLength);
+ shortcuts.emplace_back(&target, shortcutProbability);
}
}
return WordProperty(&codePointVector, ptNodeParams.isNotAWord(),
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/AlphabetShifted.java b/tests/src/com/android/inputmethod/keyboard/layout/AlphabetShifted.java
index be3ed12de..b81061ab8 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/AlphabetShifted.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/AlphabetShifted.java
@@ -28,13 +28,12 @@ import java.util.Locale;
* The generic upper case alphabet keyboard layout.
*/
public final class AlphabetShifted extends LayoutBase {
- public static ExpectedKey[][] getAlphabet(final ExpectedKey[][] lowerCaseKeyboard,
+ public static ExpectedKey[][] getDefaultLayout(final ExpectedKey[][] lowerCaseKeyboard,
final Locale locale) {
- final ExpectedKey[][] upperCaseKeyboard = ExpectedKeyboardBuilder.toUpperCase(
- lowerCaseKeyboard, locale);
- return new ExpectedKeyboardBuilder(upperCaseKeyboard)
- .replaceKeyOfAll(SHIFT_KEY, SHIFTED_SHIFT_KEY)
- .build();
+ final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(lowerCaseKeyboard);
+ builder.toUpperCase(locale);
+ builder.replaceKeysOfAll(SHIFT_KEY, SHIFTED_SHIFT_KEY);
+ return builder.build();
}
// Icon id.
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java b/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java
index f7179b739..325b78450 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java
@@ -24,8 +24,10 @@ import com.android.inputmethod.keyboard.layout.expected.LayoutBase;
* The QWERTY alphabet keyboard.
*/
public final class Qwerty extends LayoutBase {
- public static ExpectedKey[][] getAlphabet(final boolean isPhone) {
- return toCommonAlphabet(ALPHABET_COMMON, isPhone);
+ public static final String LAYOUT_NAME = "qwerty";
+
+ public static ExpectedKey[][] getLayout(final boolean isPhone) {
+ return getDefaultAlphabetLayout(ALPHABET_COMMON, isPhone);
}
private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder(10, 9, 7, 3)
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java b/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java
index 03d7f07e9..6fcfa0520 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java
@@ -25,15 +25,87 @@ import com.android.inputmethod.latin.Constants;
* The symbols keyboard layout.
*/
public final class Symbols extends LayoutBase {
- public static ExpectedKey[][] getSymbols(final boolean isPhone) {
+ public static ExpectedKey[][] getLayout(final boolean isPhone) {
return isPhone ? toPhoneSymbol(SYMBOLS_COMMON) : toTabletSymbols(SYMBOLS_COMMON);
}
+ public static ExpectedKey[][] getDefaultLayout(final boolean isPhone) {
+ final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(getLayout(isPhone));
+ builder.replaceKeyOfLabel(CURRENCY, Symbols.CURRENCY_DOLLAR);
+ builder.replaceKeyOfLabel(DOUBLE_QUOTE,
+ key("\"", join(Symbols.DOUBLE_QUOTES_9LR, Symbols.DOUBLE_ANGLE_QUOTES_LR)));
+ builder.replaceKeyOfLabel(SINGLE_QUOTE,
+ key("'", join(Symbols.SINGLE_QUOTES_9LR, Symbols.SINGLE_ANGLE_QUOTES_LR)));
+ return builder.build();
+ }
+
// Functional keys.
public static final ExpectedKey ALPHABET_KEY = key("ABC", Constants.CODE_SWITCH_ALPHA_SYMBOL);
public static final ExpectedKey SYMBOLS_SHIFT_KEY = key("= \\ <", Constants.CODE_SHIFT);
public static final ExpectedKey TABLET_SYMBOLS_SHIFT_KEY = key("~ [ <", Constants.CODE_SHIFT);
+ // Variations of the "currency" key on the 2nd row.
+ public static final String CURRENCY = "currency";
+ // U+00A2: "¢" CENT SIGN
+ // U+00A3: "£" POUND SIGN
+ // U+00A5: "¥" YEN SIGN
+ // U+20AC: "€" EURO SIGN
+ // U+20B1: "₱" PESO SIGN
+ public static final ExpectedKey DOLLAR_SIGN = key("$");
+ public static final ExpectedKey CENT_SIGN = key("\u00A2");
+ public static final ExpectedKey POUND_SIGN = key("\u00A3");
+ public static final ExpectedKey YEN_SIGN = key("\u00A5");
+ public static final ExpectedKey EURO_SIGN = key("\u20AC");
+ public static final ExpectedKey PESO_SIGN = key("\u20B1");
+ public static final ExpectedKey CURRENCY_DOLLAR = key("$",
+ CENT_SIGN, POUND_SIGN, EURO_SIGN, YEN_SIGN, PESO_SIGN);
+ public static final ExpectedKey CURRENCY_EURO = key("\u20AC",
+ CENT_SIGN, POUND_SIGN, DOLLAR_SIGN, YEN_SIGN, PESO_SIGN);
+
+ // Variations of the "double quote" key's "more keys" on the 3rd row.
+ public static final String DOUBLE_QUOTE = "double_quote";
+ // U+201C: "“" LEFT DOUBLE QUOTATION MARK
+ // U+201D: "”" RIGHT DOUBLE QUOTATION MARK
+ // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK
+ static final ExpectedKey DQUOTE_LEFT = key("\u201C");
+ static final ExpectedKey DQUOTE_RIGHT = key("\u201D");
+ static final ExpectedKey DQUOTE_LOW9 = key("\u201E");
+ public static ExpectedKey[] DOUBLE_QUOTES_9LR = { DQUOTE_LOW9, DQUOTE_LEFT, DQUOTE_RIGHT };
+ public static ExpectedKey[] DOUBLE_QUOTES_R9L = { DQUOTE_RIGHT, DQUOTE_LOW9, DQUOTE_LEFT };
+ public static ExpectedKey[] DOUBLE_QUOTES_L9R = { DQUOTE_LEFT, DQUOTE_LOW9, DQUOTE_RIGHT };
+ public static ExpectedKey[] DOUBLE_QUOTES_LR9 = { DQUOTE_LEFT, DQUOTE_RIGHT, DQUOTE_LOW9 };
+ // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
+ // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
+ private static final ExpectedKey DAQUOTE_LEFT = key("\u00AB");
+ private static final ExpectedKey DAQUOTE_RIGHT = key("\u00BB");
+ private static final ExpectedKey DAQUOTE_LEFT_RTL = key("\u00AB", "\u00BB");
+ private static final ExpectedKey DAQUOTE_RIGHT_RTL = key("\u00BB", "\u00AB");
+ public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_LR = { DAQUOTE_LEFT, DAQUOTE_RIGHT };
+ public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_RL = { DAQUOTE_RIGHT, DAQUOTE_LEFT };
+ public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_RTL = { DAQUOTE_LEFT_RTL, DAQUOTE_RIGHT_RTL };
+
+ // Variations of the "single quote" key's "more keys" on the 3rd row.
+ public static final String SINGLE_QUOTE = "single_quote";
+ // U+2018: "‘" LEFT SINGLE QUOTATION MARK
+ // U+2019: "’" RIGHT SINGLE QUOTATION MARK
+ // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK
+ static final ExpectedKey SQUOTE_LEFT = key("\u2018");
+ static final ExpectedKey SQUOTE_RIGHT = key("\u2019");
+ static final ExpectedKey SQUOTE_LOW9 = key("\u201A");
+ public static ExpectedKey[] SINGLE_QUOTES_9LR = { SQUOTE_LOW9, SQUOTE_LEFT, SQUOTE_RIGHT };
+ public static ExpectedKey[] SINGLE_QUOTES_R9L = { SQUOTE_RIGHT, SQUOTE_LOW9, SQUOTE_LEFT };
+ public static ExpectedKey[] SINGLE_QUOTES_L9R = { SQUOTE_LEFT, SQUOTE_LOW9, SQUOTE_RIGHT };
+ public static ExpectedKey[] SINGLE_QUOTES_LR9 = { SQUOTE_LEFT, SQUOTE_RIGHT, SQUOTE_LOW9 };
+ // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
+ // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
+ private static final ExpectedKey SAQUOTE_LEFT = key("\u2039");
+ private static final ExpectedKey SAQUOTE_RIGHT = key("\u203A");
+ private static final ExpectedKey SAQUOTE_LEFT_RTL = key("\u2039", "\u203A");
+ private static final ExpectedKey SAQUOTE_RIGHT_RTL = key("\u203A", "\u2039");
+ public static ExpectedKey[] SINGLE_ANGLE_QUOTES_LR = { SAQUOTE_LEFT, SAQUOTE_RIGHT };
+ public static ExpectedKey[] SINGLE_ANGLE_QUOTES_RL = { SAQUOTE_RIGHT, SAQUOTE_LEFT };
+ public static ExpectedKey[] SINGLE_ANGLE_QUOTES_RTL = { SAQUOTE_LEFT_RTL, SAQUOTE_RIGHT_RTL };
+
// Common symbols keyboard layout.
public static final ExpectedKey[][] SYMBOLS_COMMON = new ExpectedKeyboardBuilder(10, 9, 7, 5)
.setLabelsOfRow(1, "1", "2", "3", "4", "5", "6", "7", "8", "9", "0")
@@ -59,13 +131,7 @@ public final class Symbols extends LayoutBase {
// U+207F: "ⁿ" SUPERSCRIPT LATIN SMALL LETTER N
// U+2205: "∅" EMPTY SET
.setMoreKeysOf("0", "\u207F", "\u2205")
- .setLabelsOfRow(2, "@", "#", "$", "%", "&", "-", "+", "(", ")")
- // U+00A2: "¢" CENT SIGN
- // U+00A3: "£" POUND SIGN
- // U+20AC: "€" EURO SIGN
- // U+00A5: "¥" YEN SIGN
- // U+20B1: "₱" PESO SIGN
- .setMoreKeysOf("$", "\u00A2", "\u00A3", "\u20AC", "\u00A5", "\u20B1")
+ .setLabelsOfRow(2, "@", "#", CURRENCY, "%", "&", "-", "+", "(", ")")
// U+2030: "‰" PER MILLE SIGN
.setMoreKeysOf("%", "\u2030")
// U+2013: "–" EN DASH
@@ -76,23 +142,11 @@ public final class Symbols extends LayoutBase {
.setMoreKeysOf("+", "\u00B1")
.setMoreKeysOf("(", "<", "{", "[")
.setMoreKeysOf(")", ">", "}", "]")
- .setLabelsOfRow(3, "*", "\"", "'", ":", ";", "!", "?")
+ .setLabelsOfRow(3, "*", DOUBLE_QUOTE, SINGLE_QUOTE, ":", ";", "!", "?")
// U+2020: "†" DAGGER
// U+2021: "‡" DOUBLE DAGGER
// U+2605: "★" BLACK STAR
.setMoreKeysOf("*", "\u2020", "\u2021", "\u2605")
- // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK
- // U+201C: "“" LEFT DOUBLE QUOTATION MARK
- // U+201D: "”" RIGHT DOUBLE QUOTATION MARK
- // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
- // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
- .setMoreKeysOf("\"", "\u201E", "\u201C", "\u201D", "\u00AB", "\u00BB")
- // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK
- // U+2018: "‘" LEFT SINGLE QUOTATION MARK
- // U+2019: "’" RIGHT SINGLE QUOTATION MARK
- // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
- // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
- .setMoreKeysOf("'", "\u201A", "\u2018", "\u2019", "\u2039", "\u203A")
// U+00A1: "¡" INVERTED EXCLAMATION MARK
.setMoreKeysOf("!", "\u00A1")
// U+00BF: "¿" INVERTED QUESTION MARK
@@ -123,65 +177,4 @@ public final class Symbols extends LayoutBase {
.addKeysOnTheRightOfRow(4, EMOJI_KEY)
.build();
}
-
- // Helper method to add currency symbols for Euro.
- public static ExpectedKeyboardBuilder euro(final ExpectedKeyboardBuilder builder) {
- return builder
- // U+20AC: "€" EURO SIGN
- // U+00A2: "¢" CENT SIGN
- // U+00A3: "£" POUND SIGN
- // U+00A5: "¥" YEN SIGN
- // U+20B1: "₱" PESO SIGN
- .replaceKeyOfLabel("$", key("\u20AC",
- moreKey("\u00A2"), moreKey("\u00A3"), moreKey("$"),
- moreKey("\u00A5"), moreKey("\u20B1")));
- }
-
- // Helper method to add single quotes "more keys".
- // "9LLR" means "9-low/Left quotation marks, Left/Right-pointing angle quotation marks".
- public static ExpectedKeyboardBuilder singleQuotes9LLR(final ExpectedKeyboardBuilder builder) {
- return builder
- // U+2019: "’" RIGHT SINGLE QUOTATION MARK
- // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK
- // U+2018: "‘" LEFT SINGLE QUOTATION MARK
- // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
- // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
- .setMoreKeysOf("'", "\u2019", "\u201A", "\u2018", "\u2039", "\u203A");
- }
-
- // Helper method to add single quotes "more keys".
- // "9LLR" means "9-low/Left quotation marks, Right/Left-pointing angle quotation marks".
- public static ExpectedKeyboardBuilder singleQuotes9LRL(final ExpectedKeyboardBuilder builder) {
- return builder
- // U+2019: "’" RIGHT SINGLE QUOTATION MARK
- // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK
- // U+2018: "‘" LEFT SINGLE QUOTATION MARK
- // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
- // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
- .setMoreKeysOf("'", "\u2019", "\u201A", "\u2018", "\u203A", "\u2039");
- }
-
- // Helper method to add double quotes "more keys".
- // "9LLR" means "9-low/Left quotation marks, Left/Right-pointing angle quotation marks".
- public static ExpectedKeyboardBuilder doubleQuotes9LLR(final ExpectedKeyboardBuilder builder) {
- return builder
- // U+201D: "”" RIGHT DOUBLE QUOTATION MARK
- // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK
- // U+201C: "“" LEFT DOUBLE QUOTATION MARK
- // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
- // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
- .setMoreKeysOf("\"", "\u201D", "\u201E", "\u201C", "\u00AB", "\u00BB");
- }
-
- // Helper method to add double quotes "more keys".
- // "9LLR" means "9-low/Left quotation marks, Right/Left-pointing angle quotation marks".
- public static ExpectedKeyboardBuilder doubleQuotes9LRL(final ExpectedKeyboardBuilder builder) {
- return builder
- // U+201D: "”" RIGHT DOUBLE QUOTATION MARK
- // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK
- // U+201C: "“" LEFT DOUBLE QUOTATION MARK
- // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
- // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
- .setMoreKeysOf("\"", "\u201D", "\u201E", "\u201C", "\u00BB", "\u00AB");
- }
}
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java b/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java
index 368f9db46..4d9ae4348 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java
@@ -25,17 +25,33 @@ import com.android.inputmethod.latin.Constants;
* The symbols shifted keyboard layout.
*/
public final class SymbolsShifted extends LayoutBase {
- public static ExpectedKey[][] getSymbolsShifted(final boolean isPhone) {
+ public static ExpectedKey[][] getLayout(final boolean isPhone) {
return isPhone ? toPhoneSymbolsShifted(SYMBOLS_SHIFTED_COMMON)
: toTabletSymbolsShifted(SYMBOLS_SHIFTED_COMMON);
}
+ public static ExpectedKey[][] getDefaultLayout(final boolean isPhone) {
+ final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(getLayout(isPhone));
+ builder.replaceKeyOfLabel(OTHER_CURRENCIES, SymbolsShifted.CURRENCIES_OTHER_THAN_DOLLAR);
+ return builder.build();
+ }
+
// Functional key.
public static final ExpectedKey BACK_TO_SYMBOLS_KEY = key("?123", Constants.CODE_SHIFT);
+ // Variations of the "other currencies" keys on the 2rd row.
+ public static final String OTHER_CURRENCIES = "other_currencies";
+ public static final ExpectedKey[] CURRENCIES_OTHER_THAN_DOLLAR = {
+ Symbols.POUND_SIGN, Symbols.CENT_SIGN, Symbols.EURO_SIGN, Symbols.YEN_SIGN
+ };
+ public static final ExpectedKey[] CURRENCIES_OTHER_THAN_EURO = {
+ Symbols.POUND_SIGN, Symbols.YEN_SIGN, key(Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN),
+ Symbols.CENT_SIGN
+ };
+
// Common symbols shifted keyboard layout.
public static final ExpectedKey[][] SYMBOLS_SHIFTED_COMMON =
- new ExpectedKeyboardBuilder(10, 9, 7, 5)
+ new ExpectedKeyboardBuilder(10, 1 /* other_currencies */ + 5, 7, 5)
// U+0060: "`" GRAVE ACCENT
// U+2022: "•" BULLET
// U+221A: "√" SQUARE ROOT
@@ -60,14 +76,8 @@ public final class SymbolsShifted extends LayoutBase {
// U+00B6: "¶" PILCROW SIGN
// U+00A7: "§" SECTION SIGN
.setMoreKeysOf("\u00B6", "\u00A7")
- // U+00A3: "£" POUND SIGN
- // U+00A2: "¢" CENT SIGN
- // U+20AC: "€" EURO SIGN
- // U+00A5: "¥" YEN SIGN
// U+00B0: "°" DEGREE SIGN
- .setLabelsOfRow(2,
- "\u00A3", "\u00A2", "\u20AC", "\u00A5", "^",
- "\u00B0", "=", "{", "}")
+ .setLabelsOfRow(2, OTHER_CURRENCIES, "^", "\u00B0", "=", "{", "}")
// U+2191: "↑" UPWARDS ARROW
// U+2193: "↓" DOWNWARDS ARROW
// U+2190: "←" LEFTWARDS ARROW
@@ -125,18 +135,4 @@ public final class SymbolsShifted extends LayoutBase {
.addKeysOnTheRightOfRow(4, EMOJI_KEY)
.build();
}
-
- // Helper method to add currency symbols for Euro.
- public static ExpectedKeyboardBuilder euro(final ExpectedKeyboardBuilder builder) {
- return builder
- // U+00A5: "¥" YEN SIGN
- // U+00A2: "¢" CENT SIGN
- .replaceKeyOfLabel("\u00A5", key("\u00A2"))
- // U+20AC: "€" EURO SIGN
- // U+00A2: "¢" CENT SIGN
- .replaceKeyOfLabel("\u20AC", key("$", moreKey("\u00A2")))
- // U+00A2: "¢" CENT SIGN
- // U+00A5: "¥" YEN SIGN
- .replaceKeyOfLabel("\u00A2", key("\u00A5"));
- }
}
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java
index 45449b762..682ac20a1 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java
@@ -73,6 +73,14 @@ abstract class AbstractKeyboardBuilder<E> {
}
/**
+ * Return the number of rows.
+ * @return the number of rows being constructed.
+ */
+ int getRowCount() {
+ return mRows.length;
+ }
+
+ /**
* Get the current contents of the specified row.
* @param row the row number to get the contents.
* @return the array of elements at row number <code>row</code>.
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
index 61288f048..57f842b74 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
@@ -52,32 +52,56 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
}
// A replacement job to be performed.
- interface ReplaceJob {
- // Returns a {@link ExpectedKey} object to replace.
- ExpectedKey replace(final ExpectedKey oldKey);
+ private interface ReplaceJob {
+ // Returns a {@link ExpectedKey} objects to replace.
+ ExpectedKey[] replacingKeys(final ExpectedKey oldKey);
// Return true if replacing should be stopped at first occurrence.
boolean stopAtFirstOccurrence();
}
+ private static ExpectedKey[] replaceKeyAt(final ExpectedKey[] keys, final int columnIndex,
+ final ExpectedKey[] replacingKeys) {
+ // Optimization for replacing a key with another key.
+ if (replacingKeys.length == 1) {
+ keys[columnIndex] = replacingKeys[0];
+ return keys;
+ }
+ final int newLength = keys.length - 1 + replacingKeys.length;
+ // Remove the key at columnIndex.
+ final ExpectedKey[] newKeys = Arrays.copyOf(keys, newLength);
+ System.arraycopy(keys, columnIndex + 1, newKeys, columnIndex + replacingKeys.length,
+ keys.length - 1 - columnIndex);
+ // Insert replacing keys at columnIndex.
+ System.arraycopy(replacingKeys, 0, newKeys, columnIndex, replacingKeys.length);
+ return newKeys;
+
+ }
+
// Replace key(s) that has the specified visual.
private void replaceKeyOf(final ExpectedKeyVisual visual, final ReplaceJob job) {
int replacedCount = 0;
- final ExpectedKey[][] rows = build();
- for (int rowIndex = 0; rowIndex < rows.length; rowIndex++) {
- final ExpectedKey[] keys = rows[rowIndex];
- for (int columnIndex = 0; columnIndex < keys.length; columnIndex++) {
- if (keys[columnIndex].getVisual().equalsTo(visual)) {
- keys[columnIndex] = job.replace(keys[columnIndex]);
- replacedCount++;
- if (job.stopAtFirstOccurrence()) {
- return;
- }
+ final int rowCount = getRowCount();
+ for (int row = 1; row <= rowCount; row++) {
+ ExpectedKey[] keys = getRowAt(row);
+ for (int columnIndex = 0; columnIndex < keys.length; /* nothing */) {
+ final ExpectedKey currentKey = keys[columnIndex];
+ if (!currentKey.getVisual().equalsTo(visual)) {
+ columnIndex++;
+ continue;
+ }
+ final ExpectedKey[] replacingKeys = job.replacingKeys(currentKey);
+ keys = replaceKeyAt(keys, columnIndex, replacingKeys);
+ columnIndex += replacingKeys.length;
+ setRowAt(row, keys);
+ replacedCount++;
+ if (job.stopAtFirstOccurrence()) {
+ return;
}
}
}
if (replacedCount == 0) {
throw new RuntimeException(
- "Can't find key that has visual: " + visual + " in\n" + toString(rows));
+ "Can't find key that has visual: " + visual + " in\n" + this);
}
}
@@ -137,8 +161,10 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
private void setMoreKeysOf(final ExpectedKeyVisual visual, final ExpectedKey[] moreKeys) {
replaceKeyOf(visual, new ReplaceJob() {
@Override
- public ExpectedKey replace(final ExpectedKey oldKey) {
- return ExpectedKey.newInstance(oldKey.getVisual(), oldKey.getOutput(), moreKeys);
+ public ExpectedKey[] replacingKeys(final ExpectedKey oldKey) {
+ return new ExpectedKey[] {
+ ExpectedKey.newInstance(oldKey.getVisual(), oldKey.getOutput(), moreKeys)
+ };
}
@Override
public boolean stopAtFirstOccurrence() {
@@ -194,17 +220,18 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
}
/**
- * Replace the most top-left key that has the specified label with the new key.
- * @param label the label of the key to set <code>newKey</code>.
- * @param newKey the key to be set.
+ * Replace the most top-left key that has the specified label with the new keys.
+ * @param label the label of the key to set <code>newKeys</code>.
+ * @param newKeys the keys to be set.
* @return this builder.
*/
- public ExpectedKeyboardBuilder replaceKeyOfLabel(final String label, final ExpectedKey newKey) {
+ public ExpectedKeyboardBuilder replaceKeyOfLabel(final String label,
+ final ExpectedKey ... newKeys) {
final ExpectedKeyVisual visual = ExpectedKeyVisual.newInstance(label);
replaceKeyOf(visual, new ReplaceJob() {
@Override
- public ExpectedKey replace(final ExpectedKey oldKey) {
- return newKey;
+ public ExpectedKey[] replacingKeys(final ExpectedKey oldKey) {
+ return newKeys;
}
@Override
public boolean stopAtFirstOccurrence() {
@@ -215,17 +242,17 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
}
/**
- * Replace the all specified keys with the new key.
- * @param key the key to be replaced by <code>newKey</code>.
- * @param newKey the key to be set.
+ * Replace the all specified keys with the new keys.
+ * @param key the key to be replaced by <code>newKeys</code>.
+ * @param newKeys the keys to be set.
* @return this builder.
*/
- public ExpectedKeyboardBuilder replaceKeyOfAll(final ExpectedKey key,
- final ExpectedKey newKey) {
+ public ExpectedKeyboardBuilder replaceKeysOfAll(final ExpectedKey key,
+ final ExpectedKey ... newKeys) {
replaceKeyOf(key.getVisual(), new ReplaceJob() {
@Override
- public ExpectedKey replace(final ExpectedKey oldKey) {
- return newKey;
+ public ExpectedKey[] replacingKeys(final ExpectedKey oldKey) {
+ return newKeys;
}
@Override
public boolean stopAtFirstOccurrence() {
@@ -236,22 +263,26 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
}
/**
- * Returns new keyboard instance that has upper case keys of the specified keyboard.
- * @param rows the lower case keyboard.
+ * Convert all keys of this keyboard builder to upper case keys.
* @param locale the locale used to convert cases.
- * @return the upper case keyboard.
+ * @return this builder
*/
- public static ExpectedKey[][] toUpperCase(final ExpectedKey[][] rows, final Locale locale) {
- final ExpectedKey[][] upperCaseRows = new ExpectedKey[rows.length][];
- for (int rowIndex = 0; rowIndex < rows.length; rowIndex++) {
- final ExpectedKey[] lowerCaseKeys = rows[rowIndex];
+ public ExpectedKeyboardBuilder toUpperCase(final Locale locale) {
+ final int rowCount = getRowCount();
+ for (int row = 1; row <= rowCount; row++) {
+ final ExpectedKey[] lowerCaseKeys = getRowAt(row);
final ExpectedKey[] upperCaseKeys = new ExpectedKey[lowerCaseKeys.length];
for (int columnIndex = 0; columnIndex < lowerCaseKeys.length; columnIndex++) {
upperCaseKeys[columnIndex] = lowerCaseKeys[columnIndex].toUpperCase(locale);
}
- upperCaseRows[rowIndex] = upperCaseKeys;
+ setRowAt(row, upperCaseKeys);
}
- return upperCaseRows;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return toString(build());
}
/**
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java
index 1aeb8c0cd..1d242d0b8 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java
@@ -18,6 +18,10 @@ package com.android.inputmethod.keyboard.layout.expected;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.utils.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
/**
* Base class to create an expected keyboard for unit test.
@@ -71,6 +75,24 @@ public class LayoutBase {
return ExpectedKey.newInstance(label, code);
}
+ // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
+ // {@link ExpectedKey} array, and {@link String}.
+ public static ExpectedKey[] join(final Object ... keys) {
+ final ArrayList<ExpectedKey> list = CollectionUtils.newArrayList();
+ for (final Object key : keys) {
+ if (key instanceof ExpectedKey) {
+ list.add((ExpectedKey)key);
+ } else if (key instanceof ExpectedKey[]) {
+ list.addAll(Arrays.asList((ExpectedKey[])key));
+ } else if (key instanceof String) {
+ list.add(key((String)key));
+ } else {
+ throw new RuntimeException("Unknown expected key type: " + key);
+ }
+ }
+ return list.toArray(new ExpectedKey[list.size()]);
+ }
+
// Icon ids.
private static final int ICON_SHIFT = KeyboardIconsSet.getIconId("shift_key");
private static final int ICON_DELETE = KeyboardIconsSet.getIconId("delete_key");
@@ -99,9 +121,11 @@ public class LayoutBase {
"&", "%", "+", "\"", "-", ":", "@"
};
- private static ExpectedKeyboardBuilder toPhoneAlphabet(final ExpectedKeyboardBuilder builder) {
- return builder
- .addKeysOnTheLeftOfRow(3, key(SHIFT_KEY, CAPSLOCK_MORE_KEY))
+ // Helper method to create alphabet layout for phone by adding special function keys except
+ // shift key.
+ private static ExpectedKeyboardBuilder convertToPhoneAlphabetKeyboardBuilder(
+ final ExpectedKey[][] commonLayout) {
+ return new ExpectedKeyboardBuilder(commonLayout)
.addKeysOnTheRightOfRow(3, DELETE_KEY)
.setLabelsOfRow(4, ",", " ", ".")
.setMoreKeysOf(",", SETTINGS_KEY)
@@ -112,9 +136,9 @@ public class LayoutBase {
// Helper method to create alphabet layout for tablet by adding special function keys except
// shift key.
- public static ExpectedKeyboardBuilder toTabletAlphabetWithoutShiftKeys(
- final ExpectedKeyboardBuilder builder) {
- return builder
+ private static ExpectedKeyboardBuilder convertToTabletAlphabetKeyboardBuilder(
+ final ExpectedKey[][] commonLayout) {
+ return new ExpectedKeyboardBuilder(commonLayout)
// U+00BF: "¿" INVERTED QUESTION MARK
// U+00A1: "¡" INVERTED EXCLAMATION MARK
.addKeysOnTheRightOfRow(3,
@@ -128,13 +152,20 @@ public class LayoutBase {
}
// Helper method to create alphabet layout by adding special function keys.
- public static ExpectedKey[][] toCommonAlphabet(final ExpectedKey[][] common,
+ public static ExpectedKey[][] getAlphabetLayoutWithoutShiftKeys(
+ final ExpectedKey[][] commonLayout, final boolean isPhone) {
+ return isPhone ? convertToPhoneAlphabetKeyboardBuilder(commonLayout).build()
+ : convertToTabletAlphabetKeyboardBuilder(commonLayout).build();
+ }
+
+ // Helper method to create alphabet layout by adding special function keys.
+ public static ExpectedKey[][] getDefaultAlphabetLayout(final ExpectedKey[][] commonLayout,
final boolean isPhone) {
- final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(common);
+ final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(
+ getAlphabetLayoutWithoutShiftKeys(commonLayout, isPhone));
if (isPhone) {
- toPhoneAlphabet(builder);
+ builder.addKeysOnTheLeftOfRow(3, key(SHIFT_KEY, CAPSLOCK_MORE_KEY));
} else {
- toTabletAlphabetWithoutShiftKeys(builder);
builder.addKeysOnTheLeftOfRow(3, key(SHIFT_KEY, CAPSLOCK_MORE_KEY))
.addKeysOnTheRightOfRow(3, key(SHIFT_KEY, CAPSLOCK_MORE_KEY));
}
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
index 427e7de49..5c51d088b 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
@@ -68,6 +68,11 @@ abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase {
return LayoutBase.key(label, outputText, moreKeys);
}
+ // Helper method to create {@link ExpectedKey} object that has new "more keys".
+ static ExpectedKey key(final ExpectedKey key, final ExpectedKey ... moreKeys) {
+ return LayoutBase.key(key, moreKeys);
+ }
+
// Helper method to create {@link ExpectedKey} object for "more key" that has the label.
static ExpectedKey moreKey(final String label) {
return LayoutBase.moreKey(label);
@@ -79,6 +84,12 @@ abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase {
return LayoutBase.moreKey(label, outputText);
}
+ // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
+ // {@link ExpectedKey} array, and {@link String}.
+ static ExpectedKey[] join(final Object ... keys) {
+ return LayoutBase.join(keys);
+ }
+
// Locale for testing subtype.
abstract Locale getTestLocale();
@@ -86,73 +97,73 @@ abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase {
abstract String getTestKeyboardLayout();
// Alphabet keyboard for testing subtype.
- abstract ExpectedKey[][] getAlphabet(final boolean isPhone);
+ abstract ExpectedKey[][] getAlphabetLayout(final boolean isPhone);
// Alphabet automatic shifted keyboard for testing subtype.
- ExpectedKey[][] getAlphabetAutomaticShifted(final boolean isPhone) {
- return AlphabetShifted.getAlphabet(getAlphabet(isPhone), getTestLocale());
+ ExpectedKey[][] getAlphabetAutomaticShiftedLayout(final boolean isPhone) {
+ return AlphabetShifted.getDefaultLayout(getAlphabetLayout(isPhone), getTestLocale());
}
// Alphabet manual shifted keyboard for testing subtype.
- ExpectedKey[][] getAlphabetManualShifted(final boolean isPhone) {
- return AlphabetShifted.getAlphabet(getAlphabet(isPhone), getTestLocale());
+ ExpectedKey[][] getAlphabetManualShiftedLayout(final boolean isPhone) {
+ return AlphabetShifted.getDefaultLayout(getAlphabetLayout(isPhone), getTestLocale());
}
// Alphabet shift locked keyboard for testing subtype.
- ExpectedKey[][] getAlphabetShiftLocked(final boolean isPhone) {
- return AlphabetShifted.getAlphabet(getAlphabet(isPhone), getTestLocale());
+ ExpectedKey[][] getAlphabetShiftLockedLayout(final boolean isPhone) {
+ return AlphabetShifted.getDefaultLayout(getAlphabetLayout(isPhone), getTestLocale());
}
// Alphabet shift lock shifted keyboard for testing subtype.
- ExpectedKey[][] getAlphabetShiftLockShifted(final boolean isPhone) {
- return AlphabetShifted.getAlphabet(getAlphabet(isPhone), getTestLocale());
+ ExpectedKey[][] getAlphabetShiftLockShiftedLayout(final boolean isPhone) {
+ return AlphabetShifted.getDefaultLayout(getAlphabetLayout(isPhone), getTestLocale());
}
// Symbols keyboard for testing subtype.
- ExpectedKey[][] getSymbols(final boolean isPhone) {
- return Symbols.getSymbols(isPhone);
+ ExpectedKey[][] getSymbolsLayout(final boolean isPhone) {
+ return Symbols.getDefaultLayout(isPhone);
}
// Symbols shifted keyboard for testing subtype.
- ExpectedKey[][] getSymbolsShifted(final boolean isPhone) {
- return SymbolsShifted.getSymbolsShifted(isPhone);
+ ExpectedKey[][] getSymbolsShiftedLayout(final boolean isPhone) {
+ return SymbolsShifted.getDefaultLayout(isPhone);
}
// TODO: Add phone, phone symbols, number, number password layout tests.
public final void testAlphabet() {
final int elementId = KeyboardId.ELEMENT_ALPHABET;
- doKeyboardTests(elementId, getAlphabet(isPhone()));
+ doKeyboardTests(elementId, getAlphabetLayout(isPhone()));
}
public final void testAlphabetAutomaticShifted() {
final int elementId = KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED;
- doKeyboardTests(elementId, getAlphabetAutomaticShifted(isPhone()));
+ doKeyboardTests(elementId, getAlphabetAutomaticShiftedLayout(isPhone()));
}
public final void testAlphabetManualShifted() {
final int elementId = KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED;
- doKeyboardTests(elementId, getAlphabetManualShifted(isPhone()));
+ doKeyboardTests(elementId, getAlphabetManualShiftedLayout(isPhone()));
}
public final void testAlphabetShiftLocked() {
final int elementId = KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED;
- doKeyboardTests(elementId, getAlphabetShiftLocked(isPhone()));
+ doKeyboardTests(elementId, getAlphabetShiftLockedLayout(isPhone()));
}
public final void testAlphabetShiftLockShifted() {
final int elementId = KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED;
- doKeyboardTests(elementId, getAlphabetShiftLockShifted(isPhone()));
+ doKeyboardTests(elementId, getAlphabetShiftLockShiftedLayout(isPhone()));
}
public final void testSymbols() {
final int elementId = KeyboardId.ELEMENT_SYMBOLS;
- doKeyboardTests(elementId, getSymbols(isPhone()));
+ doKeyboardTests(elementId, getSymbolsLayout(isPhone()));
}
public final void testSymbolsShifted() {
final int elementId = KeyboardId.ELEMENT_SYMBOLS_SHIFTED;
- doKeyboardTests(elementId, getSymbolsShifted(isPhone()));
+ doKeyboardTests(elementId, getSymbolsShiftedLayout(isPhone()));
}
// Comparing expected keyboard and actual keyboard.
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java
index 0792a5789..fd1a60619 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java
@@ -36,12 +36,12 @@ public final class TestsEnglishUS extends LayoutTestsBase {
@Override
String getTestKeyboardLayout() {
- return "qwerty";
+ return Qwerty.LAYOUT_NAME;
}
@Override
- ExpectedKey[][] getAlphabet(final boolean isPhone) {
- final ExpectedKey[][] keyboard = Qwerty.getAlphabet(isPhone);
+ ExpectedKey[][] getAlphabetLayout(final boolean isPhone) {
+ final ExpectedKey[][] keyboard = Qwerty.getLayout(isPhone);
final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(keyboard);
setAccentedLetters(builder);
return builder.build();