MoreKeySpec.java revision 35ff94547c16c84c5b6fafdae0b4a683be782b97
135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka/* 235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * Copyright (C) 2012 The Android Open Source Project 335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * 435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * Licensed under the Apache License, Version 2.0 (the "License"); you may not 535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * use this file except in compliance with the License. You may obtain a copy of 635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * the License at 735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * 835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * http://www.apache.org/licenses/LICENSE-2.0 935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * 1035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * Unless required by applicable law or agreed to in writing, software 1135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 1235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 1335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * License for the specific language governing permissions and limitations under 1435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * the License. 1535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka */ 1635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 1735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokapackage com.android.inputmethod.keyboard.internal; 1835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 1935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokaimport com.android.inputmethod.keyboard.Keyboard; 2035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokaimport com.android.inputmethod.latin.StringUtils; 2135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 2235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokaimport java.util.Locale; 2335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 2435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokapublic class MoreKeySpec { 2535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public final int mCode; 2635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public final String mLabel; 2735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public final String mOutputText; 2835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public final int mIconId; 2935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 3035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public MoreKeySpec(final String moreKeySpec, boolean needsToUpperCase, final Locale locale, 3135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final KeyboardCodesSet codesSet) { 3235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mLabel = KeySpecParser.toUpperCaseOfStringForLocale( 3335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka KeySpecParser.getLabel(moreKeySpec), needsToUpperCase, locale); 3435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int code = KeySpecParser.toUpperCaseOfCodeForLocale( 3535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka KeySpecParser.getCode(moreKeySpec, codesSet), needsToUpperCase, locale); 3635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (code == Keyboard.CODE_UNSPECIFIED) { 3735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka // Some letter, for example German Eszett (U+00DF: "ß"), has multiple characters 3835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka // upper case representation ("SS"). 3935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mCode = Keyboard.CODE_OUTPUT_TEXT; 4035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mOutputText = mLabel; 4135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } else { 4235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mCode = code; 4335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mOutputText = KeySpecParser.toUpperCaseOfStringForLocale( 4435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka KeySpecParser.getOutputText(moreKeySpec), needsToUpperCase, locale); 4535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 4635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mIconId = KeySpecParser.getIconId(moreKeySpec); 4735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 4835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 4935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka @Override 5035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public String toString() { 5135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final String label = (mIconId == KeyboardIconsSet.ICON_UNDEFINED ? mLabel 5235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka : KeySpecParser.PREFIX_ICON + KeyboardIconsSet.getIconName(mIconId)); 5335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final String output = (mCode == Keyboard.CODE_OUTPUT_TEXT ? mOutputText 5435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka : Keyboard.printableCode(mCode)); 5535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (StringUtils.codePointCount(label) == 1 && label.codePointAt(0) == mCode) { 5635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka return output; 5735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } else { 5835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka return label + "|" + output; 5935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka} 62