1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.keyboard;
import android.content.Context;
import android.content.res.Resources;
import android.text.InputType;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyVisual;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.utils.RunInLocale;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.Locale;
abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBase {
static class ExpectedActionKey {
static ExpectedActionKey newIconKey(final String iconName) {
final int iconId = KeyboardIconsSet.getIconId(iconName);
return new ExpectedActionKey(ExpectedKeyVisual.newInstance(iconId));
}
static ExpectedActionKey newLabelKey(final String label) {
return new ExpectedActionKey(ExpectedKeyVisual.newInstance(label));
}
static ExpectedActionKey newLabelKey(final int labelResId,
final Locale labelLocale, final Context context) {
final RunInLocale<String> getString = new RunInLocale<String>() {
@Override
protected String job(final Resources res) {
return res.getString(labelResId);
}
};
return newLabelKey(getString.runInLocale(context.getResources(), labelLocale));
}
private final ExpectedKeyVisual mVisual;
private ExpectedActionKey(final ExpectedKeyVisual visual) {
mVisual = visual;
}
public int getIconId() { return mVisual.getIconId(); }
public String getLabel() { return mVisual.getLabel(); }
}
protected static Locale getLabelLocale(final InputMethodSubtype subtype) {
if (subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE)) {
return null;
}
return SubtypeLocaleUtils.getSubtypeLocale(subtype);
}
public void testActionUnspecified() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_ENTER_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "unspecifiled "
+ SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, expectedKey);
}
}
public void testActionNone() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_ENTER_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NONE, expectedKey);
}
}
public void testActionSearch() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_SEARCH_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEARCH, expectedKey);
}
}
public abstract void testActionGo();
public abstract void testActionSend();
public abstract void testActionNext();
public abstract void testActionDone();
public abstract void testActionPrevious();
public void testActionCustom() {
for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
final EditorInfo editorInfo = new EditorInfo();
editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED;
editorInfo.actionLabel = "customLabel";
final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey("customLabel");
doTestActionKey(tag, subtype, editorInfo, expectedKey);
}
}
private static void assertActionKey(final String tag, final KeyboardLayoutSet layoutSet,
final int elementId, final ExpectedActionKey expectedKey) {
final Keyboard keyboard = layoutSet.getKeyboard(elementId);
final Key actualKey = keyboard.getKey(Constants.CODE_ENTER);
assertNotNull(tag + " enter key on " + keyboard.mId, actualKey);
assertEquals(tag + " label " + expectedKey, expectedKey.getLabel(), actualKey.getLabel());
assertEquals(tag + " icon " + expectedKey, expectedKey.getIconId(), actualKey.getIconId());
}
protected void doTestActionKey(final String tag, final InputMethodSubtype subtype,
final int actionId, final ExpectedActionKey expectedKey) {
final EditorInfo editorInfo = new EditorInfo();
editorInfo.imeOptions = actionId;
doTestActionKey(tag, subtype, editorInfo, expectedKey);
}
protected void doTestActionKey(final String tag, final InputMethodSubtype subtype,
final EditorInfo editorInfo, final ExpectedActionKey expectedKey) {
// Test text layouts.
editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo);
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, expectedKey);
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, expectedKey);
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, expectedKey);
// Test phone number layouts.
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, expectedKey);
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, expectedKey);
// Test normal number layout.
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, expectedKey);
// Test number password layout.
editorInfo.inputType =
InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo);
assertActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, expectedKey);
}
}
|