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.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey;
20
21/**
22 * Base class to create an expected keyboard for unit test.
23 */
24public 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.
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.
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.
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.
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.
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".
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.
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.
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.
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.
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.
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}.
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}.
102    public static ExpectedKey[] joinKeys(final Object ... keys) {
103        return ExpectedKeyboardBuilder.joinKeys(keys);
104    }
105}
106