• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.inputmethod.keyboard.layout.expected;
18 
19 import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
20 import com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey;
21 import com.android.inputmethod.latin.common.Constants;
22 
23 /**
24  * Base class to create an expected keyboard for unit test.
25  */
26 public abstract class AbstractLayoutBase {
27     // Those helper methods have a lower case name to be readable when defining expected keyboard
28     // layouts.
29 
30     // Helper method to create an {@link ExpectedKey} object that has the label.
key(final String label, final ExpectedKey ... moreKeys)31     public static ExpectedKey key(final String label, final ExpectedKey ... moreKeys) {
32         return ExpectedKey.newInstance(label, moreKeys);
33     }
34 
35     // Helper method to create an {@link ExpectedKey} object that has the label and the output text.
key(final String label, final String outputText, final ExpectedKey ... moreKeys)36     public static ExpectedKey key(final String label, final String outputText,
37             final ExpectedKey ... moreKeys) {
38         return ExpectedKey.newInstance(label, outputText, moreKeys);
39     }
40 
41     // Helper method to create an {@link ExpectedKey} object that has the label and the output code.
key(final String label, final int code, final ExpectedKey ... moreKeys)42     public static ExpectedKey key(final String label, final int code,
43             final ExpectedKey ... moreKeys) {
44         return ExpectedKey.newInstance(label, code, moreKeys);
45     }
46 
47     // Helper method to create an {@link ExpectedKey} object that has the icon and the output text.
key(final int iconId, final String outputText, final ExpectedKey ... moreKeys)48     public static ExpectedKey key(final int iconId, final String outputText,
49             final ExpectedKey ... moreKeys) {
50         return ExpectedKey.newInstance(iconId, outputText, moreKeys);
51     }
52 
53     // Helper method to create an {@link ExpectedKey} object that has the icon and the output code.
key(final int iconId, final int code, final ExpectedKey ... moreKeys)54     public static ExpectedKey key(final int iconId, final int code,
55             final ExpectedKey ... moreKeys) {
56         return ExpectedKey.newInstance(iconId, code, moreKeys);
57     }
58 
59     // Helper method to create an {@link ExpectedKey} object that has new "more keys".
key(final ExpectedKey key, final ExpectedKey ... moreKeys)60     public static ExpectedKey key(final ExpectedKey key, final ExpectedKey ... moreKeys) {
61         return ExpectedKey.newInstance(key.getVisual(), key.getOutput(), moreKeys);
62     }
63 
64     // Helper method to create an {@link ExpectedAdditionalMoreKey} object for an
65     // "additional more key" that has the label.
66     // The additional more keys can be defined independently from other more keys. The position of
67     // the additional more keys in the long press popup keyboard can be controlled by specifying
68     // special marker "%" in the usual more keys definitions.
additionalMoreKey(final String label)69     public static ExpectedAdditionalMoreKey additionalMoreKey(final String label) {
70         return ExpectedAdditionalMoreKey.newInstance(label);
71     }
72 
73     // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label.
moreKey(final String label)74     public static ExpectedKey moreKey(final String label) {
75         return ExpectedKey.newInstance(label);
76     }
77 
78     // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label
79     // and the output text.
moreKey(final String label, final String outputText)80     public static ExpectedKey moreKey(final String label, final String outputText) {
81         return ExpectedKey.newInstance(label, outputText);
82     }
83 
84     // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label
85     // and the output code.
moreKey(final String label, final int code)86     public static ExpectedKey moreKey(final String label, final int code) {
87         return ExpectedKey.newInstance(label, code);
88     }
89 
90     // Helper method to create an {@link ExpectedKey} object for a "more key" that has the icon
91     // and the output text.
moreKey(final int iconId, final String outputText)92     public static ExpectedKey moreKey(final int iconId, final String outputText) {
93         return ExpectedKey.newInstance(iconId, outputText);
94     }
95 
96     // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
97     // {@link ExpectedKey} array, and {@link String}.
joinMoreKeys(final Object ... moreKeys)98     public static ExpectedKey[] joinMoreKeys(final Object ... moreKeys) {
99         return joinKeys(moreKeys);
100     }
101 
102     // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
103     // {@link ExpectedKey} array, and {@link String}.
joinKeys(final Object ... keys)104     public static ExpectedKey[] joinKeys(final Object ... keys) {
105         return ExpectedKeyboardBuilder.joinKeys(keys);
106     }
107 
108     // Icon ids.
109     private static final int ICON_DELETE = KeyboardIconsSet.getIconId(
110             KeyboardIconsSet.NAME_DELETE_KEY);
111     private static final int ICON_SPACE = KeyboardIconsSet.getIconId(
112             KeyboardIconsSet.NAME_SPACE_KEY);
113     private static final int ICON_TAB = KeyboardIconsSet.getIconId(
114             KeyboardIconsSet.NAME_TAB_KEY);
115     private static final int ICON_SHORTCUT = KeyboardIconsSet.getIconId(
116             KeyboardIconsSet.NAME_SHORTCUT_KEY);
117     private static final int ICON_SETTINGS = KeyboardIconsSet.getIconId(
118             KeyboardIconsSet.NAME_SETTINGS_KEY);
119     private static final int ICON_LANGUAGE_SWITCH = KeyboardIconsSet.getIconId(
120             KeyboardIconsSet.NAME_LANGUAGE_SWITCH_KEY);
121     private static final int ICON_ENTER = KeyboardIconsSet.getIconId(
122             KeyboardIconsSet.NAME_ENTER_KEY);
123     private static final int ICON_EMOJI_ACTION = KeyboardIconsSet.getIconId(
124             KeyboardIconsSet.NAME_EMOJI_ACTION_KEY);
125     private static final int ICON_EMOJI_NORMAL = KeyboardIconsSet.getIconId(
126             KeyboardIconsSet.NAME_EMOJI_NORMAL_KEY);
127     private static final int ICON_SHIFT = KeyboardIconsSet.getIconId(
128             KeyboardIconsSet.NAME_SHIFT_KEY);
129     private static final int ICON_SHIFTED_SHIFT = KeyboardIconsSet.getIconId(
130             KeyboardIconsSet.NAME_SHIFT_KEY_SHIFTED);
131     private static final int ICON_ZWNJ = KeyboardIconsSet.getIconId(
132             KeyboardIconsSet.NAME_ZWNJ_KEY);
133     private static final int ICON_ZWJ = KeyboardIconsSet.getIconId(
134             KeyboardIconsSet.NAME_ZWJ_KEY);
135 
136     // Functional keys.
137     protected static final ExpectedKey DELETE_KEY = key(ICON_DELETE, Constants.CODE_DELETE);
138     protected static final ExpectedKey TAB_KEY = key(ICON_TAB, Constants.CODE_TAB);
139     protected static final ExpectedKey SHORTCUT_KEY = key(ICON_SHORTCUT, Constants.CODE_SHORTCUT);
140     protected static final ExpectedKey SETTINGS_KEY = key(ICON_SETTINGS, Constants.CODE_SETTINGS);
141     protected static final ExpectedKey LANGUAGE_SWITCH_KEY = key(
142             ICON_LANGUAGE_SWITCH, Constants.CODE_LANGUAGE_SWITCH);
143     protected static final ExpectedKey ENTER_KEY = key(ICON_ENTER, Constants.CODE_ENTER);
144     protected static final ExpectedKey EMOJI_ACTION_KEY = key(ICON_EMOJI_ACTION, Constants.CODE_EMOJI);
145     protected static final ExpectedKey EMOJI_NORMAL_KEY = key(ICON_EMOJI_NORMAL, Constants.CODE_EMOJI);
146     protected static final ExpectedKey SPACE_KEY = key(ICON_SPACE, Constants.CODE_SPACE);
147     protected static final ExpectedKey CAPSLOCK_MORE_KEY = key(" ", Constants.CODE_CAPSLOCK);
148     protected static final ExpectedKey SHIFT_KEY = key(ICON_SHIFT,
149             Constants.CODE_SHIFT, CAPSLOCK_MORE_KEY);
150     protected static final ExpectedKey SHIFTED_SHIFT_KEY = key(ICON_SHIFTED_SHIFT,
151             Constants.CODE_SHIFT, CAPSLOCK_MORE_KEY);
152     protected static final ExpectedKey ALPHABET_KEY = key("ABC", Constants.CODE_SWITCH_ALPHA_SYMBOL);
153     protected static final ExpectedKey SYMBOLS_KEY = key("?123", Constants.CODE_SWITCH_ALPHA_SYMBOL);
154     protected static final ExpectedKey BACK_TO_SYMBOLS_KEY = key("?123", Constants.CODE_SHIFT);
155     protected static final ExpectedKey SYMBOLS_SHIFT_KEY = key("= \\ <", Constants.CODE_SHIFT);
156     protected static final ExpectedKey TABLET_SYMBOLS_SHIFT_KEY = key("~ [ <", Constants.CODE_SHIFT);
157 
158     // U+00A1: "¡" INVERTED EXCLAMATION MARK
159     // U+00BF: "¿" INVERTED QUESTION MARK
160     protected static final ExpectedKey[] EXCLAMATION_AND_QUESTION_MARKS = joinKeys(
161             key("!", moreKey("\u00A1")), key("?", moreKey("\u00BF")));
162     // U+200C: ZERO WIDTH NON-JOINER
163     // U+200D: ZERO WIDTH JOINER
164     protected static final ExpectedKey ZWNJ_KEY = key(ICON_ZWNJ, "\u200C");
165     protected static final ExpectedKey ZWJ_KEY = key(ICON_ZWJ, "\u200D");
166     // Domain key
167     protected static final ExpectedKey DOMAIN_KEY =
168             key(".com", joinMoreKeys(".net", ".org", ".gov", ".edu")).preserveCase();
169 
170     // Punctuation more keys for phone form factor.
171     protected static final ExpectedKey[] PHONE_PUNCTUATION_MORE_KEYS = joinKeys(
172             ",", "?", "!", "#", ")", "(", "/", ";",
173             "'", "@", ":", "-", "\"", "+", "%", "&");
174     // Punctuation more keys for tablet form factor.
175     protected static final ExpectedKey[] TABLET_PUNCTUATION_MORE_KEYS = joinKeys(
176             ",", "'", "#", ")", "(", "/", ";",
177             "@", ":", "-", "\"", "+", "%", "&");
178 }
179