TestsDvorakUrl.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.KeyboardId;
25import com.android.inputmethod.keyboard.KeyboardLayoutSet;
26import com.android.inputmethod.keyboard.layout.Dvorak;
27import com.android.inputmethod.keyboard.layout.LayoutBase;
28import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
29import com.android.inputmethod.keyboard.layout.tests.TestsEnglishDvorak.EnglishDvorakCustomizer;
30
31import java.util.Locale;
32
33/**
34 * en_US: English (United States)/dvorak, URL input field.
35 */
36@SmallTest
37public class TestsDvorakUrl extends LayoutTestsBase {
38    private static final Locale LOCALE = new Locale("en", "US");
39    private static final LayoutBase LAYOUT = new DvorakEmail(new DvorakUrlCustomizer(LOCALE));
40
41    @Override
42    LayoutBase getLayout() { return LAYOUT; }
43
44    @Override
45    protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
46            final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
47            final boolean languageSwitchKeyEnabled) {
48        final EditorInfo emailField = new EditorInfo();
49        emailField.inputType =
50                InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
51        return super.createKeyboardLayoutSet(
52                subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled);
53    }
54
55    private static class DvorakUrlCustomizer extends EnglishDvorakCustomizer {
56        DvorakUrlCustomizer(final Locale locale) {
57            super(locale);
58        }
59
60        @Override
61        public ExpectedKey getEnterKey(final boolean isPhone) {
62            return isPhone ? LayoutBase.ENTER_KEY : super.getEnterKey(isPhone);
63        }
64
65        @Override
66        public ExpectedKey getEmojiKey(final boolean isPhone) {
67            return LayoutBase.DOMAIN_KEY;
68        }
69
70        @Override
71        public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) {
72            return isPhone ? super.getKeysLeftToSpacebar(isPhone)
73                    : joinKeys(key("/", LayoutBase.SETTINGS_KEY));
74        }
75    }
76
77    private static class DvorakEmail extends Dvorak {
78        public DvorakEmail(final LayoutCustomizer customizer) {
79            super(customizer);
80        }
81
82        @Override
83        protected ExpectedKey getRow1_1Key(final boolean isPhone, final int elementId) {
84            if (isPhone && (elementId == KeyboardId.ELEMENT_ALPHABET
85                    || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED)) {
86                return key("/", joinMoreKeys(additionalMoreKey("1")));
87            }
88            return super.getRow1_1Key(isPhone, elementId);
89        }
90    }
91}
92