summaryrefslogtreecommitdiff
path: root/tests/src/com/android/inputmethod/keyboard/layout/PcQwerty.java
blob: 3f7340fd0d096bc74bbb9eb1c6861209e57ec85a (plain)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
 * 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;

import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;

import java.util.Locale;

/**
 * The PC QWERTY alphabet keyboard.
 */
public final class PcQwerty extends LayoutBase {
    private static final String LAYOUT_NAME = "pcqwerty";

    public PcQwerty(final LayoutCustomizer customizer) {
        super(customizer, Symbols.class, SymbolsShifted.class);
    }

    @Override
    public String getName() { return LAYOUT_NAME; }

    public static class PcQwertyCustomizer extends LayoutCustomizer {
        public PcQwertyCustomizer(final Locale locale) { super(locale); }

        @Override
        public int getNumberOfRows() { return 5; }

        @Override
        public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) {
            return joinKeys(SHIFT_KEY);
        }

        @Override
        public ExpectedKey[] getRightShiftKeys(final boolean isPhone) {
            return joinKeys(SHIFT_KEY);
        }

        @Override
        public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) {
            return joinKeys(SETTINGS_KEY);
        }

        @Override
        public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) {
            return isPhone
                    ? joinKeys(key(ENTER_KEY, EMOJI_ACTION_KEY))
                    : joinKeys(EMOJI_NORMAL_KEY);
        }
    }

    @Override
    ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) {
        final LayoutCustomizer customizer = getCustomizer();
        final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON);
        customizer.setAccentedLetters(builder);
        builder.replaceKeyOfLabel(ROW1_1, key("`", moreKey("~")))
                .replaceKeyOfLabel(ROW2_11, key("[", moreKey("{")))
                .replaceKeyOfLabel(ROW2_12, key("]", moreKey("}")))
                .replaceKeyOfLabel(ROW2_13, key("\\", moreKey("|")))
                .replaceKeyOfLabel(ROW3_10, key(";", moreKey(":")))
                .replaceKeyOfLabel(ROW3_11, key("'", joinMoreKeys(additionalMoreKey("\""),
                        customizer.getDoubleQuoteMoreKeys(),
                        customizer.getSingleQuoteMoreKeys())))
                .setAdditionalMoreKeysPositionOf("'", 4)
                .replaceKeyOfLabel(ROW4_8, key(",", moreKey("<")))
                .replaceKeyOfLabel(ROW4_9, key(".", moreKey(">")))
                // U+00BF: "¿" INVERTED QUESTION MARK
                .replaceKeyOfLabel(ROW4_10, key("/", joinMoreKeys("?", "\u00BF")));
        if (isPhone) {
            // U+221E: "∞" INFINITY
            // U+2260: "≠" NOT EQUAL TO
            // U+2248: "≈" ALMOST EQUAL TO
            builder.replaceKeyOfLabel(ROW1_13, key("=",
                    joinMoreKeys("\u221E", "\u2260", "\u2248", "+")));
        } else {
            // U+221E: "∞" INFINITY
            // U+2260: "≠" NOT EQUAL TO
            // U+2248: "≈" ALMOST EQUAL TO
            builder.replaceKeyOfLabel(ROW1_13, key("=",
                    joinMoreKeys("+", "\u221E", "\u2260", "\u2248")));
        }
        return builder.build();
    }

    @Override
    ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) {
        final ExpectedKeyboardBuilder builder;
        if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED
                || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED) {
            builder = new ExpectedKeyboardBuilder(getCommonAlphabetLayout(isPhone));
        } else {
            builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON);
            final LayoutCustomizer customizer = getCustomizer();
            customizer.setAccentedLetters(builder);
            builder.setKeysOfRow(1,
                    "~",
                    // U+00A1: "¡" INVERTED EXCLAMATION MARK
                    key("!", moreKey("\u00A1")),
                    "@", "#",
                    customizer.getCurrencyKey(),
                    // U+2030: "‰" PER MILLE SIGN
                    key("%", moreKey("\u2030")),
                    "^", "&",
                    // U+2020: "†" DAGGER
                    // U+2021: "‡" DOUBLE DAGGER
                    // U+2605: "★" BLACK STAR
                    key("*", joinMoreKeys("\u2020", "\u2021", "\u2605")),
                    "(", ")", "_",
                    // U+00B1: "±" PLUS-MINUS SIGN
                    // U+00D7: "×" MULTIPLICATION SIGN
                    // U+00F7: "÷" DIVISION SIGN
                    // U+221A: "√" SQUARE ROOT
                    key("+", joinMoreKeys("\u00B1", "\u00D7", "\u00F7", "\u221A")))
                    .replaceKeyOfLabel(ROW2_11, key("{"))
                    .replaceKeyOfLabel(ROW2_12, key("}"))
                    .replaceKeyOfLabel(ROW2_13, key("|"))
                    .replaceKeyOfLabel(ROW3_10, key(":"))
                    .replaceKeyOfLabel(ROW3_11, key("\"", joinMoreKeys(
                            customizer.getDoubleQuoteMoreKeys(),
                            customizer.getSingleQuoteMoreKeys())))
                    // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
                    // U+2264: "≤" LESS-THAN OR EQUAL TO
                    // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
                    .replaceKeyOfLabel(ROW4_8, key("<", joinMoreKeys("\u2039", "\u2264", "\u00AB")))
                    // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
                    // U+2265: "≥" GREATER-THAN EQUAL TO
                    // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
                    .replaceKeyOfLabel(ROW4_9, key(">", joinMoreKeys("\u203A", "\u2265", "\u00BB")))
                    // U+00BF: "¿" INVERTED QUESTION MARK
                    .replaceKeyOfLabel(ROW4_10, key("?", moreKey("\u00BF")));
        }
        builder.toUpperCase(getLocale());
        return builder.build();
    }

    // Helper method to create alphabet layout by adding special function keys.
    @Override
    ExpectedKeyboardBuilder convertCommonLayoutToKeyboard(final ExpectedKeyboardBuilder builder,
            final boolean isPhone) {
        final LayoutCustomizer customizer = getCustomizer();
        builder.setKeysOfRow(5, (Object[])customizer.getSpaceKeys(isPhone));
        builder.addKeysOnTheLeftOfRow(5, (Object[])customizer.getKeysLeftToSpacebar(isPhone));
        builder.addKeysOnTheRightOfRow(5, (Object[])customizer.getKeysRightToSpacebar(isPhone));
        if (isPhone) {
            builder.addKeysOnTheRightOfRow(3, DELETE_KEY);
        } else {
            builder.addKeysOnTheRightOfRow(1, DELETE_KEY)
                    .addKeysOnTheLeftOfRow(2, TAB_KEY)
                    .addKeysOnTheRightOfRow(3, ENTER_KEY);
        }
        builder.addKeysOnTheLeftOfRow(4, (Object[])customizer.getLeftShiftKeys(isPhone))
                .addKeysOnTheRightOfRow(4, (Object[])customizer.getRightShiftKeys(isPhone));
        return builder;
    }

    @Override
    public ExpectedKey[][] getLayout(final boolean isPhone, final int elementId) {
        if (elementId == KeyboardId.ELEMENT_SYMBOLS
                || elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) {
            return null;
        }
        return super.getLayout(isPhone, elementId);
    }

    private static final String ROW1_1 = "ROW1_1";
    private static final String ROW1_13 = "ROW1_13";
    private static final String ROW2_11 = "ROW2_11";
    private static final String ROW2_12 = "ROW2_12";
    private static final String ROW2_13 = "ROW2_13";
    private static final String ROW3_10 = "ROW3_10";
    private static final String ROW3_11 = "ROW3_11";
    private static final String ROW4_8 = "ROW4_8";
    private static final String ROW4_9 = "ROW4_9";
    private static final String ROW4_10 = "ROW4_10";

    private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder()
            .setKeysOfRow(1,
                    ROW1_1,
                    // U+00A1: "¡" INVERTED EXCLAMATION MARK
                    // U+00B9: "¹" SUPERSCRIPT ONE
                    // U+00BD: "½" VULGAR FRACTION ONE HALF
                    // U+2153: "⅓" VULGAR FRACTION ONE THIRD
                    // U+00BC: "¼" VULGAR FRACTION ONE QUARTER
                    // U+215B: "⅛" VULGAR FRACTION ONE EIGHTH
                    key("1", joinMoreKeys(
                            "!", "\u00A1", "\u00B9", "\u00BD", "\u2153", "\u00BC", "\u215B")),
                    // U+00B2: "²" SUPERSCRIPT TWO
                    // U+2154: "⅔" VULGAR FRACTION TWO THIRDS
                    key("2", joinMoreKeys("@", "\u00B2", "\u2154")),
                    // U+00B3: "³" SUPERSCRIPT THREE
                    // U+00BE: "¾" VULGAR FRACTION THREE QUARTERS
                    // U+215C: "⅜" VULGAR FRACTION THREE EIGHTHS
                    key("3", joinMoreKeys("#", "\u00B3", "\u00BE", "\u215C")),
                    // U+2074: "⁴" SUPERSCRIPT FOUR
                    key("4", joinMoreKeys("$", "\u2074")),
                    // U+215D: "⅝" VULGAR FRACTION FIVE EIGHTHS
                    key("5", joinMoreKeys("%", "\u215D")),
                    key("6", moreKey("^")),
                    // U+215E: "⅞" VULGAR FRACTION SEVEN EIGHTHS
                    key("7", joinMoreKeys("&", "\u215E")),
                    key("8", moreKey("*")),
                    key("9", moreKey("(")),
                    // U+207F: "ⁿ" SUPERSCRIPT LATIN SMALL LETTER N
                    // U+2205: "∅" EMPTY SET
                    key("0", joinMoreKeys(")", "\u207F", "\u2205")),
                    // U+2013: "–" EN DASH
                    // U+2014: "—" EM DASH
                    // U+00B7: "·" MIDDLE DOT
                    key("-", joinMoreKeys("_", "\u2013", "\u2014", "\u00B7")),
                    ROW1_13)
            .setKeysOfRow(2, "q", "w", "e", "r", "t", "y", "u", "i", "o", "p",
                    ROW2_11, ROW2_12, ROW2_13)
            .setKeysOfRow(3, "a", "s", "d", "f", "g", "h", "j", "k", "l", ROW3_10, ROW3_11)
            .setKeysOfRow(4, "z", "x", "c", "v", "b", "n", "m", ROW4_8, ROW4_9, ROW4_10)
            .build();
}