Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ca325f4 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Make KeySpecParser and CSV parser code point aware"

parents 51fd1632 e01d2726
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -28,8 +28,9 @@ import android.util.Xml;
import com.android.inputmethod.keyboard.internal.KeyStyles;
import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.MoreKeySpecParser;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.XmlParseUtils;

import org.xmlpull.v1.XmlPullParser;
@@ -128,7 +129,7 @@ public class Key {
    private boolean mEnabled = true;

    private static Drawable getIcon(Keyboard.Params params, String moreKeySpec) {
        final int iconAttrId = MoreKeySpecParser.getIconAttrId(moreKeySpec);
        final int iconAttrId = KeySpecParser.getIconAttrId(moreKeySpec);
        if (iconAttrId == KeyboardIconsSet.ICON_UNDEFINED) {
            return null;
        } else {
@@ -141,9 +142,9 @@ public class Key {
     */
    public Key(Resources res, Keyboard.Params params, String moreKeySpec,
            int x, int y, int width, int height) {
        this(params, MoreKeySpecParser.getLabel(moreKeySpec), null, getIcon(params, moreKeySpec),
                MoreKeySpecParser.getCode(res, moreKeySpec),
                MoreKeySpecParser.getOutputText(moreKeySpec),
        this(params, KeySpecParser.getLabel(moreKeySpec), null, getIcon(params, moreKeySpec),
                KeySpecParser.getCode(res, moreKeySpec),
                KeySpecParser.getOutputText(moreKeySpec),
                x, y, width, height);
    }

@@ -245,7 +246,7 @@ public class Key {
        int actionFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags, 0);
        final String[] additionalMoreKeys = style.getStringArray(
                keyAttr, R.styleable.Keyboard_Key_additionalMoreKeys);
        final String[] moreKeys = MoreKeySpecParser.insertAddtionalMoreKeys(style.getStringArray(
        final String[] moreKeys = KeySpecParser.insertAddtionalMoreKeys(style.getStringArray(
                keyAttr, R.styleable.Keyboard_Key_moreKeys), additionalMoreKeys);
        if (moreKeys != null) {
            actionFlags |= ACTION_FLAGS_ENABLE_LONG_PRESS;
@@ -270,7 +271,7 @@ public class Key {
        // Choose the first letter of the label as primary code if not specified.
        if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
                && !TextUtils.isEmpty(mLabel)) {
            if (mLabel.codePointCount(0, mLabel.length()) == 1) {
            if (Utils.codePointCount(mLabel) == 1) {
                // Use the first letter of the hint label if shiftedLetterActivated flag is
                // specified.
                if (hasShiftedLetterHint() && isShiftedLetterActivated()
@@ -308,7 +309,7 @@ public class Key {
        if (!Keyboard.isLetterCode(code) || preserveCase) return code;
        final String text = new String(new int[] { code } , 0, 1);
        final String casedText = adjustCaseOfStringForKeyboardId(text, preserveCase, id);
        return casedText.codePointCount(0, casedText.length()) == 1
        return Utils.codePointCount(casedText) == 1
                ? casedText.codePointAt(0) : Keyboard.CODE_UNSPECIFIED;
    }

@@ -380,7 +381,7 @@ public class Key {
    @Override
    public String toString() {
        String top = Keyboard.printableCode(mCode);
        if (mLabel != null && mLabel.codePointCount(0, mLabel.length()) != 1) {
        if (Utils.codePointCount(mLabel) != 1) {
            top += "/\"" + mLabel + '"';
        }
        return String.format("%s %d,%d", top, mX, mY);
+2 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.inputmethod.compat.FrameLayoutCompatUtils;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
import com.android.inputmethod.latin.Utils;

import java.util.HashMap;

@@ -851,7 +852,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
        if (key.mLabel != null) {
            // TODO Should take care of temporaryShiftLabel here.
            previewText.setCompoundDrawables(null, null, null, null);
            if (key.mLabel.length() > 1) {
            if (Utils.codePointCount(key.mLabel) > 1) {
                previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mKeyLetterSize);
                previewText.setTypeface(Typeface.DEFAULT_BOLD);
            } else {
+2 −2
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.inputmethod.keyboard;

import android.graphics.Paint;

import com.android.inputmethod.keyboard.internal.MoreKeySpecParser;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.R;

public class MiniKeyboard extends Keyboard {
@@ -235,7 +235,7 @@ public class MiniKeyboard extends Keyboard {
            Paint paint = null;
            int maxWidth = minKeyWidth;
            for (String moreKeySpec : moreKeys) {
                final String label = MoreKeySpecParser.getLabel(moreKeySpec);
                final String label = KeySpecParser.getLabel(moreKeySpec);
                // If the label is single letter, minKeyWidth is enough to hold the label.
                if (label != null && label.length() > 1) {
                    if (paint == null) {
+9 −6
Original line number Diff line number Diff line
@@ -39,14 +39,14 @@ import java.util.Arrays;
 * Note that the character '@' and '\' are also parsed by XML parser and CSV parser as well.
 * See {@link KeyboardIconsSet} about icon_number.
 */
public class MoreKeySpecParser {
public class KeySpecParser {
    private static final boolean DEBUG = LatinImeLogger.sDBG;
    private static final char LABEL_END = '|';
    private static final String PREFIX_ICON = Utils.PREFIX_AT + "icon" + Utils.SUFFIX_SLASH;
    private static final String PREFIX_CODE = Utils.PREFIX_AT + "integer" + Utils.SUFFIX_SLASH;
    private static final String ADDITIONAL_MORE_KEY_MARKER = "%";

    private MoreKeySpecParser() {
    private KeySpecParser() {
        // Intentional empty constructor for utility class.
    }

@@ -79,7 +79,9 @@ public class MoreKeySpecParser {
        for (int pos = 0; pos < length; pos++) {
            final char c = text.charAt(pos);
            if (c == Utils.ESCAPE_CHAR && pos + 1 < length) {
                sb.append(text.charAt(++pos));
                // Skip escape char
                pos++;
                sb.append(text.charAt(pos));
            } else {
                sb.append(c);
            }
@@ -99,6 +101,7 @@ public class MoreKeySpecParser {
        for (int pos = start; pos < length; pos++) {
            final char c = moreKeySpec.charAt(pos);
            if (c == Utils.ESCAPE_CHAR && pos + 1 < length) {
                // Skip escape char
                pos++;
            } else if (c == LABEL_END) {
                return pos;
@@ -142,7 +145,7 @@ public class MoreKeySpecParser {
            throw new MoreKeySpecParserError("Empty label: " + moreKeySpec);
        }
        // Code is automatically generated for one letter label. See {@link getCode()}.
        return (label.length() == 1) ? null : label;
        return (Utils.codePointCount(label) == 1) ? null : label;
    }

    public static int getCode(Resources res, String moreKeySpec) {
@@ -162,8 +165,8 @@ public class MoreKeySpecParser {
        }
        final String label = getLabel(moreKeySpec);
        // Code is automatically generated for one letter label.
        if (label != null && label.length() == 1) {
            return label.charAt(0);
        if (Utils.codePointCount(label) == 1) {
            return label.codePointAt(0);
        }
        return Keyboard.CODE_OUTPUT_TEXT;
    }
+5 −5
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.view.inputmethod.EditorInfo;

import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.keyboard.internal.MoreKeySpecParser;
import com.android.inputmethod.keyboard.internal.KeySpecParser;

import java.util.Arrays;
import java.util.Locale;
@@ -158,7 +158,7 @@ public class SettingsValues {
        final StringBuilder sb = new StringBuilder();
        if (puncs != null) {
            for (final String puncSpec : puncs) {
                sb.append(MoreKeySpecParser.getLabel(puncSpec));
                sb.append(KeySpecParser.getLabel(puncSpec));
            }
        }
        return sb.toString();
@@ -168,7 +168,7 @@ public class SettingsValues {
        final SuggestedWords.Builder builder = new SuggestedWords.Builder();
        if (puncs != null) {
            for (final String puncSpec : puncs) {
                builder.addWord(MoreKeySpecParser.getLabel(puncSpec));
                builder.addWord(KeySpecParser.getLabel(puncSpec));
            }
        }
        return builder.setIsPunctuationSuggestions().build();
@@ -178,11 +178,11 @@ public class SettingsValues {
        final SuggestedWords.Builder builder = new SuggestedWords.Builder();
        if (puncs != null) {
            for (final String puncSpec : puncs) {
                final String outputText = MoreKeySpecParser.getOutputText(puncSpec);
                final String outputText = KeySpecParser.getOutputText(puncSpec);
                if (outputText != null) {
                    builder.addWord(outputText);
                } else {
                    builder.addWord(MoreKeySpecParser.getLabel(puncSpec));
                    builder.addWord(KeySpecParser.getLabel(puncSpec));
                }
            }
        }
Loading