MoreKeySpec.java revision 35ff94547c16c84c5b6fafdae0b4a683be782b97
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.android.inputmethod.keyboard.internal; 18 19import com.android.inputmethod.keyboard.Keyboard; 20import com.android.inputmethod.latin.StringUtils; 21 22import java.util.Locale; 23 24public class MoreKeySpec { 25 public final int mCode; 26 public final String mLabel; 27 public final String mOutputText; 28 public final int mIconId; 29 30 public MoreKeySpec(final String moreKeySpec, boolean needsToUpperCase, final Locale locale, 31 final KeyboardCodesSet codesSet) { 32 mLabel = KeySpecParser.toUpperCaseOfStringForLocale( 33 KeySpecParser.getLabel(moreKeySpec), needsToUpperCase, locale); 34 final int code = KeySpecParser.toUpperCaseOfCodeForLocale( 35 KeySpecParser.getCode(moreKeySpec, codesSet), needsToUpperCase, locale); 36 if (code == Keyboard.CODE_UNSPECIFIED) { 37 // Some letter, for example German Eszett (U+00DF: "ß"), has multiple characters 38 // upper case representation ("SS"). 39 mCode = Keyboard.CODE_OUTPUT_TEXT; 40 mOutputText = mLabel; 41 } else { 42 mCode = code; 43 mOutputText = KeySpecParser.toUpperCaseOfStringForLocale( 44 KeySpecParser.getOutputText(moreKeySpec), needsToUpperCase, locale); 45 } 46 mIconId = KeySpecParser.getIconId(moreKeySpec); 47 } 48 49 @Override 50 public String toString() { 51 final String label = (mIconId == KeyboardIconsSet.ICON_UNDEFINED ? mLabel 52 : KeySpecParser.PREFIX_ICON + KeyboardIconsSet.getIconName(mIconId)); 53 final String output = (mCode == Keyboard.CODE_OUTPUT_TEXT ? mOutputText 54 : Keyboard.printableCode(mCode)); 55 if (StringUtils.codePointCount(label) == 1 && label.codePointAt(0) == mCode) { 56 return output; 57 } else { 58 return label + "|" + output; 59 } 60 } 61} 62