1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
* Copyright (C) 2014 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.
*/
package com.android.inputmethod.keyboard.layout.customizer;
import com.android.inputmethod.keyboard.layout.Symbols;
import com.android.inputmethod.keyboard.layout.SymbolsShifted;
import com.android.inputmethod.keyboard.layout.expected.AbstractLayoutBase;
import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
import java.util.Locale;
/**
* This class is used to customize common keyboard layout to language specific layout.
*/
public class LayoutCustomizer extends AbstractLayoutBase {
private final Locale mLocale;
// Empty keys definition to remove keys by adding this.
protected static final ExpectedKey[] EMPTY_KEYS = joinKeys();
public LayoutCustomizer(final Locale locale) { mLocale = locale; }
public final Locale getLocale() { return mLocale; }
public int getNumberOfRows() { return 4; }
/**
* Set accented letters to a specific keyboard element.
* @param builder the {@link ExpectedKeyboardBuilder} object that contains common keyboard
* layout.
* @param elementId the element id of keyboard
* @return the {@link ExpectedKeyboardBuilder} object that contains accented letters as
* "more keys".
*/
public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder,
final int elementId) {
// This method can be overridden by an extended class to provide customized expected
// accented letters depending on the shift state of keyboard.
// This is a default behavior to call a shift-state-independent
// {@link #setAccentedLetters(ExpectedKeyboardBuilder)} implementation, so that
// <code>elementId</code> is ignored here.
return setAccentedLetters(builder);
}
/**
* Set accented letters to common layout.
* @param builder the {@link ExpectedKeyboardBuilder} object that contains common keyboard
* layout.
* @return the {@link ExpectedKeyboardBuilder} object that contains accented letters as
* "more keys".
*/
public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) {
return builder;
}
/**
* Get the function key to switch to alphabet layout.
* @return the {@link ExpectedKey} of the alphabet key.
*/
public ExpectedKey getAlphabetKey() { return ALPHABET_KEY; }
/**
* Get the function key to switch to symbols layout.
* @return the {@link ExpectedKey} of the symbols key.
*/
public ExpectedKey getSymbolsKey() { return SYMBOLS_KEY; }
/**
* Get the function key to switch to symbols shift layout.
* @param isPhone true if requesting phone's key.
* @return the {@link ExpectedKey} of the symbols shift key.
*/
public ExpectedKey getSymbolsShiftKey(boolean isPhone) {
return isPhone ? SYMBOLS_SHIFT_KEY : TABLET_SYMBOLS_SHIFT_KEY;
}
/**
* Get the function key to switch from symbols shift to symbols layout.
* @return the {@link ExpectedKey} of the back to symbols key.
*/
public ExpectedKey getBackToSymbolsKey() { return BACK_TO_SYMBOLS_KEY; }
/**
* Get the currency key.
* @return the {@link ExpectedKey} of the currency key.
*/
public ExpectedKey getCurrencyKey() { return Symbols.CURRENCY_DOLLAR; }
/**
* Get other currencies keys.
* @return the array of {@link ExpectedKey} that represents other currency keys.
*/
public ExpectedKey[] getOtherCurrencyKeys() {
return SymbolsShifted.CURRENCIES_OTHER_THAN_DOLLAR;
}
/**
* Get "more keys" of double quotation mark.
* @return the array of {@link ExpectedKey} of more double quotation marks in natural order.
*/
public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_9LR; }
/**
* Get "more keys" of single quotation mark.
* @return the array of {@link ExpectedKey} of more single quotation marks in natural order.
*/
public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_9LR; }
/**
* Get double angle quotation marks in natural order.
* @return the array of {@link ExpectedKey} of double angle quotation marks in natural
* order.
*/
public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_LR; }
/**
* Get single angle quotation marks in natural order.
* @return the array of {@link ExpectedKey} of single angle quotation marks in natural
* order.
*/
public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_LR; }
/**
* Get the left shift keys.
* @param isPhone true if requesting phone's keys.
* @return the array of {@link ExpectedKey} that should be placed at left edge of the
* keyboard.
*/
public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) {
return joinKeys(SHIFT_KEY);
}
/**
* Get the right shift keys.
* @param isPhone true if requesting phone's keys.
* @return the array of {@link ExpectedKey} that should be placed at right edge of the
* keyboard.
*/
public ExpectedKey[] getRightShiftKeys(final boolean isPhone) {
return isPhone ? EMPTY_KEYS : joinKeys(EXCLAMATION_AND_QUESTION_MARKS, SHIFT_KEY);
}
/**
* Get the enter key.
* @param isPhone true if requesting phone's key.
* @return the array of {@link ExpectedKey} that should be placed as an enter key.
*/
public ExpectedKey getEnterKey(final boolean isPhone) {
return isPhone ? key(ENTER_KEY, EMOJI_ACTION_KEY) : ENTER_KEY;
}
/**
* Get the emoji key.
* @param isPhone true if requesting phone's key.
* @return the array of {@link ExpectedKey} that should be placed as an emoji key.
*/
public ExpectedKey getEmojiKey(final boolean isPhone) {
return EMOJI_NORMAL_KEY;
}
/**
* Get the space keys.
* @param isPhone true if requesting phone's keys.
* @return the array of {@link ExpectedKey} that should be placed at the center of the
* keyboard.
*/
public ExpectedKey[] getSpaceKeys(final boolean isPhone) {
return joinKeys(LANGUAGE_SWITCH_KEY, SPACE_KEY);
}
/**
* Get the keys left to the spacebar.
* @param isPhone true if requesting phone's keys.
* @return the array of {@link ExpectedKey} that should be placed at left of the spacebar.
*/
public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) {
// U+002C: "," COMMA
return joinKeys(key("\u002C", SETTINGS_KEY));
}
/**
* Get the keys right to the spacebar.
* @param isPhone true if requesting phone's keys.
* @return the array of {@link ExpectedKey} that should be placed at right of the spacebar.
*/
public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) {
final ExpectedKey periodKey = key(".", getPunctuationMoreKeys(isPhone));
return joinKeys(periodKey);
}
/**
* Get "more keys" for the punctuation key (usually the period key).
* @param isPhone true if requesting phone's keys.
* @return the array of {@link ExpectedKey} that are "more keys" of the punctuation key.
*/
public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) {
return isPhone ? PHONE_PUNCTUATION_MORE_KEYS : TABLET_PUNCTUATION_MORE_KEYS;
}
}
|