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 import com.android.inputmethod.latin.common.Constants; 24 25 import java.util.Locale; 26 27 /** 28 * The Thai alphabet keyboard. 29 */ 30 public final class Thai extends LayoutBase { 31 private static final String LAYOUT_NAME = "thai"; 32 Thai(final Locale locale)33 public Thai(final Locale locale) { 34 super(new ThaiCustomizer(locale), Symbols.class, SymbolsShifted.class); 35 } 36 37 @Override getName()38 public String getName() { return LAYOUT_NAME; } 39 40 private static class ThaiCustomizer extends LayoutCustomizer { ThaiCustomizer(final Locale locale)41 ThaiCustomizer(final Locale locale) { super(locale); } 42 43 @Override getNumberOfRows()44 public int getNumberOfRows() { return 5; } 45 46 @Override getAlphabetKey()47 public ExpectedKey getAlphabetKey() { return THAI_ALPHABET_KEY; } 48 49 @Override getCurrencyKey()50 public ExpectedKey getCurrencyKey() { return CURRENCY_BAHT; } 51 52 @Override getOtherCurrencyKeys()53 public ExpectedKey[] getOtherCurrencyKeys() { 54 return SymbolsShifted.CURRENCIES_OTHER_GENERIC; 55 } 56 57 @Override getRightShiftKeys(final boolean isPhone)58 public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { return EMPTY_KEYS; } 59 60 // U+0E01: "ก" THAI CHARACTER KO KAI 61 // U+0E02: "ข" THAI CHARACTER KHO KHAI 62 // U+0E04: "ค" THAI CHARACTER KHO KHWAI 63 private static final ExpectedKey THAI_ALPHABET_KEY = key( 64 "\u0E01\u0E02\u0E04", Constants.CODE_SWITCH_ALPHA_SYMBOL); 65 66 // U+0E3F: "฿" THAI CURRENCY SYMBOL BAHT 67 private static final ExpectedKey CURRENCY_BAHT = key("\u0E3F", 68 Symbols.CURRENCY_GENERIC_MORE_KEYS); 69 } 70 71 @Override getCommonAlphabetLayout(final boolean isPhone)72 ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { 73 final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); 74 if (isPhone) { 75 // U+0E03: "ฃ" THAI CHARACTER KHO KHUAT 76 builder.addKeysOnTheRightOfRow(3, "\u0E03"); 77 } else { 78 // U+0E03: "ฃ" THAI CHARACTER KHO KHUAT 79 builder.addKeysOnTheRightOfRow(2, "\u0E03") 80 .addKeysOnTheRightOfRow(4, (Object[])EXCLAMATION_AND_QUESTION_MARKS); 81 } 82 return builder.build(); 83 } 84 85 @Override getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId)86 public ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, 87 final int elementId) { 88 if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { 89 return getCommonAlphabetLayout(isPhone); 90 } 91 final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( 92 ALPHABET_SHIFTED_COMMON); 93 if (isPhone) { 94 // U+0E05: "ฅ" THAI CHARACTER KHO KHON 95 builder.addKeysOnTheRightOfRow(3, "\u0E05"); 96 } else { 97 // U+0E05: "ฅ" THAI CHARACTER KHO KHON 98 builder.addKeysOnTheRightOfRow(2, "\u0E05"); 99 } 100 return builder.build(); 101 } 102 103 private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() 104 .setKeysOfRow(1, 105 // U+0E45: "ๅ" THAI CHARACTER LAKKHANGYAO 106 "\u0E45", 107 // U+0E51: "๑" THAI DIGIT ONE 108 key("/", joinMoreKeys("1", "\u0E51")), 109 // U+0E52: "๒" THAI DIGIT TWO 110 key("_", joinMoreKeys("2", "\u0E52")), 111 // U+0E20: "ภ" THAI CHARACTER PHO SAMPHAO 112 // U+0E53: "๓" THAI DIGIT THREE 113 key("\u0E20", joinMoreKeys("3", "\u0E53")), 114 // U+0E16: "ถ" THAI CHARACTER THO THUNG 115 // U+0E54: "๔" THAI DIGIT FOUR 116 key("\u0E16", joinMoreKeys("4", "\u0E54")), 117 // U+0E38: " ุ" THAI CHARACTER SARA U 118 key(" \u0E38", "\u0E38"), 119 // U+0E36: " ึ" THAI CHARACTER SARA UE 120 key(" \u0E36", "\u0E36"), 121 // U+0E04: "ค" THAI CHARACTER KHO KHWAI 122 // U+0E55: "๕" THAI DIGIT FIVE 123 key("\u0E04", joinMoreKeys("5", "\u0E55")), 124 // U+0E15: "ต" THAI CHARACTER TO TAO 125 // U+0E56: "๖" THAI DIGIT SIX 126 key("\u0E15", joinMoreKeys("6", "\u0E56")), 127 // U+0E08: "จ" THAI CHARACTER CHO CHAN 128 // U+0E57: "๗" THAI DIGIT SEVEN 129 key("\u0E08", joinMoreKeys("7", "\u0E57")), 130 // U+0E02: "ข" THAI CHARACTER KHO KHAI 131 // U+0E58: "๘" THAI DIGIT EIGHT 132 key("\u0E02", joinMoreKeys("8", "\u0E58")), 133 // U+0E0A: "ช" THAI CHARACTER CHO CHANG 134 // U+0E59: "๙" THAI DIGIT NINE 135 key("\u0E0A", joinMoreKeys("9", "\u0E59"))) 136 .setKeysOfRow(2, 137 // U+0E46: "ๆ" THAI CHARACTER MAIYAMOK 138 // U+0E50: "๐" THAI DIGIT ZERO 139 key("\u0E46", joinMoreKeys("0", "\u0E50")), 140 // U+0E44: "ไ" THAI CHARACTER SARA AI MAIMALAI 141 // U+0E33: "ำ" THAI CHARACTER SARA AM 142 // U+0E1E: "พ" THAI CHARACTER PHO PHAN 143 // U+0E30: "ะ" THAI CHARACTER SARA A 144 "\u0E44", "\u0E33", "\u0E1E", "\u0E30", 145 // U+0E31: " ั" THAI CHARACTER MAI HAN-AKAT 146 key(" \u0E31", "\u0E31"), 147 // U+0E35: " ี" HAI CHARACTER SARA II 148 key(" \u0E35", "\u0E35"), 149 // U+0E23: "ร" THAI CHARACTER RO RUA 150 // U+0E19: "น" THAI CHARACTER NO NU 151 // U+0E22: "ย" THAI CHARACTER YO YAK 152 // U+0E1A: "บ" THAI CHARACTER BO BAIMAI 153 // U+0E25: "ล" THAI CHARACTER LO LING 154 "\u0E23", "\u0E19", "\u0E22", "\u0E1A", "\u0E25") 155 .setKeysOfRow(3, 156 // U+0E1F: "ฟ" THAI CHARACTER FO FAN 157 // U+0E2B: "ห" THAI CHARACTER HO HIP 158 // U+0E01: "ก" THAI CHARACTER KO KAI 159 // U+0E14: "ด" THAI CHARACTER DO DEK 160 // U+0E40: "เ" THAI CHARACTER SARA E 161 "\u0E1F", "\u0E2B", "\u0E01", "\u0E14", "\u0E40", 162 // U+0E49: " ้" THAI CHARACTER MAI THO 163 key(" \u0E49", "\u0E49"), 164 // U+0E48: " ่" THAI CHARACTER MAI EK 165 key(" \u0E48", "\u0E48"), 166 // U+0E32: "า" THAI CHARACTER SARA AA 167 // U+0E2A: "ส" THAI CHARACTER SO SUA 168 // U+0E27: "ว" THAI CHARACTER WO WAEN 169 // U+0E07: "ง" THAI CHARACTER NGO NGU 170 "\u0E32", "\u0E2A", "\u0E27", "\u0E07") 171 .setKeysOfRow(4, 172 // U+0E1C: "ผ" THAI CHARACTER PHO PHUNG 173 // U+0E1B: "ป" THAI CHARACTER PO PLA 174 // U+0E41: "แ" THAI CHARACTER SARA AE 175 // U+0E2D: "อ" THAI CHARACTER O ANG 176 "\u0E1C", "\u0E1B", "\u0E41", "\u0E2D", 177 // U+0E34: " ิ" THAI CHARACTER SARA I 178 key(" \u0E34", "\u0E34"), 179 // U+0E37: " ื" THAI CHARACTER SARA UEE 180 key(" \u0E37", "\u0E37"), 181 // U+0E17: "ท" THAI CHARACTER THO THAHAN 182 // U+0E21: "ม" THAI CHARACTER MO MA 183 // U+0E43: "ใ" THAI CHARACTER SARA AI MAIMUAN 184 // U+0E1D: "ฝ" THAI CHARACTER FO FA 185 "\u0E17", "\u0E21", "\u0E43", "\u0E1D") 186 .build(); 187 188 private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() 189 .setKeysOfRow(1, 190 // U+0E51: "๑" THAI DIGIT ONE 191 // U+0E52: "๒" THAI DIGIT TWO 192 // U+0E53: "๓" THAI DIGIT THREE 193 // U+0E54: "๔" THAI DIGIT FOUR 194 // U+0E39: " ู" THAI CHARACTER SARA UU 195 "+", "\u0E51", "\u0E52", "\u0E53", "\u0E54", 196 key(" \u0E39", "\u0E39"), 197 // U+0E3F: "฿" THAI CURRENCY SYMBOL BAHT 198 // U+0E55: "๕" THAI DIGIT FIVE 199 // U+0E56: "๖" THAI DIGIT SIX 200 // U+0E57: "๗" THAI DIGIT SEVEN 201 // U+0E58: "๘" THAI DIGIT EIGHT 202 // U+0E59: "๙" THAI DIGIT NINE 203 "\u0E3F", "\u0E55", "\u0E56", "\u0E57", "\u0E58", "\u0E59") 204 .setKeysOfRow(2, 205 // U+0E50: "๐" THAI DIGIT ZERO 206 // U+0E0E: "ฎ" THAI CHARACTER DO CHADA 207 // U+0E11: "ฑ" THAI CHARACTER THO NANGMONTHO 208 // U+0E18: "ธ" THAI CHARACTER THO THONG 209 "\u0E50", "\"", "\u0E0E", "\u0E11", "\u0E18", 210 // U+0E4D: " ํ" THAI CHARACTER THANTHAKHAT 211 key(" \u0E4D", "\u0E4D"), 212 // U+0E4A: " ๊" THAI CHARACTER MAI TRI 213 key(" \u0E4A", "\u0E4A"), 214 // U+0E13: "ณ" THAI CHARACTER NO NEN 215 // U+0E2F: "ฯ" THAI CHARACTER PAIYANNOI 216 // U+0E0D: "ญ" THAI CHARACTER YO YING 217 // U+0E10: "ฐ" THAI CHARACTER THO THAN 218 "\u0E13", "\u0E2F", "\u0E0D", "\u0E10", ",") 219 .setKeysOfRow(3, 220 // U+0E24: "ฤ" THAI CHARACTER RU 221 // U+0E06: "ฆ" THAI CHARACTER KHO RAKHANG 222 // U+0E0F: "ฏ" THAI CHARACTER TO PATAK 223 // U+0E42: "โ" THAI CHARACTER SARA O 224 // U+0E0C: "ฌ" THAI CHARACTER CHO CHOE 225 "\u0E24", "\u0E06", "\u0E0F", "\u0E42", "\u0E0C", 226 // U+0E47: " ็" THAI CHARACTER MAITAIKHU 227 key(" \u0E47", "\u0E47"), 228 // U+0E4B: " ๋" THAI CHARACTER MAI CHATTAWA 229 key(" \u0E4B", "\u0E4B"), 230 // U+0E29: "ษ" THAI CHARACTER SO RUSI 231 // U+0E28: "ศ" THAI CHARACTER SO SALA 232 // U+0E0B: "ซ" THAI CHARACTER SO SO 233 "\u0E29", "\u0E28", "\u0E0B", ".") 234 .setKeysOfRow(4, 235 // U+0E09: "ฉ" THAI CHARACTER CHO CHING 236 // U+0E2E: "ฮ" THAI CHARACTER HO NOKHUK 237 "(", ")", "\u0E09", "\u0E2E", 238 // U+0E3A: " ฺ" THAI CHARACTER PHINTHU 239 key(" \u0E3A", "\u0E3A"), 240 // U+0E4C: " ์" THAI CHARACTER THANTHAKHAT 241 key(" \u0E4C", "\u0E4C"), 242 // U+0E12: "ฒ" THAI CHARACTER THO PHUTHAO 243 // U+0E2C: "ฬ" THAI CHARACTER LO CHULA 244 // U+0E26: "ฦ" THAI CHARACTER LU 245 "?", "\u0E12", "\u0E2C", "\u0E26") 246 .build(); 247 } 248