• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.customizer.LayoutCustomizer;
20 import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
21 import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
22 import com.android.inputmethod.keyboard.layout.expected.AbstractLayoutBase;
23 
24 /**
25  * The symbols shifted keyboard layout.
26  */
27 public class SymbolsShifted extends AbstractLayoutBase {
28     private final LayoutCustomizer mCustomizer;
29 
SymbolsShifted(final LayoutCustomizer customizer)30     public SymbolsShifted(final LayoutCustomizer customizer) {
31         mCustomizer = customizer;
32     }
33 
getLayout(final boolean isPhone)34     public ExpectedKey[][] getLayout(final boolean isPhone) {
35         final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(SYMBOLS_SHIFTED_COMMON);
36         final LayoutCustomizer customizer = mCustomizer;
37         builder.replaceKeyOfLabel(OTHER_CURRENCIES, (Object[])customizer.getOtherCurrencyKeys());
38         if (isPhone) {
39             builder.addKeysOnTheLeftOfRow(3, customizer.getBackToSymbolsKey())
40                     .addKeysOnTheRightOfRow(3, DELETE_KEY)
41                     .addKeysOnTheLeftOfRow(4, customizer.getAlphabetKey())
42                     .addKeysOnTheRightOfRow(4, customizer.getEnterKey(isPhone));
43         } else {
44             // Tablet symbols shifted keyboard has extra two keys at the right edge of the 3rd row.
45             // U+00BF: "¿" INVERTED QUESTION MARK
46             // U+00A1: "¡" INVERTED EXCLAMATION MARK
47             builder.addKeysOnTheRightOfRow(3, (Object[])joinKeys("\u00A1", "\u00BF"));
48             builder.addKeysOnTheRightOfRow(1, DELETE_KEY)
49                     .addKeysOnTheRightOfRow(2, customizer.getEnterKey(isPhone))
50                     .addKeysOnTheLeftOfRow(3, customizer.getBackToSymbolsKey())
51                     .addKeysOnTheRightOfRow(3, customizer.getBackToSymbolsKey())
52                     .addKeysOnTheLeftOfRow(4, customizer.getAlphabetKey())
53                     .addKeysOnTheRightOfRow(4, customizer.getEmojiKey(isPhone));
54         }
55         return builder.build();
56     }
57 
58     // Variations of the "other currencies" keys on the 2rd row.
59     public static final String OTHER_CURRENCIES = "OTHER_CURRENCY";
60     public static final ExpectedKey[] CURRENCIES_OTHER_THAN_DOLLAR = {
61         Symbols.POUND_SIGN, Symbols.CENT_SIGN, Symbols.EURO_SIGN, Symbols.YEN_SIGN
62     };
63     public static final ExpectedKey[] CURRENCIES_OTHER_THAN_EURO = {
64         Symbols.POUND_SIGN, Symbols.YEN_SIGN, key(Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN),
65         Symbols.CENT_SIGN
66     };
67     public static final ExpectedKey[] CURRENCIES_OTHER_GENERIC = {
68         Symbols.POUND_SIGN, Symbols.EURO_SIGN, key(Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN),
69         Symbols.CENT_SIGN
70     };
71 
72     // Common symbols shifted keyboard layout.
73     private static final ExpectedKey[][] SYMBOLS_SHIFTED_COMMON = new ExpectedKeyboardBuilder()
74             .setKeysOfRow(1,
75                     // U+0060: "`" GRAVE ACCENT
76                     "~", "\u0060", "|",
77                     // U+2022: "•" BULLET
78                     // U+266A: "♪" EIGHTH NOTE
79                     // U+2665: "♥" BLACK HEART SUIT
80                     // U+2660: "♠" BLACK SPADE SUIT
81                     // U+2666: "♦" BLACK DIAMOND SUIT
82                     // U+2663: "♣" BLACK CLUB SUIT
83                     key("\u2022", joinMoreKeys("\u266A", "\u2665", "\u2660", "\u2666", "\u2663")),
84                     // U+221A: "√" SQUARE ROOT
85                     "\u221A",
86                     // U+03C0: "π" GREEK SMALL LETTER PI
87                     // U+03A0: "Π" GREEK CAPITAL LETTER PI
88                     key("\u03C0", moreKey("\u03A0")),
89                     // U+00F7: "÷" DIVISION SIGN
90                     // U+00D7: "×" MULTIPLICATION SIGN
91                     "\u00F7", "\u00D7",
92                     // U+00B6: "¶" PILCROW SIGN
93                     // U+00A7: "§" SECTION SIGN
94                     key("\u00B6", moreKey("\u00A7")),
95                     // U+2206: "∆" INCREMENT
96                     "\u2206")
97             .setKeysOfRow(2,
98                     OTHER_CURRENCIES,
99                     // U+2191: "↑" UPWARDS ARROW
100                     // U+2193: "↓" DOWNWARDS ARROW
101                     // U+2190: "←" LEFTWARDS ARROW
102                     // U+2192: "→" RIGHTWARDS ARROW
103                     key("^", joinMoreKeys("\u2191", "\u2193", "\u2190", "\u2192")),
104                     // U+00B0: "°" DEGREE SIGN
105                     // U+2032: "′" PRIME
106                     // U+2033: "″" DOUBLE PRIME
107                     key("\u00B0", joinMoreKeys("\u2032", "\u2033")),
108                     // U+2260: "≠" NOT EQUAL TO
109                     // U+2248: "≈" ALMOST EQUAL TO
110                     // U+221E: "∞" INFINITY
111                     key("=", joinMoreKeys("\u2260", "\u2248", "\u221E")),
112                     "{", "}")
113             .setKeysOfRow(3,
114                     // U+00A9: "©" COPYRIGHT SIGN
115                     // U+00AE: "®" REGISTERED SIGN
116                     // U+2122: "™" TRADE MARK SIGN
117                     // U+2105: "℅" CARE OF
118                     "\\", "\u00A9", "\u00AE", "\u2122", "\u2105", "[", "]")
119             .setKeysOfRow(4,
120                     ",",
121                     // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
122                     // U+2264: "≤" LESS-THAN OR EQUAL TO
123                     // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
124                     key("<", joinMoreKeys("\u2039", "\u2264", "\u00AB")),
125                     SPACE_KEY,
126                     // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
127                     // U+2265: "≥" GREATER-THAN EQUAL TO
128                     // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
129                     key(">", joinMoreKeys("\u203A", "\u2265", "\u00BB")),
130                     // U+2026: "…" HORIZONTAL ELLIPSIS
131                     key(".", moreKey("\u2026")))
132             .build();
133 
134     public static class RtlSymbolsShifted extends SymbolsShifted {
RtlSymbolsShifted(final LayoutCustomizer customizer)135         public RtlSymbolsShifted(final LayoutCustomizer customizer) {
136             super(customizer);
137         }
138 
139         @Override
getLayout(final boolean isPhone)140         public ExpectedKey[][] getLayout(final boolean isPhone) {
141             return new ExpectedKeyboardBuilder(super.getLayout(isPhone))
142                 .replaceKeyOfLabel("{", key("{", "}"))
143                 .replaceKeyOfLabel("}", key("}", "{"))
144                 .replaceKeyOfLabel("[", key("[", "]"))
145                 .replaceKeyOfLabel("]", key("]", "["))
146                 // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
147                 // U+2264: "≤" LESS-THAN OR EQUAL TO
148                 // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
149                 .replaceKeyOfLabel("<", key("<", ">",
150                         moreKey("\u2039", "\u203A"), moreKey("\u2264", "\u2265"),
151                         moreKey("\u00AB", "\u00BB")))
152                 // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
153                 // U+2265: "≥" GREATER-THAN EQUAL TO
154                 // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
155                 .replaceKeyOfLabel(">", key(">", "<",
156                         moreKey("\u203A", "\u2039"), moreKey("\u2265", "\u2264"),
157                         moreKey("\u00BB", "\u00AB")))
158                 .build();
159         }
160     }
161 }
162