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.LayoutBase.LayoutCustomizer;
     20 import com.android.inputmethod.keyboard.layout.expected.AbstractLayoutBase;
     21 import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
     22 import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
     23 
     24 /**
     25  * The symbols keyboard layout.
     26  */
     27 public class Symbols extends AbstractLayoutBase {
     28     private final LayoutCustomizer mCustomizer;
     29 
     30     public Symbols(final LayoutCustomizer customizer) {
     31         mCustomizer = customizer;
     32     }
     33 
     34     public ExpectedKey[][] getLayout(final boolean isPhone) {
     35         final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(SYMBOLS_COMMON);
     36         final LayoutCustomizer customizer = mCustomizer;
     37         builder.replaceKeyOfLabel(CURRENCY, customizer.getCurrencyKey());
     38         builder.replaceKeyOfLabel(DOUBLE_QUOTE, key("\"", joinMoreKeys(
     39                 customizer.getDoubleQuoteMoreKeys(), customizer.getDoubleAngleQuoteKeys())));
     40         builder.replaceKeyOfLabel(SINGLE_QUOTE, key("'", joinMoreKeys(
     41                 customizer.getSingleQuoteMoreKeys(), customizer.getSingleAngleQuoteKeys())));
     42         if (isPhone) {
     43             builder.addKeysOnTheLeftOfRow(3, customizer.getSymbolsShiftKey(isPhone))
     44                     .addKeysOnTheRightOfRow(3, LayoutBase.DELETE_KEY)
     45                     .addKeysOnTheLeftOfRow(4, customizer.getAlphabetKey())
     46                     .addKeysOnTheRightOfRow(4, customizer.getEnterKey(isPhone));
     47         } else {
     48             // Tablet symbols keyboard has extra two keys at the left edge of the 3rd row.
     49             builder.addKeysOnTheLeftOfRow(3, (Object[])joinKeys("\\", "="));
     50             builder.addKeysOnTheRightOfRow(1, LayoutBase.DELETE_KEY)
     51                     .addKeysOnTheRightOfRow(2, customizer.getEnterKey(isPhone))
     52                     .addKeysOnTheLeftOfRow(3, customizer.getSymbolsShiftKey(isPhone))
     53                     .addKeysOnTheRightOfRow(3, customizer.getSymbolsShiftKey(isPhone))
     54                     .addKeysOnTheLeftOfRow(4, customizer.getAlphabetKey())
     55                     .addKeysOnTheRightOfRow(4, customizer.getEmojiKey(isPhone));
     56         }
     57         return builder.build();
     58     }
     59 
     60     // Variations of the "currency" key on the 2nd row.
     61     public static final String CURRENCY = "CURRENCY";
     62     // U+00A2: "" CENT SIGN
     63     // U+00A3: "" POUND SIGN
     64     // U+00A5: "" YEN SIGN
     65     // U+20AC: "" EURO SIGN
     66     // U+20B1: "" PESO SIGN
     67     public static final ExpectedKey DOLLAR_SIGN = key("$");
     68     public static final ExpectedKey CENT_SIGN = key("\u00A2");
     69     public static final ExpectedKey POUND_SIGN = key("\u00A3");
     70     public static final ExpectedKey YEN_SIGN = key("\u00A5");
     71     public static final ExpectedKey EURO_SIGN = key("\u20AC");
     72     public static final ExpectedKey PESO_SIGN = key("\u20B1");
     73     public static final ExpectedKey CURRENCY_DOLLAR = key("$",
     74             CENT_SIGN, POUND_SIGN, EURO_SIGN, YEN_SIGN, PESO_SIGN);
     75     public static final ExpectedKey CURRENCY_EURO = key("\u20AC",
     76             CENT_SIGN, POUND_SIGN, DOLLAR_SIGN, YEN_SIGN, PESO_SIGN);
     77     public static final ExpectedKey[] CURRENCY_GENERIC_MORE_KEYS = joinMoreKeys(
     78             Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN, Symbols.EURO_SIGN, Symbols.POUND_SIGN,
     79             Symbols.YEN_SIGN, Symbols.PESO_SIGN);
     80 
     81     // Variations of the "double quote" key's "more keys" on the 3rd row.
     82     public static final String DOUBLE_QUOTE = "DOUBLE_QUOTE";
     83     // U+201C: "" LEFT DOUBLE QUOTATION MARK
     84     // U+201D: "" RIGHT DOUBLE QUOTATION MARK
     85     // U+201E: "" DOUBLE LOW-9 QUOTATION MARK
     86     private static final ExpectedKey DQUOTE_LEFT = key("\u201C");
     87     private static final ExpectedKey DQUOTE_RIGHT = key("\u201D");
     88     private static final ExpectedKey DQUOTE_LOW9 = key("\u201E");
     89     public static ExpectedKey[] DOUBLE_QUOTES_9LR = { DQUOTE_LOW9, DQUOTE_LEFT, DQUOTE_RIGHT };
     90     public static ExpectedKey[] DOUBLE_QUOTES_R9L = { DQUOTE_RIGHT, DQUOTE_LOW9, DQUOTE_LEFT };
     91     public static ExpectedKey[] DOUBLE_QUOTES_L9R = { DQUOTE_LEFT, DQUOTE_LOW9, DQUOTE_RIGHT };
     92     public static ExpectedKey[] DOUBLE_QUOTES_LR9 = { DQUOTE_LEFT, DQUOTE_RIGHT, DQUOTE_LOW9 };
     93     // U+00AB: "" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
     94     // U+00BB: "" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
     95     private static final ExpectedKey DAQUOTE_LEFT = key("\u00AB");
     96     private static final ExpectedKey DAQUOTE_RIGHT = key("\u00BB");
     97     public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_LR = { DAQUOTE_LEFT, DAQUOTE_RIGHT };
     98     public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_RL = { DAQUOTE_RIGHT, DAQUOTE_LEFT };
     99 
    100     // Variations of the "single quote" key's "more keys" on the 3rd row.
    101     public static final String SINGLE_QUOTE = "SINGLE_QUOTE";
    102     // U+2018: "" LEFT SINGLE QUOTATION MARK
    103     // U+2019: "" RIGHT SINGLE QUOTATION MARK
    104     // U+201A: "" SINGLE LOW-9 QUOTATION MARK
    105     private static final ExpectedKey SQUOTE_LEFT = key("\u2018");
    106     private static final ExpectedKey SQUOTE_RIGHT = key("\u2019");
    107     private static final ExpectedKey SQUOTE_LOW9 = key("\u201A");
    108     public static ExpectedKey[] SINGLE_QUOTES_9LR = { SQUOTE_LOW9, SQUOTE_LEFT, SQUOTE_RIGHT };
    109     public static ExpectedKey[] SINGLE_QUOTES_R9L = { SQUOTE_RIGHT, SQUOTE_LOW9, SQUOTE_LEFT };
    110     public static ExpectedKey[] SINGLE_QUOTES_L9R = { SQUOTE_LEFT, SQUOTE_LOW9, SQUOTE_RIGHT };
    111     public static ExpectedKey[] SINGLE_QUOTES_LR9 = { SQUOTE_LEFT, SQUOTE_RIGHT, SQUOTE_LOW9 };
    112     // U+2039: "" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
    113     // U+203A: "" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
    114     private static final ExpectedKey SAQUOTE_LEFT = key("\u2039");
    115     private static final ExpectedKey SAQUOTE_RIGHT = key("\u203A");
    116     public static ExpectedKey[] SINGLE_ANGLE_QUOTES_LR = { SAQUOTE_LEFT, SAQUOTE_RIGHT };
    117     public static ExpectedKey[] SINGLE_ANGLE_QUOTES_RL = { SAQUOTE_RIGHT, SAQUOTE_LEFT };
    118 
    119     // Common symbols keyboard layout.
    120     private static final ExpectedKey[][] SYMBOLS_COMMON = new ExpectedKeyboardBuilder()
    121             .setKeysOfRow(1,
    122                     // U+00B9: "" SUPERSCRIPT ONE
    123                     // U+00BD: "" VULGAR FRACTION ONE HALF
    124                     // U+2153: "" VULGAR FRACTION ONE THIRD
    125                     // U+00BC: "" VULGAR FRACTION ONE QUARTER
    126                     // U+215B: "" VULGAR FRACTION ONE EIGHTH
    127                     key("1", joinMoreKeys("\u00B9", "\u00BD", "\u2153", "\u00BC", "\u215B")),
    128                     // U+00B2: "" SUPERSCRIPT TWO
    129                     // U+2154: "" VULGAR FRACTION TWO THIRDS
    130                     key("2", joinMoreKeys("\u00B2", "\u2154")),
    131                     // U+00B3: "" SUPERSCRIPT THREE
    132                     // U+00BE: "" VULGAR FRACTION THREE QUARTERS
    133                     // U+215C: "" VULGAR FRACTION THREE EIGHTHS
    134                     key("3", joinMoreKeys("\u00B3", "\u00BE", "\u215C")),
    135                     // U+2074: "" SUPERSCRIPT FOUR
    136                     key("4", moreKey("\u2074")),
    137                     // U+215D: "" VULGAR FRACTION FIVE EIGHTHS
    138                     key("5", moreKey("\u215D")),
    139                     "6",
    140                     // U+215E: "" VULGAR FRACTION SEVEN EIGHTHS
    141                     key("7", moreKey("\u215E")),
    142                     "8", "9",
    143                     // U+207F: "" SUPERSCRIPT LATIN SMALL LETTER N
    144                     // U+2205: "" EMPTY SET
    145                     key("0", joinMoreKeys("\u207F", "\u2205")))
    146             .setKeysOfRow(2,
    147                     key("@"), key("#"), key(CURRENCY),
    148                     // U+2030: "" PER MILLE SIGN
    149                     key("%", moreKey("\u2030")),
    150                     "&",
    151                     // U+2013: "" EN DASH
    152                     // U+2014: "" EM DASH
    153                     // U+00B7: "" MIDDLE DOT
    154                     key("-", joinMoreKeys("_", "\u2013", "\u2014", "\u00B7")),
    155                     // U+00B1: "" PLUS-MINUS SIGN
    156                     key("+", moreKey("\u00B1")),
    157                     key("(", joinMoreKeys("<", "{", "[")),
    158                     key(")", joinMoreKeys(">", "}", "]")))
    159             .setKeysOfRow(3,
    160                     // U+2020: "" DAGGER
    161                     // U+2021: "" DOUBLE DAGGER
    162                     // U+2605: "" BLACK STAR
    163                     key("*", joinMoreKeys("\u2020", "\u2021", "\u2605")),
    164                     key(DOUBLE_QUOTE), key(SINGLE_QUOTE), key(":"), key(";"),
    165                     // U+00A1: "" INVERTED EXCLAMATION MARK
    166                     key("!", moreKey("\u00A1")),
    167                     // U+00BF: "" INVERTED QUESTION MARK
    168                     key("?", moreKey("\u00BF")))
    169             .setKeysOfRow(4,
    170                     key(","), key("_"), LayoutBase.SPACE_KEY, key("/"),
    171                     // U+2026: "" HORIZONTAL ELLIPSIS
    172                     key(".", moreKey("\u2026")))
    173             .build();
    174 
    175     public static class RtlSymbols extends Symbols {
    176         public RtlSymbols(final LayoutCustomizer customizer) {
    177             super(customizer);
    178         }
    179 
    180         // U+00AB: "" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
    181         // U+00BB: "" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
    182         private static final ExpectedKey DAQUOTE_LEFT_RTL = key("\u00AB", "\u00BB");
    183         private static final ExpectedKey DAQUOTE_RIGHT_RTL = key("\u00BB", "\u00AB");
    184         public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_LR_RTL = {
    185                 DAQUOTE_LEFT_RTL, DAQUOTE_RIGHT_RTL
    186         };
    187         // U+2039: "" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
    188         // U+203A: "" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
    189         private static final ExpectedKey SAQUOTE_LEFT_RTL = key("\u2039", "\u203A");
    190         private static final ExpectedKey SAQUOTE_RIGHT_RTL = key("\u203A", "\u2039");
    191         public static ExpectedKey[] SINGLE_ANGLE_QUOTES_LR_RTL = {
    192                 SAQUOTE_LEFT_RTL, SAQUOTE_RIGHT_RTL
    193         };
    194 
    195         @Override
    196         public ExpectedKey[][] getLayout(final boolean isPhone) {
    197             return new ExpectedKeyboardBuilder(super.getLayout(isPhone))
    198                     .replaceKeyOfLabel("(", key("(", ")",
    199                             moreKey("<", ">"), moreKey("{", "}"), moreKey("[", "]")))
    200                     .replaceKeyOfLabel(")", key(")", "(",
    201                             moreKey(">", "<"), moreKey("}", "{"), moreKey("]", "[")))
    202                     .build();
    203         }
    204     }
    205 }
    206