mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Update tests to successfully compile again
This commit is contained in:
parent
c3edb7c5ce
commit
65173aa6b2
@ -63,22 +63,6 @@ public final class KeyboardIconsSet {
|
|||||||
private DynamicThemeProvider provider;
|
private DynamicThemeProvider provider;
|
||||||
public void loadIcons(final TypedArray keyboardAttrs, @Nullable DynamicThemeProvider provider) {
|
public void loadIcons(final TypedArray keyboardAttrs, @Nullable DynamicThemeProvider provider) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
/*
|
|
||||||
final int size = ATTR_ID_TO_ICON_ID.size();
|
|
||||||
for (int index = 0; index < size; index++) {
|
|
||||||
final int attrId = ATTR_ID_TO_ICON_ID.keyAt(index);
|
|
||||||
try {
|
|
||||||
final Drawable icon = DynamicThemeProvider.Companion.getDrawableOrDefault(attrId, keyboardAttrs, provider);
|
|
||||||
setDefaultBounds(icon);
|
|
||||||
final Integer iconId = ATTR_ID_TO_ICON_ID.get(attrId);
|
|
||||||
mIcons[iconId] = icon;
|
|
||||||
} catch (Resources.NotFoundException e) {
|
|
||||||
Log.w(TAG, "Drawable resource for icon #"
|
|
||||||
+ keyboardAttrs.getResources().getResourceEntryName(attrId)
|
|
||||||
+ " not found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -53,6 +53,24 @@ data class KeyboardLayoutElement(
|
|||||||
|
|
||||||
KeyboardLayoutKind.Number -> KeyboardId.ELEMENT_NUMBER
|
KeyboardLayoutKind.Number -> KeyboardId.ELEMENT_NUMBER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun fromElementId(value: Int): KeyboardLayoutElement =
|
||||||
|
when(value) {
|
||||||
|
KeyboardId.ELEMENT_ALPHABET -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.Base)
|
||||||
|
KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.Shifted)
|
||||||
|
KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.Shifted)
|
||||||
|
KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.ShiftLocked)
|
||||||
|
KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.ShiftLocked)
|
||||||
|
KeyboardId.ELEMENT_SYMBOLS -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Symbols, page = KeyboardLayoutPage.Base)
|
||||||
|
KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Symbols, page = KeyboardLayoutPage.Shifted)
|
||||||
|
KeyboardId.ELEMENT_PHONE -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Phone, page = KeyboardLayoutPage.Base)
|
||||||
|
KeyboardId.ELEMENT_PHONE_SYMBOLS -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Phone, page = KeyboardLayoutPage.Shifted)
|
||||||
|
KeyboardId.ELEMENT_NUMBER -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Number, page = KeyboardLayoutPage.Base)
|
||||||
|
else -> throw IllegalArgumentException("Invalid elementId $value")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SwitchActions {
|
interface SwitchActions {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -88,7 +88,6 @@ import org.futo.inputmethod.latin.touchinputconsumer.GestureConsumer;
|
|||||||
import org.futo.inputmethod.latin.uix.settings.SettingsActivity;
|
import org.futo.inputmethod.latin.uix.settings.SettingsActivity;
|
||||||
import org.futo.inputmethod.latin.utils.ApplicationUtils;
|
import org.futo.inputmethod.latin.utils.ApplicationUtils;
|
||||||
import org.futo.inputmethod.latin.utils.DialogUtils;
|
import org.futo.inputmethod.latin.utils.DialogUtils;
|
||||||
import org.futo.inputmethod.latin.utils.ImportantNoticeUtils;
|
|
||||||
import org.futo.inputmethod.latin.utils.IntentUtils;
|
import org.futo.inputmethod.latin.utils.IntentUtils;
|
||||||
import org.futo.inputmethod.latin.utils.JniUtils;
|
import org.futo.inputmethod.latin.utils.JniUtils;
|
||||||
import org.futo.inputmethod.latin.utils.LeakGuardHandlerWrapper;
|
import org.futo.inputmethod.latin.utils.LeakGuardHandlerWrapper;
|
||||||
@ -1272,7 +1271,6 @@ public class LatinIMELegacy implements KeyboardActionListener,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(boolean allGranted) {
|
public void onRequestPermissionsResult(boolean allGranted) {
|
||||||
ImportantNoticeUtils.updateContactsNoticeShown(mInputMethodService /* context */);
|
|
||||||
setNeutralSuggestionStrip();
|
setNeutralSuggestionStrip();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1533,15 +1531,11 @@ public class LatinIMELegacy implements KeyboardActionListener,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean shouldShowImportantNotice =
|
final boolean shouldShowImportantNotice = false;
|
||||||
ImportantNoticeUtils.shouldShowImportantNotice(mInputMethodService, currentSettingsValues);
|
|
||||||
final boolean shouldShowSuggestionCandidates =
|
final boolean shouldShowSuggestionCandidates =
|
||||||
currentSettingsValues.mInputAttributes.mShouldShowSuggestions
|
currentSettingsValues.mInputAttributes.mShouldShowSuggestions
|
||||||
&& currentSettingsValues.isSuggestionsEnabledPerUserSettings();
|
&& currentSettingsValues.isSuggestionsEnabledPerUserSettings();
|
||||||
final boolean shouldShowSuggestionsStripUnlessPassword = shouldShowImportantNotice
|
final boolean shouldShowSuggestionsStripUnlessPassword = currentSettingsValues.mShowsVoiceInputKey || shouldShowSuggestionCandidates || currentSettingsValues.isApplicationSpecifiedCompletionsOn();
|
||||||
|| currentSettingsValues.mShowsVoiceInputKey
|
|
||||||
|| shouldShowSuggestionCandidates
|
|
||||||
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn();
|
|
||||||
final boolean shouldShowSuggestionsStrip = shouldShowSuggestionsStripUnlessPassword
|
final boolean shouldShowSuggestionsStrip = shouldShowSuggestionsStripUnlessPassword
|
||||||
&& !currentSettingsValues.mInputAttributes.mIsPasswordField;
|
&& !currentSettingsValues.mInputAttributes.mIsPasswordField;
|
||||||
mSuggestionStripController.updateVisibility(shouldShowSuggestionsStrip, mInputMethodService.isFullscreenMode());
|
mSuggestionStripController.updateVisibility(shouldShowSuggestionsStrip, mInputMethodService.isFullscreenMode());
|
||||||
@ -1557,13 +1551,6 @@ public class LatinIMELegacy implements KeyboardActionListener,
|
|||||||
|| isEmptyApplicationSpecifiedCompletions;
|
|| isEmptyApplicationSpecifiedCompletions;
|
||||||
final boolean isBeginningOfSentencePrediction = (suggestedWords.mInputStyle
|
final boolean isBeginningOfSentencePrediction = (suggestedWords.mInputStyle
|
||||||
== SuggestedWords.INPUT_STYLE_BEGINNING_OF_SENTENCE_PREDICTION);
|
== SuggestedWords.INPUT_STYLE_BEGINNING_OF_SENTENCE_PREDICTION);
|
||||||
final boolean noSuggestionsToOverrideImportantNotice = noSuggestionsFromDictionaries
|
|
||||||
|| isBeginningOfSentencePrediction;
|
|
||||||
if (shouldShowImportantNotice && noSuggestionsToOverrideImportantNotice) {
|
|
||||||
if (mSuggestionStripController.maybeShowImportantNoticeTitle()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentSettingsValues.isSuggestionsEnabledPerUserSettings()
|
if (currentSettingsValues.isSuggestionsEnabledPerUserSettings()
|
||||||
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn()
|
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn()
|
||||||
|
@ -180,13 +180,17 @@ object Subtypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun makeSubtype(locale: String, layout: String): InputMethodSubtype =
|
||||||
|
InputMethodSubtypeBuilder()
|
||||||
|
.setSubtypeLocale(locale)
|
||||||
|
.setSubtypeExtraValue("KeyboardLayoutSet=$layout")
|
||||||
|
.build()
|
||||||
|
|
||||||
fun addLanguage(context: Context, language: Locale, layout: String) {
|
fun addLanguage(context: Context, language: Locale, layout: String) {
|
||||||
val value = subtypeToString(
|
val value = subtypeToString(makeSubtype(
|
||||||
InputMethodSubtypeBuilder()
|
language.stripExtensionsIfNeeded().toString(), layout
|
||||||
.setSubtypeLocale(language.stripExtensionsIfNeeded().toString())
|
))
|
||||||
.setSubtypeExtraValue("KeyboardLayoutSet=$layout")
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
val currentSetting = context.getSettingBlocking(SubtypesSetting)
|
val currentSetting = context.getSettingBlocking(SubtypesSetting)
|
||||||
|
|
||||||
context.setSettingBlocking(SubtypesSetting.key, currentSetting + setOf(value))
|
context.setSettingBlocking(SubtypesSetting.key, currentSetting + setOf(value))
|
||||||
|
@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.futo.inputmethod.latin.utils;
|
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.futo.inputmethod.annotations.UsedForTesting;
|
|
||||||
import org.futo.inputmethod.latin.R;
|
|
||||||
import org.futo.inputmethod.latin.permissions.PermissionsUtil;
|
|
||||||
import org.futo.inputmethod.latin.settings.SettingsValues;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public final class ImportantNoticeUtils {
|
|
||||||
private static final String TAG = ImportantNoticeUtils.class.getSimpleName();
|
|
||||||
|
|
||||||
// {@link SharedPreferences} name to save the last important notice version that has been
|
|
||||||
// displayed to users.
|
|
||||||
private static final String PREFERENCE_NAME = "important_notice_pref";
|
|
||||||
|
|
||||||
private static final String KEY_SUGGEST_CONTACTS_NOTICE = "important_notice_suggest_contacts";
|
|
||||||
|
|
||||||
@UsedForTesting
|
|
||||||
static final String KEY_TIMESTAMP_OF_CONTACTS_NOTICE = "timestamp_of_suggest_contacts_notice";
|
|
||||||
|
|
||||||
@UsedForTesting
|
|
||||||
static final long TIMEOUT_OF_IMPORTANT_NOTICE = TimeUnit.HOURS.toMillis(23);
|
|
||||||
|
|
||||||
// Copy of the hidden {@link Settings.Secure#USER_SETUP_COMPLETE} settings key.
|
|
||||||
// The value is zero until each multiuser completes system setup wizard.
|
|
||||||
// Caveat: This is a hidden API.
|
|
||||||
private static final String Settings_Secure_USER_SETUP_COMPLETE = "user_setup_complete";
|
|
||||||
private static final int USER_SETUP_IS_NOT_COMPLETE = 0;
|
|
||||||
|
|
||||||
private ImportantNoticeUtils() {
|
|
||||||
// This utility class is not publicly instantiable.
|
|
||||||
}
|
|
||||||
|
|
||||||
@UsedForTesting
|
|
||||||
static boolean isInSystemSetupWizard(final Context context) {
|
|
||||||
try {
|
|
||||||
final int userSetupComplete = Settings.Secure.getInt(
|
|
||||||
context.getContentResolver(), Settings_Secure_USER_SETUP_COMPLETE);
|
|
||||||
return userSetupComplete == USER_SETUP_IS_NOT_COMPLETE;
|
|
||||||
} catch (final SettingNotFoundException e) {
|
|
||||||
Log.w(TAG, "Can't find settings in Settings.Secure: key="
|
|
||||||
+ Settings_Secure_USER_SETUP_COMPLETE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean shouldShowImportantNotice(final Context context,
|
|
||||||
final SettingsValues settingsValues) {
|
|
||||||
// Check to see whether "Use Contacts" is enabled by the user.
|
|
||||||
/*
|
|
||||||
if (!settingsValues.mUseContactsDict) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasContactsNoticeShown(context)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't show the dialog if we have all the permissions.
|
|
||||||
if (PermissionsUtil.checkAllPermissionsGranted(
|
|
||||||
context, Manifest.permission.READ_CONTACTS)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String importantNoticeTitle = getSuggestContactsNoticeTitle(context);
|
|
||||||
if (TextUtils.isEmpty(importantNoticeTitle)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isInSystemSetupWizard(context)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (hasContactsNoticeTimeoutPassed(context, System.currentTimeMillis())) {
|
|
||||||
updateContactsNoticeShown(context);
|
|
||||||
return false;
|
|
||||||
}*/
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getSuggestContactsNoticeTitle(final Context context) {
|
|
||||||
return context.getResources().getString(R.string.important_notice_suggest_contact_names);
|
|
||||||
}
|
|
||||||
|
|
||||||
@UsedForTesting
|
|
||||||
static boolean hasContactsNoticeTimeoutPassed(
|
|
||||||
final Context context, final long currentTimeInMillis) {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateContactsNoticeShown(final Context context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -575,9 +575,13 @@ data class LayoutEngine(
|
|||||||
params.mBaseHeight = totalKeyboardHeight
|
params.mBaseHeight = totalKeyboardHeight
|
||||||
params.mDefaultRowHeight = rowHeightPx.roundToInt()
|
params.mDefaultRowHeight = rowHeightPx.roundToInt()
|
||||||
|
|
||||||
val provider = DynamicThemeProvider.obtainFromContext(context)
|
try {
|
||||||
|
val provider = DynamicThemeProvider.obtainFromContext(context)
|
||||||
|
params.mIconsSet.loadIcons(null, provider)
|
||||||
|
} catch(_: IllegalArgumentException) {
|
||||||
|
// May fail during test because provider is unavailable
|
||||||
|
}
|
||||||
|
|
||||||
params.mIconsSet.loadIcons(null, provider)
|
|
||||||
params.mThemeId = 3
|
params.mThemeId = 3
|
||||||
params.mTextsSet.setLocale(params.mId.locale, context)
|
params.mTextsSet.setLocale(params.mId.locale, context)
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
package="org.futo.inputmethod.latin.tests">
|
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
|
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
|
||||||
|
|
||||||
@ -28,7 +27,7 @@
|
|||||||
</application>
|
</application>
|
||||||
|
|
||||||
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
|
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||||
android:targetPackage="org.futo.inputmethod.latin"
|
android:targetPackage="org.futo.inputmethod.latin.tests"
|
||||||
android:label="LatinIME tests">
|
android:label="LatinIME tests">
|
||||||
</instrumentation>
|
</instrumentation>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -21,13 +21,17 @@ import android.view.inputmethod.EditorInfo;
|
|||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import org.futo.inputmethod.keyboard.internal.KeyboardIconsSet;
|
import org.futo.inputmethod.keyboard.internal.KeyboardIconsSet;
|
||||||
|
import org.futo.inputmethod.keyboard.internal.KeyboardLayoutElement;
|
||||||
import org.futo.inputmethod.keyboard.internal.MoreKeySpec;
|
import org.futo.inputmethod.keyboard.internal.MoreKeySpec;
|
||||||
import org.futo.inputmethod.latin.R;
|
import org.futo.inputmethod.latin.R;
|
||||||
import org.futo.inputmethod.latin.RichInputMethodManager;
|
import org.futo.inputmethod.latin.RichInputMethodManager;
|
||||||
|
import org.futo.inputmethod.latin.Subtypes;
|
||||||
import org.futo.inputmethod.latin.common.Constants;
|
import org.futo.inputmethod.latin.common.Constants;
|
||||||
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
abstract class KeyboardLayoutSetNavigateMoreKeysBase extends KeyboardLayoutSetTestsBase {
|
abstract class KeyboardLayoutSetNavigateMoreKeysBase extends KeyboardLayoutSetTestsBase {
|
||||||
@ -82,38 +86,38 @@ abstract class KeyboardLayoutSetNavigateMoreKeysBase extends KeyboardLayoutSetTe
|
|||||||
final EditorInfo editorInfo = new EditorInfo();
|
final EditorInfo editorInfo = new EditorInfo();
|
||||||
editorInfo.inputType = inputType;
|
editorInfo.inputType = inputType;
|
||||||
editorInfo.imeOptions = imeOptions;
|
editorInfo.imeOptions = imeOptions;
|
||||||
final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo);
|
final KeyboardLayoutSetV2 layoutSet = createKeyboardLayoutSet(subtype, editorInfo);
|
||||||
final Keyboard keyboard = layoutSet.getKeyboard(elementId);
|
final Keyboard keyboard = layoutSet.getKeyboard(KeyboardLayoutElement.fromElementId(elementId));
|
||||||
|
|
||||||
final Key actualKey = keyboard.getKey(code);
|
final Key actualKey = keyboard.getKey(code);
|
||||||
final MoreKeySpec[] actualMoreKeys = actualKey.getMoreKeys();
|
final List<MoreKeySpec> actualMoreKeys = actualKey.getMoreKeys();
|
||||||
final String tag = actualKey.toString() + " moreKeys=" + Arrays.toString(actualMoreKeys);
|
final String tag = actualKey.toString() + " moreKeys=" + actualMoreKeys.toString();
|
||||||
if (expectedMoreKeys.length == 0) {
|
if (expectedMoreKeys.length == 0) {
|
||||||
assertEquals(tag, null, actualMoreKeys);
|
assertEquals(tag, 0, actualMoreKeys.size());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (expectedMoreKeys.length == 1) {
|
if (expectedMoreKeys.length == 1) {
|
||||||
assertEquals(tag + " fixedOrder", false, actualKey.isMoreKeysFixedOrder());
|
assertFalse(tag + " fixedOrder", actualKey.isMoreKeysFixedOrder());
|
||||||
assertEquals(tag + " fixedColumn", false, actualKey.isMoreKeysFixedColumn());
|
assertFalse(tag + " fixedColumn", actualKey.isMoreKeysFixedColumn());
|
||||||
} else {
|
} else {
|
||||||
assertEquals(tag + " fixedOrder", true, actualKey.isMoreKeysFixedOrder());
|
assertTrue(tag + " fixedOrder", actualKey.isMoreKeysFixedOrder());
|
||||||
assertEquals(tag + " fixedColumn", true, actualKey.isMoreKeysFixedColumn());
|
assertTrue(tag + " fixedColumn", actualKey.isMoreKeysFixedColumn());
|
||||||
// TODO: Can't handle multiple rows of more keys.
|
// TODO: Can't handle multiple rows of more keys.
|
||||||
assertEquals(tag + " column",
|
assertEquals(tag + " column",
|
||||||
expectedMoreKeys.length, actualKey.getMoreKeysColumnNumber());
|
expectedMoreKeys.length, actualKey.getMoreKeysColumnNumber());
|
||||||
}
|
}
|
||||||
assertNotNull(tag + " moreKeys", actualMoreKeys);
|
assertNotNull(tag + " moreKeys", actualMoreKeys);
|
||||||
assertEquals(tag, expectedMoreKeys.length, actualMoreKeys.length);
|
assertEquals(tag, expectedMoreKeys.length, actualMoreKeys.size());
|
||||||
for (int index = 0; index < actualMoreKeys.length; index++) {
|
for (int index = 0; index < actualMoreKeys.size(); index++) {
|
||||||
final int expectedLabelResId = expectedMoreKeys[index].mLabelResId;
|
final int expectedLabelResId = expectedMoreKeys[index].mLabelResId;
|
||||||
if (expectedLabelResId == ExpectedMoreKey.NO_LABEL) {
|
if (expectedLabelResId == ExpectedMoreKey.NO_LABEL) {
|
||||||
assertEquals(tag + " label " + index, null, actualMoreKeys[index].mLabel);
|
assertEquals(tag + " label " + index, null, actualMoreKeys.get(index).mLabel);
|
||||||
} else {
|
} else {
|
||||||
final CharSequence expectedLabel = getContext().getText(expectedLabelResId);
|
final CharSequence expectedLabel = getContext().getText(expectedLabelResId);
|
||||||
assertEquals(tag + " label " + index, expectedLabel, actualMoreKeys[index].mLabel);
|
assertEquals(tag + " label " + index, expectedLabel, actualMoreKeys.get(index).mLabel);
|
||||||
}
|
}
|
||||||
final String expectedIconId = expectedMoreKeys[index].mIconId;
|
final String expectedIconId = expectedMoreKeys[index].mIconId;
|
||||||
assertEquals(tag + " icon " + index, expectedIconId, actualMoreKeys[index].mIconId);
|
assertEquals(tag + " icon " + index, expectedIconId, actualMoreKeys.get(index).mIconId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +286,7 @@ abstract class KeyboardLayoutSetNavigateMoreKeysBase extends KeyboardLayoutSetTe
|
|||||||
|
|
||||||
public void testMoreKeysOfEnterKey() {
|
public void testMoreKeysOfEnterKey() {
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
final InputMethodSubtype subtype = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
final InputMethodSubtype subtype = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.US.toString(), SubtypeLocaleUtils.QWERTY);
|
Locale.US.toString(), SubtypeLocaleUtils.QWERTY);
|
||||||
|
|
||||||
// Password field.
|
// Password field.
|
||||||
|
@ -33,6 +33,8 @@ import org.futo.inputmethod.latin.settings.Settings;
|
|||||||
import org.futo.inputmethod.latin.utils.AdditionalSubtypeUtils;
|
import org.futo.inputmethod.latin.utils.AdditionalSubtypeUtils;
|
||||||
import org.futo.inputmethod.latin.utils.ResourceUtils;
|
import org.futo.inputmethod.latin.utils.ResourceUtils;
|
||||||
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2Params;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -79,12 +81,12 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
|||||||
AdditionalSubtypeUtils.createAdditionalSubtypesArray(
|
AdditionalSubtypeUtils.createAdditionalSubtypesArray(
|
||||||
AdditionalSubtypeUtils.createPrefSubtypes(
|
AdditionalSubtypeUtils.createPrefSubtypes(
|
||||||
res.getStringArray(R.array.predefined_subtypes)));
|
res.getStringArray(R.array.predefined_subtypes)));
|
||||||
mRichImm.setAdditionalInputMethodSubtypes(predefinedAdditionalSubtypes);
|
//mRichImm.setAdditionalInputMethodSubtypes(predefinedAdditionalSubtypes);
|
||||||
|
|
||||||
final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById(
|
final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById(
|
||||||
getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES);
|
getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES);
|
||||||
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
||||||
KeyboardLayoutSet.onKeyboardThemeChanged();
|
KeyboardLayoutSetV2.onKeyboardThemeChanged();
|
||||||
|
|
||||||
mScreenMetrics = Settings.readScreenMetrics(res);
|
mScreenMetrics = Settings.readScreenMetrics(res);
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
|||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
// Restore additional subtypes preference.
|
// Restore additional subtypes preference.
|
||||||
mRichImm.setAdditionalInputMethodSubtypes(mSavedAdditionalSubtypes);
|
//mRichImm.setAdditionalInputMethodSubtypes(mSavedAdditionalSubtypes);
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,25 +145,32 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
|||||||
"Unknown subtype: locale=" + locale + " keyboardLayout=" + keyboardLayout);
|
"Unknown subtype: locale=" + locale + " keyboardLayout=" + keyboardLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
protected KeyboardLayoutSetV2 createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
||||||
final EditorInfo editorInfo) {
|
final EditorInfo editorInfo) {
|
||||||
return createKeyboardLayoutSet(subtype, editorInfo, false /* voiceInputKeyEnabled */,
|
return createKeyboardLayoutSet(subtype, editorInfo, false /* voiceInputKeyEnabled */,
|
||||||
false /* languageSwitchKeyEnabled */, false /* splitLayoutEnabled */);
|
false /* languageSwitchKeyEnabled */, false /* splitLayoutEnabled */);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
protected KeyboardLayoutSetV2 createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
||||||
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
||||||
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
|
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
|
||||||
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
|
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
|
||||||
final Builder builder = new Builder(context, editorInfo);
|
|
||||||
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
|
final RichInputMethodSubtype richInputMethodSubtype = RichInputMethodSubtype.getRichInputMethodSubtype(subtype);
|
||||||
.setSubtype(RichInputMethodSubtype.getRichInputMethodSubtype(subtype))
|
|
||||||
.setVoiceInputKeyEnabled(voiceInputKeyEnabled)
|
return new KeyboardLayoutSetV2(
|
||||||
.setBottomEmojiKeyEnabled(languageSwitchKeyEnabled)
|
context,
|
||||||
.setSplitLayoutEnabledByUser(splitLayoutEnabled);
|
new KeyboardLayoutSetV2Params(
|
||||||
return builder.build();
|
keyboardWidth, keyboardHeight,
|
||||||
|
richInputMethodSubtype.getKeyboardLayoutSetName(),
|
||||||
|
richInputMethodSubtype.getLocale(),
|
||||||
|
editorInfo, false,
|
||||||
|
4.0f, splitLayoutEnabled,
|
||||||
|
languageSwitchKeyEnabled ? 1 : null
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,69 +13,94 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License
|
* limitations under the License
|
||||||
*/
|
*/
|
||||||
|
package org.futo.inputmethod.keyboard
|
||||||
|
|
||||||
package org.futo.inputmethod.keyboard;
|
import androidx.test.filters.SmallTest
|
||||||
|
import androidx.test.runner.AndroidJUnit4
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.futo.inputmethod.v2keyboard.KeyVisualStyle
|
||||||
|
import org.junit.Assert
|
||||||
import androidx.test.filters.SmallTest;
|
import org.junit.Test
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
public class KeyboardLayoutTest {
|
class KeyboardLayoutTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNewKeyboardLayout() {
|
fun testNewKeyboardLayout() {
|
||||||
KeyboardLayout keyboardLayout = KeyboardLayout
|
var keyboardLayout = KeyboardLayout
|
||||||
.newKeyboardLayout(new ArrayList<Key>(), 11, 12, 13, 14);
|
.newKeyboardLayout(ArrayList(), 11, 12, 13, 14)
|
||||||
|
|
||||||
assertEquals(11, keyboardLayout.mMostCommonKeyWidth);
|
Assert.assertEquals(11, keyboardLayout.mMostCommonKeyWidth.toLong())
|
||||||
assertEquals(12, keyboardLayout.mMostCommonKeyHeight);
|
Assert.assertEquals(12, keyboardLayout.mMostCommonKeyHeight.toLong())
|
||||||
assertEquals(13, keyboardLayout.mKeyboardWidth);
|
Assert.assertEquals(13, keyboardLayout.mKeyboardWidth.toLong())
|
||||||
assertEquals(14, keyboardLayout.mKeyboardHeight);
|
Assert.assertEquals(14, keyboardLayout.mKeyboardHeight.toLong())
|
||||||
|
|
||||||
assertEquals(0, keyboardLayout.getKeyCodes().length);
|
Assert.assertEquals(0, keyboardLayout.keyCodes.size.toLong())
|
||||||
assertEquals(0, keyboardLayout.getKeyWidths().length);
|
Assert.assertEquals(0, keyboardLayout.keyWidths.size.toLong())
|
||||||
assertEquals(0, keyboardLayout.getKeyHeights().length);
|
Assert.assertEquals(0, keyboardLayout.keyHeights.size.toLong())
|
||||||
assertEquals(0, keyboardLayout.getKeyXCoordinates().length);
|
Assert.assertEquals(0, keyboardLayout.keyXCoordinates.size.toLong())
|
||||||
assertEquals(0, keyboardLayout.getKeyYCoordinates().length);
|
Assert.assertEquals(0, keyboardLayout.keyYCoordinates.size.toLong())
|
||||||
|
|
||||||
Key key1 = new Key("label1", 101, 102, "101", "101hint", 103, 104, 105, 106, 1100, 1101,
|
val key1 = Key(
|
||||||
10, 10);
|
code = 101,
|
||||||
Key key2 = new Key("label2", 201, 103, "201", "201hint", 203, 204, 205, 206, 2100, 2101,
|
label = "label1",
|
||||||
10, 10);
|
hintLabel = "101hint",
|
||||||
|
width = 1100,
|
||||||
|
height = 1101,
|
||||||
|
horizontalGap = 10,
|
||||||
|
verticalGap = 10,
|
||||||
|
actionFlags = 102,
|
||||||
|
labelFlags = 103,
|
||||||
|
visualStyle = KeyVisualStyle.Normal,
|
||||||
|
x = 105,
|
||||||
|
y = 106
|
||||||
|
)
|
||||||
|
|
||||||
ArrayList<Key> sortedKeys = new ArrayList<>(2);
|
val key2 = Key(
|
||||||
sortedKeys.add(key1);
|
code = 201,
|
||||||
sortedKeys.add(key2);
|
label = "label2",
|
||||||
keyboardLayout = KeyboardLayout.newKeyboardLayout(sortedKeys, 11, 12, 13, 14);
|
hintLabel = "201hint",
|
||||||
assertEquals(2, keyboardLayout.getKeyCodes().length);
|
width = 2100,
|
||||||
assertEquals(2, keyboardLayout.getKeyWidths().length);
|
height = 2101,
|
||||||
assertEquals(2, keyboardLayout.getKeyHeights().length);
|
horizontalGap = 10,
|
||||||
assertEquals(2, keyboardLayout.getKeyXCoordinates().length);
|
verticalGap = 10,
|
||||||
assertEquals(2, keyboardLayout.getKeyYCoordinates().length);
|
actionFlags = 202,
|
||||||
|
labelFlags = 203,
|
||||||
|
visualStyle = KeyVisualStyle.Normal,
|
||||||
|
x = 205,
|
||||||
|
y = 206
|
||||||
|
)
|
||||||
|
|
||||||
assertEquals(102, keyboardLayout.getKeyCodes()[0]);
|
//Key key1 = new Key("label1", 101, 102, "101", "101hint", 103, 104, 105, 106, 1100, 1101,
|
||||||
|
// 10, 10);
|
||||||
|
//Key key2 = new Key("label2", 201, 103, "201", "201hint", 203, 204, 205, 206, 2100, 2101,
|
||||||
|
// 10, 10);
|
||||||
|
val sortedKeys = ArrayList<Key>(2)
|
||||||
|
sortedKeys.add(key1)
|
||||||
|
sortedKeys.add(key2)
|
||||||
|
keyboardLayout = KeyboardLayout.newKeyboardLayout(sortedKeys, 11, 12, 13, 14)
|
||||||
|
Assert.assertEquals(2, keyboardLayout.keyCodes.size.toLong())
|
||||||
|
Assert.assertEquals(2, keyboardLayout.keyWidths.size.toLong())
|
||||||
|
Assert.assertEquals(2, keyboardLayout.keyHeights.size.toLong())
|
||||||
|
Assert.assertEquals(2, keyboardLayout.keyXCoordinates.size.toLong())
|
||||||
|
Assert.assertEquals(2, keyboardLayout.keyYCoordinates.size.toLong())
|
||||||
|
|
||||||
|
Assert.assertEquals(102, keyboardLayout.keyCodes[0].toLong())
|
||||||
// xCo + horizontalGap/2
|
// xCo + horizontalGap/2
|
||||||
assertEquals(105 + 5, keyboardLayout.getKeyXCoordinates()[0]);
|
Assert.assertEquals((105 + 5).toLong(), keyboardLayout.keyXCoordinates[0].toLong())
|
||||||
assertEquals(106, keyboardLayout.getKeyYCoordinates()[0]);
|
Assert.assertEquals(106, keyboardLayout.keyYCoordinates[0].toLong())
|
||||||
// width - horizontalGap
|
// width - horizontalGap
|
||||||
assertEquals(1100 - 10, keyboardLayout.getKeyWidths()[0]);
|
Assert.assertEquals((1100 - 10).toLong(), keyboardLayout.keyWidths[0].toLong())
|
||||||
// height - verticalGap
|
// height - verticalGap
|
||||||
assertEquals(1101 - 10, keyboardLayout.getKeyHeights()[0]);
|
Assert.assertEquals((1101 - 10).toLong(), keyboardLayout.keyHeights[0].toLong())
|
||||||
|
|
||||||
assertEquals(103, keyboardLayout.getKeyCodes()[1]);
|
Assert.assertEquals(103, keyboardLayout.keyCodes[1].toLong())
|
||||||
// xCo + horizontalGap/2
|
// xCo + horizontalGap/2
|
||||||
assertEquals(205 + 5, keyboardLayout.getKeyXCoordinates()[1]);
|
Assert.assertEquals((205 + 5).toLong(), keyboardLayout.keyXCoordinates[1].toLong())
|
||||||
assertEquals(206, keyboardLayout.getKeyYCoordinates()[1]);
|
Assert.assertEquals(206, keyboardLayout.keyYCoordinates[1].toLong())
|
||||||
// width - horizontalGap
|
// width - horizontalGap
|
||||||
assertEquals(2100 - 10, keyboardLayout.getKeyWidths()[1]);
|
Assert.assertEquals((2100 - 10).toLong(), keyboardLayout.keyWidths[1].toLong())
|
||||||
// height - verticalGap
|
// height - verticalGap
|
||||||
assertEquals(2101 - 10, keyboardLayout.getKeyHeights()[1]);
|
Assert.assertEquals((2101 - 10).toLong(), keyboardLayout.keyHeights[1].toLong())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,13 @@ import org.futo.inputmethod.keyboard.Key;
|
|||||||
import org.futo.inputmethod.keyboard.Keyboard;
|
import org.futo.inputmethod.keyboard.Keyboard;
|
||||||
import org.futo.inputmethod.keyboard.KeyboardId;
|
import org.futo.inputmethod.keyboard.KeyboardId;
|
||||||
import org.futo.inputmethod.keyboard.KeyboardLayoutSetTestsBase;
|
import org.futo.inputmethod.keyboard.KeyboardLayoutSetTestsBase;
|
||||||
|
import org.futo.inputmethod.keyboard.internal.KeyboardLayoutElement;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKeyVisual;
|
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKeyVisual;
|
||||||
import org.futo.inputmethod.latin.common.Constants;
|
import org.futo.inputmethod.latin.common.Constants;
|
||||||
import org.futo.inputmethod.latin.common.LocaleUtils;
|
import org.futo.inputmethod.latin.common.LocaleUtils;
|
||||||
import org.futo.inputmethod.latin.utils.RunInLocale;
|
import org.futo.inputmethod.latin.utils.RunInLocale;
|
||||||
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -74,9 +76,9 @@ abstract class ActionTestsBase extends KeyboardLayoutSetTestsBase {
|
|||||||
return LocaleUtils.constructLocaleFromString(localeString);
|
return LocaleUtils.constructLocaleFromString(localeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertActionKey(final String tag, final KeyboardLayoutSet layoutSet,
|
private static void assertActionKey(final String tag, final KeyboardLayoutSetV2 layoutSet,
|
||||||
final int elementId, final ExpectedActionKey expectedKey) {
|
final int elementId, final ExpectedActionKey expectedKey) {
|
||||||
final Keyboard keyboard = layoutSet.getKeyboard(elementId);
|
final Keyboard keyboard = layoutSet.getKeyboard(KeyboardLayoutElement.fromElementId(elementId));
|
||||||
final Key actualKey = keyboard.getKey(Constants.CODE_ENTER);
|
final Key actualKey = keyboard.getKey(Constants.CODE_ENTER);
|
||||||
assertNotNull(tag + " enter key on " + keyboard.mId, actualKey);
|
assertNotNull(tag + " enter key on " + keyboard.mId, actualKey);
|
||||||
assertEquals(tag + " label " + expectedKey, expectedKey.getLabel(), actualKey.getLabel());
|
assertEquals(tag + " label " + expectedKey, expectedKey.getLabel(), actualKey.getLabel());
|
||||||
@ -94,7 +96,7 @@ abstract class ActionTestsBase extends KeyboardLayoutSetTestsBase {
|
|||||||
final EditorInfo editorInfo, final ExpectedActionKey expectedKey) {
|
final EditorInfo editorInfo, final ExpectedActionKey expectedKey) {
|
||||||
// Test text layouts.
|
// Test text layouts.
|
||||||
editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
|
editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
|
||||||
final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo);
|
final KeyboardLayoutSetV2 layoutSet = createKeyboardLayoutSet(subtype, editorInfo);
|
||||||
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, expectedKey);
|
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, expectedKey);
|
||||||
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, expectedKey);
|
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, expectedKey);
|
||||||
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, expectedKey);
|
assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, expectedKey);
|
||||||
@ -106,7 +108,7 @@ abstract class ActionTestsBase extends KeyboardLayoutSetTestsBase {
|
|||||||
// Test number password layout.
|
// Test number password layout.
|
||||||
editorInfo.inputType =
|
editorInfo.inputType =
|
||||||
InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
|
InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
|
||||||
final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo);
|
final KeyboardLayoutSetV2 passwordSet = createKeyboardLayoutSet(subtype, editorInfo);
|
||||||
assertActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, expectedKey);
|
assertActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, expectedKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,10 @@ import org.futo.inputmethod.keyboard.internal.KeyboardIconsSet;
|
|||||||
import org.futo.inputmethod.keyboard.internal.KeyboardTextsSet;
|
import org.futo.inputmethod.keyboard.internal.KeyboardTextsSet;
|
||||||
import org.futo.inputmethod.latin.R;
|
import org.futo.inputmethod.latin.R;
|
||||||
import org.futo.inputmethod.latin.RichInputMethodManager;
|
import org.futo.inputmethod.latin.RichInputMethodManager;
|
||||||
|
import org.futo.inputmethod.latin.Subtypes;
|
||||||
import org.futo.inputmethod.latin.utils.RunInLocale;
|
import org.futo.inputmethod.latin.utils.RunInLocale;
|
||||||
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ public class KlpActionLabelTests extends KlpActionTestsBase {
|
|||||||
final Locale labelLocale, final Locale systemLocale) {
|
final Locale labelLocale, final Locale systemLocale) {
|
||||||
// Simulate system locale changing, see {@link SystemBroadcastReceiver}.
|
// Simulate system locale changing, see {@link SystemBroadcastReceiver}.
|
||||||
if (!systemLocale.equals(mSystemLocale)) {
|
if (!systemLocale.equals(mSystemLocale)) {
|
||||||
KeyboardLayoutSet.onSystemLocaleChanged();
|
KeyboardLayoutSetV2.onSystemLocaleChanged();
|
||||||
mSystemLocale = systemLocale;
|
mSystemLocale = systemLocale;
|
||||||
}
|
}
|
||||||
final ExpectedActionKey enterKey = ExpectedActionKey.newIconKey(
|
final ExpectedActionKey enterKey = ExpectedActionKey.newIconKey(
|
||||||
@ -87,7 +89,7 @@ public class KlpActionLabelTests extends KlpActionTestsBase {
|
|||||||
|
|
||||||
public void testActionLabelInOtherLocale() {
|
public void testActionLabelInOtherLocale() {
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
final InputMethodSubtype italian = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY);
|
Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY);
|
||||||
// An action label should be displayed in subtype's locale regardless of the system locale.
|
// An action label should be displayed in subtype's locale regardless of the system locale.
|
||||||
doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.US);
|
doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.US);
|
||||||
@ -98,7 +100,7 @@ public class KlpActionLabelTests extends KlpActionTestsBase {
|
|||||||
|
|
||||||
public void testNoLanguageSubtypeActionLabel() {
|
public void testNoLanguageSubtypeActionLabel() {
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
final InputMethodSubtype noLanguage = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
final InputMethodSubtype noLanguage = Subtypes.INSTANCE.makeSubtype(
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY);
|
SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY);
|
||||||
// An action label of no language keyboard should be displayed in the system locale.
|
// An action label of no language keyboard should be displayed in the system locale.
|
||||||
doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.US, Locale.US);
|
doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.US, Locale.US);
|
||||||
@ -111,7 +113,7 @@ public class KlpActionLabelTests extends KlpActionTestsBase {
|
|||||||
final Locale labelLocale, final Locale systemLocale) {
|
final Locale labelLocale, final Locale systemLocale) {
|
||||||
// Simulate system locale changing, see {@link SystemBroadcastReceiver}.
|
// Simulate system locale changing, see {@link SystemBroadcastReceiver}.
|
||||||
if (!systemLocale.equals(mSystemLocale)) {
|
if (!systemLocale.equals(mSystemLocale)) {
|
||||||
KeyboardLayoutSet.onSystemLocaleChanged();
|
KeyboardLayoutSetV2.onSystemLocaleChanged();
|
||||||
mSystemLocale = systemLocale;
|
mSystemLocale = systemLocale;
|
||||||
}
|
}
|
||||||
final KeyboardTextsSet textsSet = new KeyboardTextsSet();
|
final KeyboardTextsSet textsSet = new KeyboardTextsSet();
|
||||||
@ -146,7 +148,7 @@ public class KlpActionLabelTests extends KlpActionTestsBase {
|
|||||||
public void testHinglishActionLabel() {
|
public void testHinglishActionLabel() {
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
final Locale hi_ZZ = new Locale("hi", "ZZ");
|
final Locale hi_ZZ = new Locale("hi", "ZZ");
|
||||||
final InputMethodSubtype hiLatn = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
final InputMethodSubtype hiLatn = Subtypes.INSTANCE.makeSubtype(
|
||||||
hi_ZZ.toString(), SubtypeLocaleUtils.QWERTY);
|
hi_ZZ.toString(), SubtypeLocaleUtils.QWERTY);
|
||||||
// This is a preliminary subtype and may not exist.
|
// This is a preliminary subtype and may not exist.
|
||||||
if (hiLatn == null) {
|
if (hiLatn == null) {
|
||||||
@ -163,7 +165,7 @@ public class KlpActionLabelTests extends KlpActionTestsBase {
|
|||||||
public void testSerbianLatinActionLabel() {
|
public void testSerbianLatinActionLabel() {
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
final Locale sr_ZZ = new Locale("sr", "ZZ");
|
final Locale sr_ZZ = new Locale("sr", "ZZ");
|
||||||
final InputMethodSubtype srLatn = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
final InputMethodSubtype srLatn = Subtypes.INSTANCE.makeSubtype(
|
||||||
sr_ZZ.toString(), "serbian_qwertz");
|
sr_ZZ.toString(), "serbian_qwertz");
|
||||||
// This is a preliminary subtype and may not exist.
|
// This is a preliminary subtype and may not exist.
|
||||||
if (srLatn == null) {
|
if (srLatn == null) {
|
||||||
|
@ -94,7 +94,7 @@ public class KeyboardStateTestsBase extends AndroidTestCase
|
|||||||
* @param afterPress the keyboard state after pressing the key.
|
* @param afterPress the keyboard state after pressing the key.
|
||||||
*/
|
*/
|
||||||
public void pressKey(final int code, final int afterPress) {
|
public void pressKey(final int code, final int afterPress) {
|
||||||
mSwitcher.expireDoubleTapTimeout();
|
//mSwitcher.expireDoubleTapTimeout();
|
||||||
pressKeyWithoutTimerExpire(code, true, afterPress);
|
pressKeyWithoutTimerExpire(code, true, afterPress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ public class KeyboardStateTestsBase extends AndroidTestCase
|
|||||||
* @param afterPress the keyboard state after pressing chording key.
|
* @param afterPress the keyboard state after pressing chording key.
|
||||||
*/
|
*/
|
||||||
public void chordingPressKey(final int code, final int afterPress) {
|
public void chordingPressKey(final int code, final int afterPress) {
|
||||||
mSwitcher.expireDoubleTapTimeout();
|
//mSwitcher.expireDoubleTapTimeout();
|
||||||
pressKeyWithoutTimerExpire(code, false, afterPress);
|
pressKeyWithoutTimerExpire(code, false, afterPress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,11 +18,13 @@ package org.futo.inputmethod.keyboard.internal;
|
|||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.futo.inputmethod.event.Event;
|
import org.futo.inputmethod.event.Event;
|
||||||
import org.futo.inputmethod.latin.common.Constants;
|
import org.futo.inputmethod.latin.common.Constants;
|
||||||
import org.futo.inputmethod.latin.utils.RecapitalizeStatus;
|
import org.futo.inputmethod.latin.utils.RecapitalizeStatus;
|
||||||
|
|
||||||
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
public class MockKeyboardSwitcher implements SwitchActions {
|
||||||
public interface MockConstants {
|
public interface MockConstants {
|
||||||
// Argument for {@link KeyboardState#onPressKey} and {@link KeyboardState#onReleaseKey}.
|
// Argument for {@link KeyboardState#onPressKey} and {@link KeyboardState#onReleaseKey}.
|
||||||
public static final boolean NOT_SLIDING = false;
|
public static final boolean NOT_SLIDING = false;
|
||||||
@ -54,7 +56,6 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||||||
// Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS.
|
// Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS.
|
||||||
private int mAutoCapsState = MockConstants.CAP_MODE_OFF;
|
private int mAutoCapsState = MockConstants.CAP_MODE_OFF;
|
||||||
|
|
||||||
private boolean mIsInDoubleTapShiftKeyTimeout;
|
|
||||||
private int mLongPressTimeoutCode;
|
private int mLongPressTimeoutCode;
|
||||||
|
|
||||||
private final KeyboardState mState = new KeyboardState(this);
|
private final KeyboardState mState = new KeyboardState(this);
|
||||||
@ -81,48 +82,9 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||||||
mAutoCapsState = autoCaps;
|
mAutoCapsState = autoCaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expireDoubleTapTimeout() {
|
|
||||||
mIsInDoubleTapShiftKeyTimeout = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAlphabetKeyboard() {
|
public void setKeyboard(@NonNull KeyboardLayoutElement element) {
|
||||||
mLayout = MockConstants.ALPHABET_UNSHIFTED;
|
mLayout = element.getElementId();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAlphabetManualShiftedKeyboard() {
|
|
||||||
mLayout = MockConstants.ALPHABET_MANUAL_SHIFTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAlphabetAutomaticShiftedKeyboard() {
|
|
||||||
mLayout = MockConstants.ALPHABET_AUTOMATIC_SHIFTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAlphabetShiftLockedKeyboard() {
|
|
||||||
mLayout = MockConstants.ALPHABET_SHIFT_LOCKED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAlphabetShiftLockShiftedKeyboard() {
|
|
||||||
mLayout = MockConstants.ALPHABET_SHIFT_LOCK_SHIFTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSymbolsKeyboard() {
|
|
||||||
mLayout = MockConstants.SYMBOLS_UNSHIFTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSymbolsShiftedKeyboard() {
|
|
||||||
mLayout = MockConstants.SYMBOLS_SHIFTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEmojiKeyboard() {
|
|
||||||
// Just ignore.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -131,27 +93,12 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||||||
mState.onUpdateShiftState(currentAutoCapsState, currentRecapitalizeState);
|
mState.onUpdateShiftState(currentAutoCapsState, currentRecapitalizeState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startDoubleTapShiftKeyTimer() {
|
|
||||||
mIsInDoubleTapShiftKeyTimeout = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cancelDoubleTapShiftKeyTimer() {
|
|
||||||
mIsInDoubleTapShiftKeyTimeout = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInDoubleTapShiftKeyTimeout() {
|
|
||||||
return mIsInDoubleTapShiftKeyTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateShiftState() {
|
public void updateShiftState() {
|
||||||
mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadKeyboard() {
|
public void loadKeyboard() {
|
||||||
mState.onLoadKeyboard(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
mState.onLoadKeyboard(null, mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveKeyboardState() {
|
public void saveKeyboardState() {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.futo.inputmethod.keyboard.internal;
|
package org.futo.inputmethod.keyboard.internal;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
@ -27,8 +28,7 @@ import androidx.test.InstrumentationRegistry;
|
|||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import org.futo.inputmethod.latin.tests.R;
|
//import org.futo.inputmethod.latin.tests.R;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -46,8 +46,8 @@ public class MoreKeySpecStringReferenceTests {
|
|||||||
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||||
final Context testContext = instrumentation.getContext();
|
final Context testContext = instrumentation.getContext();
|
||||||
final Resources testRes = testContext.getResources();
|
final Resources testRes = testContext.getResources();
|
||||||
final String testPackageName = testRes.getResourcePackageName(R.string.empty_string);
|
//final String testPackageName = testRes.getResourcePackageName(R.string.empty_string);
|
||||||
mTextsSet.setLocale(TEST_LOCALE, testRes, testPackageName);
|
mTextsSet.setLocale(TEST_LOCALE, testContext);//, testPackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertTextArray(final String message, final String value,
|
private void assertTextArray(final String message, final String value,
|
||||||
@ -69,14 +69,12 @@ public class MoreKeySpecStringReferenceTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResolveNullText() {
|
public void testResolveNullText() {
|
||||||
assertEquals("resolve null",
|
assertNull("resolve null", mTextsSet.resolveTextReference(null));
|
||||||
mTextsSet.resolveTextReference(null), null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResolveEmptyText() {
|
public void testResolveEmptyText() {
|
||||||
assertEquals("resolve empty text",
|
assertNull("resolve empty text", mTextsSet.resolveTextReference("!string/empty_string"));
|
||||||
mTextsSet.resolveTextReference("!string/empty_string"), null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -29,31 +29,31 @@ public abstract class AbstractLayoutBase {
|
|||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object that has the label.
|
// Helper method to create an {@link ExpectedKey} object that has the label.
|
||||||
public static ExpectedKey key(final String label, final ExpectedKey ... moreKeys) {
|
public static ExpectedKey key(final String label, final ExpectedKey ... moreKeys) {
|
||||||
return ExpectedKey.newInstance(label, moreKeys);
|
return ExpectedKey.newLabelInstance(label, moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object that has the label and the output text.
|
// Helper method to create an {@link ExpectedKey} object that has the label and the output text.
|
||||||
public static ExpectedKey key(final String label, final String outputText,
|
public static ExpectedKey key(final String label, final String outputText,
|
||||||
final ExpectedKey ... moreKeys) {
|
final ExpectedKey ... moreKeys) {
|
||||||
return ExpectedKey.newInstance(label, outputText, moreKeys);
|
return ExpectedKey.newLabelInstance(label, outputText, moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object that has the label and the output code.
|
// Helper method to create an {@link ExpectedKey} object that has the label and the output code.
|
||||||
public static ExpectedKey key(final String label, final int code,
|
public static ExpectedKey key(final String label, final int code,
|
||||||
final ExpectedKey ... moreKeys) {
|
final ExpectedKey ... moreKeys) {
|
||||||
return ExpectedKey.newInstance(label, code, moreKeys);
|
return ExpectedKey.newLabelInstance(label, code, moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object that has the icon and the output text.
|
// Helper method to create an {@link ExpectedKey} object that has the icon and the output text.
|
||||||
public static ExpectedKey key(final int iconId, final String outputText,
|
public static ExpectedKey iconKey(final String iconId, final String outputText,
|
||||||
final ExpectedKey ... moreKeys) {
|
final ExpectedKey ... moreKeys) {
|
||||||
return ExpectedKey.newInstance(iconId, outputText, moreKeys);
|
return ExpectedKey.newIconInstance(iconId, outputText, moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object that has the icon and the output code.
|
// Helper method to create an {@link ExpectedKey} object that has the icon and the output code.
|
||||||
public static ExpectedKey key(final int iconId, final int code,
|
public static ExpectedKey iconKey(final String iconId, final int code,
|
||||||
final ExpectedKey ... moreKeys) {
|
final ExpectedKey ... moreKeys) {
|
||||||
return ExpectedKey.newInstance(iconId, code, moreKeys);
|
return ExpectedKey.newIconInstance(iconId, code, moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object that has new "more keys".
|
// Helper method to create an {@link ExpectedKey} object that has new "more keys".
|
||||||
@ -72,25 +72,25 @@ public abstract class AbstractLayoutBase {
|
|||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object for a "more key" that has the label.
|
// Helper method to create an {@link ExpectedKey} object for a "more key" that has the label.
|
||||||
public static ExpectedKey moreKey(final String label) {
|
public static ExpectedKey moreKey(final String label) {
|
||||||
return ExpectedKey.newInstance(label);
|
return ExpectedKey.newLabelInstance(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object for a "more key" that has the label
|
// Helper method to create an {@link ExpectedKey} object for a "more key" that has the label
|
||||||
// and the output text.
|
// and the output text.
|
||||||
public static ExpectedKey moreKey(final String label, final String outputText) {
|
public static ExpectedKey moreKey(final String label, final String outputText) {
|
||||||
return ExpectedKey.newInstance(label, outputText);
|
return ExpectedKey.newLabelInstance(label, outputText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object for a "more key" that has the label
|
// Helper method to create an {@link ExpectedKey} object for a "more key" that has the label
|
||||||
// and the output code.
|
// and the output code.
|
||||||
public static ExpectedKey moreKey(final String label, final int code) {
|
public static ExpectedKey moreKey(final String label, final int code) {
|
||||||
return ExpectedKey.newInstance(label, code);
|
return ExpectedKey.newLabelInstance(label, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create an {@link ExpectedKey} object for a "more key" that has the icon
|
// Helper method to create an {@link ExpectedKey} object for a "more key" that has the icon
|
||||||
// and the output text.
|
// and the output text.
|
||||||
public static ExpectedKey moreKey(final int iconId, final String outputText) {
|
public static ExpectedKey moreIconKey(final String iconId, final String outputText) {
|
||||||
return ExpectedKey.newInstance(iconId, outputText);
|
return ExpectedKey.newIconInstance(iconId, outputText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
|
// Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
|
||||||
@ -121,20 +121,20 @@ public abstract class AbstractLayoutBase {
|
|||||||
private static final String ICON_ZWJ = KeyboardIconsSet.NAME_ZWJ_KEY;
|
private static final String ICON_ZWJ = KeyboardIconsSet.NAME_ZWJ_KEY;
|
||||||
|
|
||||||
// Functional keys.
|
// Functional keys.
|
||||||
protected static final ExpectedKey DELETE_KEY = key(ICON_DELETE, Constants.CODE_DELETE);
|
protected static final ExpectedKey DELETE_KEY = iconKey(ICON_DELETE, Constants.CODE_DELETE);
|
||||||
protected static final ExpectedKey TAB_KEY = key(ICON_TAB, Constants.CODE_TAB);
|
protected static final ExpectedKey TAB_KEY = iconKey(ICON_TAB, Constants.CODE_TAB);
|
||||||
protected static final ExpectedKey SHORTCUT_KEY = key(ICON_SHORTCUT, Constants.CODE_SHORTCUT);
|
protected static final ExpectedKey SHORTCUT_KEY = iconKey(ICON_SHORTCUT, Constants.CODE_SHORTCUT);
|
||||||
protected static final ExpectedKey SETTINGS_KEY = key(ICON_SETTINGS, Constants.CODE_SETTINGS);
|
protected static final ExpectedKey SETTINGS_KEY = iconKey(ICON_SETTINGS, Constants.CODE_SETTINGS);
|
||||||
protected static final ExpectedKey LANGUAGE_SWITCH_KEY = key(
|
protected static final ExpectedKey LANGUAGE_SWITCH_KEY = iconKey(
|
||||||
ICON_LANGUAGE_SWITCH, Constants.CODE_LANGUAGE_SWITCH);
|
ICON_LANGUAGE_SWITCH, Constants.CODE_LANGUAGE_SWITCH);
|
||||||
protected static final ExpectedKey ENTER_KEY = key(ICON_ENTER, Constants.CODE_ENTER);
|
protected static final ExpectedKey ENTER_KEY = iconKey(ICON_ENTER, Constants.CODE_ENTER);
|
||||||
protected static final ExpectedKey EMOJI_ACTION_KEY = key(ICON_EMOJI_ACTION, Constants.CODE_EMOJI);
|
protected static final ExpectedKey EMOJI_ACTION_KEY = iconKey(ICON_EMOJI_ACTION, Constants.CODE_EMOJI);
|
||||||
protected static final ExpectedKey EMOJI_NORMAL_KEY = key(ICON_EMOJI_NORMAL, Constants.CODE_EMOJI);
|
protected static final ExpectedKey EMOJI_NORMAL_KEY = iconKey(ICON_EMOJI_NORMAL, Constants.CODE_EMOJI);
|
||||||
protected static final ExpectedKey SPACE_KEY = key(ICON_SPACE, Constants.CODE_SPACE);
|
protected static final ExpectedKey SPACE_KEY = iconKey(ICON_SPACE, Constants.CODE_SPACE);
|
||||||
protected static final ExpectedKey CAPSLOCK_MORE_KEY = key(" ", Constants.CODE_CAPSLOCK);
|
protected static final ExpectedKey CAPSLOCK_MORE_KEY = key(" ", Constants.CODE_CAPSLOCK);
|
||||||
protected static final ExpectedKey SHIFT_KEY = key(ICON_SHIFT,
|
protected static final ExpectedKey SHIFT_KEY = iconKey(ICON_SHIFT,
|
||||||
Constants.CODE_SHIFT, CAPSLOCK_MORE_KEY);
|
Constants.CODE_SHIFT, CAPSLOCK_MORE_KEY);
|
||||||
protected static final ExpectedKey SHIFTED_SHIFT_KEY = key(ICON_SHIFTED_SHIFT,
|
protected static final ExpectedKey SHIFTED_SHIFT_KEY = iconKey(ICON_SHIFTED_SHIFT,
|
||||||
Constants.CODE_SHIFT, CAPSLOCK_MORE_KEY);
|
Constants.CODE_SHIFT, CAPSLOCK_MORE_KEY);
|
||||||
protected static final ExpectedKey ALPHABET_KEY = key("ABC", Constants.CODE_SWITCH_ALPHA_SYMBOL);
|
protected static final ExpectedKey ALPHABET_KEY = key("ABC", Constants.CODE_SWITCH_ALPHA_SYMBOL);
|
||||||
protected static final ExpectedKey SYMBOLS_KEY = key("?123", Constants.CODE_SWITCH_ALPHA_SYMBOL);
|
protected static final ExpectedKey SYMBOLS_KEY = key("?123", Constants.CODE_SWITCH_ALPHA_SYMBOL);
|
||||||
@ -148,8 +148,8 @@ public abstract class AbstractLayoutBase {
|
|||||||
key("!", moreKey("\u00A1")), key("?", moreKey("\u00BF")));
|
key("!", moreKey("\u00A1")), key("?", moreKey("\u00BF")));
|
||||||
// U+200C: ZERO WIDTH NON-JOINER
|
// U+200C: ZERO WIDTH NON-JOINER
|
||||||
// U+200D: ZERO WIDTH JOINER
|
// U+200D: ZERO WIDTH JOINER
|
||||||
protected static final ExpectedKey ZWNJ_KEY = key(ICON_ZWNJ, "\u200C");
|
protected static final ExpectedKey ZWNJ_KEY = iconKey(ICON_ZWNJ, "\u200C");
|
||||||
protected static final ExpectedKey ZWJ_KEY = key(ICON_ZWJ, "\u200D");
|
protected static final ExpectedKey ZWJ_KEY = iconKey(ICON_ZWJ, "\u200D");
|
||||||
// Domain key
|
// Domain key
|
||||||
protected static final ExpectedKey DOMAIN_KEY =
|
protected static final ExpectedKey DOMAIN_KEY =
|
||||||
key(".com", joinMoreKeys(".net", ".org", ".gov", ".edu")).preserveCase();
|
key(".com", joinMoreKeys(".net", ".org", ".gov", ".edu")).preserveCase();
|
||||||
|
@ -24,6 +24,7 @@ import org.futo.inputmethod.latin.common.StringUtils;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -108,10 +109,10 @@ public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
static String toString(final String label, final int iconId, final String outputText,
|
static String toString(final String label, final String iconId, final String outputText,
|
||||||
final int code) {
|
final int code) {
|
||||||
final String visual = (iconId != KeyboardIconsSet.ICON_UNDEFINED)
|
final String visual = (!Objects.equals(iconId, KeyboardIconsSet.ICON_UNDEFINED))
|
||||||
? KeyboardIconsSet.getIconName(iconId) : label;
|
? iconId : label;
|
||||||
final String output;
|
final String output;
|
||||||
if (code == Constants.CODE_OUTPUT_TEXT) {
|
if (code == Constants.CODE_OUTPUT_TEXT) {
|
||||||
output = outputText;
|
output = outputText;
|
||||||
@ -142,12 +143,12 @@ public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> {
|
|||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
sb.append(MoreKeySpecStringizer.toString(
|
sb.append(MoreKeySpecStringizer.toString(
|
||||||
key.getLabel(), key.getIconId(), key.getOutputText(), key.getCode()));
|
key.getLabel(), key.getIconId(), key.getOutputText(), key.getCode()));
|
||||||
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
final List<MoreKeySpec> moreKeys = key.getMoreKeys();
|
||||||
if (moreKeys == null) {
|
if (moreKeys.isEmpty()) {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
sb.append("^");
|
sb.append("^");
|
||||||
sb.append(MoreKeySpecStringizer.STRINGIZER.join(moreKeys));
|
sb.append(MoreKeySpecStringizer.STRINGIZER.join(moreKeys.toArray(new MoreKeySpec[0])));
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,44 +21,45 @@ import org.futo.inputmethod.keyboard.internal.MoreKeySpec;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents an expected key.
|
* This class represents an expected key.
|
||||||
*/
|
*/
|
||||||
public class ExpectedKey {
|
public class ExpectedKey {
|
||||||
static ExpectedKey EMPTY_KEY = newInstance("");
|
static ExpectedKey EMPTY_KEY = newLabelInstance("");
|
||||||
|
|
||||||
// A key that has a string label and may have "more keys".
|
// A key that has a string label and may have "more keys".
|
||||||
static ExpectedKey newInstance(final String label, final ExpectedKey... moreKeys) {
|
static ExpectedKey newLabelInstance(final String label, final ExpectedKey... moreKeys) {
|
||||||
return newInstance(label, label, moreKeys);
|
return newLabelInstance(label, label, moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A key that has a string label and a different output text and may have "more keys".
|
// A key that has a string label and a different output text and may have "more keys".
|
||||||
static ExpectedKey newInstance(final String label, final String outputText,
|
static ExpectedKey newLabelInstance(final String label, final String outputText,
|
||||||
final ExpectedKey... moreKeys) {
|
final ExpectedKey... moreKeys) {
|
||||||
return newInstance(ExpectedKeyVisual.newInstance(label),
|
return newInstance(ExpectedKeyVisual.newInstance(label),
|
||||||
ExpectedKeyOutput.newInstance(outputText), moreKeys);
|
ExpectedKeyOutput.newInstance(outputText), moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A key that has a string label and a code point output and may have "more keys".
|
// A key that has a string label and a code point output and may have "more keys".
|
||||||
static ExpectedKey newInstance(final String label, final int code,
|
static ExpectedKey newLabelInstance(final String label, final int code,
|
||||||
final ExpectedKey... moreKeys) {
|
final ExpectedKey... moreKeys) {
|
||||||
return newInstance(ExpectedKeyVisual.newInstance(label),
|
return newInstance(ExpectedKeyVisual.newInstance(label),
|
||||||
ExpectedKeyOutput.newInstance(code), moreKeys);
|
ExpectedKeyOutput.newInstance(code), moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A key that has an icon and an output text and may have "more keys".
|
// A key that has an icon and an output text and may have "more keys".
|
||||||
static ExpectedKey newInstance(final int iconId, final String outputText,
|
static ExpectedKey newIconInstance(final String iconId, final String outputText,
|
||||||
final ExpectedKey... moreKeys) {
|
final ExpectedKey... moreKeys) {
|
||||||
return newInstance(ExpectedKeyVisual.newInstance(iconId),
|
return newInstance(ExpectedKeyVisual.newIconInstance(iconId),
|
||||||
ExpectedKeyOutput.newInstance(outputText), moreKeys);
|
ExpectedKeyOutput.newInstance(outputText), moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A key that has an icon and a code point output and may have "more keys".
|
// A key that has an icon and a code point output and may have "more keys".
|
||||||
static ExpectedKey newInstance(final int iconId, final int code,
|
static ExpectedKey newIconInstance(final String iconId, final int code,
|
||||||
final ExpectedKey... moreKeys) {
|
final ExpectedKey... moreKeys) {
|
||||||
return newInstance(ExpectedKeyVisual.newInstance(iconId),
|
return newInstance(ExpectedKeyVisual.newIconInstance(iconId),
|
||||||
ExpectedKeyOutput.newInstance(code), moreKeys);
|
ExpectedKeyOutput.newInstance(code), moreKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,14 +277,14 @@ public class ExpectedKey {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equalsTo(final Key key) {
|
public boolean equalsTo(final Key key) {
|
||||||
if (getVisual().hasSameKeyVisual(key) && getOutput().hasSameKeyOutput(key)) {
|
if (getVisual().hasSameKeyVisual(key) && getOutput().hasSameKeyOutput(key)) {
|
||||||
final MoreKeySpec[] moreKeySpecs = key.getMoreKeys();
|
final List<MoreKeySpec> moreKeySpecs = key.getMoreKeys();
|
||||||
final ExpectedKey[] moreKeys = getMoreKeys();
|
final ExpectedKey[] moreKeys = getMoreKeys();
|
||||||
// This key should have at least one "more key".
|
// This key should have at least one "more key".
|
||||||
if (moreKeySpecs == null || moreKeySpecs.length != moreKeys.length) {
|
if (moreKeySpecs == null || moreKeySpecs.size() != moreKeys.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int index = 0; index < moreKeySpecs.length; index++) {
|
for (int index = 0; index < moreKeySpecs.size(); index++) {
|
||||||
if (!moreKeys[index].equalsTo(moreKeySpecs[index])) {
|
if (!moreKeys[index].equalsTo(moreKeySpecs.get(index))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
|
|||||||
} else if (key instanceof ExpectedKey[]) {
|
} else if (key instanceof ExpectedKey[]) {
|
||||||
list.addAll(Arrays.asList((ExpectedKey[])key));
|
list.addAll(Arrays.asList((ExpectedKey[])key));
|
||||||
} else if (key instanceof String) {
|
} else if (key instanceof String) {
|
||||||
list.add(ExpectedKey.newInstance((String)key));
|
list.add(ExpectedKey.newLabelInstance((String)key));
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unknown expected key type: " + key);
|
throw new RuntimeException("Unknown expected key type: " + key);
|
||||||
}
|
}
|
||||||
@ -160,8 +160,8 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
|
|||||||
* {@link ExpectedKey}, {@link ExpectedKey} array, and {@link String}.
|
* {@link ExpectedKey}, {@link ExpectedKey} array, and {@link String}.
|
||||||
* @return this builder.
|
* @return this builder.
|
||||||
*/
|
*/
|
||||||
public ExpectedKeyboardBuilder setMoreKeysOf(final int iconId, final Object ... moreKeys) {
|
public ExpectedKeyboardBuilder setMoreIconKeysOf(final String iconId, final Object ... moreKeys) {
|
||||||
setMoreKeysOf(ExpectedKeyVisual.newInstance(iconId), joinKeys(moreKeys));
|
setMoreKeysOf(ExpectedKeyVisual.newIconInstance(iconId), joinKeys(moreKeys));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import org.futo.inputmethod.keyboard.Keyboard;
|
|||||||
import org.futo.inputmethod.keyboard.KeyboardId;
|
import org.futo.inputmethod.keyboard.KeyboardId;
|
||||||
import org.futo.inputmethod.keyboard.KeyboardLayoutSetTestsBase;
|
import org.futo.inputmethod.keyboard.KeyboardLayoutSetTestsBase;
|
||||||
import org.futo.inputmethod.keyboard.KeyboardTheme;
|
import org.futo.inputmethod.keyboard.KeyboardTheme;
|
||||||
|
import org.futo.inputmethod.keyboard.internal.KeyboardLayoutElement;
|
||||||
import org.futo.inputmethod.keyboard.layout.LayoutBase;
|
import org.futo.inputmethod.keyboard.layout.LayoutBase;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.AbstractLayoutBase;
|
import org.futo.inputmethod.keyboard.layout.expected.AbstractLayoutBase;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.ActualKeyboardBuilder;
|
import org.futo.inputmethod.keyboard.layout.expected.ActualKeyboardBuilder;
|
||||||
@ -31,6 +32,7 @@ import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
|||||||
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey;
|
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
|
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
|
||||||
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase {
|
|||||||
private LayoutBase mLayout;
|
private LayoutBase mLayout;
|
||||||
private InputMethodSubtype mSubtype;
|
private InputMethodSubtype mSubtype;
|
||||||
private String mLogTag;
|
private String mLogTag;
|
||||||
private KeyboardLayoutSet mKeyboardLayoutSet;
|
private KeyboardLayoutSetV2 mKeyboardLayoutSet;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
@ -138,7 +140,7 @@ abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase {
|
|||||||
}
|
}
|
||||||
final String tag = mLogTag + "/" + KeyboardId.elementIdToName(elementId);
|
final String tag = mLogTag + "/" + KeyboardId.elementIdToName(elementId);
|
||||||
// Create actual keyboard object.
|
// Create actual keyboard object.
|
||||||
final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(elementId);
|
final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(KeyboardLayoutElement.fromElementId(elementId));
|
||||||
// Create actual keyboard to be compared with the expected keyboard.
|
// Create actual keyboard to be compared with the expected keyboard.
|
||||||
final Key[][] actualKeyboard = ActualKeyboardBuilder.buildKeyboard(
|
final Key[][] actualKeyboard = ActualKeyboardBuilder.buildKeyboard(
|
||||||
keyboard.getSortedKeys());
|
keyboard.getSortedKeys());
|
||||||
|
@ -27,6 +27,7 @@ import org.futo.inputmethod.keyboard.layout.LayoutBase;
|
|||||||
import org.futo.inputmethod.keyboard.layout.customizer.DvorakCustomizer.EnglishDvorakCustomizer;
|
import org.futo.inputmethod.keyboard.layout.customizer.DvorakCustomizer.EnglishDvorakCustomizer;
|
||||||
import org.futo.inputmethod.keyboard.layout.customizer.LayoutCustomizer;
|
import org.futo.inputmethod.keyboard.layout.customizer.LayoutCustomizer;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -42,9 +43,9 @@ public class TestsDvorakEmail extends LayoutTestsBase {
|
|||||||
LayoutBase getLayout() { return LAYOUT; }
|
LayoutBase getLayout() { return LAYOUT; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
protected KeyboardLayoutSetV2 createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
||||||
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
||||||
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
||||||
final EditorInfo emailField = new EditorInfo();
|
final EditorInfo emailField = new EditorInfo();
|
||||||
emailField.inputType =
|
emailField.inputType =
|
||||||
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
||||||
|
@ -27,6 +27,7 @@ import org.futo.inputmethod.keyboard.layout.LayoutBase;
|
|||||||
import org.futo.inputmethod.keyboard.layout.customizer.DvorakCustomizer.EnglishDvorakCustomizer;
|
import org.futo.inputmethod.keyboard.layout.customizer.DvorakCustomizer.EnglishDvorakCustomizer;
|
||||||
import org.futo.inputmethod.keyboard.layout.customizer.LayoutCustomizer;
|
import org.futo.inputmethod.keyboard.layout.customizer.LayoutCustomizer;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -42,9 +43,9 @@ public class TestsDvorakUrl extends LayoutTestsBase {
|
|||||||
LayoutBase getLayout() { return LAYOUT; }
|
LayoutBase getLayout() { return LAYOUT; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
protected KeyboardLayoutSetV2 createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
||||||
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
||||||
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
||||||
final EditorInfo emailField = new EditorInfo();
|
final EditorInfo emailField = new EditorInfo();
|
||||||
emailField.inputType =
|
emailField.inputType =
|
||||||
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
|
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
|
||||||
|
@ -25,6 +25,7 @@ import org.futo.inputmethod.keyboard.layout.LayoutBase;
|
|||||||
import org.futo.inputmethod.keyboard.layout.Qwerty;
|
import org.futo.inputmethod.keyboard.layout.Qwerty;
|
||||||
import org.futo.inputmethod.keyboard.layout.customizer.EnglishCustomizer;
|
import org.futo.inputmethod.keyboard.layout.customizer.EnglishCustomizer;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -40,9 +41,9 @@ public class TestsQwertyEmail extends LayoutTestsBase {
|
|||||||
LayoutBase getLayout() { return LAYOUT; }
|
LayoutBase getLayout() { return LAYOUT; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
protected KeyboardLayoutSetV2 createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
||||||
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
||||||
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
||||||
final EditorInfo emailField = new EditorInfo();
|
final EditorInfo emailField = new EditorInfo();
|
||||||
emailField.inputType =
|
emailField.inputType =
|
||||||
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
||||||
|
@ -25,6 +25,7 @@ import org.futo.inputmethod.keyboard.layout.LayoutBase;
|
|||||||
import org.futo.inputmethod.keyboard.layout.Qwerty;
|
import org.futo.inputmethod.keyboard.layout.Qwerty;
|
||||||
import org.futo.inputmethod.keyboard.layout.customizer.EnglishCustomizer;
|
import org.futo.inputmethod.keyboard.layout.customizer.EnglishCustomizer;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -40,9 +41,9 @@ public class TestsQwertyUrl extends LayoutTestsBase {
|
|||||||
LayoutBase getLayout() { return LAYOUT; }
|
LayoutBase getLayout() { return LAYOUT; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
protected KeyboardLayoutSetV2 createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
||||||
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
||||||
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
||||||
final EditorInfo emailField = new EditorInfo();
|
final EditorInfo emailField = new EditorInfo();
|
||||||
emailField.inputType =
|
emailField.inputType =
|
||||||
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
|
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
|
||||||
|
@ -24,6 +24,7 @@ import org.futo.inputmethod.keyboard.layout.LayoutBase;
|
|||||||
import org.futo.inputmethod.keyboard.layout.Qwerty;
|
import org.futo.inputmethod.keyboard.layout.Qwerty;
|
||||||
import org.futo.inputmethod.keyboard.layout.customizer.EnglishCustomizer;
|
import org.futo.inputmethod.keyboard.layout.customizer.EnglishCustomizer;
|
||||||
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
import org.futo.inputmethod.keyboard.layout.expected.ExpectedKey;
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -36,9 +37,9 @@ public class TestsSplitLayoutQwertyEnglishUS extends LayoutTestsBase {
|
|||||||
private static final LayoutBase LAYOUT = new Qwerty(new EnglishSplitCustomizer(LOCALE));
|
private static final LayoutBase LAYOUT = new Qwerty(new EnglishSplitCustomizer(LOCALE));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
protected KeyboardLayoutSetV2 createKeyboardLayoutSet(final InputMethodSubtype subtype,
|
||||||
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
|
||||||
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
||||||
return super.createKeyboardLayoutSet(subtype, editorInfo, voiceInputKeyEnabled,
|
return super.createKeyboardLayoutSet(subtype, editorInfo, voiceInputKeyEnabled,
|
||||||
languageSwitchKeyEnabled, true /* splitLayoutEnabled */);
|
languageSwitchKeyEnabled, true /* splitLayoutEnabled */);
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
|||||||
private static final String TYPE_TEST = "test";
|
private static final String TYPE_TEST = "test";
|
||||||
private static final PhonyDictionary DICTIONARY_TEST = new PhonyDictionary(TYPE_TEST);
|
private static final PhonyDictionary DICTIONARY_TEST = new PhonyDictionary(TYPE_TEST);
|
||||||
|
|
||||||
|
protected LatinIME mLatinIME;
|
||||||
protected LatinIMELegacy mLatinIMELegacy;
|
protected LatinIMELegacy mLatinIMELegacy;
|
||||||
protected Keyboard mKeyboard;
|
protected Keyboard mKeyboard;
|
||||||
protected MyEditText mEditText;
|
protected MyEditText mEditText;
|
||||||
@ -84,6 +85,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
|||||||
public InputTestsBase(Class<LatinIME> serviceClass) {
|
public InputTestsBase(Class<LatinIME> serviceClass) {
|
||||||
super(serviceClass);
|
super(serviceClass);
|
||||||
}
|
}
|
||||||
|
public InputTestsBase() {
|
||||||
|
super(LatinIME.class);
|
||||||
|
}
|
||||||
|
|
||||||
// A helper class to ease span tests
|
// A helper class to ease span tests
|
||||||
public static class SpanGetter {
|
public static class SpanGetter {
|
||||||
@ -380,7 +384,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
|||||||
// TODO: Use {@link InputMethodSubtype.InputMethodSubtypeBuilder} directly or indirectly so
|
// TODO: Use {@link InputMethodSubtype.InputMethodSubtypeBuilder} directly or indirectly so
|
||||||
// that {@link InputMethodSubtype#isAsciiCapable} can return the correct value.
|
// that {@link InputMethodSubtype#isAsciiCapable} can return the correct value.
|
||||||
final String EXTRA_VALUE_FOR_TEST =
|
final String EXTRA_VALUE_FOR_TEST =
|
||||||
"KeyboardLayoutSet=" + SubtypeLocaleUtils.QWERTY
|
"KeyboardLayoutSetV2=" + SubtypeLocaleUtils.QWERTY
|
||||||
+ "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE
|
+ "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE
|
||||||
+ "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE
|
+ "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE
|
||||||
+ "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE
|
+ "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE
|
||||||
|
@ -29,7 +29,7 @@ public class PunctuationTests extends InputTestsBase {
|
|||||||
final String PUNCTUATION_FROM_STRIP = "!";
|
final String PUNCTUATION_FROM_STRIP = "!";
|
||||||
final String EXPECTED_RESULT = "this!! ";
|
final String EXPECTED_RESULT = "this!! ";
|
||||||
final boolean defaultNextWordPredictionOption =
|
final boolean defaultNextWordPredictionOption =
|
||||||
mLatinIMELegacy.getResources().getBoolean(R.bool.config_default_next_word_prediction);
|
mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
|
||||||
final boolean previousNextWordPredictionOption =
|
final boolean previousNextWordPredictionOption =
|
||||||
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
|
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
|
||||||
defaultNextWordPredictionOption);
|
defaultNextWordPredictionOption);
|
||||||
|
@ -93,7 +93,7 @@ public class RichInputMethodSubtypeTests {
|
|||||||
AdditionalSubtypeUtils.createAdditionalSubtypesArray(
|
AdditionalSubtypeUtils.createAdditionalSubtypesArray(
|
||||||
AdditionalSubtypeUtils.createPrefSubtypes(
|
AdditionalSubtypeUtils.createPrefSubtypes(
|
||||||
mRes.getStringArray(R.array.predefined_subtypes)));
|
mRes.getStringArray(R.array.predefined_subtypes)));
|
||||||
mRichImm.setAdditionalInputMethodSubtypes(predefinedAddtionalSubtypes);
|
//mRichImm.setAdditionalInputMethodSubtypes(predefinedAddtionalSubtypes);
|
||||||
|
|
||||||
final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme();
|
final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme();
|
||||||
final int subtypeCount = imi.getSubtypeCount();
|
final int subtypeCount = imi.getSubtypeCount();
|
||||||
@ -102,27 +102,27 @@ public class RichInputMethodSubtypeTests {
|
|||||||
mSubtypesList.add(new RichInputMethodSubtype(subtype));
|
mSubtypesList.add(new RichInputMethodSubtype(subtype));
|
||||||
}
|
}
|
||||||
|
|
||||||
EN_US = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
EN_US = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.US.toString(), "qwerty"));
|
Locale.US.toString(), "qwerty"));
|
||||||
EN_GB = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
EN_GB = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.UK.toString(), "qwerty"));
|
Locale.UK.toString(), "qwerty"));
|
||||||
ES_US = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
ES_US = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
"es_US", "spanish"));
|
"es_US", "spanish"));
|
||||||
FR = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
FR = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.FRENCH.toString(), "azerty"));
|
Locale.FRENCH.toString(), "azerty"));
|
||||||
FR_CA = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
FR_CA = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.CANADA_FRENCH.toString(), "qwerty"));
|
Locale.CANADA_FRENCH.toString(), "qwerty"));
|
||||||
FR_CH = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
FR_CH = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
"fr_CH", "swiss"));
|
"fr_CH", "swiss"));
|
||||||
DE = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
DE = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.GERMAN.toString(), "qwertz"));
|
Locale.GERMAN.toString(), "qwertz"));
|
||||||
DE_CH = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
DE_CH = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
"de_CH", "swiss"));
|
"de_CH", "swiss"));
|
||||||
HI = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
HI = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
"hi", "hindi"));
|
"hi", "hindi"));
|
||||||
SR = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
SR = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
"sr", "south_slavic"));
|
"sr", "south_slavic"));
|
||||||
ZZ = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
ZZ = new RichInputMethodSubtype(Subtypes.INSTANCE.makeSubtype(
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, "qwerty"));
|
SubtypeLocaleUtils.NO_LANGUAGE, "qwerty"));
|
||||||
DE_QWERTY = new RichInputMethodSubtype(
|
DE_QWERTY = new RichInputMethodSubtype(
|
||||||
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
||||||
@ -146,7 +146,7 @@ public class RichInputMethodSubtypeTests {
|
|||||||
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty"));
|
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty"));
|
||||||
|
|
||||||
final InputMethodSubtype hiLatn = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
final InputMethodSubtype hiLatn = Subtypes.INSTANCE.makeSubtype(
|
||||||
"hi_ZZ", "qwerty");
|
"hi_ZZ", "qwerty");
|
||||||
if (hiLatn != null) {
|
if (hiLatn != null) {
|
||||||
HI_LATN = new RichInputMethodSubtype(hiLatn);
|
HI_LATN = new RichInputMethodSubtype(hiLatn);
|
||||||
@ -154,7 +154,7 @@ public class RichInputMethodSubtypeTests {
|
|||||||
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
||||||
"hi_ZZ", "dvorak"));
|
"hi_ZZ", "dvorak"));
|
||||||
}
|
}
|
||||||
final InputMethodSubtype srLatn = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
final InputMethodSubtype srLatn = Subtypes.INSTANCE.makeSubtype(
|
||||||
"sr_ZZ", "serbian_qwertz");
|
"sr_ZZ", "serbian_qwertz");
|
||||||
if (srLatn != null) {
|
if (srLatn != null) {
|
||||||
SR_LATN = new RichInputMethodSubtype(srLatn);
|
SR_LATN = new RichInputMethodSubtype(srLatn);
|
||||||
@ -167,7 +167,7 @@ public class RichInputMethodSubtypeTests {
|
|||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
// Restore additional subtypes.
|
// Restore additional subtypes.
|
||||||
mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes);
|
//mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -56,7 +56,7 @@ public class AdditionalSubtypeUtilsTests {
|
|||||||
* final int SUBTYPE_ID_EN_US_DVORAK = Arrays.hashCode(new Object[] {
|
* final int SUBTYPE_ID_EN_US_DVORAK = Arrays.hashCode(new Object[] {
|
||||||
* "en_US",
|
* "en_US",
|
||||||
* "keyboard",
|
* "keyboard",
|
||||||
* "KeyboardLayoutSet=dvorak"
|
* "KeyboardLayoutSetV2=dvorak"
|
||||||
* + ",AsciiCapable"
|
* + ",AsciiCapable"
|
||||||
* + ",UntranslatableReplacementStringInSubtypeName=Dvorak"
|
* + ",UntranslatableReplacementStringInSubtypeName=Dvorak"
|
||||||
* + ",EmojiCapable"
|
* + ",EmojiCapable"
|
||||||
@ -67,16 +67,16 @@ public class AdditionalSubtypeUtilsTests {
|
|||||||
*/
|
*/
|
||||||
private static int SUBTYPE_ID_EN_US_DVORAK = 0xb3c0cc56;
|
private static int SUBTYPE_ID_EN_US_DVORAK = 0xb3c0cc56;
|
||||||
private static String EXTRA_VALUE_EN_US_DVORAK_ICS =
|
private static String EXTRA_VALUE_EN_US_DVORAK_ICS =
|
||||||
"KeyboardLayoutSet=dvorak" +
|
"KeyboardLayoutSetV2=dvorak" +
|
||||||
",AsciiCapable" +
|
",AsciiCapable" +
|
||||||
",isAdditionalSubtype";
|
",isAdditionalSubtype";
|
||||||
private static String EXTRA_VALUE_EN_US_DVORAK_JELLY_BEAN =
|
private static String EXTRA_VALUE_EN_US_DVORAK_JELLY_BEAN =
|
||||||
"KeyboardLayoutSet=dvorak" +
|
"KeyboardLayoutSetV2=dvorak" +
|
||||||
",AsciiCapable" +
|
",AsciiCapable" +
|
||||||
",UntranslatableReplacementStringInSubtypeName=Dvorak" +
|
",UntranslatableReplacementStringInSubtypeName=Dvorak" +
|
||||||
",isAdditionalSubtype";
|
",isAdditionalSubtype";
|
||||||
private static String EXTRA_VALUE_EN_US_DVORAK_KITKAT =
|
private static String EXTRA_VALUE_EN_US_DVORAK_KITKAT =
|
||||||
"KeyboardLayoutSet=dvorak" +
|
"KeyboardLayoutSetV2=dvorak" +
|
||||||
",AsciiCapable" +
|
",AsciiCapable" +
|
||||||
",UntranslatableReplacementStringInSubtypeName=Dvorak" +
|
",UntranslatableReplacementStringInSubtypeName=Dvorak" +
|
||||||
",EmojiCapable" +
|
",EmojiCapable" +
|
||||||
@ -90,7 +90,7 @@ public class AdditionalSubtypeUtilsTests {
|
|||||||
* final int SUBTYPE_ID_ZZ_AZERTY = Arrays.hashCode(new Object[] {
|
* final int SUBTYPE_ID_ZZ_AZERTY = Arrays.hashCode(new Object[] {
|
||||||
* "zz",
|
* "zz",
|
||||||
* "keyboard",
|
* "keyboard",
|
||||||
* "KeyboardLayoutSet=azerty"
|
* "KeyboardLayoutSetV2=azerty"
|
||||||
* + ",AsciiCapable"
|
* + ",AsciiCapable"
|
||||||
* + ",EmojiCapable"
|
* + ",EmojiCapable"
|
||||||
* + ",isAdditionalSubtype",
|
* + ",isAdditionalSubtype",
|
||||||
@ -100,11 +100,11 @@ public class AdditionalSubtypeUtilsTests {
|
|||||||
*/
|
*/
|
||||||
private static int SUBTYPE_ID_ZZ_AZERTY = 0x5b6be697;
|
private static int SUBTYPE_ID_ZZ_AZERTY = 0x5b6be697;
|
||||||
private static String EXTRA_VALUE_ZZ_AZERTY_ICS =
|
private static String EXTRA_VALUE_ZZ_AZERTY_ICS =
|
||||||
"KeyboardLayoutSet=azerty" +
|
"KeyboardLayoutSetV2=azerty" +
|
||||||
",AsciiCapable" +
|
",AsciiCapable" +
|
||||||
",isAdditionalSubtype";
|
",isAdditionalSubtype";
|
||||||
private static String EXTRA_VALUE_ZZ_AZERTY_KITKAT =
|
private static String EXTRA_VALUE_ZZ_AZERTY_KITKAT =
|
||||||
"KeyboardLayoutSet=azerty" +
|
"KeyboardLayoutSetV2=azerty" +
|
||||||
",AsciiCapable" +
|
",AsciiCapable" +
|
||||||
",EmojiCapable" +
|
",EmojiCapable" +
|
||||||
",isAdditionalSubtype";
|
",isAdditionalSubtype";
|
||||||
|
@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.futo.inputmethod.latin.utils;
|
|
||||||
|
|
||||||
import static org.futo.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_CONTACTS_NOTICE;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
import androidx.test.InstrumentationRegistry;
|
|
||||||
import androidx.test.filters.MediumTest;
|
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.futo.inputmethod.latin.settings.SettingsValues;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class ImportantNoticeUtilsTests {
|
|
||||||
|
|
||||||
private ImportantNoticePreferences mImportantNoticePreferences;
|
|
||||||
|
|
||||||
@Mock private SettingsValues mMockSettingsValues;
|
|
||||||
|
|
||||||
private Context getContext() {
|
|
||||||
return InstrumentationRegistry.getTargetContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ImportantNoticePreferences {
|
|
||||||
private final SharedPreferences mPref;
|
|
||||||
|
|
||||||
private Long mLastTime;
|
|
||||||
|
|
||||||
public ImportantNoticePreferences(final Context context) {
|
|
||||||
mPref = ImportantNoticeUtils.getImportantNoticePreferences(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Integer getInt(final String key) {
|
|
||||||
if (mPref.contains(key)) {
|
|
||||||
return mPref.getInt(key, 0);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getLong(final String key) {
|
|
||||||
if (mPref.contains(key)) {
|
|
||||||
return mPref.getLong(key, 0);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void putInt(final String key, final Integer value) {
|
|
||||||
if (value == null) {
|
|
||||||
removePreference(key);
|
|
||||||
} else {
|
|
||||||
mPref.edit().putInt(key, value).apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void putLong(final String key, final Long value) {
|
|
||||||
if (value == null) {
|
|
||||||
removePreference(key);
|
|
||||||
} else {
|
|
||||||
mPref.edit().putLong(key, value).apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removePreference(final String key) {
|
|
||||||
mPref.edit().remove(key).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
mLastTime = getLong(KEY_TIMESTAMP_OF_CONTACTS_NOTICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void restore() {
|
|
||||||
putLong(KEY_TIMESTAMP_OF_CONTACTS_NOTICE, mLastTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
removePreference(KEY_TIMESTAMP_OF_CONTACTS_NOTICE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mImportantNoticePreferences = new ImportantNoticePreferences(getContext());
|
|
||||||
mImportantNoticePreferences.save();
|
|
||||||
when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
mImportantNoticePreferences.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPersonalizationSetting() {
|
|
||||||
mImportantNoticePreferences.clear();
|
|
||||||
|
|
||||||
// Personalization enabled.
|
|
||||||
when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true);
|
|
||||||
assertEquals("Current boolean with personalization enabled", true,
|
|
||||||
ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
|
|
||||||
|
|
||||||
// Personalization disabled.
|
|
||||||
when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(false);
|
|
||||||
assertEquals("Current boolean with personalization disabled", false,
|
|
||||||
ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
|
|
||||||
}
|
|
||||||
}
|
|
@ -31,6 +31,7 @@ import androidx.test.runner.AndroidJUnit4;
|
|||||||
|
|
||||||
import org.futo.inputmethod.latin.RichInputMethodManager;
|
import org.futo.inputmethod.latin.RichInputMethodManager;
|
||||||
import org.futo.inputmethod.latin.RichInputMethodSubtype;
|
import org.futo.inputmethod.latin.RichInputMethodSubtype;
|
||||||
|
import org.futo.inputmethod.latin.Subtypes;
|
||||||
import org.futo.inputmethod.latin.utils.AdditionalSubtypeUtils;
|
import org.futo.inputmethod.latin.utils.AdditionalSubtypeUtils;
|
||||||
import org.futo.inputmethod.latin.utils.LanguageOnSpacebarUtils;
|
import org.futo.inputmethod.latin.utils.LanguageOnSpacebarUtils;
|
||||||
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
@ -81,7 +82,7 @@ public class LanguageOnSpacebarUtilsTests {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private RichInputMethodSubtype findSubtypeOf(final String localeString,
|
private RichInputMethodSubtype findSubtypeOf(final String localeString,
|
||||||
final String keyboardLayoutSetName) {
|
final String keyboardLayoutSetName) {
|
||||||
final InputMethodSubtype subtype = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
final InputMethodSubtype subtype = Subtypes.INSTANCE.makeSubtype(
|
||||||
localeString, keyboardLayoutSetName);
|
localeString, keyboardLayoutSetName);
|
||||||
if (subtype == null) {
|
if (subtype == null) {
|
||||||
throw new RuntimeException("Can't find subtype of " + localeString + " with "
|
throw new RuntimeException("Can't find subtype of " + localeString + " with "
|
||||||
|
@ -34,6 +34,7 @@ import org.futo.inputmethod.latin.R;
|
|||||||
import org.futo.inputmethod.latin.RichInputMethodManager;
|
import org.futo.inputmethod.latin.RichInputMethodManager;
|
||||||
import org.futo.inputmethod.latin.RichInputMethodSubtype;
|
import org.futo.inputmethod.latin.RichInputMethodSubtype;
|
||||||
|
|
||||||
|
import org.futo.inputmethod.latin.Subtypes;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -90,7 +91,7 @@ public class SubtypeLocaleUtilsTests {
|
|||||||
AdditionalSubtypeUtils.createAdditionalSubtypesArray(
|
AdditionalSubtypeUtils.createAdditionalSubtypesArray(
|
||||||
AdditionalSubtypeUtils.createPrefSubtypes(
|
AdditionalSubtypeUtils.createPrefSubtypes(
|
||||||
mRes.getStringArray(R.array.predefined_subtypes)));
|
mRes.getStringArray(R.array.predefined_subtypes)));
|
||||||
mRichImm.setAdditionalInputMethodSubtypes(predefinedAddtionalSubtypes);
|
//mRichImm.setAdditionalInputMethodSubtypes(predefinedAddtionalSubtypes);
|
||||||
|
|
||||||
final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme();
|
final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme();
|
||||||
final int subtypeCount = imi.getSubtypeCount();
|
final int subtypeCount = imi.getSubtypeCount();
|
||||||
@ -99,51 +100,51 @@ public class SubtypeLocaleUtilsTests {
|
|||||||
mSubtypesList.add(new RichInputMethodSubtype(subtype));
|
mSubtypesList.add(new RichInputMethodSubtype(subtype));
|
||||||
}
|
}
|
||||||
|
|
||||||
EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
EN_US = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.US.toString(), "qwerty");
|
Locale.US.toString(), "qwerty");
|
||||||
EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
EN_GB = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.UK.toString(), "qwerty");
|
Locale.UK.toString(), "qwerty");
|
||||||
ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
ES_US = Subtypes.INSTANCE.makeSubtype(
|
||||||
"es_US", "spanish");
|
"es_US", "spanish");
|
||||||
FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
FR = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.FRENCH.toString(), "azerty");
|
Locale.FRENCH.toString(), "azerty");
|
||||||
FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
FR_CA = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.CANADA_FRENCH.toString(), "qwerty");
|
Locale.CANADA_FRENCH.toString(), "qwerty");
|
||||||
FR_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
FR_CH = Subtypes.INSTANCE.makeSubtype(
|
||||||
"fr_CH", "swiss");
|
"fr_CH", "swiss");
|
||||||
DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
DE = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.GERMAN.toString(), "qwertz");
|
Locale.GERMAN.toString(), "qwertz");
|
||||||
DE_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
DE_CH = Subtypes.INSTANCE.makeSubtype(
|
||||||
"de_CH", "swiss");
|
"de_CH", "swiss");
|
||||||
HI = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
HI = Subtypes.INSTANCE.makeSubtype(
|
||||||
"hi", "hindi");
|
"hi", "hindi");
|
||||||
SR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
SR = Subtypes.INSTANCE.makeSubtype(
|
||||||
"sr", "south_slavic");
|
"sr", "south_slavic");
|
||||||
ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
ZZ = Subtypes.INSTANCE.makeSubtype(
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, "qwerty");
|
SubtypeLocaleUtils.NO_LANGUAGE, "qwerty");
|
||||||
DE_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
DE_QWERTY = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.GERMAN.toString(), "qwerty");
|
Locale.GERMAN.toString(), "qwerty");
|
||||||
FR_QWERTZ = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
FR_QWERTZ = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.FRENCH.toString(), "qwertz");
|
Locale.FRENCH.toString(), "qwertz");
|
||||||
EN_US_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
EN_US_AZERTY = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.US.toString(), "azerty");
|
Locale.US.toString(), "azerty");
|
||||||
EN_UK_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
EN_UK_DVORAK = Subtypes.INSTANCE.makeSubtype(
|
||||||
Locale.UK.toString(), "dvorak");
|
Locale.UK.toString(), "dvorak");
|
||||||
ES_US_COLEMAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
ES_US_COLEMAK = Subtypes.INSTANCE.makeSubtype(
|
||||||
"es_US", "colemak");
|
"es_US", "colemak");
|
||||||
ZZ_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
ZZ_AZERTY = Subtypes.INSTANCE.makeSubtype(
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, "azerty");
|
SubtypeLocaleUtils.NO_LANGUAGE, "azerty");
|
||||||
ZZ_PC = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
ZZ_PC = Subtypes.INSTANCE.makeSubtype(
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty");
|
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty");
|
||||||
|
|
||||||
HI_LATN = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("hi_ZZ", "qwerty");
|
HI_LATN = Subtypes.INSTANCE.makeSubtype("hi_ZZ", "qwerty");
|
||||||
if (HI_LATN != null) {
|
if (HI_LATN != null) {
|
||||||
HI_LATN_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
HI_LATN_DVORAK = Subtypes.INSTANCE.makeSubtype(
|
||||||
"hi_ZZ", "dvorak");
|
"hi_ZZ", "dvorak");
|
||||||
}
|
}
|
||||||
SR_LATN = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("sr_ZZ", "serbian_qwertz");
|
SR_LATN = Subtypes.INSTANCE.makeSubtype("sr_ZZ", "serbian_qwertz");
|
||||||
if (SR_LATN != null) {
|
if (SR_LATN != null) {
|
||||||
SR_LATN_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
SR_LATN_QWERTY = Subtypes.INSTANCE.makeSubtype(
|
||||||
"sr_ZZ", "qwerty");
|
"sr_ZZ", "qwerty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +152,7 @@ public class SubtypeLocaleUtilsTests {
|
|||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
// Restore additional subtypes.
|
// Restore additional subtypes.
|
||||||
mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes);
|
//mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -473,14 +474,11 @@ public class SubtypeLocaleUtilsTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsRtlLanguage() {
|
public void testIsRtlLanguage() {
|
||||||
// Known Right-to-Left language subtypes.
|
// Known Right-to-Left language subtypes.
|
||||||
final InputMethodSubtype ARABIC = mRichImm
|
final InputMethodSubtype ARABIC = Subtypes.INSTANCE.makeSubtype("ar", "arabic");
|
||||||
.findSubtypeByLocaleAndKeyboardLayoutSet("ar", "arabic");
|
|
||||||
assertNotNull("Arabic", ARABIC);
|
assertNotNull("Arabic", ARABIC);
|
||||||
final InputMethodSubtype FARSI = mRichImm
|
final InputMethodSubtype FARSI = Subtypes.INSTANCE.makeSubtype("fa", "farsi");
|
||||||
.findSubtypeByLocaleAndKeyboardLayoutSet("fa", "farsi");
|
|
||||||
assertNotNull("Farsi", FARSI);
|
assertNotNull("Farsi", FARSI);
|
||||||
final InputMethodSubtype HEBREW = mRichImm
|
final InputMethodSubtype HEBREW = Subtypes.INSTANCE.makeSubtype("iw", "hebrew");
|
||||||
.findSubtypeByLocaleAndKeyboardLayoutSet("iw", "hebrew");
|
|
||||||
assertNotNull("Hebrew", HEBREW);
|
assertNotNull("Hebrew", HEBREW);
|
||||||
|
|
||||||
for (final RichInputMethodSubtype subtype : mSubtypesList) {
|
for (final RichInputMethodSubtype subtype : mSubtypesList) {
|
||||||
|
Loading…
Reference in New Issue
Block a user