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