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 24 /** 25 * The Dvorak alphabet keyboard. 26 */ 27 public class Dvorak extends LayoutBase { 28 private static final String LAYOUT_NAME = "dvorak"; 29 30 public Dvorak(final LayoutCustomizer customizer) { 31 super(customizer, Symbols.class, SymbolsShifted.class); 32 } 33 34 @Override 35 public String getName() { return LAYOUT_NAME; } 36 37 @Override 38 public ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { 39 return ALPHABET_COMMON; 40 } 41 42 /** 43 * Get the left most key of the first row. 44 * @param isPhone true if requesting phone's keys. 45 * @param elementId the element id of the requesting shifted mode. 46 * @return the left most key of the first row. 47 */ 48 protected ExpectedKey getRow1_1Key(final boolean isPhone, final int elementId) { 49 if (elementId == KeyboardId.ELEMENT_ALPHABET 50 || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { 51 return key("'", joinMoreKeys(additionalMoreKey("1"), "!", "\"")); 52 } 53 return key("\"", additionalMoreKey("1")); 54 } 55 56 /** 57 * Get the 2nd left key of the first row. 58 * @param isPhone true if requesting phone's keys. 59 * @param elementId the element id of the requesting shifted mode. 60 * @return the 2nd left key of the first row. 61 */ 62 protected ExpectedKey getRow1_2Key(final boolean isPhone, final int elementId) { 63 if (elementId == KeyboardId.ELEMENT_ALPHABET 64 || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { 65 return key(",", joinMoreKeys(additionalMoreKey("2"), "?", "<")); 66 } 67 return key("<", additionalMoreKey("2")); 68 } 69 70 /** 71 * Get the 3rd left key of the first row. 72 * @param isPhone true if requesting phone's keys. 73 * @param elementId the element id of the requesting shifted mode. 74 * @return the 3rd left key of the first row. 75 */ 76 protected ExpectedKey getRow1_3Key(final boolean isPhone, final int elementId) { 77 if (elementId == KeyboardId.ELEMENT_ALPHABET 78 || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { 79 return key(".", joinMoreKeys(additionalMoreKey("3"), ">")); 80 } 81 return key(">", additionalMoreKey("3")); 82 } 83 84 @Override 85 public ExpectedKey[][] getLayout(final boolean isPhone, final int elementId) { 86 if (elementId == KeyboardId.ELEMENT_SYMBOLS 87 || elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) { 88 return super.getLayout(isPhone, elementId); 89 } 90 final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( 91 getCommonAlphabetLayout(isPhone)); 92 builder.replaceKeyOfLabel(ROW1_1, getRow1_1Key(isPhone, elementId)) 93 .replaceKeyOfLabel(ROW1_2, getRow1_2Key(isPhone, elementId)) 94 .replaceKeyOfLabel(ROW1_3, getRow1_3Key(isPhone, elementId)); 95 convertCommonLayoutToKeyboard(builder, isPhone); 96 getCustomizer().setAccentedLetters(builder); 97 if (elementId != KeyboardId.ELEMENT_ALPHABET) { 98 builder.toUpperCase(getLocale()); 99 builder.replaceKeysOfAll(SHIFT_KEY, SHIFTED_SHIFT_KEY); 100 } 101 return builder.build(); 102 } 103 104 public static final String ROW1_1 = "ROW1_1"; 105 public static final String ROW1_2 = "ROW1_2"; 106 public static final String ROW1_3 = "ROW1_3"; 107 108 private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() 109 .setKeysOfRow(1, 110 ROW1_1, ROW1_2, ROW1_3, 111 key("p", additionalMoreKey("4")), 112 key("y", additionalMoreKey("5")), 113 key("f", additionalMoreKey("6")), 114 key("g", additionalMoreKey("7")), 115 key("c", additionalMoreKey("8")), 116 key("r", additionalMoreKey("9")), 117 key("l", additionalMoreKey("0"))) 118 .setKeysOfRow(2, "a", "o", "e", "u", "i", "d", "h", "t", "n", "s") 119 .setKeysOfRow(3, "j", "k", "x", "b", "m", "w", "v") 120 .build(); 121 } 122