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