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