AbstractLayoutBase.java revision a94c89e017dac92e2c23dcf05a8e6b4000d021d3
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 17package com.android.inputmethod.keyboard.layout.expected; 18 19import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; 20import com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey; 21import com.android.inputmethod.latin.Constants; 22 23/** 24 * Base class to create an expected keyboard for unit test. 25 */ 26public abstract class AbstractLayoutBase { 27 // Those helper methods have a lower case name to be readable when defining expected keyboard 28 // layouts. 29 30 // Helper method to create an {@link ExpectedKey} object that has the label. 31 public static ExpectedKey key(final String label, final ExpectedKey ... moreKeys) { 32 return ExpectedKey.newInstance(label, moreKeys); 33 } 34 35 // Helper method to create an {@link ExpectedKey} object that has the label and the output text. 36 public static ExpectedKey key(final String label, final String outputText, 37 final ExpectedKey ... moreKeys) { 38 return ExpectedKey.newInstance(label, outputText, moreKeys); 39 } 40 41 // Helper method to create an {@link ExpectedKey} object that has the label and the output code. 42 public static ExpectedKey key(final String label, final int code, 43 final ExpectedKey ... moreKeys) { 44 return ExpectedKey.newInstance(label, code, moreKeys); 45 } 46 47 // Helper method to create an {@link ExpectedKey} object that has the icon and the output text. 48 public static ExpectedKey key(final int iconId, final String outputText, 49 final ExpectedKey ... moreKeys) { 50 return ExpectedKey.newInstance(iconId, outputText, moreKeys); 51 } 52 53 // Helper method to create an {@link ExpectedKey} object that has the icon and the output code. 54 public static ExpectedKey key(final int iconId, final int code, 55 final ExpectedKey ... moreKeys) { 56 return ExpectedKey.newInstance(iconId, code, moreKeys); 57 } 58 59 // Helper method to create an {@link ExpectedKey} object that has new "more keys". 60 public static ExpectedKey key(final ExpectedKey key, final ExpectedKey ... moreKeys) { 61 return ExpectedKey.newInstance(key.getVisual(), key.getOutput(), moreKeys); 62 } 63 64 // Helper method to create an {@link ExpectedAdditionalMoreKey} object for an 65 // "additional more key" that has the label. 66 // The additional more keys can be defined independently from other more keys. The position of 67 // the additional more keys in the long press popup keyboard can be controlled by specifying 68 // special marker "%" in the usual more keys definitions. 69 public static ExpectedAdditionalMoreKey additionalMoreKey(final String label) { 70 return ExpectedAdditionalMoreKey.newInstance(label); 71 } 72 73 // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label. 74 public static ExpectedKey moreKey(final String label) { 75 return ExpectedKey.newInstance(label); 76 } 77 78 // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label 79 // and the output text. 80 public static ExpectedKey moreKey(final String label, final String outputText) { 81 return ExpectedKey.newInstance(label, outputText); 82 } 83 84 // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label 85 // and the output code. 86 public static ExpectedKey moreKey(final String label, final int code) { 87 return ExpectedKey.newInstance(label, code); 88 } 89 90 // Helper method to create an {@link ExpectedKey} object for a "more key" that has the icon 91 // and the output text. 92 public static ExpectedKey moreKey(final int iconId, final String outputText) { 93 return ExpectedKey.newInstance(iconId, outputText); 94 } 95 96 // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey}, 97 // {@link ExpectedKey} array, and {@link String}. 98 public static ExpectedKey[] joinMoreKeys(final Object ... moreKeys) { 99 return joinKeys(moreKeys); 100 } 101 102 // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey}, 103 // {@link ExpectedKey} array, and {@link String}. 104 public static ExpectedKey[] joinKeys(final Object ... keys) { 105 return ExpectedKeyboardBuilder.joinKeys(keys); 106 } 107 108 // Icon ids. 109 private static final int ICON_DELETE = KeyboardIconsSet.getIconId( 110 KeyboardIconsSet.NAME_DELETE_KEY); 111 private static final int ICON_SPACE = KeyboardIconsSet.getIconId( 112 KeyboardIconsSet.NAME_SPACE_KEY); 113 private static final int ICON_TAB = KeyboardIconsSet.getIconId( 114 KeyboardIconsSet.NAME_TAB_KEY); 115 private static final int ICON_SHORTCUT = KeyboardIconsSet.getIconId( 116 KeyboardIconsSet.NAME_SHORTCUT_KEY); 117 private static final int ICON_SETTINGS = KeyboardIconsSet.getIconId( 118 KeyboardIconsSet.NAME_SETTINGS_KEY); 119 private static final int ICON_LANGUAGE_SWITCH = KeyboardIconsSet.getIconId( 120 KeyboardIconsSet.NAME_LANGUAGE_SWITCH_KEY); 121 private static final int ICON_ENTER = KeyboardIconsSet.getIconId( 122 KeyboardIconsSet.NAME_ENTER_KEY); 123 private static final int ICON_EMOJI_ACTION = KeyboardIconsSet.getIconId( 124 KeyboardIconsSet.NAME_EMOJI_ACTION_KEY); 125 private static final int ICON_EMOJI_NORMAL = KeyboardIconsSet.getIconId( 126 KeyboardIconsSet.NAME_EMOJI_NORMAL_KEY); 127 128 // Functional keys. 129 public static final ExpectedKey DELETE_KEY = key(ICON_DELETE, Constants.CODE_DELETE); 130 public static final ExpectedKey TAB_KEY = key(ICON_TAB, Constants.CODE_TAB); 131 public static final ExpectedKey SHORTCUT_KEY = key(ICON_SHORTCUT, Constants.CODE_SHORTCUT); 132 public static final ExpectedKey SETTINGS_KEY = key(ICON_SETTINGS, Constants.CODE_SETTINGS); 133 public static final ExpectedKey LANGUAGE_SWITCH_KEY = key( 134 ICON_LANGUAGE_SWITCH, Constants.CODE_LANGUAGE_SWITCH); 135 public static final ExpectedKey ENTER_KEY = key(ICON_ENTER, Constants.CODE_ENTER); 136 public static final ExpectedKey EMOJI_ACTION_KEY = key(ICON_EMOJI_ACTION, Constants.CODE_EMOJI); 137 public static final ExpectedKey EMOJI_NORMAL_KEY = key(ICON_EMOJI_NORMAL, Constants.CODE_EMOJI); 138 public static final ExpectedKey SPACE_KEY = key(ICON_SPACE, Constants.CODE_SPACE); 139} 140