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.expected;
18 
19 import com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey;
20 
21 /**
22  * Base class to create an expected keyboard for unit test.
23  */
24 public abstract class AbstractLayoutBase {
25     // Those helper methods have a lower case name to be readable when defining expected keyboard
26     // layouts.
27 
28     // Helper method to create an {@link ExpectedKey} object that has the label.
key(final String label, final ExpectedKey ... moreKeys)29     public static ExpectedKey key(final String label, final ExpectedKey ... moreKeys) {
30         return ExpectedKey.newInstance(label, moreKeys);
31     }
32 
33     // Helper method to create an {@link ExpectedKey} object that has the label and the output text.
key(final String label, final String outputText, final ExpectedKey ... moreKeys)34     public static ExpectedKey key(final String label, final String outputText,
35             final ExpectedKey ... moreKeys) {
36         return ExpectedKey.newInstance(label, outputText, moreKeys);
37     }
38 
39     // Helper method to create an {@link ExpectedKey} object that has the label and the output code.
key(final String label, final int code, final ExpectedKey ... moreKeys)40     public static ExpectedKey key(final String label, final int code,
41             final ExpectedKey ... moreKeys) {
42         return ExpectedKey.newInstance(label, code, moreKeys);
43     }
44 
45     // Helper method to create an {@link ExpectedKey} object that has the icon and the output text.
key(final int iconId, final String outputText, final ExpectedKey ... moreKeys)46     public static ExpectedKey key(final int iconId, final String outputText,
47             final ExpectedKey ... moreKeys) {
48         return ExpectedKey.newInstance(iconId, outputText, moreKeys);
49     }
50 
51     // Helper method to create an {@link ExpectedKey} object that has the icon and the output code.
key(final int iconId, final int code, final ExpectedKey ... moreKeys)52     public static ExpectedKey key(final int iconId, final int code,
53             final ExpectedKey ... moreKeys) {
54         return ExpectedKey.newInstance(iconId, code, moreKeys);
55     }
56 
57     // Helper method to create an {@link ExpectedKey} object that has new "more keys".
key(final ExpectedKey key, final ExpectedKey ... moreKeys)58     public static ExpectedKey key(final ExpectedKey key, final ExpectedKey ... moreKeys) {
59         return ExpectedKey.newInstance(key.getVisual(), key.getOutput(), moreKeys);
60     }
61 
62     // Helper method to create an {@link ExpectedAdditionalMoreKey} object for an
63     // "additional more key" that has the label.
64     // The additional more keys can be defined independently from other more keys. The position of
65     // the additional more keys in the long press popup keyboard can be controlled by specifying
66     // special marker "%" in the usual more keys definitions.
additionalMoreKey(final String label)67     public static ExpectedAdditionalMoreKey additionalMoreKey(final String label) {
68         return ExpectedAdditionalMoreKey.newInstance(label);
69     }
70 
71     // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label.
moreKey(final String label)72     public static ExpectedKey moreKey(final String label) {
73         return ExpectedKey.newInstance(label);
74     }
75 
76     // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label
77     // and the output text.
moreKey(final String label, final String outputText)78     public static ExpectedKey moreKey(final String label, final String outputText) {
79         return ExpectedKey.newInstance(label, outputText);
80     }
81 
82     // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label
83     // and the output code.
moreKey(final String label, final int code)84     public static ExpectedKey moreKey(final String label, final int code) {
85         return ExpectedKey.newInstance(label, code);
86     }
87 
88     // Helper method to create an {@link ExpectedKey} object for a "more key" that has the icon
89     // and the output text.
moreKey(final int iconId, final String outputText)90     public static ExpectedKey moreKey(final int iconId, final String outputText) {
91         return ExpectedKey.newInstance(iconId, outputText);
92     }
93 
94     // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
95     // {@link ExpectedKey} array, and {@link String}.
joinMoreKeys(final Object ... moreKeys)96     public static ExpectedKey[] joinMoreKeys(final Object ... moreKeys) {
97         return joinKeys(moreKeys);
98     }
99 
100     // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
101     // {@link ExpectedKey} array, and {@link String}.
joinKeys(final Object ... keys)102     public static ExpectedKey[] joinKeys(final Object ... keys) {
103         return ExpectedKeyboardBuilder.joinKeys(keys);
104     }
105 }
106