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.expected.ExpectedKey;
21 import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
22 import com.android.inputmethod.latin.Constants;
23 
24 import java.util.Locale;
25 
26 /**
27  * The Greek alphabet keyboard.
28  */
29 public final class Greek extends LayoutBase {
30     private static final String LAYOUT_NAME = "greek";
31 
Greek(final LayoutCustomizer customizer)32     public Greek(final LayoutCustomizer customizer) {
33         super(customizer, Symbols.class, SymbolsShifted.class);
34     }
35 
36     @Override
getName()37     public String getName() { return LAYOUT_NAME; }
38 
39     public static class GreekCustomizer extends EuroCustomizer {
GreekCustomizer(final Locale locale)40         public GreekCustomizer(final Locale locale) { super(locale); }
41 
42         @Override
getAlphabetKey()43         public ExpectedKey getAlphabetKey() { return GREEK_ALPHABET_KEY; }
44 
45         // U+0391: "Α" GREEK CAPITAL LETTER ALPHA
46         // U+0392: "Β" GREEK CAPITAL LETTER BETA
47         // U+0393: "Γ" GREEK CAPITAL LETTER GAMMA
48         private static final ExpectedKey GREEK_ALPHABET_KEY = key(
49                 "\u0391\u0392\u0393", Constants.CODE_SWITCH_ALPHA_SYMBOL);
50     }
51 
52     @Override
getCommonAlphabetLayout(final boolean isPhone)53     ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) {
54         final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON);
55         builder.replaceKeyOfLabel(ROW1_1, ROW1_1_SEMICOLON);
56         builder.replaceKeyOfLabel(ROW1_2, ROW1_2_FINAL_SIGMA);
57         return builder.build();
58     }
59 
60     @Override
getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId)61     ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) {
62         final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON);
63         builder.toUpperCase(getLocale());
64         if (elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED
65                 || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED) {
66             builder.replaceKeyOfLabel(ROW1_1, ROW1_1_COLON);
67         } else {
68             builder.replaceKeyOfLabel(ROW1_1, ROW1_1_SEMICOLON);
69         }
70         builder.replaceKeyOfLabel(ROW1_2, ROW1_2_FINAL_SIGMA);
71         return builder.build();
72     }
73 
74     private static final String ROW1_1 = "ROW1_1";
75     private static final ExpectedKey ROW1_1_SEMICOLON = key(";", joinMoreKeys("1", ":"));
76     private static final ExpectedKey ROW1_1_COLON = key(":", joinMoreKeys("1", ";"));
77 
78     private static final String ROW1_2 = "ROW2_2";
79     // U+03C2: "ς" GREEK SMALL LETTER FINAL SIGMA
80     private static final ExpectedKey ROW1_2_FINAL_SIGMA = key("\u03C2", moreKey("2"));
81 
82     private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder()
83             .setKeysOfRow(1,
84                     key(ROW1_1, moreKey("1")),
85                     key(ROW1_2, moreKey("2")),
86                     // U+03B5: "ε" GREEK SMALL LETTER EPSILON
87                     // U+03AD: "έ" GREEK SMALL LETTER EPSILON WITH TONOS
88                     key("\u03B5", joinMoreKeys("\u03AD", "3")),
89                     // U+03C1: "ρ" GREEK SMALL LETTER RHO
90                     key("\u03C1", moreKey("4")),
91                     // U+03C4: "τ" GREEK SMALL LETTER TAU
92                     key("\u03C4", moreKey("5")),
93                     // U+03C5: "υ" GREEK SMALL LETTER UPSILON
94                     // U+03CD: "ύ" GREEK SMALL LETTER UPSILON WITH TONOS
95                     // U+03CB: "ϋ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA
96                     // U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
97                     key("\u03C5", joinMoreKeys("\u03CD", "6", "\u03CB", "\u03B0")),
98                     // U+03B8: "θ" GREEK SMALL LETTER THETA
99                     key("\u03B8", moreKey("7")),
100                     // U+03B9: "ι" GREEK SMALL LETTER IOTA
101                     // U+03AF: "ί" GREEK SMALL LETTER IOTA WITH TONOS
102                     // U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA
103                     // U+0390: "ΐ" GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS
104                     key("\u03B9", joinMoreKeys("\u03AF", "8", "\u03CA", "\u0390")),
105                     // U+03BF: "ο" GREEK SMALL LETTER OMICRON
106                     // U+03CC: "ό" GREEK SMALL LETTER OMICRON WITH TONOS
107                     key("\u03BF", joinMoreKeys("\u03CC", "9")),
108                     // U+03C0: "π" GREEK SMALL LETTER PI
109                     key("\u03C0", moreKey("0")))
110             .setKeysOfRow(2,
111                     // U+03B1: "α" GREEK SMALL LETTER ALPHA
112                     // U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS
113                     key("\u03B1", moreKey("\u03AC")),
114                     // U+03C3: "σ" GREEK SMALL LETTER SIGMA
115                     // U+03B4: "δ" GREEK SMALL LETTER DELTA
116                     // U+03C6: "φ" GREEK SMALL LETTER PHI
117                     // U+03B3: "γ" GREEK SMALL LETTER GAMMA
118                     "\u03C3", "\u03B4", "\u03C6", "\u03B3",
119                     // U+03B7: "η" GREEK SMALL LETTER ETA
120                     // U+03AE: "ή" GREEK SMALL LETTER ETA WITH TONOS
121                     key("\u03B7", moreKey("\u03AE")),
122                     // U+03BE: "ξ" GREEK SMALL LETTER XI
123                     // U+03BA: "κ" GREEK SMALL LETTER KAPPA
124                     // U+03BB: "λ" GREEK SMALL LETTER LAMDA
125                     "\u03BE", "\u03BA", "\u03BB")
126             .setKeysOfRow(3,
127                     // U+03B6: "ζ" GREEK SMALL LETTER ZETA
128                     // U+03C7: "χ" GREEK SMALL LETTER CHI
129                     // U+03C8: "ψ" GREEK SMALL LETTER PSI
130                     "\u03B6", "\u03C7", "\u03C8",
131                     // U+03C9: "ω" GREEK SMALL LETTER OMEGA
132                     // U+03CE: "ώ" GREEK SMALL LETTER OMEGA WITH TONOS
133                     key("\u03C9", moreKey("\u03CE")),
134                     // U+03B2: "β" GREEK SMALL LETTER BETA
135                     // U+03BD: "ν" GREEK SMALL LETTER NU
136                     // U+03BC: "μ" GREEK SMALL LETTER MU
137                     "\u03B2", "\u03BD", "\u03BC")
138             .build();
139 }
140