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