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

Commit ff858c7f authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Use MoreKeySpecParser to parse puctuations strip resources

This change also
  * Doesn't use Key.getRtlParenthesisCode to get correct parentheses
    code in RTL context. Intead uses the outputText feature of
    moreKeys specification.
  * Move CVS string parser from KeyStyles to Utils.

Bug: 5948247
Change-Id: I45752c7d01b4f7d3f3da900b110a2185b336a1f0
parent a5c96f37
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2012, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- The all letters need to be mirrored are found at
         http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBinaryProperties.txt -->
    <!-- Symbols that are suggested between words -->
    <string name="suggested_punctuations">!,?,\\,,:,;,\u0022,(|),)|(,\u0027,-,/,@,_</string>
</resources>
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2012, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- The all letters need to be mirrored are found at
         http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBinaryProperties.txt -->
    <!-- Symbols that are suggested between words -->
    <string name="suggested_punctuations">!,?,\\,,:,;,\u0022,(|),)|(,\u0027,-,/,@,_</string>
</resources>
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- Symbols that are suggested between words -->
    <string name="suggested_punctuations">!?,:;\u0022()\u0027-/@_</string>
    <string name="suggested_punctuations">!,?,\\,,:,;,\u0022,(,),\u0027,-,/,@,_</string>
    <!-- Symbols that should be swapped with a magic space -->
    <string name="magic_space_swapping_symbols">.,;:!?)]}\u0022</string>
    <!-- Symbols that should strip a magic space -->
+2 −59
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.inputmethod.keyboard.internal;

import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.Log;

@@ -28,7 +27,6 @@ import com.android.inputmethod.latin.XmlParseUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.util.ArrayList;
import java.util.HashMap;

public class KeyStyles {
@@ -74,63 +72,8 @@ public class KeyStyles {
        protected static String[] parseStringArray(TypedArray a, int index) {
            if (!a.hasValue(index))
                return null;
            return parseCsvString(a.getString(index), a.getResources(), R.string.english_ime_name);
        }
    }

    /* package for test */
    static String[] parseCsvString(String rawText, Resources res, int packageNameResId) {
        final String text = Utils.resolveStringResource(rawText, res, packageNameResId);
        final int size = text.length();
        if (size == 0) {
            return null;
        }
        if (size == 1) {
            return new String[] { text };
        }

        final StringBuilder sb = new StringBuilder();
        ArrayList<String> list = null;
        int start = 0;
        for (int pos = 0; pos < size; pos++) {
            final char c = text.charAt(pos);
            if (c == ',') {
                if (list == null) {
                    list = new ArrayList<String>();
                }
                if (sb.length() == 0) {
                    list.add(text.substring(start, pos));
                } else {
                    list.add(sb.toString());
                    sb.setLength(0);
                }
                start = pos + 1;
                continue;
            } else if (c == Utils.ESCAPE_CHAR) {
                if (start == pos) {
                    // Skip escape character at the beginning of the value.
                    start++;
                    pos++;
                } else {
                    if (start < pos && sb.length() == 0) {
                        sb.append(text.subSequence(start, pos));
                    }
                    pos++;
                    if (pos < size) {
                        sb.append(text.charAt(pos));
                    }
                }
            } else if (sb.length() > 0) {
                sb.append(c);
            }
        }
        if (list == null) {
            return new String[] {
                    sb.length() > 0 ? sb.toString() : text.substring(start)
            };
        } else {
            list.add(sb.length() > 0 ? sb.toString() : text.substring(start));
            return list.toArray(new String[list.size()]);
            return Utils.parseCsvString(
                    a.getString(index), a.getResources(), R.string.english_ime_name);
        }
    }

+3 −7
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardId;
@@ -1897,16 +1896,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
            // So, LatinImeLogger logs "" as a user's input.
            LatinImeLogger.logOnManualSuggestion(
                    "", suggestion.toString(), index, suggestions.mWords);
            final CharSequence outputText = mSettingsValues.mSuggestPuncOutputTextList
                    .getWord(index);
            final int primaryCode = outputText.charAt(0);
            // Find out whether the previous character is a space. If it is, as a special case
            // for punctuation entered through the suggestion strip, it should be swapped
            // if it was a magic or a weak space. This is meant to help in case the user
            // pressed space on purpose of displaying the suggestion strip punctuation.
            final int rawPrimaryCode = suggestion.charAt(0);
            // Maybe apply the "bidi mirrored" conversions for parentheses
            final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
            final boolean isRtl = keyboard != null && keyboard.mIsRtlKeyboard;
            final int primaryCode = Key.getRtlParenthesisCode(rawPrimaryCode, isRtl);

            insertPunctuationFromSuggestionStrip(ic, primaryCode);
            // TODO: the following endBatchEdit seems useless, check
            if (ic != null) {
Loading