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.layout.Symbols.RtlSymbols;
     20 import com.android.inputmethod.keyboard.layout.SymbolsShifted.RtlSymbolsShifted;
     21 import com.android.inputmethod.keyboard.layout.customizer.LayoutCustomizer;
     22 import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
     23 import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
     24 import com.android.inputmethod.latin.common.Constants;
     25 
     26 import java.util.Locale;
     27 
     28 public final class Hebrew extends LayoutBase {
     29     private static final String LAYOUT_NAME = "hebrew";
     30 
     31     public Hebrew(final Locale locale) {
     32         super(new HebrewCustomizer(locale), HebrewSymbols.class, RtlSymbolsShifted.class);
     33     }
     34 
     35     @Override
     36     public String getName() { return LAYOUT_NAME; }
     37 
     38     private static class HebrewCustomizer extends LayoutCustomizer {
     39         HebrewCustomizer(final Locale locale) { super(locale); }
     40 
     41         @Override
     42         public ExpectedKey getAlphabetKey() { return HEBREW_ALPHABET_KEY; }
     43 
     44         @Override
     45         public ExpectedKey getCurrencyKey() { return CURRENCY_NEW_SHEQEL; }
     46 
     47         @Override
     48         public ExpectedKey[] getOtherCurrencyKeys() {
     49             return SymbolsShifted.CURRENCIES_OTHER_GENERIC;
     50         }
     51 
     52         @Override
     53         public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_LR9; }
     54 
     55         @Override
     56         public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_LR9; }
     57 
     58         @Override
     59         public ExpectedKey[] getDoubleAngleQuoteKeys() {
     60             return RtlSymbols.DOUBLE_ANGLE_QUOTES_LR_RTL;
     61         }
     62 
     63         @Override
     64         public ExpectedKey[] getSingleAngleQuoteKeys() {
     65             return RtlSymbols.SINGLE_ANGLE_QUOTES_LR_RTL;
     66         }
     67 
     68         @Override
     69         public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) {
     70             return EMPTY_KEYS;
     71         }
     72 
     73         @Override
     74         public ExpectedKey[] getRightShiftKeys(final boolean isPhone) {
     75             return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS;
     76         }
     77 
     78         @Override
     79         public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) {
     80             return isPhone ? RTL_PHONE_PUNCTUATION_MORE_KEYS
     81                     : RTL_TABLET_PUNCTUATION_MORE_KEYS;
     82         }
     83 
     84         // U+05D0: "" HEBREW LETTER ALEF
     85         // U+05D1: "" HEBREW LETTER BET
     86         // U+05D2: "" HEBREW LETTER GIMEL
     87         private static final ExpectedKey HEBREW_ALPHABET_KEY = key(
     88                 "\u05D0\u05D1\u05D2", Constants.CODE_SWITCH_ALPHA_SYMBOL);
     89         // U+20AA: "" NEW SHEQEL SIGN
     90         private static final ExpectedKey CURRENCY_NEW_SHEQEL = key("\u20AA",
     91                 Symbols.CURRENCY_GENERIC_MORE_KEYS);
     92         private static final ExpectedKey[] RTL_PHONE_PUNCTUATION_MORE_KEYS = joinKeys(
     93                 ",", "?", "!", "#", key(")", "("), key("(", ")"), "/", ";",
     94                 "'", "@", ":", "-", "\"", "+", "%", "&");
     95         // Punctuation more keys for tablet form factor.
     96         private static final ExpectedKey[] RTL_TABLET_PUNCTUATION_MORE_KEYS = joinKeys(
     97                 ",", "'", "#", key(")", "("), key("(", ")"), "/", ";",
     98                 "@", ":", "-", "\"", "+", "%", "&");
     99     }
    100 
    101     @Override
    102     ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; }
    103 
    104     @Override
    105     ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) {
    106         return null;
    107     }
    108 
    109     private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder()
    110             .setKeysOfRow(1,
    111                     key("'", joinMoreKeys("1", "\"")),
    112                     key("-", joinMoreKeys("2", "_")),
    113                     // U+05E7: "" HEBREW LETTER QOF
    114                     key("\u05E7", moreKey("3")),
    115                     // U+05E8: "" HEBREW LETTER RESH
    116                     key("\u05E8", moreKey("4")),
    117                     // U+05D0: "" HEBREW LETTER ALEF
    118                     key("\u05D0", moreKey("5")),
    119                     // U+05D8: "" HEBREW LETTER TET
    120                     key("\u05D8", moreKey("6")),
    121                     // U+05D5: "" HEBREW LETTER VAV
    122                     key("\u05D5", moreKey("7")),
    123                     // U+05DF: "" HEBREW LETTER FINAL NUN
    124                     key("\u05DF", moreKey("8")),
    125                     // U+05DD: "" HEBREW LETTER FINAL MEM
    126                     key("\u05DD", moreKey("9")),
    127                     // U+05E4: "" HEBREW LETTER PE
    128                     key("\u05E4", moreKey("0")))
    129             .setKeysOfRow(2,
    130                     // U+05E9: "" HEBREW LETTER SHIN
    131                     // U+05D3: "" HEBREW LETTER DALET
    132                     "\u05E9", "\u05D3",
    133                     // U+05D2: "" HEBREW LETTER GIMEL
    134                     // U+05D2 U+05F3: "" HEBREW LETTER GIMEL + HEBREW PUNCTUATION GERESH
    135                     key("\u05D2", moreKey("\u05D2\u05F3")),
    136                     // U+05DB: "" HEBREW LETTER KAF
    137                     // U+05E2: "" HEBREW LETTER AYIN
    138                     "\u05DB", "\u05E2",
    139                     // U+05D9: "" HEBREW LETTER YOD
    140                     // U+05F2 U+05B7: "" HEBREW LIGATURE YIDDISH DOUBLE YOD + HEBREW POINT PATAH
    141                     key("\u05D9", moreKey("\u05F2\u05B7")),
    142                     // U+05D7: "" HEBREW LETTER HET
    143                     // U+05D7 U+05F3: "" HEBREW LETTER HET + HEBREW PUNCTUATION GERESH
    144                     key("\u05D7", moreKey("\u05D7\u05F3")),
    145                     // U+05DC: "" HEBREW LETTER LAMED
    146                     // U+05DA: "" HEBREW LETTER FINAL KAF
    147                     // U+05E3: "" HEBREW LETTER FINAL PE
    148                     "\u05DC", "\u05DA", "\u05E3")
    149             .setKeysOfRow(3,
    150                     // U+05D6: "" HEBREW LETTER ZAYIN
    151                     // U+05D6 U+05F3: "" HEBREW LETTER ZAYIN + HEBREW PUNCTUATION GERESH
    152                     key("\u05D6", moreKey("\u05D6\u05F3")),
    153                     // U+05E1: "" HEBREW LETTER SAMEKH
    154                     // U+05D1: "" HEBREW LETTER BET
    155                     // U+05D4: "" HEBREW LETTER HE
    156                     // U+05E0: "" HEBREW LETTER NUN
    157                     // U+05DE: "" HEBREW LETTER MEM
    158                     "\u05E1", "\u05D1", "\u05D4", "\u05E0", "\u05DE",
    159                     // U+05E6: "" HEBREW LETTER TSADI
    160                     // U+05E6 U+05F3: "" HEBREW LETTER TSADI + HEBREW PUNCTUATION GERESH
    161                     key("\u05E6", moreKey("\u05E6\u05F3")),
    162                     // U+05EA: "" HEBREW LETTER TAV
    163                     // U+05EA U+05F3: "" HEBREW LETTER TAV + HEBREW PUNCTUATION GERESH
    164                     key("\u05EA", moreKey("\u05EA\u05F3")),
    165                     // U+05E5: "" HEBREW LETTER FINAL TSADI
    166                     // U+05E5 U+05F3: "" HEBREW LETTER FINAL TSADI + HEBREW PUNCTUATION GERESH
    167                     key("\u05E5", moreKey("\u05E5\u05F3")))
    168             .build();
    169 
    170     private static class HebrewSymbols extends RtlSymbols {
    171         public HebrewSymbols(final LayoutCustomizer customizer) {
    172             super(customizer);
    173         }
    174 
    175         @Override
    176         public ExpectedKey[][] getLayout(final boolean isPhone) {
    177             return new ExpectedKeyboardBuilder(super.getLayout(isPhone))
    178                     // U+00B1: "" PLUS-MINUS SIGN
    179                     // U+FB29: "" HEBREW LETTER ALTERNATIVE PLUS SIGN
    180                     .setMoreKeysOf("+", "\u00B1", "\uFB29")
    181                     // U+2605: "" BLACK STAR
    182                     .setMoreKeysOf("*", "\u2605")
    183                     .build();
    184         }
    185     }
    186 }
    187