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;
18 
19 import com.android.inputmethod.keyboard.KeyboardId;
20 import com.android.inputmethod.keyboard.layout.customizer.LayoutCustomizer;
21 import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
22 import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
23 
24 /**
25  * The Colemak alphabet keyboard.
26  */
27 public final class Colemak extends LayoutBase {
28     private static final String LAYOUT_NAME = "colemak";
29 
Colemak(final LayoutCustomizer customizer)30     public Colemak(final LayoutCustomizer customizer) {
31         super(customizer, Symbols.class, SymbolsShifted.class);
32     }
33 
34     @Override
getName()35     public String getName() { return LAYOUT_NAME; }
36 
37     @Override
getCommonAlphabetLayout(final boolean isPhone)38     ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) {
39         final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON);
40         getCustomizer().setAccentedLetters(builder);
41         builder.replaceKeyOfLabel(ROW1_10, key(";", additionalMoreKey("0"), moreKey(":")));
42         return builder.build();
43     }
44 
45     @Override
getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId)46     ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) {
47         final ExpectedKeyboardBuilder builder;
48         if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED
49                 || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED) {
50             builder = new ExpectedKeyboardBuilder(getCommonAlphabetLayout(isPhone));
51         } else {
52             builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON);
53             getCustomizer().setAccentedLetters(builder);
54             builder.replaceKeyOfLabel(ROW1_10, key(":", additionalMoreKey("0")));
55         }
56         builder.toUpperCase(getLocale());
57         return builder.build();
58     }
59 
60     private static final String ROW1_10 = "ROW1_10";
61 
62     private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder()
63             .setKeysOfRow(1,
64                     key("q", additionalMoreKey("1")),
65                     key("w", additionalMoreKey("2")),
66                     key("f", additionalMoreKey("3")),
67                     key("p", additionalMoreKey("4")),
68                     key("g", additionalMoreKey("5")),
69                     key("j", additionalMoreKey("6")),
70                     key("l", additionalMoreKey("7")),
71                     key("u", additionalMoreKey("8")),
72                     key("y", additionalMoreKey("9")),
73                     ROW1_10)
74             .setKeysOfRow(2, "a", "r", "s", "t", "d", "h", "n", "e", "i", "o")
75             .setKeysOfRow(3, "z", "x", "c", "v", "b", "k", "m")
76             .build();
77 }
78