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