TestsQwertyEmail.java revision c9aa1beb6de6bbea71af8eba94354bff3001e0ac
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.inputmethod.keyboard.layout.tests;
18
19import android.test.suitebuilder.annotation.SmallTest;
20import android.text.InputType;
21import android.view.inputmethod.EditorInfo;
22import android.view.inputmethod.InputMethodSubtype;
23
24import com.android.inputmethod.keyboard.KeyboardLayoutSet;
25import com.android.inputmethod.keyboard.layout.LayoutBase;
26import com.android.inputmethod.keyboard.layout.Qwerty;
27import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
28
29import java.util.Locale;
30
31/**
32 * en_US: English (United States)/qwerty, email input field.
33 */
34@SmallTest
35public class TestsQwertyEmail extends LayoutTestsBase {
36    private static final Locale LOCALE = new Locale("en", "US");
37    private static final LayoutBase LAYOUT = new Qwerty(new EnglishEmailCustomizer(LOCALE));
38
39    @Override
40    LayoutBase getLayout() { return LAYOUT; }
41
42    @Override
43    protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
44            final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
45            final boolean languageSwitchKeyEnabled) {
46        final EditorInfo emailField = new EditorInfo();
47        emailField.inputType =
48                InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
49        return super.createKeyboardLayoutSet(
50                subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled);
51    }
52
53    private static class EnglishEmailCustomizer extends EnglishCustomizer {
54        EnglishEmailCustomizer(final Locale locale) {
55            super(locale);
56        }
57
58        @Override
59        public ExpectedKey getEnterKey(final boolean isPhone) {
60            return isPhone ? LayoutBase.ENTER_KEY : super.getEnterKey(isPhone);
61        }
62
63        @Override
64        public ExpectedKey getEmojiKey(final boolean isPhone) {
65            return LayoutBase.DOMAIN_KEY;
66        }
67
68        @Override
69        public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) {
70            return joinKeys(key("@", LayoutBase.SETTINGS_KEY));
71        }
72    }
73}
74