mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
154 lines
6.9 KiB
Java
154 lines
6.9 KiB
Java
/*
|
|
* 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);
|
|
}
|
|
}
|