Home | History | Annotate | Download | only in customizer
      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 
     17 package com.android.inputmethod.keyboard.layout.customizer;
     18 
     19 import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
     20 import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder;
     21 import com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey;
     22 
     23 import java.util.Locale;
     24 
     25 public class DvorakCustomizer extends LayoutCustomizer {
     26     public DvorakCustomizer(final Locale locale) { super(locale); }
     27 
     28     @Override
     29     public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) {
     30         return isPhone ? joinKeys(SHIFT_KEY): joinKeys(SHIFT_KEY, key("q"));
     31     }
     32 
     33     @Override
     34     public ExpectedKey[] getRightShiftKeys(final boolean isPhone) {
     35         return isPhone ? EMPTY_KEYS : joinKeys(key("z"), SHIFT_KEY);
     36     }
     37 
     38     @Override
     39     public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) {
     40         // U+00A1: "" INVERTED EXCLAMATION MARK
     41         return isPhone ? joinKeys(key("q", SETTINGS_KEY))
     42                 : joinKeys(key("!", joinMoreKeys("\u00A1", SETTINGS_KEY)));
     43     }
     44 
     45     @Override
     46     public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) {
     47         final ExpectedAdditionalMoreKey[] punctuationMoreKeys =
     48                 convertToAdditionalMoreKeys(getPunctuationMoreKeys(isPhone));
     49         // U+00BF: "" INVERTED QUESTION MARK
     50         return isPhone
     51                 ? joinKeys(key("z", punctuationMoreKeys))
     52                 : joinKeys(key("?", joinMoreKeys(punctuationMoreKeys, "\u00BF")));
     53     }
     54 
     55     private static ExpectedAdditionalMoreKey[] convertToAdditionalMoreKeys(
     56             final ExpectedKey ... moreKeys) {
     57         final ExpectedAdditionalMoreKey[] additionalMoreKeys =
     58                 new ExpectedAdditionalMoreKey[moreKeys.length];
     59         for (int index = 0; index < moreKeys.length; index++) {
     60             additionalMoreKeys[index] = ExpectedAdditionalMoreKey.newInstance(moreKeys[index]);
     61         }
     62         return additionalMoreKeys;
     63     }
     64 
     65     public static class EnglishDvorakCustomizer extends DvorakCustomizer {
     66         private final EnglishCustomizer mEnglishCustomizer;
     67 
     68         public EnglishDvorakCustomizer(final Locale locale) {
     69             super(locale);
     70             mEnglishCustomizer = new EnglishCustomizer(locale);
     71         }
     72 
     73         @Override
     74         public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) {
     75             return mEnglishCustomizer.setAccentedLetters(builder);
     76         }
     77     }
     78 }
     79