Home | History | Annotate | Download | only in layout
      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 
     33     public Thai(final Locale locale) {
     34         super(new ThaiCustomizer(locale), Symbols.class, SymbolsShifted.class);
     35     }
     36 
     37     @Override
     38     public String getName() { return LAYOUT_NAME; }
     39 
     40     private static class ThaiCustomizer extends LayoutCustomizer {
     41         ThaiCustomizer(final Locale locale) { super(locale); }
     42 
     43         @Override
     44         public int getNumberOfRows() { return 5; }
     45 
     46         @Override
     47         public ExpectedKey getAlphabetKey() { return THAI_ALPHABET_KEY; }
     48 
     49         @Override
     50         public ExpectedKey getCurrencyKey() { return CURRENCY_BAHT; }
     51 
     52         @Override
     53         public ExpectedKey[] getOtherCurrencyKeys() {
     54             return SymbolsShifted.CURRENCIES_OTHER_GENERIC;
     55         }
     56 
     57         @Override
     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
     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
     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