diff options
Diffstat (limited to 'java/src')
44 files changed, 1506 insertions, 857 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java index bc094b117..d50dd3ee6 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java @@ -68,7 +68,6 @@ public final class AccessibilityUtils { // These only need to be initialized if the kill switch is off. sInstance.initInternal(context); KeyCodeDescriptionMapper.init(); - AccessibleKeyboardViewProxy.init(context); } public static AccessibilityUtils getInstance() { diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index 2e6649bf2..0499a3456 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -189,9 +189,14 @@ public final class KeyCodeDescriptionMapper { break; case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED: - case KeyboardId.ELEMENT_SYMBOLS_SHIFTED: resId = R.string.spoken_description_shift_shifted; break; + case KeyboardId.ELEMENT_SYMBOLS: + resId = R.string.spoken_description_symbols_shift; + break; + case KeyboardId.ELEMENT_SYMBOLS_SHIFTED: + resId = R.string.spoken_description_symbols_shift_shifted; + break; default: resId = R.string.spoken_description_shift; } diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java index 322127a12..10929424b 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java @@ -36,9 +36,7 @@ import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; -public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat { - private static final AccessibleKeyboardViewProxy sInstance = new AccessibleKeyboardViewProxy(); - +public final class MainKeyboardAccessibilityDelegate extends AccessibilityDelegateCompat { /** Map of keyboard modes to resource IDs. */ private static final SparseIntArray KEYBOARD_MODE_RES_IDS = new SparseIntArray(); @@ -54,9 +52,9 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp KEYBOARD_MODE_RES_IDS.put(KeyboardId.MODE_URL, R.string.keyboard_mode_url); } - private MainKeyboardView mView; + private final MainKeyboardView mView; private Keyboard mKeyboard; - private AccessibilityEntityProvider mAccessibilityNodeProvider; + private MainKeyboardAccessibilityNodeProvider mAccessibilityNodeProvider; private Key mLastHoverKey = null; @@ -69,46 +67,14 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp private int mLastKeyboardMode = KEYBOARD_IS_HIDDEN; private static final int KEYBOARD_IS_HIDDEN = -1; - public static void init(final Context context) { - sInstance.initInternal(context); - } - - public static AccessibleKeyboardViewProxy getInstance() { - return sInstance; - } - - private AccessibleKeyboardViewProxy() { - // Not publicly instantiable. - } - - private void initInternal(final Context context) { + public MainKeyboardAccessibilityDelegate(final MainKeyboardView view) { + final Context context = view.getContext(); mEdgeSlop = context.getResources().getDimensionPixelSize( R.dimen.config_accessibility_edge_slop); - } - - /** - * Sets the view wrapped by this proxy. - * - * @param view The view to wrap. - */ - public void setView(final MainKeyboardView view) { - if (view == null) { - // Ignore null views. - return; - } mView = view; // Ensure that the view has an accessibility delegate. ViewCompat.setAccessibilityDelegate(view, this); - - if (mAccessibilityNodeProvider == null) { - return; - } - mAccessibilityNodeProvider.setView(view); - - // Since this class is constructed lazily, we might not get a subsequent - // call to setKeyboard() and therefore need to call it now. - setKeyboard(view.getKeyboard()); } /** @@ -136,12 +102,19 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp return; } // Announce the language name only when the language is changed. - if (lastKeyboard == null || !lastKeyboard.mId.mSubtype.equals(keyboard.mId.mSubtype)) { + if (lastKeyboard == null || !keyboard.mId.mSubtype.equals(lastKeyboard.mId.mSubtype)) { announceKeyboardLanguage(keyboard); + return; } // Announce the mode only when the mode is changed. - if (lastKeyboardMode != keyboard.mId.mMode) { + if (keyboard.mId.mMode != lastKeyboardMode) { announceKeyboardMode(keyboard); + return; + } + // Announce the keyboard type only when the type is changed. + if (keyboard.mId.mElementId != lastKeyboard.mId.mElementId) { + announceKeyboardType(keyboard, lastKeyboard); + return; } } @@ -149,9 +122,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp * Called when the keyboard is hidden and accessibility is enabled. */ public void onHideWindow() { - if (mView == null) { - return; - } announceKeyboardHidden(); mLastKeyboardMode = KEYBOARD_IS_HIDDEN; } @@ -174,9 +144,8 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp * @param keyboard The new keyboard. */ private void announceKeyboardMode(final Keyboard keyboard) { - final int mode = keyboard.mId.mMode; final Context context = mView.getContext(); - final int modeTextResId = KEYBOARD_MODE_RES_IDS.get(mode); + final int modeTextResId = KEYBOARD_MODE_RES_IDS.get(keyboard.mId.mMode); if (modeTextResId == 0) { return; } @@ -186,6 +155,50 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** + * Announces which type of keyboard is being displayed. + * + * @param keyboard The new keyboard. + * @param lastKeyboard The last keyboard. + */ + private void announceKeyboardType(final Keyboard keyboard, final Keyboard lastKeyboard) { + final int lastElementId = lastKeyboard.mId.mElementId; + final int resId; + switch (keyboard.mId.mElementId) { + case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: + case KeyboardId.ELEMENT_ALPHABET: + if (lastElementId == KeyboardId.ELEMENT_ALPHABET + || lastElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return; + } + resId = R.string.spoken_description_mode_alpha; + break; + case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED: + resId = R.string.spoken_description_shiftmode_on; + break; + case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: + case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED: + resId = R.string.spoken_description_shiftmode_locked; + break; + case KeyboardId.ELEMENT_SYMBOLS: + resId = R.string.spoken_description_mode_symbol; + break; + case KeyboardId.ELEMENT_SYMBOLS_SHIFTED: + resId = R.string.spoken_description_mode_symbol_shift; + break; + case KeyboardId.ELEMENT_PHONE: + resId = R.string.spoken_description_mode_phone; + break; + case KeyboardId.ELEMENT_PHONE_SYMBOLS: + resId = R.string.spoken_description_mode_phone_shift; + break; + default: + return; + } + final String text = mView.getContext().getString(resId); + sendWindowStateChanged(text); + } + + /** * Announces that the keyboard has been hidden. */ private void announceKeyboardHidden() { @@ -214,7 +227,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** - * Proxy method for View.getAccessibilityNodeProvider(). This method is called in SDK + * Delegate method for View.getAccessibilityNodeProvider(). This method is called in SDK * version 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) and higher to obtain the virtual * node hierarchy provider. * @@ -222,10 +235,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp * @return The accessibility node provider for the current keyboard. */ @Override - public AccessibilityEntityProvider getAccessibilityNodeProvider(final View host) { - if (mView == null) { - return null; - } + public MainKeyboardAccessibilityNodeProvider getAccessibilityNodeProvider(final View host) { return getAccessibilityNodeProvider(); } @@ -238,10 +248,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp * @return {@code true} if the event is handled */ public boolean dispatchHoverEvent(final MotionEvent event, final KeyDetector keyDetector) { - if (mView == null) { - return false; - } - final int x = (int) event.getX(); final int y = (int) event.getY(); final Key previousKey = mLastHoverKey; @@ -275,14 +281,14 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** - * @return A lazily-instantiated node provider for this view proxy. + * @return A lazily-instantiated node provider for this view delegate. */ - private AccessibilityEntityProvider getAccessibilityNodeProvider() { + private MainKeyboardAccessibilityNodeProvider getAccessibilityNodeProvider() { // Instantiate the provide only when requested. Since the system // will call this method multiple times it is a good practice to // cache the provider instance. if (mAccessibilityNodeProvider == null) { - mAccessibilityNodeProvider = new AccessibilityEntityProvider(mView); + mAccessibilityNodeProvider = new MainKeyboardAccessibilityNodeProvider(mView); } return mAccessibilityNodeProvider; } @@ -301,7 +307,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** - * Simulates a key press by injecting touch event into the keyboard view. + * Simulates a key press by injecting touch an event into the keyboard view. * This avoids the complexity of trackers and listeners within the keyboard. * * @param key The key to press. @@ -318,7 +324,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** - * Simulates a key release by injecting touch event into the keyboard view. + * Simulates a key release by injecting touch an event into the keyboard view. * This avoids the complexity of trackers and listeners within the keyboard. * * @param key The key to release. @@ -367,7 +373,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp if (key == null) { return false; } - final AccessibilityEntityProvider provider = getAccessibilityNodeProvider(); + final MainKeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider(); switch (event.getAction()) { case MotionEvent.ACTION_HOVER_ENTER: @@ -383,72 +389,4 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } return true; } - - /** - * Notifies the user of changes in the keyboard shift state. - */ - public void notifyShiftState() { - if (mView == null || mKeyboard == null) { - return; - } - - final KeyboardId keyboardId = mKeyboard.mId; - final int elementId = keyboardId.mElementId; - final Context context = mView.getContext(); - final CharSequence text; - - switch (elementId) { - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED: - text = context.getText(R.string.spoken_description_shiftmode_locked); - break; - case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED: - case KeyboardId.ELEMENT_SYMBOLS_SHIFTED: - text = context.getText(R.string.spoken_description_shiftmode_on); - break; - default: - text = context.getText(R.string.spoken_description_shiftmode_off); - } - AccessibilityUtils.getInstance().announceForAccessibility(mView, text); - } - - /** - * Notifies the user of changes in the keyboard symbols state. - */ - public void notifySymbolsState() { - if (mView == null || mKeyboard == null) { - return; - } - - final KeyboardId keyboardId = mKeyboard.mId; - final int elementId = keyboardId.mElementId; - final Context context = mView.getContext(); - final int resId; - - switch (elementId) { - case KeyboardId.ELEMENT_ALPHABET: - case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED: - resId = R.string.spoken_description_mode_alpha; - break; - case KeyboardId.ELEMENT_SYMBOLS: - case KeyboardId.ELEMENT_SYMBOLS_SHIFTED: - resId = R.string.spoken_description_mode_symbol; - break; - case KeyboardId.ELEMENT_PHONE: - resId = R.string.spoken_description_mode_phone; - break; - case KeyboardId.ELEMENT_PHONE_SYMBOLS: - resId = R.string.spoken_description_mode_phone_shift; - break; - default: - return; - } - - final String text = context.getString(resId); - AccessibilityUtils.getInstance().announceForAccessibility(mView, text); - } } diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityNodeProvider.java index ec1ab3565..f69d316c9 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java +++ b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityNodeProvider.java @@ -47,8 +47,8 @@ import java.util.List; * virtual views, thus conveying their logical structure. * </p> */ -public final class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat { - private static final String TAG = AccessibilityEntityProvider.class.getSimpleName(); +public final class MainKeyboardAccessibilityNodeProvider extends AccessibilityNodeProviderCompat { + private static final String TAG = MainKeyboardAccessibilityNodeProvider.class.getSimpleName(); private static final int UNDEFINED = Integer.MIN_VALUE; private final KeyCodeDescriptionMapper mKeyCodeDescriptionMapper; @@ -64,23 +64,14 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider private int mAccessibilityFocusedView = UNDEFINED; /** The current keyboard view. */ - private KeyboardView mKeyboardView; + private final KeyboardView mKeyboardView; /** The current keyboard. */ private Keyboard mKeyboard; - public AccessibilityEntityProvider(final KeyboardView keyboardView) { + public MainKeyboardAccessibilityNodeProvider(final KeyboardView keyboardView) { mKeyCodeDescriptionMapper = KeyCodeDescriptionMapper.getInstance(); mAccessibilityUtils = AccessibilityUtils.getInstance(); - setView(keyboardView); - } - - /** - * Sets the keyboard view represented by this node provider. - * - * @param keyboardView The keyboard view to represent. - */ - public void setView(final KeyboardView keyboardView) { mKeyboardView = keyboardView; updateParentLocation(); diff --git a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java index a0d76415c..6e32e74ab 100644 --- a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java @@ -29,8 +29,8 @@ public final class UserDictionaryCompatUtils { Context.class, String.class, Integer.TYPE, String.class, Locale.class); @SuppressWarnings("deprecation") - public static void addWord(final Context context, final String word, final int freq, - final String shortcut, final Locale locale) { + public static void addWord(final Context context, final String word, + final int freq, final String shortcut, final Locale locale) { if (hasNewerAddWord()) { CompatUtils.invoke(Words.class, null, METHOD_addWord, context, word, freq, shortcut, locale); diff --git a/java/src/com/android/inputmethod/event/CombinerChain.java b/java/src/com/android/inputmethod/event/CombinerChain.java index 8b59dc52a..990f7deea 100644 --- a/java/src/com/android/inputmethod/event/CombinerChain.java +++ b/java/src/com/android/inputmethod/event/CombinerChain.java @@ -23,6 +23,7 @@ import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; +import java.util.HashMap; /** * This class implements the logic chain between receiving events and generating code points. @@ -43,6 +44,13 @@ public class CombinerChain { private SpannableStringBuilder mStateFeedback; private final ArrayList<Combiner> mCombiners; + private static final HashMap<String, Class> IMPLEMENTED_COMBINERS + = new HashMap<String, Class>(); + static { + IMPLEMENTED_COMBINERS.put("MyanmarReordering", MyanmarReordering.class); + } + private static final String COMBINER_SPEC_SEPARATOR = ";"; + /** * Create an combiner chain. * @@ -56,6 +64,9 @@ public class CombinerChain { mCombiners = CollectionUtils.newArrayList(); // The dead key combiner is always active, and always first mCombiners.add(new DeadKeyCombiner()); + for (final Combiner combiner : combinerList) { + mCombiners.add(combiner); + } mCombinedText = new StringBuilder(); mStateFeedback = new SpannableStringBuilder(); } @@ -114,4 +125,29 @@ public class CombinerChain { final SpannableStringBuilder s = new SpannableStringBuilder(mCombinedText); return s.append(mStateFeedback); } + + public static Combiner[] createCombiners(final String spec) { + if (TextUtils.isEmpty(spec)) { + return new Combiner[0]; + } + final String[] combinerDescriptors = spec.split(COMBINER_SPEC_SEPARATOR); + final Combiner[] combiners = new Combiner[combinerDescriptors.length]; + int i = 0; + for (final String combinerDescriptor : combinerDescriptors) { + final Class combinerClass = IMPLEMENTED_COMBINERS.get(combinerDescriptor); + if (null == combinerClass) { + throw new RuntimeException("Unknown combiner descriptor: " + combinerDescriptor); + } + try { + combiners[i++] = (Combiner)combinerClass.newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException("Unable to instantiate combiner: " + combinerDescriptor, + e); + } catch (IllegalAccessException e) { + throw new RuntimeException("Unable to instantiate combiner: " + combinerDescriptor, + e); + } + } + return combiners; + } } diff --git a/java/src/com/android/inputmethod/event/MyanmarReordering.java b/java/src/com/android/inputmethod/event/MyanmarReordering.java new file mode 100644 index 000000000..27b8c14bb --- /dev/null +++ b/java/src/com/android/inputmethod/event/MyanmarReordering.java @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2014 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. + */ + +package com.android.inputmethod.event; + +import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.utils.CollectionUtils; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * A combiner that reorders input for Myanmar. + */ +public class MyanmarReordering implements Combiner { + // U+1031 MYANMAR VOWEL SIGN E + private final static int VOWEL_E = 0x1031; // Code point for vowel E that we need to reorder + // U+200C ZERO WIDTH NON-JOINER + // U+200B ZERO WIDTH SPACE + private final static int ZERO_WIDTH_NON_JOINER = 0x200B; // should be 0x200C + + private final ArrayList<Event> mCurrentEvents = CollectionUtils.newArrayList(); + + // List of consonants : + // U+1000 MYANMAR LETTER KA + // U+1001 MYANMAR LETTER KHA + // U+1002 MYANMAR LETTER GA + // U+1003 MYANMAR LETTER GHA + // U+1004 MYANMAR LETTER NGA + // U+1005 MYANMAR LETTER CA + // U+1006 MYANMAR LETTER CHA + // U+1007 MYANMAR LETTER JA + // U+1008 MYANMAR LETTER JHA + // U+1009 MYANMAR LETTER NYA + // U+100A MYANMAR LETTER NNYA + // U+100B MYANMAR LETTER TTA + // U+100C MYANMAR LETTER TTHA + // U+100D MYANMAR LETTER DDA + // U+100E MYANMAR LETTER DDHA + // U+100F MYANMAR LETTER NNA + // U+1010 MYANMAR LETTER TA + // U+1011 MYANMAR LETTER THA + // U+1012 MYANMAR LETTER DA + // U+1013 MYANMAR LETTER DHA + // U+1014 MYANMAR LETTER NA + // U+1015 MYANMAR LETTER PA + // U+1016 MYANMAR LETTER PHA + // U+1017 MYANMAR LETTER BA + // U+1018 MYANMAR LETTER BHA + // U+1019 MYANMAR LETTER MA + // U+101A MYANMAR LETTER YA + // U+101B MYANMAR LETTER RA + // U+101C MYANMAR LETTER LA + // U+101D MYANMAR LETTER WA + // U+101E MYANMAR LETTER SA + // U+101F MYANMAR LETTER HA + // U+1020 MYANMAR LETTER LLA + // U+103F MYANMAR LETTER GREAT SA + private static boolean isConsonant(final int codePoint) { + return (codePoint >= 0x1000 && codePoint <= 0x1020) || 0x103F == codePoint; + } + + // List of medials : + // U+103B MYANMAR CONSONANT SIGN MEDIAL YA + // U+103C MYANMAR CONSONANT SIGN MEDIAL RA + // U+103D MYANMAR CONSONANT SIGN MEDIAL WA + // U+103E MYANMAR CONSONANT SIGN MEDIAL HA + // U+105E MYANMAR CONSONANT SIGN MON MEDIAL NA + // U+105F MYANMAR CONSONANT SIGN MON MEDIAL MA + // U+1060 MYANMAR CONSONANT SIGN MON MEDIAL LA + // U+1082 MYANMAR CONSONANT SIGN SHAN MEDIAL WA + private static int[] MEDIAL_LIST = { 0x103B, 0x103C, 0x103D, 0x103E, + 0x105E, 0x105F, 0x1060, 0x1082}; + private static boolean isMedial(final int codePoint) { + return Arrays.binarySearch(MEDIAL_LIST, codePoint) >= 0; + } + + private static boolean isConsonantOrMedial(final int codePoint) { + return isConsonant(codePoint) || isMedial(codePoint); + } + + private Event getLastEvent() { + final int size = mCurrentEvents.size(); + if (size <= 0) { + return null; + } + return mCurrentEvents.get(size - 1); + } + + private CharSequence getCharSequence() { + final StringBuilder s = new StringBuilder(); + for (final Event e : mCurrentEvents) { + s.appendCodePoint(e.mCodePoint); + } + return s; + } + + /** + * Clears the currently combining stream of events and returns the resulting software text + * event corresponding to the stream. Optionally adds a new event to the cleared stream. + * @param newEvent the new event to add to the stream. null if none. + * @return the resulting software text event. Null if none. + */ + private Event clearAndGetResultingEvent(final Event newEvent) { + final CharSequence combinedText; + if (mCurrentEvents.size() > 0) { + combinedText = getCharSequence(); + mCurrentEvents.clear(); + } else { + combinedText = null; + } + if (null != newEvent) { + mCurrentEvents.add(newEvent); + } + return null == combinedText ? null + : Event.createSoftwareTextEvent(combinedText, Event.NOT_A_KEY_CODE); + } + + @Override + public Event processEvent(ArrayList<Event> previousEvents, Event newEvent) { + final int codePoint = newEvent.mCodePoint; + if (VOWEL_E == codePoint) { + final Event lastEvent = getLastEvent(); + if (null == lastEvent) { + mCurrentEvents.add(newEvent); + return null; + } else if (isConsonantOrMedial(lastEvent.mCodePoint)) { + final Event resultingEvent = clearAndGetResultingEvent(null); + mCurrentEvents.add(Event.createSoftwareKeypressEvent(ZERO_WIDTH_NON_JOINER, + Event.NOT_A_KEY_CODE, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */)); + mCurrentEvents.add(newEvent); + return resultingEvent; + } else { // VOWEL_E == lastCodePoint. But if that was anything else this is correct too. + return clearAndGetResultingEvent(newEvent); + } + } if (isConsonant(codePoint)) { + final Event lastEvent = getLastEvent(); + if (null == lastEvent) { + mCurrentEvents.add(newEvent); + return null; + } else if (VOWEL_E == lastEvent.mCodePoint) { + final int eventSize = mCurrentEvents.size(); + if (eventSize >= 2 + && mCurrentEvents.get(eventSize - 2).mCodePoint == ZERO_WIDTH_NON_JOINER) { + // We have a ZWJN before a vowel E. We need to remove the ZWNJ and then + // reorder the vowel with respect to the consonant. + mCurrentEvents.remove(eventSize - 1); + mCurrentEvents.remove(eventSize - 2); + mCurrentEvents.add(newEvent); + mCurrentEvents.add(lastEvent); + return null; + } + // If there is already a consonant, then we are starting a new syllable. + for (int i = eventSize - 2; i >= 0; --i) { + if (isConsonant(mCurrentEvents.get(i).mCodePoint)) { + return clearAndGetResultingEvent(newEvent); + } + } + // If we come here, we didn't have a consonant so we reorder + mCurrentEvents.remove(eventSize - 1); + mCurrentEvents.add(newEvent); + mCurrentEvents.add(lastEvent); + return null; + } else { // lastCodePoint is a consonant/medial. But if it's something else it's fine + return clearAndGetResultingEvent(newEvent); + } + } else if (isMedial(codePoint)) { + final Event lastEvent = getLastEvent(); + if (null == lastEvent) { + mCurrentEvents.add(newEvent); + return null; + } else if (VOWEL_E == lastEvent.mCodePoint) { + final int eventSize = mCurrentEvents.size(); + // If there is already a consonant, then we are in the middle of a syllable, and we + // need to reorder. + boolean hasConsonant = false; + for (int i = eventSize - 2; i >= 0; --i) { + if (isConsonant(mCurrentEvents.get(i).mCodePoint)) { + hasConsonant = true; + break; + } + } + if (hasConsonant) { + mCurrentEvents.remove(eventSize - 1); + mCurrentEvents.add(newEvent); + mCurrentEvents.add(lastEvent); + return null; + } + // Otherwise, we just commit everything. + return clearAndGetResultingEvent(null); + } else { // lastCodePoint is a consonant/medial. But if it's something else it's fine + return clearAndGetResultingEvent(newEvent); + } + } else if (Constants.CODE_DELETE == newEvent.mKeyCode) { + if (mCurrentEvents.size() > 0) { + mCurrentEvents.remove(mCurrentEvents.size() - 1); + return null; + } + } + // This character is not part of the combining scheme, so we should reset everything. + if (mCurrentEvents.size() > 0) { + // If we have events in flight, then add the new event and return the resulting event. + mCurrentEvents.add(newEvent); + return clearAndGetResultingEvent(null); + } else { + // If we don't have any events in flight, then just pass this one through. + return newEvent; + } + } + + @Override + public CharSequence getCombiningStateFeedback() { + return getCharSequence(); + } + + @Override + public void reset() { + mCurrentEvents.clear(); + } +} diff --git a/java/src/com/android/inputmethod/keyboard/EmojiCategoryPageIndicatorView.java b/java/src/com/android/inputmethod/keyboard/EmojiCategoryPageIndicatorView.java index d56a3cf25..4ef9e2232 100644 --- a/java/src/com/android/inputmethod/keyboard/EmojiCategoryPageIndicatorView.java +++ b/java/src/com/android/inputmethod/keyboard/EmojiCategoryPageIndicatorView.java @@ -25,7 +25,7 @@ import android.util.AttributeSet; import android.widget.LinearLayout; public class EmojiCategoryPageIndicatorView extends LinearLayout { - private static final float BOTTOM_MARGIN_RATIO = 0.66f; + private static final float BOTTOM_MARGIN_RATIO = 1.0f; private final Paint mPaint = new Paint(); private int mCategoryPageSize = 0; private int mCurrentCategoryPageId = 0; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 0235fde38..4a46a4a46 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -26,7 +26,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.inputmethod.EditorInfo; -import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException; import com.android.inputmethod.keyboard.internal.KeyboardState; @@ -65,7 +64,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { * what user actually typed. */ private boolean mIsAutoCorrectionActive; - private KeyboardTheme mKeyboardTheme = KeyboardTheme.getDefaultKeyboardTheme(); + private KeyboardTheme mKeyboardTheme; private Context mThemeContext; private static final KeyboardSwitcher sInstance = new KeyboardSwitcher(); @@ -102,7 +101,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context, final KeyboardTheme keyboardTheme) { - if (mThemeContext == null || mKeyboardTheme.mThemeId != keyboardTheme.mThemeId) { + if (mThemeContext == null || !keyboardTheme.equals(mKeyboardTheme)) { mKeyboardTheme = keyboardTheme; mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId); KeyboardLayoutSet.clearKeyboardCache(); @@ -123,7 +122,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { builder.setOptions( mSubtypeSwitcher.isShortcutImeEnabled(), settingsValues.mShowsVoiceInputKey, - mLatinIME.shouldSwitchToOtherInputMethods()); + mLatinIME.shouldShowLanguageSwitchKey()); mKeyboardLayoutSet = builder.build(); mCurrentSettingsValues = settingsValues; try { @@ -148,6 +147,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { public void onHideWindow() { mIsAutoCorrectionActive = false; + if (mKeyboardView != null) { + mKeyboardView.onHideWindow(); + } } private void setKeyboard(final Keyboard keyboard) { @@ -340,7 +342,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { mKeyboardView.closing(); } - updateKeyboardThemeAndContextThemeWrapper(mLatinIME, mKeyboardTheme); + updateKeyboardThemeAndContextThemeWrapper( + mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs)); mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate( R.layout.input_view, null); mMainKeyboardFrame = mCurrentInputView.findViewById(R.id.main_keyboard_frame); @@ -353,11 +356,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { mEmojiPalettesView.setHardwareAcceleratedDrawingEnabled( isHardwareAcceleratedDrawingEnabled); mEmojiPalettesView.setKeyboardActionListener(mLatinIME); - - // This always needs to be set since the accessibility state can - // potentially change without the input view being re-created. - AccessibleKeyboardViewProxy.getInstance().setView(mKeyboardView); - return mCurrentInputView; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java index 4db72ad4d..429c7ddd7 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java @@ -17,34 +17,85 @@ package com.android.inputmethod.keyboard; import android.content.SharedPreferences; +import android.os.Build; +import android.os.Build.VERSION_CODES; import android.util.Log; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.settings.Settings; + +import java.util.Arrays; +import java.util.Comparator; public final class KeyboardTheme { private static final String TAG = KeyboardTheme.class.getSimpleName(); - public static final int THEME_ID_ICS = 0; - public static final int THEME_ID_KLP = 2; - private static final int DEFAULT_THEME_ID = THEME_ID_KLP; + static final String KITKAT_KEYBOARD_THEME_KEY = "pref_keyboard_layout_20110916"; + static final String KEYBOARD_THEME_KEY = "pref_keyboard_theme_20140509"; + + static final int THEME_ID_ICS = 0; + static final int THEME_ID_KLP = 2; + static final int THEME_ID_LMP = 3; + static final int DEFAULT_THEME_ID = THEME_ID_KLP; private static final KeyboardTheme[] KEYBOARD_THEMES = { - new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS), - new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP), + new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS, + VERSION_CODES.ICE_CREAM_SANDWICH), + new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP, + VERSION_CODES.KITKAT), + new KeyboardTheme(THEME_ID_LMP, R.style.KeyboardTheme_LMP, + // TODO: Update this constant once the *next* version becomes available. + VERSION_CODES.CUR_DEVELOPMENT), }; + static { + // Sort {@link #KEYBOARD_THEME} by descending order of {@link #mMinApiVersion}. + Arrays.sort(KEYBOARD_THEMES, new Comparator<KeyboardTheme>() { + @Override + public int compare(final KeyboardTheme lhs, final KeyboardTheme rhs) { + if (lhs.mMinApiVersion > rhs.mMinApiVersion) return -1; + if (lhs.mMinApiVersion < rhs.mMinApiVersion) return 1; + return 0; + } + }); + } public final int mThemeId; public final int mStyleId; + final int mMinApiVersion; // Note: The themeId should be aligned with "themeId" attribute of Keyboard style - // in values/style.xml. - public KeyboardTheme(final int themeId, final int styleId) { + // in values/themes-<style>.xml. + private KeyboardTheme(final int themeId, final int styleId, final int minApiVersion) { mThemeId = themeId; mStyleId = styleId; + mMinApiVersion = minApiVersion; + } + + @Override + public boolean equals(final Object o) { + if (o == this) return true; + return (o instanceof KeyboardTheme) && ((KeyboardTheme)o).mThemeId == mThemeId; } - private static KeyboardTheme searchKeyboardTheme(final int themeId) { + @Override + public int hashCode() { + return mThemeId; + } + + // TODO: This method should be removed when {@link LatinImeLogger} is removed. + public int getCompatibleThemeIdForLogging() { + switch (mThemeId) { + case THEME_ID_ICS: + return 5; + case THEME_ID_KLP: + return 9; + case THEME_ID_LMP: + return 10; + default: // Invalid theme + return -1; + } + } + + private static KeyboardTheme searchKeyboardThemeById(final int themeId) { // TODO: This search algorithm isn't optimal if there are many themes. for (final KeyboardTheme theme : KEYBOARD_THEMES) { if (theme.mThemeId == themeId) { @@ -54,18 +105,57 @@ public final class KeyboardTheme { return null; } - public static KeyboardTheme getDefaultKeyboardTheme() { - return searchKeyboardTheme(DEFAULT_THEME_ID); + private static int getSdkVersion() { + final int sdkVersion = Build.VERSION.SDK_INT; + // TODO: Consider to remove this check once the *next* version becomes available. + if (sdkVersion == VERSION_CODES.KITKAT && Build.VERSION.CODENAME.startsWith("L")) { + return VERSION_CODES.CUR_DEVELOPMENT; + } + return sdkVersion; + } + + static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs, + final int sdkVersion) { + final String obsoleteIdString = prefs.getString(KITKAT_KEYBOARD_THEME_KEY, null); + if (obsoleteIdString != null) { + // Remove old preference. + prefs.edit().remove(KITKAT_KEYBOARD_THEME_KEY).apply(); + if (sdkVersion <= VERSION_CODES.KITKAT) { + try { + final int themeId = Integer.parseInt(obsoleteIdString); + final KeyboardTheme theme = searchKeyboardThemeById(themeId); + if (theme != null) { + return theme; + } + Log.w(TAG, "Unknown keyboard theme in preference: " + obsoleteIdString); + } catch (final NumberFormatException e) { + Log.w(TAG, "Illegal keyboard theme in preference: " + obsoleteIdString); + } + } + } + // TODO: This search algorithm isn't optimal if there are many themes. + for (final KeyboardTheme theme : KEYBOARD_THEMES) { + if (sdkVersion >= theme.mMinApiVersion) { + return theme; + } + } + return searchKeyboardThemeById(DEFAULT_THEME_ID); + } + + public static void saveKeyboardThemeId(final String themeIdString, + final SharedPreferences prefs) { + prefs.edit().putString(KEYBOARD_THEME_KEY, themeIdString).apply(); } public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) { - final String themeIdString = prefs.getString(Settings.PREF_KEYBOARD_LAYOUT, null); + final int sdkVersion = getSdkVersion(); + final String themeIdString = prefs.getString(KEYBOARD_THEME_KEY, null); if (themeIdString == null) { - return getDefaultKeyboardTheme(); + return getDefaultKeyboardTheme(prefs, sdkVersion); } try { final int themeId = Integer.parseInt(themeIdString); - final KeyboardTheme theme = searchKeyboardTheme(themeId); + final KeyboardTheme theme = searchKeyboardThemeById(themeId); if (theme != null) { return theme; } @@ -73,9 +163,8 @@ public final class KeyboardTheme { } catch (final NumberFormatException e) { Log.w(TAG, "Illegal keyboard theme in preference: " + themeIdString); } - // Reset preference to default value. - final String defaultThemeIdString = Integer.toString(DEFAULT_THEME_ID); - prefs.edit().putString(Settings.PREF_KEYBOARD_LAYOUT, defaultThemeIdString).apply(); - return getDefaultKeyboardTheme(); + // Remove preference. + prefs.edit().remove(KEYBOARD_THEME_KEY).apply(); + return getDefaultKeyboardTheme(prefs, sdkVersion); } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 8ca00b005..4450a4474 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -82,6 +82,7 @@ public class KeyboardView extends View { private final float mVerticalCorrection; private final Drawable mKeyBackground; private final Rect mKeyBackgroundPadding = new Rect(); + private static final float KET_TEXT_SHADOW_RADIUS_DISABLED = -1.0f; // HORIZONTAL ELLIPSIS "...", character for popup hint. private static final String POPUP_HINT_CHAR = "\u2026"; @@ -133,7 +134,7 @@ public class KeyboardView extends View { mKeyShiftedLetterHintPadding = keyboardViewAttr.getDimension( R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0.0f); mKeyTextShadowRadius = keyboardViewAttr.getFloat( - R.styleable.KeyboardView_keyTextShadowRadius, 0.0f); + R.styleable.KeyboardView_keyTextShadowRadius, KET_TEXT_SHADOW_RADIUS_DISABLED); mVerticalCorrection = keyboardViewAttr.getDimension( R.styleable.KeyboardView_verticalCorrection, 0.0f); keyboardViewAttr.recycle(); @@ -414,18 +415,23 @@ public class KeyboardView extends View { } } - paint.setColor(key.selectTextColor(params)); if (key.isEnabled()) { - // Set a drop shadow for the text - paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor); + paint.setColor(key.selectTextColor(params)); + // Set a drop shadow for the text if the shadow radius is positive value. + if (mKeyTextShadowRadius > 0.0f) { + paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor); + } else { + paint.clearShadowLayer(); + } } else { // Make label invisible paint.setColor(Color.TRANSPARENT); + paint.clearShadowLayer(); } blendAlpha(paint, params.mAnimAlpha); canvas.drawText(label, 0, label.length(), positionX, baseline, paint); // Turn off drop shadow and reset x-scale. - paint.setShadowLayer(0.0f, 0.0f, 0.0f, Color.TRANSPARENT); + paint.clearShadowLayer(); paint.setTextScaleX(1.0f); if (icon != null) { diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index ecef8cc6c..1a8e4b7e9 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -39,7 +39,7 @@ import android.view.inputmethod.InputMethodSubtype; import android.widget.TextView; import com.android.inputmethod.accessibility.AccessibilityUtils; -import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; +import com.android.inputmethod.accessibility.MainKeyboardAccessibilityDelegate; import com.android.inputmethod.annotations.ExternallyReferenced; import com.android.inputmethod.keyboard.internal.DrawingHandler; import com.android.inputmethod.keyboard.internal.DrawingPreviewPlacerView; @@ -74,6 +74,7 @@ import java.util.WeakHashMap; * @attr ref R.styleable#MainKeyboardView_autoCorrectionSpacebarLedIcon * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextRatio * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor + * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowRadius * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor * @attr ref R.styleable#MainKeyboardView_spacebarBackground * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha @@ -129,7 +130,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack private final float mLanguageOnSpacebarTextRatio; private float mLanguageOnSpacebarTextSize; private final int mLanguageOnSpacebarTextColor; + private final float mLanguageOnSpacebarTextShadowRadius; private final int mLanguageOnSpacebarTextShadowColor; + private static final float LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED = -1.0f; // The minimum x-scale to fit the language name on spacebar. private static final float MINIMUM_XSCALE_OF_LANGUAGE_NAME = 0.8f; // Stuff to draw auto correction LED on spacebar. @@ -179,6 +182,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack private final DrawingHandler mDrawingHandler = new DrawingHandler(this); + private final MainKeyboardAccessibilityDelegate mAccessibilityDelegate; + public MainKeyboardView(final Context context, final AttributeSet attrs) { this(context, attrs, R.attr.mainKeyboardViewStyle); } @@ -229,6 +234,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f); mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor( R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0); + mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat( + R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius, + LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED); mLanguageOnSpacebarTextShadowColor = mainKeyboardViewAttr.getColor( R.styleable.MainKeyboardView_languageOnSpacebarTextShadowColor, 0); mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt( @@ -278,6 +286,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mLanguageOnSpacebarHorizontalMargin = (int)getResources().getDimension( R.dimen.config_language_on_spacebar_horizontal_margin); + + mAccessibilityDelegate = new MainKeyboardAccessibilityDelegate(this); } @Override @@ -404,9 +414,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack ResearchLogger.mainKeyboardView_setKeyboard(keyboard, orientation); } - // This always needs to be set since the accessibility state can - // potentially change without the keyboard being set again. - AccessibleKeyboardViewProxy.getInstance().setKeyboard(keyboard); + mAccessibilityDelegate.setKeyboard(keyboard); } /** @@ -769,6 +777,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mMoreKeysKeyboardCache.clear(); } + public void onHideWindow() { + if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) { + mAccessibilityDelegate.onHideWindow(); + } + } + /** * Receives hover events from the input framework. * @@ -779,8 +793,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack @Override public boolean dispatchHoverEvent(final MotionEvent event) { if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - return AccessibleKeyboardViewProxy.getInstance().dispatchHoverEvent( - event, mKeyDetector); + return mAccessibilityDelegate.dispatchHoverEvent(event, mKeyDetector); } // Reflection doesn't support calling superclass methods. @@ -941,12 +954,17 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack final float descent = paint.descent(); final float textHeight = -paint.ascent() + descent; final float baseline = height / 2 + textHeight / 2; - paint.setColor(mLanguageOnSpacebarTextShadowColor); - paint.setAlpha(mLanguageOnSpacebarAnimAlpha); - canvas.drawText(language, width / 2, baseline - descent - 1, paint); + if (mLanguageOnSpacebarTextShadowRadius > 0.0f) { + paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0, + mLanguageOnSpacebarTextShadowColor); + } else { + paint.clearShadowLayer(); + } paint.setColor(mLanguageOnSpacebarTextColor); paint.setAlpha(mLanguageOnSpacebarAnimAlpha); canvas.drawText(language, width / 2, baseline - descent, paint); + paint.clearShadowLayer(); + paint.setTextScaleX(1.0f); } // Draw the spacebar icon at the bottom diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index dfe0df04c..2aeeed87f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -664,6 +664,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> { R.styleable.Keyboard_Case_isMultiLine, id.isMultiLine()); final boolean imeActionMatched = matchInteger(caseAttr, R.styleable.Keyboard_Case_imeAction, id.imeAction()); + final boolean isIconDefinedMatched = isIconDefined(caseAttr, + R.styleable.Keyboard_Case_isIconDefined, mParams.mIconsSet); final boolean localeCodeMatched = matchString(caseAttr, R.styleable.Keyboard_Case_localeCode, id.mLocale.toString()); final boolean languageCodeMatched = matchString(caseAttr, @@ -675,10 +677,11 @@ public class KeyboardBuilder<KP extends KeyboardParams> { && passwordInputMatched && clobberSettingsKeyMatched && supportsSwitchingToShortcutImeMatched && hasShortcutKeyMatched && languageSwitchKeyEnabledMatched && isMultiLineMatched && imeActionMatched - && localeCodeMatched && languageCodeMatched && countryCodeMatched; + && isIconDefinedMatched && localeCodeMatched && languageCodeMatched + && countryCodeMatched; if (DEBUG) { - startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, + startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, textAttr(caseAttr.getString( R.styleable.Keyboard_Case_keyboardLayoutSet), "keyboardLayoutSet"), textAttr(caseAttr.getString( @@ -704,6 +707,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> { "languageSwitchKeyEnabled"), booleanAttr(caseAttr, R.styleable.Keyboard_Case_isMultiLine, "isMultiLine"), + textAttr(caseAttr.getString(R.styleable.Keyboard_Case_isIconDefined), + "isIconDefined"), textAttr(caseAttr.getString(R.styleable.Keyboard_Case_localeCode), "localeCode"), textAttr(caseAttr.getString(R.styleable.Keyboard_Case_languageCode), @@ -755,6 +760,16 @@ public class KeyboardBuilder<KP extends KeyboardParams> { return false; } + private static boolean isIconDefined(final TypedArray a, final int index, + final KeyboardIconsSet iconsSet) { + if (!a.hasValue(index)) { + return true; + } + final String iconName = a.getString(index); + final int iconId = KeyboardIconsSet.getIconId(iconName); + return iconsSet.getIconDrawable(iconId) != null; + } + private boolean parseDefault(final XmlPullParser parser, final KeyboardRow row, final boolean skip) throws XmlPullParserException, IOException { if (DEBUG) startTag("<%s>", TAG_DEFAULT); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java index 6c9b5adc3..65d6a5633 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java @@ -42,7 +42,12 @@ public final class KeyboardIconsSet { public static final String NAME_SPACE_KEY = "space_key"; public static final String NAME_SPACE_KEY_FOR_NUMBER_LAYOUT = "space_key_for_number_layout"; public static final String NAME_ENTER_KEY = "enter_key"; + public static final String NAME_GO_KEY = "go_key"; public static final String NAME_SEARCH_KEY = "search_key"; + public static final String NAME_SEND_KEY = "send_key"; + public static final String NAME_NEXT_KEY = "next_key"; + public static final String NAME_DONE_KEY = "done_key"; + public static final String NAME_PREVIOUS_KEY = "previous_key"; public static final String NAME_TAB_KEY = "tab_key"; public static final String NANE_TAB_KEY_PREVIEW = "tab_key_preview"; public static final String NAME_SHORTCUT_KEY = "shortcut_key"; @@ -64,7 +69,12 @@ public final class KeyboardIconsSet { NAME_SETTINGS_KEY, R.styleable.Keyboard_iconSettingsKey, NAME_SPACE_KEY, R.styleable.Keyboard_iconSpaceKey, NAME_ENTER_KEY, R.styleable.Keyboard_iconEnterKey, + NAME_GO_KEY, R.styleable.Keyboard_iconGoKey, NAME_SEARCH_KEY, R.styleable.Keyboard_iconSearchKey, + NAME_SEND_KEY, R.styleable.Keyboard_iconSendKey, + NAME_NEXT_KEY, R.styleable.Keyboard_iconNextKey, + NAME_DONE_KEY, R.styleable.Keyboard_iconDoneKey, + NAME_PREVIOUS_KEY, R.styleable.Keyboard_iconPreviousKey, NAME_TAB_KEY, R.styleable.Keyboard_iconTabKey, NAME_SHORTCUT_KEY, R.styleable.Keyboard_iconShortcutKey, NAME_SPACE_KEY_FOR_NUMBER_LAYOUT, R.styleable.Keyboard_iconSpaceKeyForNumberLayout, diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java index 14fa76744..7e6181a4e 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java @@ -95,18 +95,18 @@ public final class KeyboardTextsTable { /* 5:23 */ "morekeys_c", /* 6:23 */ "double_quotes", /* 7:22 */ "morekeys_n", - /* 8:22 */ "single_quotes", - /* 9:21 */ "keylabel_to_alpha", + /* 8:22 */ "keylabel_to_alpha", + /* 9:22 */ "single_quotes", /* 10:20 */ "morekeys_s", /* 11:14 */ "morekeys_y", /* 12:13 */ "morekeys_d", /* 13:12 */ "morekeys_z", /* 14:10 */ "morekeys_t", /* 15:10 */ "morekeys_l", - /* 16: 9 */ "morekeys_g", - /* 17: 9 */ "single_angle_quotes", - /* 18: 9 */ "double_angle_quotes", - /* 19: 9 */ "keyspec_currency", + /* 16:10 */ "keyspec_currency", + /* 17: 9 */ "morekeys_g", + /* 18: 9 */ "single_angle_quotes", + /* 19: 9 */ "double_angle_quotes", /* 20: 8 */ "morekeys_r", /* 21: 6 */ "morekeys_k", /* 22: 6 */ "morekeys_cyrillic_ie", @@ -119,29 +119,29 @@ public final class KeyboardTextsTable { /* 29: 5 */ "keyspec_east_slavic_row2_11", /* 30: 5 */ "keyspec_east_slavic_row3_5", /* 31: 5 */ "morekeys_cyrillic_soft_sign", - /* 32: 4 */ "morekeys_nordic_row2_11", - /* 33: 4 */ "morekeys_punctuation", - /* 34: 4 */ "keyspec_symbols_1", - /* 35: 4 */ "keyspec_symbols_2", - /* 36: 4 */ "keyspec_symbols_3", - /* 37: 4 */ "keyspec_symbols_4", - /* 38: 4 */ "keyspec_symbols_5", - /* 39: 4 */ "keyspec_symbols_6", - /* 40: 4 */ "keyspec_symbols_7", - /* 41: 4 */ "keyspec_symbols_8", - /* 42: 4 */ "keyspec_symbols_9", - /* 43: 4 */ "keyspec_symbols_0", - /* 44: 4 */ "keylabel_to_symbol", - /* 45: 4 */ "additional_morekeys_symbols_1", - /* 46: 4 */ "additional_morekeys_symbols_2", - /* 47: 4 */ "additional_morekeys_symbols_3", - /* 48: 4 */ "additional_morekeys_symbols_4", - /* 49: 4 */ "additional_morekeys_symbols_5", - /* 50: 4 */ "additional_morekeys_symbols_6", - /* 51: 4 */ "additional_morekeys_symbols_7", - /* 52: 4 */ "additional_morekeys_symbols_8", - /* 53: 4 */ "additional_morekeys_symbols_9", - /* 54: 4 */ "additional_morekeys_symbols_0", + /* 32: 5 */ "keyspec_symbols_1", + /* 33: 5 */ "keyspec_symbols_2", + /* 34: 5 */ "keyspec_symbols_3", + /* 35: 5 */ "keyspec_symbols_4", + /* 36: 5 */ "keyspec_symbols_5", + /* 37: 5 */ "keyspec_symbols_6", + /* 38: 5 */ "keyspec_symbols_7", + /* 39: 5 */ "keyspec_symbols_8", + /* 40: 5 */ "keyspec_symbols_9", + /* 41: 5 */ "keyspec_symbols_0", + /* 42: 5 */ "keylabel_to_symbol", + /* 43: 5 */ "additional_morekeys_symbols_1", + /* 44: 5 */ "additional_morekeys_symbols_2", + /* 45: 5 */ "additional_morekeys_symbols_3", + /* 46: 5 */ "additional_morekeys_symbols_4", + /* 47: 5 */ "additional_morekeys_symbols_5", + /* 48: 5 */ "additional_morekeys_symbols_6", + /* 49: 5 */ "additional_morekeys_symbols_7", + /* 50: 5 */ "additional_morekeys_symbols_8", + /* 51: 5 */ "additional_morekeys_symbols_9", + /* 52: 5 */ "additional_morekeys_symbols_0", + /* 53: 4 */ "morekeys_nordic_row2_11", + /* 54: 4 */ "morekeys_punctuation", /* 55: 4 */ "keyspec_tablet_comma", /* 56: 3 */ "keyspec_swiss_row1_11", /* 57: 3 */ "keyspec_swiss_row2_10", @@ -266,19 +266,19 @@ public final class KeyboardTextsTable { /* ~ morekeys_c */ /* double_quotes */ "!text/double_lqm_rqm", /* morekeys_n */ EMPTY, - /* single_quotes */ "!text/single_lqm_rqm", // Label for "switch to alphabetic" key. /* keylabel_to_alpha */ "ABC", + /* single_quotes */ "!text/single_lqm_rqm", /* morekeys_s ~ */ - EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, - /* ~ morekeys_g */ + EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, + /* ~ morekeys_l */ + /* keyspec_currency */ "$", + /* morekeys_g */ EMPTY, /* single_angle_quotes */ "!text/single_laqm_raqm", /* double_angle_quotes */ "!text/double_laqm_raqm", - /* keyspec_currency */ "$", /* morekeys_r ~ */ - EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, - /* ~ morekeys_nordic_row2_11 */ - /* morekeys_punctuation */ "!autoColumnOrder!8,\\,,?,!,#,!text/keyspec_right_parenthesis,!text/keyspec_left_parenthesis,/,;,',@,:,-,\",+,\\%,&", + EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, + /* ~ morekeys_cyrillic_soft_sign */ /* keyspec_symbols_1 */ "1", /* keyspec_symbols_2 */ "2", /* keyspec_symbols_3 */ "3", @@ -292,8 +292,9 @@ public final class KeyboardTextsTable { // Label for "switch to symbols" key. /* keylabel_to_symbol */ "?123", /* additional_morekeys_symbols_1 ~ */ - EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, - /* ~ additional_morekeys_symbols_0 */ + EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, + /* ~ morekeys_nordic_row2_11 */ + /* morekeys_punctuation */ "!autoColumnOrder!8,\\,,?,!,#,!text/keyspec_right_parenthesis,!text/keyspec_left_parenthesis,/,;,',@,:,-,\",+,\\%,&", /* keyspec_tablet_comma */ ",", /* keyspec_swiss_row1_11 ~ */ EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, @@ -515,7 +516,7 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u00F1,\u0144", - /* single_quotes ~ */ + /* keylabel_to_alpha ~ */ null, null, null, /* ~ morekeys_s */ // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE @@ -526,18 +527,18 @@ public final class KeyboardTextsTable { /* Locale ar: Arabic */ private static final String[] TEXTS_ar = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0623: "أ" ARABIC LETTER ALEF WITH HAMZA ABOVE // U+200C: ZERO WIDTH NON-JOINER // U+0628: "ب" ARABIC LETTER BEH // U+062C: "ج" ARABIC LETTER JEEM /* keylabel_to_alpha */ "\u0623\u200C\u0628\u200C\u062C", - /* morekeys_s ~ */ + /* single_quotes ~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, - /* ~ morekeys_punctuation */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_cyrillic_soft_sign */ // U+0661: "١" ARABIC-INDIC DIGIT ONE /* keyspec_symbols_1 */ "\u0661", // U+0662: "٢" ARABIC-INDIC DIGIT TWO @@ -573,6 +574,8 @@ public final class KeyboardTextsTable { // U+066B: "٫" ARABIC DECIMAL SEPARATOR // U+066C: "٬" ARABIC THOUSANDS SEPARATOR /* additional_morekeys_symbols_0 */ "0,\u066B,\u066C", + /* morekeys_nordic_row2_11 */ null, + /* morekeys_punctuation */ null, // U+061F: "؟" ARABIC QUESTION MARK // U+060C: "،" ARABIC COMMA // U+061B: "؛" ARABIC SEMICOLON @@ -688,15 +691,15 @@ public final class KeyboardTextsTable { /* morekeys_c */ "\u00E7,\u0107,\u010D", /* double_quotes ~ */ null, null, null, null, - /* ~ keylabel_to_alpha */ + /* ~ single_quotes */ // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE // U+0161: "š" LATIN SMALL LETTER S WITH CARON /* morekeys_s */ "\u015F,\u00DF,\u015B,\u0161", /* morekeys_y ~ */ - null, null, null, null, null, - /* ~ morekeys_l */ + null, null, null, null, null, null, + /* ~ keyspec_currency */ // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE /* morekeys_g */ "\u011F", }; @@ -708,12 +711,12 @@ public final class KeyboardTextsTable { /* ~ morekeys_c */ /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_lqm", // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE // U+0412: "В" CYRILLIC CAPITAL LETTER VE /* keylabel_to_alpha */ "\u0410\u0411\u0412", + /* single_quotes */ "!text/single_9qm_lqm", /* morekeys_s ~ */ null, null, null, null, null, null, null, null, null, null, null, null, /* ~ morekeys_k */ @@ -742,7 +745,6 @@ public final class KeyboardTextsTable { // single_quotes of Bulgarian is default single_quotes_right_left. /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ null, // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE @@ -802,23 +804,23 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u00F1,\u0144", - /* single_quotes ~ */ + /* keylabel_to_alpha ~ */ null, null, null, null, null, null, null, /* ~ morekeys_t */ // U+00B7: "·" MIDDLE DOT // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE /* morekeys_l */ "l\u00B7l,\u0142", - /* morekeys_g ~ */ + /* keyspec_currency ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, + null, null, null, null, null, null, null, null, /* ~ morekeys_nordic_row2_11 */ // U+00B7: "·" MIDDLE DOT /* morekeys_punctuation */ "!autoColumnOrder!9,\\,,?,!,\u00B7,#,),(,/,;,',@,:,-,\",+,\\%,&", - /* keyspec_symbols_1 ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + /* keyspec_tablet_comma ~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, /* ~ keyspec_south_slavic_row3_8 */ /* morekeys_tablet_punctuation */ "!autoColumnOrder!8,\\,,',\u00B7,#,),(,/,;,@,:,-,\",+,\\%,&", // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA @@ -877,8 +879,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u0148,\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE @@ -894,11 +896,11 @@ public final class KeyboardTextsTable { /* morekeys_z */ "\u017E,\u017A,\u017C", // U+0165: "ť" LATIN SMALL LETTER T WITH CARON /* morekeys_t */ "\u0165", - /* morekeys_l */ null, - /* morekeys_g */ null, + /* morekeys_l ~ */ + null, null, null, + /* ~ morekeys_g */ /* single_angle_quotes */ "!text/single_raqm_laqm", /* double_angle_quotes */ "!text/double_raqm_laqm", - /* keyspec_currency */ null, // U+0159: "ř" LATIN SMALL LETTER R WITH CARON /* morekeys_r */ "\u0159", }; @@ -936,8 +938,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE // U+0161: "š" LATIN SMALL LETTER S WITH CARON @@ -951,11 +953,12 @@ public final class KeyboardTextsTable { /* morekeys_t */ null, // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE /* morekeys_l */ "\u0142", + /* keyspec_currency */ null, /* morekeys_g */ null, /* single_angle_quotes */ "!text/single_raqm_laqm", /* double_angle_quotes */ "!text/double_raqm_laqm", - /* keyspec_currency ~ */ - null, null, null, null, + /* morekeys_r ~ */ + null, null, null, /* ~ morekeys_cyrillic_ie */ // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE /* keyspec_nordic_row1_11 */ "\u00E5", @@ -966,8 +969,9 @@ public final class KeyboardTextsTable { // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS /* morekeys_nordic_row2_10 */ "\u00E4", /* keyspec_east_slavic_row1_9 ~ */ - null, null, null, null, null, - /* ~ morekeys_cyrillic_soft_sign */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, + /* ~ additional_morekeys_symbols_0 */ // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS /* morekeys_nordic_row2_11 */ "\u00F6", }; @@ -1010,21 +1014,21 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE // U+0161: "š" LATIN SMALL LETTER S WITH CARON /* morekeys_s */ "\u00DF,\u015B,\u0161", /* morekeys_y ~ */ - null, null, null, null, null, null, + null, null, null, null, null, null, null, /* ~ morekeys_g */ /* single_angle_quotes */ "!text/single_raqm_laqm", /* double_angle_quotes */ "!text/double_raqm_laqm", - /* keyspec_currency ~ */ + /* morekeys_r ~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, + null, null, null, null, null, null, /* ~ keyspec_tablet_comma */ // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS /* keyspec_swiss_row1_11 */ "\u00FC", @@ -1043,8 +1047,8 @@ public final class KeyboardTextsTable { /* Locale el: Greek */ private static final String[] TEXTS_el = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0391: "Α" GREEK CAPITAL LETTER ALPHA // U+0392: "Β" GREEK CAPITAL LETTER BETA @@ -1063,40 +1067,40 @@ public final class KeyboardTextsTable { // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON /* morekeys_a */ "\u00E0,\u00E1,\u00E2,\u00E4,\u00E6,\u00E3,\u00E5,\u0101", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE // U+0153: "œ" LATIN SMALL LIGATURE OE // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - /* morekeys_o */ "\u00F4,\u00F6,\u00F2,\u00F3,\u0153,\u00F8,\u014D,\u00F5", + /* morekeys_o */ "\u00F3,\u00F4,\u00F6,\u00F2,\u0153,\u00F8,\u014D,\u00F5", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE - // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON - /* morekeys_u */ "\u00FB,\u00FC,\u00F9,\u00FA,\u016B", - // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + /* morekeys_u */ "\u00FA,\u00FB,\u00FC,\u00F9,\u016B", // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON - /* morekeys_e */ "\u00E8,\u00E9,\u00EA,\u00EB,\u0113", + /* morekeys_e */ "\u00E9,\u00E8,\u00EA,\u00EB,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS - // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE - /* morekeys_i */ "\u00EE,\u00EF,\u00ED,\u012B,\u00EC", + /* morekeys_i */ "\u00ED,\u00EE,\u00EF,\u012B,\u00EC", // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA /* morekeys_c */ "\u00E7", /* double_quotes */ null, // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE /* morekeys_n */ "\u00F1", - /* single_quotes */ null, /* keylabel_to_alpha */ null, + /* single_quotes */ null, // U+00DF: "ß" LATIN SMALL LETTER SHARP S /* morekeys_s */ "\u00DF", }; @@ -1169,8 +1173,8 @@ public final class KeyboardTextsTable { // U+0149: "ʼn" LATIN SMALL LETTER N PRECEDED BY APOSTROPHE // U+014B: "ŋ" LATIN SMALL LETTER ENG /* morekeys_n */ "\u00F1,\u0144,\u0146,\u0148,\u0149,\u014B", - /* single_quotes */ null, /* keylabel_to_alpha */ null, + /* single_quotes */ null, // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE @@ -1201,13 +1205,13 @@ public final class KeyboardTextsTable { // U+0140: "ŀ" LATIN SMALL LETTER L WITH MIDDLE DOT // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE /* morekeys_l */ "\u013A,\u013C,\u013E,\u0140,\u0142", + /* keyspec_currency */ null, // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE // U+0121: "ġ" LATIN SMALL LETTER G WITH DOT ABOVE // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA /* morekeys_g */ "\u011F,\u0121,\u0123", - /* single_angle_quotes ~ */ - null, null, null, - /* ~ keyspec_currency */ + /* single_angle_quotes */ null, + /* double_angle_quotes */ null, // U+0159: "ř" LATIN SMALL LETTER R WITH CARON // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA @@ -1301,9 +1305,11 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u00F1,\u0144", - /* single_quotes ~ */ + /* keylabel_to_alpha ~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, /* ~ morekeys_nordic_row2_11 */ // U+00A1: "¡" INVERTED EXCLAMATION MARK // U+00BF: "¿" INVERTED QUESTION MARK @@ -1366,8 +1372,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u0146,\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE @@ -1390,12 +1396,12 @@ public final class KeyboardTextsTable { // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON /* morekeys_l */ "\u013C,\u0142,\u013A,\u013E", + /* keyspec_currency */ null, // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE /* morekeys_g */ "\u0123,\u011F", - /* single_angle_quotes ~ */ - null, null, null, - /* ~ keyspec_currency */ + /* single_angle_quotes */ null, + /* double_angle_quotes */ null, // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA // U+0159: "ř" LATIN SMALL LETTER R WITH CARON // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE @@ -1470,22 +1476,22 @@ public final class KeyboardTextsTable { /* Locale fa: Persian */ private static final String[] TEXTS_fa = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0627: "ا" ARABIC LETTER ALEF // U+200C: ZERO WIDTH NON-JOINER // U+0628: "ب" ARABIC LETTER BEH // U+067E: "پ" ARABIC LETTER PEH /* keylabel_to_alpha */ "\u0627\u200C\u0628\u200C\u067E", - /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ double_angle_quotes */ + /* single_quotes ~ */ + null, null, null, null, null, null, null, + /* ~ morekeys_l */ // U+FDFC: "﷼" RIAL SIGN /* keyspec_currency */ "\uFDFC", - /* morekeys_r ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, null, null, - /* ~ morekeys_punctuation */ + /* morekeys_g ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + /* ~ morekeys_cyrillic_soft_sign */ // U+06F1: "۱" EXTENDED ARABIC-INDIC DIGIT ONE /* keyspec_symbols_1 */ "\u06F1", // U+06F2: "۲" EXTENDED ARABIC-INDIC DIGIT TWO @@ -1521,6 +1527,8 @@ public final class KeyboardTextsTable { // U+066B: "٫" ARABIC DECIMAL SEPARATOR // U+066C: "٬" ARABIC THOUSANDS SEPARATOR /* additional_morekeys_symbols_0 */ "0,\u066B,\u066C", + /* morekeys_nordic_row2_11 */ null, + /* morekeys_punctuation */ null, // U+060C: "،" ARABIC COMMA // U+061B: "؛" ARABIC SEMICOLON // U+061F: "؟" ARABIC QUESTION MARK @@ -1629,7 +1637,7 @@ public final class KeyboardTextsTable { /* morekeys_u */ "\u00FC", /* morekeys_e ~ */ null, null, null, null, null, null, null, - /* ~ keylabel_to_alpha */ + /* ~ single_quotes */ // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE @@ -1652,8 +1660,9 @@ public final class KeyboardTextsTable { // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE /* morekeys_nordic_row2_10 */ "\u00F8", /* keyspec_east_slavic_row1_9 ~ */ - null, null, null, null, null, - /* ~ morekeys_cyrillic_soft_sign */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, + /* ~ additional_morekeys_symbols_0 */ // U+00E6: "æ" LATIN SMALL LETTER AE /* morekeys_nordic_row2_11 */ "\u00E6", }; @@ -1786,21 +1795,21 @@ public final class KeyboardTextsTable { /* Locale hi: Hindi */ private static final String[] TEXTS_hi = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0915: "क" DEVANAGARI LETTER KA // U+0916: "ख" DEVANAGARI LETTER KHA // U+0917: "ग" DEVANAGARI LETTER GA /* keylabel_to_alpha */ "\u0915\u0916\u0917", - /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ double_angle_quotes */ + /* single_quotes ~ */ + null, null, null, null, null, null, null, + /* ~ morekeys_l */ // U+20B9: "₹" INDIAN RUPEE SIGN /* keyspec_currency */ "\u20B9", - /* morekeys_r ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, null, null, - /* ~ morekeys_punctuation */ + /* morekeys_g ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + /* ~ morekeys_cyrillic_soft_sign */ // U+0967: "१" DEVANAGARI DIGIT ONE /* keyspec_symbols_1 */ "\u0967", // U+0968: "२" DEVANAGARI DIGIT TWO @@ -1848,8 +1857,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_rqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_rqm", // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE // U+00DF: "ß" LATIN SMALL LETTER SHARP S @@ -1862,7 +1871,7 @@ public final class KeyboardTextsTable { // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE /* morekeys_z */ "\u017E,\u017A,\u017C", /* morekeys_t ~ */ - null, null, null, + null, null, null, null, /* ~ morekeys_g */ /* single_angle_quotes */ "!text/single_raqm_laqm", /* double_angle_quotes */ "!text/double_raqm_laqm", @@ -1914,8 +1923,9 @@ public final class KeyboardTextsTable { /* morekeys_c */ null, /* double_quotes */ "!text/double_9qm_rqm", /* morekeys_n */ null, + /* keylabel_to_alpha */ null, /* single_quotes */ "!text/single_9qm_rqm", - /* keylabel_to_alpha ~ */ + /* morekeys_s ~ */ null, null, null, null, null, null, null, null, /* ~ morekeys_g */ /* single_angle_quotes */ "!text/single_raqm_laqm", @@ -1925,16 +1935,17 @@ public final class KeyboardTextsTable { /* Locale hy_AM: Armenian (Armenia) */ private static final String[] TEXTS_hy_AM = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0531: "Ա" ARMENIAN CAPITAL LETTER AYB // U+0532: "Բ" ARMENIAN CAPITAL LETTER BEN // U+0533: "Գ" ARMENIAN CAPITAL LETTER GIM /* keylabel_to_alpha */ "\u0531\u0532\u0533", - /* morekeys_s ~ */ + /* single_quotes ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, /* ~ morekeys_nordic_row2_11 */ // U+055E: "՞" ARMENIAN QUESTION MARK // U+055C: "՜" ARMENIAN EXCLAMATION MARK @@ -1947,10 +1958,6 @@ public final class KeyboardTextsTable { // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK // U+055F: "՟" ARMENIAN ABBREVIATION MARK /* morekeys_punctuation */ "!autoColumnOrder!8,\\,,\u055E,\u055C,.,\u055A,\u0559,?,!,\u055D,\u055B,\u058A,\u00BB,\u00AB,\u055F,;,:", - /* keyspec_symbols_1 ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, - /* ~ additional_morekeys_symbols_0 */ // U+058F: "֏" ARMENIAN DRAM SIGN // TODO: Enable this when we have glyph for the following letter // <string name="keyspec_currency">֏</string> @@ -2026,8 +2033,8 @@ public final class KeyboardTextsTable { /* morekeys_c */ null, /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", /* morekeys_s */ null, // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS @@ -2109,21 +2116,21 @@ public final class KeyboardTextsTable { /* ~ morekeys_c */ /* double_quotes */ "!text/double_rqm_9qm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_rqm_9qm", // Label for "switch to alphabetic" key. // U+05D0: "א" HEBREW LETTER ALEF // U+05D1: "ב" HEBREW LETTER BET // U+05D2: "ג" HEBREW LETTER GIMEL /* keylabel_to_alpha */ "\u05D0\u05D1\u05D2", + /* single_quotes */ "!text/single_rqm_9qm", /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ double_angle_quotes */ + null, null, null, null, null, null, + /* ~ morekeys_l */ // U+20AA: "₪" NEW SHEQEL SIGN /* keyspec_currency */ "\u20AA", - /* morekeys_r ~ */ + /* morekeys_g ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, /* ~ morekeys_swiss_row2_11 */ // U+2605: "★" BLACK STAR /* morekeys_star */ "\u2605", @@ -2166,26 +2173,26 @@ public final class KeyboardTextsTable { /* ~ morekeys_c */ /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_lqm", // Label for "switch to alphabetic" key. // U+10D0: "ა" GEORGIAN LETTER AN // U+10D1: "ბ" GEORGIAN LETTER BAN // U+10D2: "გ" GEORGIAN LETTER GAN /* keylabel_to_alpha */ "\u10D0\u10D1\u10D2", + /* single_quotes */ "!text/single_9qm_lqm", }; /* Locale kk: Kazakh */ private static final String[] TEXTS_kk = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE // U+0412: "В" CYRILLIC CAPITAL LETTER VE /* keylabel_to_alpha */ "\u0410\u0411\u0412", - /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, + /* single_quotes ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, /* ~ morekeys_k */ // U+0451: "ё" CYRILLIC SMALL LETTER IO /* morekeys_cyrillic_ie */ "\u0451", @@ -2202,7 +2209,7 @@ public final class KeyboardTextsTable { /* keyspec_east_slavic_row3_5 */ "\u0438", // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN /* morekeys_cyrillic_soft_sign */ "\u044A", - /* morekeys_nordic_row2_11 ~ */ + /* keyspec_symbols_1 ~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, @@ -2234,14 +2241,14 @@ public final class KeyboardTextsTable { /* Locale km_KH: Khmer (Cambodia) */ private static final String[] TEXTS_km_KH = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+1780: "ក" KHMER LETTER KA // U+1781: "ខ" KHMER LETTER KHA // U+1782: "គ" KHMER LETTER KO /* keylabel_to_alpha */ "\u1780\u1781\u1782", - /* morekeys_s ~ */ + /* single_quotes ~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, @@ -2249,7 +2256,7 @@ public final class KeyboardTextsTable { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, + null, null, null, null, null, null, null, /* ~ morekeys_cyrillic_a */ // U+17DB: "៛" KHMER CURRENCY SYMBOL RIEL /* morekeys_currency_dollar */ "\u17DB,\u00A2,\u00A3,\u20AC,\u00A5,\u20B1", @@ -2258,15 +2265,15 @@ public final class KeyboardTextsTable { /* Locale ky: Kirghiz */ private static final String[] TEXTS_ky = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE // U+0412: "В" CYRILLIC CAPITAL LETTER VE /* keylabel_to_alpha */ "\u0410\u0411\u0412", - /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, + /* single_quotes ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, /* ~ morekeys_k */ // U+0451: "ё" CYRILLIC SMALL LETTER IO /* morekeys_cyrillic_ie */ "\u0451", @@ -2283,7 +2290,7 @@ public final class KeyboardTextsTable { /* keyspec_east_slavic_row3_5 */ "\u0438", // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN /* morekeys_cyrillic_soft_sign */ "\u044A", - /* morekeys_nordic_row2_11 ~ */ + /* keyspec_symbols_1 ~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, @@ -2301,16 +2308,16 @@ public final class KeyboardTextsTable { /* Locale lo_LA: Lao (Laos) */ private static final String[] TEXTS_lo_LA = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0E81: "ກ" LAO LETTER KO // U+0E82: "ຂ" LAO LETTER KHO SUNG // U+0E84: "ຄ" LAO LETTER KHO TAM /* keylabel_to_alpha */ "\u0E81\u0E82\u0E84", - /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ double_angle_quotes */ + /* single_quotes ~ */ + null, null, null, null, null, null, null, + /* ~ morekeys_l */ // U+20AD: "₭" KIP SIGN /* keyspec_currency */ "\u20AD", }; @@ -2372,8 +2379,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u0146,\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE @@ -2396,12 +2403,12 @@ public final class KeyboardTextsTable { // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON /* morekeys_l */ "\u013C,\u0142,\u013A,\u013E", + /* keyspec_currency */ null, // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE /* morekeys_g */ "\u0123,\u011F", - /* single_angle_quotes ~ */ - null, null, null, - /* ~ keyspec_currency */ + /* single_angle_quotes */ null, + /* double_angle_quotes */ null, // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA // U+0159: "ř" LATIN SMALL LETTER R WITH CARON // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE @@ -2466,8 +2473,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u0146,\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE @@ -2490,12 +2497,12 @@ public final class KeyboardTextsTable { // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON /* morekeys_l */ "\u013C,\u0142,\u013A,\u013E", + /* keyspec_currency */ null, // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE /* morekeys_g */ "\u0123,\u011F", - /* single_angle_quotes ~ */ - null, null, null, - /* ~ keyspec_currency */ + /* single_angle_quotes */ null, + /* double_angle_quotes */ null, // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA // U+0159: "ř" LATIN SMALL LETTER R WITH CARON // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE @@ -2511,12 +2518,12 @@ public final class KeyboardTextsTable { /* ~ morekeys_c */ /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_lqm", // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE // U+0412: "В" CYRILLIC CAPITAL LETTER VE /* keylabel_to_alpha */ "\u0410\u0411\u0412", + /* single_quotes */ "!text/single_9qm_lqm", /* morekeys_s ~ */ null, null, null, null, null, null, null, null, null, null, null, null, /* ~ morekeys_k */ @@ -2544,39 +2551,88 @@ public final class KeyboardTextsTable { /* Locale mn_MN: Mongolian (Mongolia) */ private static final String[] TEXTS_mn_MN = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE // U+0412: "В" CYRILLIC CAPITAL LETTER VE /* keylabel_to_alpha */ "\u0410\u0411\u0412", - /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ double_angle_quotes */ + /* single_quotes ~ */ + null, null, null, null, null, null, null, + /* ~ morekeys_l */ // U+20AE: "₮" TUGRIK SIGN /* keyspec_currency */ "\u20AE", }; + /* Locale mr_IN: Marathi (India) */ + private static final String[] TEXTS_mr_IN = { + /* morekeys_a ~ */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ + // Label for "switch to alphabetic" key. + // U+0915: "क" DEVANAGARI LETTER KA + // U+0916: "ख" DEVANAGARI LETTER KHA + // U+0917: "ग" DEVANAGARI LETTER GA + /* keylabel_to_alpha */ "\u0915\u0916\u0917", + /* single_quotes ~ */ + null, null, null, null, null, null, null, + /* ~ morekeys_l */ + // U+20B9: "₹" INDIAN RUPEE SIGN + /* keyspec_currency */ "\u20B9", + /* morekeys_g ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + /* ~ morekeys_cyrillic_soft_sign */ + // U+0967: "१" DEVANAGARI DIGIT ONE + /* keyspec_symbols_1 */ "\u0967", + // U+0968: "२" DEVANAGARI DIGIT TWO + /* keyspec_symbols_2 */ "\u0968", + // U+0969: "३" DEVANAGARI DIGIT THREE + /* keyspec_symbols_3 */ "\u0969", + // U+096A: "४" DEVANAGARI DIGIT FOUR + /* keyspec_symbols_4 */ "\u096A", + // U+096B: "५" DEVANAGARI DIGIT FIVE + /* keyspec_symbols_5 */ "\u096B", + // U+096C: "६" DEVANAGARI DIGIT SIX + /* keyspec_symbols_6 */ "\u096C", + // U+096D: "७" DEVANAGARI DIGIT SEVEN + /* keyspec_symbols_7 */ "\u096D", + // U+096E: "८" DEVANAGARI DIGIT EIGHT + /* keyspec_symbols_8 */ "\u096E", + // U+096F: "९" DEVANAGARI DIGIT NINE + /* keyspec_symbols_9 */ "\u096F", + // U+0966: "०" DEVANAGARI DIGIT ZERO + /* keyspec_symbols_0 */ "\u0966", + // Label for "switch to symbols" key. + /* keylabel_to_symbol */ "?\u0967\u0968\u0969", + /* additional_morekeys_symbols_1 */ "1", + /* additional_morekeys_symbols_2 */ "2", + /* additional_morekeys_symbols_3 */ "3", + /* additional_morekeys_symbols_4 */ "4", + /* additional_morekeys_symbols_5 */ "5", + /* additional_morekeys_symbols_6 */ "6", + /* additional_morekeys_symbols_7 */ "7", + /* additional_morekeys_symbols_8 */ "8", + /* additional_morekeys_symbols_9 */ "9", + /* additional_morekeys_symbols_0 */ "0", + }; + /* Locale my_MM: Burmese (Myanmar) */ private static final String[] TEXTS_my_MM = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+1000: "က" MYANMAR LETTER KA // U+1001: "ခ" MYANMAR LETTER KHA // U+1002: "ဂ" MYANMAR LETTER GA /* keylabel_to_alpha */ "\u1000\u1001\u1002", - /* morekeys_s ~ */ + /* single_quotes ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, /* ~ morekeys_nordic_row2_11 */ /* morekeys_punctuation */ "!autoColumnOrder!9,\u104A,.,?,!,#,),(,/,;,...,',@,:,-,\",+,\\%,&", - /* keyspec_symbols_1 ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, - /* ~ additional_morekeys_symbols_0 */ // U+104A: "၊" MYANMAR SIGN LITTLE SECTION // U+104B: "။" MYANMAR SIGN SECTION /* keyspec_tablet_comma */ "\u104A", @@ -2633,9 +2689,10 @@ public final class KeyboardTextsTable { /* morekeys_c */ null, /* double_quotes */ "!text/double_9qm_rqm", /* morekeys_n */ null, + /* keylabel_to_alpha */ null, /* single_quotes */ "!text/single_9qm_rqm", - /* keylabel_to_alpha ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, null, null, + /* morekeys_s ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, /* ~ morekeys_cyrillic_ie */ // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE /* keyspec_nordic_row1_11 */ "\u00E5", @@ -2646,8 +2703,9 @@ public final class KeyboardTextsTable { // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS /* morekeys_nordic_row2_10 */ "\u00F6", /* keyspec_east_slavic_row1_9 ~ */ - null, null, null, null, null, - /* ~ morekeys_cyrillic_soft_sign */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, + /* ~ additional_morekeys_symbols_0 */ // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS /* morekeys_nordic_row2_11 */ "\u00E4", }; @@ -2655,21 +2713,21 @@ public final class KeyboardTextsTable { /* Locale ne_NP: Nepali (Nepal) */ private static final String[] TEXTS_ne_NP = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0915: "क" DEVANAGARI LETTER KA // U+0916: "ख" DEVANAGARI LETTER KHA // U+0917: "ग" DEVANAGARI LETTER GA /* keylabel_to_alpha */ "\u0915\u0916\u0917", - /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ double_angle_quotes */ + /* single_quotes ~ */ + null, null, null, null, null, null, null, + /* ~ morekeys_l */ // U+0930/U+0941/U+002E "रु." NEPALESE RUPEE SIGN /* keyspec_currency */ "\u0930\u0941.", - /* morekeys_r ~ */ - null, null, null, null, null, null, null, null, null, null, null, null, null, null, - /* ~ morekeys_punctuation */ + /* morekeys_g ~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + /* ~ morekeys_cyrillic_soft_sign */ // U+0967: "१" DEVANAGARI DIGIT ONE /* keyspec_symbols_1 */ "\u0967", // U+0968: "२" DEVANAGARI DIGIT TWO @@ -2751,8 +2809,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_rqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_rqm", /* morekeys_s */ null, // U+0133: "ij" LATIN SMALL LIGATURE IJ /* morekeys_y */ "\u0133", @@ -2797,8 +2855,8 @@ public final class KeyboardTextsTable { // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE /* morekeys_n */ "\u0144,\u00F1", - /* single_quotes */ "!text/single_9qm_rqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_rqm", // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+0161: "š" LATIN SMALL LETTER S WITH CARON @@ -2900,8 +2958,8 @@ public final class KeyboardTextsTable { /* morekeys_c */ null, /* double_quotes */ "!text/double_9qm_rqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_rqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_rqm", // U+0219: "ș" LATIN SMALL LETTER S WITH COMMA BELOW // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE @@ -2921,12 +2979,12 @@ public final class KeyboardTextsTable { /* ~ morekeys_c */ /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_lqm", // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE // U+0412: "В" CYRILLIC CAPITAL LETTER VE /* keylabel_to_alpha */ "\u0410\u0411\u0412", + /* single_quotes */ "!text/single_9qm_lqm", /* morekeys_s ~ */ null, null, null, null, null, null, null, null, null, null, null, null, /* ~ morekeys_k */ @@ -3004,8 +3062,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE /* morekeys_n */ "\u0148,\u0146,\u00F1,\u0144", - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE @@ -3028,12 +3086,12 @@ public final class KeyboardTextsTable { // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE /* morekeys_l */ "\u013E,\u013A,\u013C,\u0142", + /* keyspec_currency */ null, // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE /* morekeys_g */ "\u0123,\u011F", /* single_angle_quotes */ "!text/single_raqm_laqm", /* double_angle_quotes */ "!text/double_raqm_laqm", - /* keyspec_currency */ null, // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE // U+0159: "ř" LATIN SMALL LETTER R WITH CARON // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA @@ -3052,8 +3110,8 @@ public final class KeyboardTextsTable { /* morekeys_c */ "\u010D,\u0107", /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_lqm", /* keylabel_to_alpha */ null, + /* single_quotes */ "!text/single_9qm_lqm", // U+0161: "š" LATIN SMALL LETTER S WITH CARON /* morekeys_s */ "\u0161", /* morekeys_y */ null, @@ -3062,7 +3120,7 @@ public final class KeyboardTextsTable { // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON /* morekeys_z */ "\u017E", /* morekeys_t ~ */ - null, null, null, + null, null, null, null, /* ~ morekeys_g */ /* single_angle_quotes */ "!text/single_raqm_laqm", /* double_angle_quotes */ "!text/double_raqm_laqm", @@ -3075,21 +3133,20 @@ public final class KeyboardTextsTable { /* ~ morekeys_c */ /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_lqm", // END: More keys definitions for Serbian (Cyrillic) // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE // U+0412: "В" CYRILLIC CAPITAL LETTER VE /* keylabel_to_alpha */ "\u0410\u0411\u0412", + /* single_quotes */ "!text/single_9qm_lqm", /* morekeys_s ~ */ - null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, /* ~ morekeys_g */ /* single_angle_quotes */ "!text/single_raqm_laqm", /* double_angle_quotes */ "!text/double_raqm_laqm", - /* keyspec_currency ~ */ - null, null, null, - /* ~ morekeys_k */ + /* morekeys_r */ null, + /* morekeys_k */ null, // U+0450: "ѐ" CYRILLIC SMALL LETTER IE WITH GRAVE /* morekeys_cyrillic_ie */ "\u0450", /* keyspec_nordic_row1_11 ~ */ @@ -3169,8 +3226,8 @@ public final class KeyboardTextsTable { // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE // U+0148: "ň" LATIN SMALL LETTER N WITH CARON /* morekeys_n */ "\u0144,\u00F1,\u0148", - /* single_quotes */ null, /* keylabel_to_alpha */ null, + /* single_quotes */ null, // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE // U+0161: "š" LATIN SMALL LETTER S WITH CARON // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA @@ -3191,10 +3248,10 @@ public final class KeyboardTextsTable { /* morekeys_t */ "\u0165,\u00FE", // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE /* morekeys_l */ "\u0142", + /* keyspec_currency */ null, /* morekeys_g */ null, /* single_angle_quotes */ "!text/single_raqm_laqm", /* double_angle_quotes */ "!text/double_raqm_laqm", - /* keyspec_currency */ null, // U+0159: "ř" LATIN SMALL LETTER R WITH CARON /* morekeys_r */ "\u0159", /* morekeys_k */ null, @@ -3209,8 +3266,9 @@ public final class KeyboardTextsTable { // U+0153: "œ" LATIN SMALL LIGATURE OE /* morekeys_nordic_row2_10 */ "\u00F8,\u0153", /* keyspec_east_slavic_row1_9 ~ */ - null, null, null, null, null, - /* ~ morekeys_cyrillic_soft_sign */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, + /* ~ additional_morekeys_symbols_0 */ // U+00E6: "æ" LATIN SMALL LETTER AE /* morekeys_nordic_row2_11 */ "\u00E6", }; @@ -3259,29 +3317,29 @@ public final class KeyboardTextsTable { /* double_quotes */ null, // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE /* morekeys_n */ "\u00F1", - /* single_quotes */ null, /* keylabel_to_alpha */ null, + /* single_quotes */ null, // U+00DF: "ß" LATIN SMALL LETTER SHARP S /* morekeys_s */ "\u00DF", /* morekeys_y ~ */ - null, null, null, null, null, - /* ~ morekeys_l */ + null, null, null, null, null, null, + /* ~ keyspec_currency */ /* morekeys_g */ "g\'", }; /* Locale th: Thai */ private static final String[] TEXTS_th = { /* morekeys_a ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ single_quotes */ + null, null, null, null, null, null, null, null, + /* ~ morekeys_n */ // Label for "switch to alphabetic" key. // U+0E01: "ก" THAI CHARACTER KO KAI // U+0E02: "ข" THAI CHARACTER KHO KHAI // U+0E04: "ค" THAI CHARACTER KHO KHWAI /* keylabel_to_alpha */ "\u0E01\u0E02\u0E04", - /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ double_angle_quotes */ + /* single_quotes ~ */ + null, null, null, null, null, null, null, + /* ~ morekeys_l */ // U+0E3F: "฿" THAI CURRENCY SYMBOL BAHT /* keyspec_currency */ "\u0E3F", }; @@ -3374,15 +3432,15 @@ public final class KeyboardTextsTable { /* morekeys_c */ "\u00E7,\u0107,\u010D", /* double_quotes ~ */ null, null, null, null, - /* ~ keylabel_to_alpha */ + /* ~ single_quotes */ // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE // U+0161: "š" LATIN SMALL LETTER S WITH CARON /* morekeys_s */ "\u015F,\u00DF,\u015B,\u0161", /* morekeys_y ~ */ - null, null, null, null, null, - /* ~ morekeys_l */ + null, null, null, null, null, null, + /* ~ keyspec_currency */ // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE /* morekeys_g */ "\u011F", }; @@ -3394,19 +3452,19 @@ public final class KeyboardTextsTable { /* ~ morekeys_c */ /* double_quotes */ "!text/double_9qm_lqm", /* morekeys_n */ null, - /* single_quotes */ "!text/single_9qm_lqm", // Label for "switch to alphabetic" key. // U+0410: "А" CYRILLIC CAPITAL LETTER A // U+0411: "Б" CYRILLIC CAPITAL LETTER BE // U+0412: "В" CYRILLIC CAPITAL LETTER VE /* keylabel_to_alpha */ "\u0410\u0411\u0412", + /* single_quotes */ "!text/single_9qm_lqm", /* morekeys_s ~ */ - null, null, null, null, null, null, null, null, null, - /* ~ double_angle_quotes */ + null, null, null, null, null, null, + /* ~ morekeys_l */ // U+20B4: "₴" HRYVNIA SIGN /* keyspec_currency */ "\u20B4", - /* morekeys_r ~ */ - null, null, null, null, null, null, null, + /* morekeys_g ~ */ + null, null, null, null, null, null, null, null, null, null, /* ~ morekeys_nordic_row2_10 */ // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA /* keyspec_east_slavic_row1_9 */ "\u0449", @@ -3418,7 +3476,7 @@ public final class KeyboardTextsTable { /* keyspec_east_slavic_row3_5 */ "\u0438", // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN /* morekeys_cyrillic_soft_sign */ "\u044A", - /* morekeys_nordic_row2_11 ~ */ + /* keyspec_symbols_1 ~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, @@ -3512,8 +3570,8 @@ public final class KeyboardTextsTable { // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE /* morekeys_d */ "\u0111", /* morekeys_z ~ */ - null, null, null, null, null, null, - /* ~ double_angle_quotes */ + null, null, null, + /* ~ morekeys_l */ // U+20AB: "₫" DONG SIGN /* keyspec_currency */ "\u20AB", }; @@ -3530,40 +3588,40 @@ public final class KeyboardTextsTable { // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON /* morekeys_a */ "\u00E0,\u00E1,\u00E2,\u00E4,\u00E6,\u00E3,\u00E5,\u0101", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE // U+0153: "œ" LATIN SMALL LIGATURE OE // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - /* morekeys_o */ "\u00F4,\u00F6,\u00F2,\u00F3,\u0153,\u00F8,\u014D,\u00F5", + /* morekeys_o */ "\u00F3,\u00F4,\u00F6,\u00F2,\u0153,\u00F8,\u014D,\u00F5", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE - // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON - /* morekeys_u */ "\u00FB,\u00FC,\u00F9,\u00FA,\u016B", - // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + /* morekeys_u */ "\u00FA,\u00FB,\u00FC,\u00F9,\u016B", // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON - /* morekeys_e */ "\u00E8,\u00E9,\u00EA,\u00EB,\u0113", + /* morekeys_e */ "\u00E9,\u00E8,\u00EA,\u00EB,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS - // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE - /* morekeys_i */ "\u00EE,\u00EF,\u00ED,\u012B,\u00EC", + /* morekeys_i */ "\u00ED,\u00EE,\u00EF,\u012B,\u00EC", // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA /* morekeys_c */ "\u00E7", /* double_quotes */ null, // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE /* morekeys_n */ "\u00F1", - /* single_quotes */ null, /* keylabel_to_alpha */ null, + /* single_quotes */ null, // U+00DF: "ß" LATIN SMALL LETTER SHARP S /* morekeys_s */ "\u00DF", }; @@ -3640,8 +3698,8 @@ public final class KeyboardTextsTable { // U+0149: "ʼn" LATIN SMALL LETTER N PRECEDED BY APOSTROPHE // U+014B: "ŋ" LATIN SMALL LETTER ENG /* morekeys_n */ "\u00F1,\u0144,\u0146,\u0148,\u0149,\u014B", - /* single_quotes */ null, /* keylabel_to_alpha */ null, + /* single_quotes */ null, // U+00DF: "ß" LATIN SMALL LETTER SHARP S // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE // U+015D: "ŝ" LATIN SMALL LETTER S WITH CIRCUMFLEX @@ -3673,14 +3731,14 @@ public final class KeyboardTextsTable { // U+0140: "ŀ" LATIN SMALL LETTER L WITH MIDDLE DOT // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE /* morekeys_l */ "\u013A,\u013C,\u013E,\u0140,\u0142", + /* keyspec_currency */ null, // U+011D: "ĝ" LATIN SMALL LETTER G WITH CIRCUMFLEX // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE // U+0121: "ġ" LATIN SMALL LETTER G WITH DOT ABOVE // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA /* morekeys_g */ "\u011D,\u011F,\u0121,\u0123", - /* single_angle_quotes ~ */ - null, null, null, - /* ~ keyspec_currency */ + /* single_angle_quotes */ null, + /* double_angle_quotes */ null, // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA // U+0159: "ř" LATIN SMALL LETTER R WITH CARON @@ -3711,26 +3769,26 @@ public final class KeyboardTextsTable { "DEFAULT", TEXTS_DEFAULT, /* 168/168 DEFAULT */ "af" , TEXTS_af, /* 7/ 12 Afrikaans */ "ar" , TEXTS_ar, /* 55/110 Arabic */ - "az_AZ" , TEXTS_az_AZ, /* 8/ 17 Azerbaijani (Azerbaijan) */ + "az_AZ" , TEXTS_az_AZ, /* 8/ 18 Azerbaijani (Azerbaijan) */ "be_BY" , TEXTS_be_BY, /* 9/ 32 Belarusian (Belarus) */ - "bg" , TEXTS_bg, /* 2/ 10 Bulgarian */ + "bg" , TEXTS_bg, /* 2/ 9 Bulgarian */ "ca" , TEXTS_ca, /* 11/ 95 Catalan */ "cs" , TEXTS_cs, /* 17/ 21 Czech */ - "da" , TEXTS_da, /* 19/ 33 Danish */ + "da" , TEXTS_da, /* 19/ 54 Danish */ "de" , TEXTS_de, /* 16/ 62 German */ - "el" , TEXTS_el, /* 1/ 10 Greek */ + "el" , TEXTS_el, /* 1/ 9 Greek */ "en" , TEXTS_en, /* 8/ 11 English */ "eo" , TEXTS_eo, /* 26/118 Esperanto */ - "es" , TEXTS_es, /* 8/ 34 Spanish */ + "es" , TEXTS_es, /* 8/ 55 Spanish */ "et_EE" , TEXTS_et_EE, /* 22/ 27 Estonian (Estonia) */ "eu_ES" , TEXTS_eu_ES, /* 7/ 8 Basque (Spain) */ "fa" , TEXTS_fa, /* 58/125 Persian */ - "fi" , TEXTS_fi, /* 10/ 33 Finnish */ + "fi" , TEXTS_fi, /* 10/ 54 Finnish */ "fr" , TEXTS_fr, /* 13/ 62 French */ "gl_ES" , TEXTS_gl_ES, /* 7/ 8 Gallegan (Spain) */ - "hi" , TEXTS_hi, /* 23/ 55 Hindi */ - "hr" , TEXTS_hr, /* 9/ 19 Croatian */ - "hu" , TEXTS_hu, /* 9/ 19 Hungarian */ + "hi" , TEXTS_hi, /* 23/ 53 Hindi */ + "hr" , TEXTS_hr, /* 9/ 20 Croatian */ + "hu" , TEXTS_hu, /* 9/ 20 Hungarian */ "hy_AM" , TEXTS_hy_AM, /* 8/126 Armenian (Armenia) */ "is" , TEXTS_is, /* 10/ 15 Icelandic */ "it" , TEXTS_it, /* 11/ 62 Italian */ @@ -3739,14 +3797,15 @@ public final class KeyboardTextsTable { "kk" , TEXTS_kk, /* 15/121 Kazakh */ "km_KH" , TEXTS_km_KH, /* 2/122 Khmer (Cambodia) */ "ky" , TEXTS_ky, /* 10/ 88 Kirghiz */ - "lo_LA" , TEXTS_lo_LA, /* 2/ 20 Lao (Laos) */ + "lo_LA" , TEXTS_lo_LA, /* 2/ 17 Lao (Laos) */ "lt" , TEXTS_lt, /* 18/ 22 Lithuanian */ "lv" , TEXTS_lv, /* 18/ 22 Latvian */ "mk" , TEXTS_mk, /* 9/ 93 Macedonian */ - "mn_MN" , TEXTS_mn_MN, /* 2/ 20 Mongolian (Mongolia) */ + "mn_MN" , TEXTS_mn_MN, /* 2/ 17 Mongolian (Mongolia) */ + "mr_IN" , TEXTS_mr_IN, /* 23/ 53 Marathi (India) */ "my_MM" , TEXTS_my_MM, /* 8/104 Burmese (Myanmar) */ - "nb" , TEXTS_nb, /* 11/ 33 Norwegian Bokmål */ - "ne_NP" , TEXTS_ne_NP, /* 23/ 55 Nepali (Nepal) */ + "nb" , TEXTS_nb, /* 11/ 54 Norwegian Bokmål */ + "ne_NP" , TEXTS_ne_NP, /* 23/ 53 Nepali (Nepal) */ "nl" , TEXTS_nl, /* 9/ 12 Dutch */ "pl" , TEXTS_pl, /* 10/ 16 Polish */ "pt" , TEXTS_pt, /* 6/ 6 Portuguese */ @@ -3754,15 +3813,15 @@ public final class KeyboardTextsTable { "ro" , TEXTS_ro, /* 6/ 15 Romanian */ "ru" , TEXTS_ru, /* 9/ 32 Russian */ "sk" , TEXTS_sk, /* 20/ 22 Slovak */ - "sl" , TEXTS_sl, /* 8/ 19 Slovenian */ + "sl" , TEXTS_sl, /* 8/ 20 Slovenian */ "sr" , TEXTS_sr, /* 11/ 93 Serbian */ - "sv" , TEXTS_sv, /* 21/ 33 Swedish */ - "sw" , TEXTS_sw, /* 9/ 17 Swahili */ - "th" , TEXTS_th, /* 2/ 20 Thai */ + "sv" , TEXTS_sv, /* 21/ 54 Swedish */ + "sw" , TEXTS_sw, /* 9/ 18 Swahili */ + "th" , TEXTS_th, /* 2/ 17 Thai */ "tl" , TEXTS_tl, /* 7/ 8 Tagalog */ - "tr" , TEXTS_tr, /* 7/ 17 Turkish */ + "tr" , TEXTS_tr, /* 7/ 18 Turkish */ "uk" , TEXTS_uk, /* 11/ 87 Ukrainian */ - "vi" , TEXTS_vi, /* 8/ 20 Vietnamese */ + "vi" , TEXTS_vi, /* 8/ 17 Vietnamese */ "zu" , TEXTS_zu, /* 8/ 11 Zulu */ "zz" , TEXTS_zz, /* 19/112 Alphabet */ }; diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index b88509fde..999508e92 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -218,6 +218,8 @@ public final class BinaryDictionary extends Dictionary { int bigramProbability); private static native String getPropertyNative(long dict, String query); private static native boolean isCorruptedNative(long dict); + private static native boolean migrateNative(long dict, String dictFilePath, + long newFormatVersion); // TODO: Move native dict into session private final void loadDictionary(final String path, final long startOffset, @@ -371,8 +373,7 @@ public final class BinaryDictionary extends Dictionary { return getProbabilityNative(mNativeDict, codePoints); } - // TODO: Add a batch process version (isValidBigramMultiple?) to avoid excessive numbers of jni - // calls when checking for changes in an entire dictionary. + @UsedForTesting public boolean isValidBigram(final String word0, final String word1) { return getBigramProbability(word0, word1) != NOT_A_PROBABILITY; } @@ -413,8 +414,8 @@ public final class BinaryDictionary extends Dictionary { public WordProperty mWordProperty; public int mNextToken; - public GetNextWordPropertyResult(final WordProperty wordPreperty, final int nextToken) { - mWordProperty = wordPreperty; + public GetNextWordPropertyResult(final WordProperty wordProperty, final int nextToken) { + mWordProperty = wordProperty; mNextToken = nextToken; } } @@ -533,11 +534,15 @@ public final class BinaryDictionary extends Dictionary { return false; } final String tmpDictFilePath = mDictFilePath + DICT_FILE_NAME_SUFFIX_FOR_MIGRATION; - // TODO: Implement migrateNative(tmpDictFilePath, newFormatVersion). + if (!migrateNative(mNativeDict, tmpDictFilePath, newFormatVersion)) { + return false; + } close(); final File dictFile = new File(mDictFilePath); final File tmpDictFile = new File(tmpDictFilePath); - FileUtils.deleteRecursively(dictFile); + if (!FileUtils.deleteRecursively(dictFile)) { + return false; + } if (!BinaryDictionaryUtils.renameDict(tmpDictFile, dictFile)) { return false; } diff --git a/java/src/com/android/inputmethod/latin/Constants.java b/java/src/com/android/inputmethod/latin/Constants.java index e71723a15..67ca59540 100644 --- a/java/src/com/android/inputmethod/latin/Constants.java +++ b/java/src/com/android/inputmethod/latin/Constants.java @@ -115,6 +115,11 @@ public final class Constants { */ public static final String IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype"; + /** + * The subtype extra value used to specify the combining rules. + */ + public static final String COMBINING_RULES = "CombiningRules"; + private ExtraValue() { // This utility class is not publicly instantiable. } @@ -164,6 +169,8 @@ public final class Constants { // How many continuous deletes at which to start deleting at a higher speed. public static final int DELETE_ACCELERATE_AT = 20; + public static final String WORD_SEPARATOR = " "; + public static boolean isValidCoordinate(final int coordinate) { // Detect {@link NOT_A_COORDINATE}, {@link SUGGESTION_STRIP_COORDINATE}, // and {@link SPELL_CHECKER_COORDINATE}. diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java index 09d0ea210..e04fcda27 100644 --- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java @@ -29,10 +29,14 @@ import android.provider.ContactsContract.Contacts; import android.text.TextUtils; import android.util.Log; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.personalization.AccountUtils; +import com.android.inputmethod.latin.utils.CollectionUtils; +import com.android.inputmethod.latin.utils.ExecutorUtils; import com.android.inputmethod.latin.utils.StringUtils; import java.io.File; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -59,10 +63,10 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { private static final int INDEX_NAME = 1; /** The number of contacts in the most recent dictionary rebuild. */ - static private int sContactCountAtLastRebuild = 0; + private int mContactCountAtLastRebuild = 0; - /** The locale for this contacts dictionary. Controls name bigram predictions. */ - public final Locale mLocale; + /** The hash code of ArrayList of contacts names in the most recent dictionary rebuild. */ + private int mHashCodeAtLastRebuild = 0; private ContentObserver mObserver; @@ -71,11 +75,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { */ private final boolean mUseFirstLastBigrams; - public ContactsBinaryDictionary(final Context context, final Locale locale) { - this(context, locale, null /* dictFile */); - } - - public ContactsBinaryDictionary(final Context context, final Locale locale, + private ContactsBinaryDictionary(final Context context, final Locale locale, final File dictFile) { this(context, locale, dictFile, NAME); } @@ -84,12 +84,17 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { final File dictFile, final String name) { super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_CONTACTS, dictFile); - mLocale = locale; mUseFirstLastBigrams = useFirstLastBigramsForLocale(locale); registerObserver(context); reloadDictionaryIfRequired(); } + @UsedForTesting + public static ContactsBinaryDictionary getDictionary(final Context context, final Locale locale, + final File dictFile) { + return new ContactsBinaryDictionary(context, locale, dictFile); + } + private synchronized void registerObserver(final Context context) { if (mObserver != null) return; ContentResolver cres = context.getContentResolver(); @@ -97,7 +102,14 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { new ContentObserver(null) { @Override public void onChange(boolean self) { - setNeedsToReload(); + ExecutorUtils.getExecutor("Check Contacts").execute(new Runnable() { + @Override + public void run() { + if (haveContentsChanged()) { + setNeedsToRecreate(); + } + } + }); } }); } @@ -144,7 +156,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { return; } if (cursor.moveToFirst()) { - sContactCountAtLastRebuild = getContactCount(); + mContactCountAtLastRebuild = getContactCount(); addWordsLocked(cursor); } } catch (final SQLiteException e) { @@ -168,9 +180,11 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { private void addWordsLocked(final Cursor cursor) { int count = 0; + final ArrayList<String> names = CollectionUtils.newArrayList(); while (!cursor.isAfterLast() && count < MAX_CONTACT_COUNT) { String name = cursor.getString(INDEX_NAME); if (isValidName(name)) { + names.add(name); addNameLocked(name); ++count; } else { @@ -180,6 +194,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { } cursor.moveToNext(); } + mHashCodeAtLastRebuild = names.hashCode(); } private int getContactCount() { @@ -259,8 +274,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { return end; } - @Override - protected boolean haveContentsChanged() { + private boolean haveContentsChanged() { final long startTime = SystemClock.uptimeMillis(); final int contactCount = getContactCount(); if (contactCount > MAX_CONTACT_COUNT) { @@ -269,9 +283,9 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { // TODO: Sort and check only the MAX_CONTACT_COUNT most recent contacts? return false; } - if (contactCount != sContactCountAtLastRebuild) { + if (contactCount != mContactCountAtLastRebuild) { if (DEBUG) { - Log.d(TAG, "Contact count changed: " + sContactCountAtLastRebuild + " to " + Log.d(TAG, "Contact count changed: " + mContactCountAtLastRebuild + " to " + contactCount); } return true; @@ -284,20 +298,20 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { if (null == cursor) { return false; } + final ArrayList<String> names = CollectionUtils.newArrayList(); try { if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { String name = cursor.getString(INDEX_NAME); - if (isValidName(name) && !isNameInDictionaryLocked(name)) { - if (DEBUG) { - Log.d(TAG, "Contact name missing: " + name + " (runtime = " - + (SystemClock.uptimeMillis() - startTime) + " ms)"); - } - return true; + if (isValidName(name)) { + names.add(name); } cursor.moveToNext(); } } + if (names.hashCode() != mHashCodeAtLastRebuild) { + return true; + } } finally { cursor.close(); } @@ -314,33 +328,4 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { } return false; } - - /** - * Checks if the words in a name are in the current binary dictionary. - */ - private boolean isNameInDictionaryLocked(final String name) { - int len = StringUtils.codePointCount(name); - String prevWord = null; - for (int i = 0; i < len; i++) { - if (Character.isLetter(name.codePointAt(i))) { - int end = getWordEndPosition(name, len, i); - String word = name.substring(i, end); - i = end - 1; - final int wordLen = StringUtils.codePointCount(word); - if (wordLen < MAX_WORD_LENGTH && wordLen > 1) { - if (!TextUtils.isEmpty(prevWord) && mUseFirstLastBigrams) { - if (!isValidBigramLocked(prevWord, word)) { - return false; - } - } else { - if (!isValidWordLocked(word)) { - return false; - } - } - prevWord = word; - } - } - } - return true; - } } diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index 0742fbde9..cd380db6b 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -57,6 +57,8 @@ public abstract class Dictionary { public static final String TYPE_USER_HISTORY = "history"; // Personalization dictionary. public static final String TYPE_PERSONALIZATION = "personalization"; + // Contextual dictionary. + public static final String TYPE_CONTEXTUAL = "contextual"; public final String mDictType; public Dictionary(final String dictType) { diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java index 5238395a4..e0220e137 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java @@ -23,8 +23,8 @@ import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import com.android.inputmethod.latin.personalization.ContextualDictionary; import com.android.inputmethod.latin.personalization.PersonalizationDictionary; -import com.android.inputmethod.latin.personalization.PersonalizationHelper; import com.android.inputmethod.latin.personalization.UserHistoryDictionary; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.ExecutorUtils; @@ -32,10 +32,14 @@ import com.android.inputmethod.latin.utils.LanguageModelParam; import com.android.inputmethod.latin.utils.SuggestionResults; import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -49,72 +53,84 @@ public class DictionaryFacilitatorForSuggest { private static final int CAPITALIZED_FORM_MAX_PROBABILITY_FOR_INSERT = 140; private Dictionaries mDictionaries = new Dictionaries(); + private boolean mIsUserDictEnabled = false; private volatile CountDownLatch mLatchForWaitingLoadingMainDictionary = new CountDownLatch(0); // To synchronize assigning mDictionaries to ensure closing dictionaries. - private Object mLock = new Object(); + private final Object mLock = new Object(); - private static final String[] dictTypesOrderedToGetSuggestion = + private static final String[] DICT_TYPES_ORDERED_TO_GET_SUGGESTION = new String[] { Dictionary.TYPE_MAIN, Dictionary.TYPE_USER_HISTORY, Dictionary.TYPE_PERSONALIZATION, Dictionary.TYPE_USER, - Dictionary.TYPE_CONTACTS + Dictionary.TYPE_CONTACTS, + Dictionary.TYPE_CONTEXTUAL }; + private static final Map<String, Class<? extends ExpandableBinaryDictionary>> + DICT_TYPE_TO_CLASS = CollectionUtils.newHashMap(); + + static { + DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_USER_HISTORY, UserHistoryDictionary.class); + DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_PERSONALIZATION, PersonalizationDictionary.class); + DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_USER, UserBinaryDictionary.class); + DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_CONTACTS, ContactsBinaryDictionary.class); + DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_CONTEXTUAL, ContextualDictionary.class); + } + + private static final String DICT_FACTORY_METHOD_NAME = "getDictionary"; + private static final Class<?>[] DICT_FACTORY_METHOD_ARG_TYPES = + new Class[] { Context.class, Locale.class, File.class }; + + private static final String[] SUB_DICT_TYPES = + Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTION, 1 /* start */, + DICT_TYPES_ORDERED_TO_GET_SUGGESTION.length); + /** * Class contains dictionaries for a locale. */ private static class Dictionaries { public final Locale mLocale; - public final ConcurrentHashMap<String, Dictionary> mDictMap = - CollectionUtils.newConcurrentHashMap(); + private Dictionary mMainDict; public final ConcurrentHashMap<String, ExpandableBinaryDictionary> mSubDictMap = CollectionUtils.newConcurrentHashMap(); - // TODO: Remove sub dictionary members and use mSubDictMap. - public final UserBinaryDictionary mUserDictionary; public Dictionaries() { mLocale = null; - mUserDictionary = null; } public Dictionaries(final Locale locale, final Dictionary mainDict, - final ExpandableBinaryDictionary contactsDict, final UserBinaryDictionary userDict, - final ExpandableBinaryDictionary userHistoryDict, - final ExpandableBinaryDictionary personalizationDict) { + final Map<String, ExpandableBinaryDictionary> subDicts) { mLocale = locale; // Main dictionary can be asynchronously loaded. setMainDict(mainDict); - setSubDict(Dictionary.TYPE_CONTACTS, contactsDict); - mUserDictionary = userDict; - setSubDict(Dictionary.TYPE_USER, mUserDictionary); - setSubDict(Dictionary.TYPE_USER_HISTORY, userHistoryDict); - setSubDict(Dictionary.TYPE_PERSONALIZATION, personalizationDict); + for (final Map.Entry<String, ExpandableBinaryDictionary> entry : subDicts.entrySet()) { + setSubDict(entry.getKey(), entry.getValue()); + } } private void setSubDict(final String dictType, final ExpandableBinaryDictionary dict) { if (dict != null) { - mDictMap.put(dictType, dict); mSubDictMap.put(dictType, dict); } } public void setMainDict(final Dictionary mainDict) { // Close old dictionary if exists. Main dictionary can be assigned multiple times. - final Dictionary oldDict; - if (mainDict != null) { - oldDict = mDictMap.put(Dictionary.TYPE_MAIN, mainDict); - } else { - oldDict = mDictMap.remove(Dictionary.TYPE_MAIN); - } + final Dictionary oldDict = mMainDict; + mMainDict = mainDict; if (oldDict != null && mainDict != oldDict) { oldDict.close(); } } - public Dictionary getMainDict() { - return mDictMap.get(Dictionary.TYPE_MAIN); + public Dictionary getDict(final String dictType) { + if (Dictionary.TYPE_MAIN.equals(dictType)) { + return mMainDict; + } else { + return getSubDict(dictType); + } } public ExpandableBinaryDictionary getSubDict(final String dictType) { @@ -122,12 +138,20 @@ public class DictionaryFacilitatorForSuggest { } public boolean hasDict(final String dictType) { - return mDictMap.containsKey(dictType); + if (Dictionary.TYPE_MAIN.equals(dictType)) { + return mMainDict != null; + } else { + return mSubDictMap.containsKey(dictType); + } } public void closeDict(final String dictType) { - final Dictionary dict = mDictMap.remove(dictType); - mSubDictMap.remove(dictType); + final Dictionary dict; + if (Dictionary.TYPE_MAIN.equals(dictType)) { + dict = mMainDict; + } else { + dict = mSubDictMap.remove(dictType); + } if (dict != null) { dict.close(); } @@ -144,6 +168,26 @@ public class DictionaryFacilitatorForSuggest { return mDictionaries.mLocale; } + private static ExpandableBinaryDictionary getSubDict(final String dictType, + final Context context, final Locale locale, final File dictFile) { + final Class<? extends ExpandableBinaryDictionary> dictClass = + DICT_TYPE_TO_CLASS.get(dictType); + if (dictClass == null) { + return null; + } + try { + final Method factoryMethod = dictClass.getMethod(DICT_FACTORY_METHOD_NAME, + DICT_FACTORY_METHOD_ARG_TYPES); + final Object dict = factoryMethod.invoke(null /* obj */, + new Object[] { context, locale, dictFile }); + return (ExpandableBinaryDictionary) dict; + } catch (final NoSuchMethodException | SecurityException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e) { + Log.e(TAG, "Cannot create dictionary: " + dictType, e); + return null; + } + } + public void resetDictionaries(final Context context, final Locale newLocale, final boolean useContactsDict, final boolean usePersonalizedDicts, final boolean forceReloadMainDictionary, @@ -151,67 +195,50 @@ public class DictionaryFacilitatorForSuggest { final boolean localeHasBeenChanged = !newLocale.equals(mDictionaries.mLocale); // We always try to have the main dictionary. Other dictionaries can be unused. final boolean reloadMainDictionary = localeHasBeenChanged || forceReloadMainDictionary; - final boolean closeContactsDictionary = localeHasBeenChanged || !useContactsDict; - final boolean closeUserDictionary = localeHasBeenChanged; - final boolean closeUserHistoryDictionary = localeHasBeenChanged || !usePersonalizedDicts; - final boolean closePersonalizationDictionary = - localeHasBeenChanged || !usePersonalizedDicts; + // TODO: Make subDictTypesToUse configurable by resource or a static final list. + final Set<String> subDictTypesToUse = CollectionUtils.newHashSet(); + if (useContactsDict) { + subDictTypesToUse.add(Dictionary.TYPE_CONTACTS); + } + subDictTypesToUse.add(Dictionary.TYPE_USER); + if (usePersonalizedDicts) { + subDictTypesToUse.add(Dictionary.TYPE_USER_HISTORY); + subDictTypesToUse.add(Dictionary.TYPE_PERSONALIZATION); + subDictTypesToUse.add(Dictionary.TYPE_CONTEXTUAL); + } final Dictionary newMainDict; if (reloadMainDictionary) { // The main dictionary will be asynchronously loaded. newMainDict = null; } else { - newMainDict = mDictionaries.getMainDict(); - } - - // Open or move contacts dictionary. - final ExpandableBinaryDictionary newContactsDict; - if (!closeContactsDictionary && mDictionaries.hasDict(Dictionary.TYPE_CONTACTS)) { - newContactsDict = mDictionaries.getSubDict(Dictionary.TYPE_CONTACTS); - } else if (useContactsDict) { - newContactsDict = new ContactsBinaryDictionary(context, newLocale); - } else { - newContactsDict = null; - } - - // Open or move user dictionary. - final UserBinaryDictionary newUserDictionary; - if (!closeUserDictionary && mDictionaries.hasDict(Dictionary.TYPE_USER)) { - newUserDictionary = mDictionaries.mUserDictionary; - } else { - newUserDictionary = new UserBinaryDictionary(context, newLocale); - } - - // Open or move user history dictionary. - final ExpandableBinaryDictionary newUserHistoryDict; - if (!closeUserHistoryDictionary && mDictionaries.hasDict(Dictionary.TYPE_USER_HISTORY)) { - newUserHistoryDict = mDictionaries.getSubDict(Dictionary.TYPE_USER_HISTORY); - } else if (usePersonalizedDicts) { - newUserHistoryDict = PersonalizationHelper.getUserHistoryDictionary(context, newLocale); - } else { - newUserHistoryDict = null; + newMainDict = mDictionaries.getDict(Dictionary.TYPE_MAIN); } - // Open or move personalization dictionary. - final ExpandableBinaryDictionary newPersonalizationDict; - if (!closePersonalizationDictionary - && mDictionaries.hasDict(Dictionary.TYPE_PERSONALIZATION)) { - newPersonalizationDict = mDictionaries.getSubDict(Dictionary.TYPE_PERSONALIZATION); - } else if (usePersonalizedDicts) { - newPersonalizationDict = - PersonalizationHelper.getPersonalizationDictionary(context, newLocale); - } else { - newPersonalizationDict = null; + final Map<String, ExpandableBinaryDictionary> subDicts = CollectionUtils.newHashMap(); + for (final String dictType : SUB_DICT_TYPES) { + if (!subDictTypesToUse.contains(dictType)) { + // This dictionary will not be used. + continue; + } + final ExpandableBinaryDictionary dict; + if (!localeHasBeenChanged && mDictionaries.hasDict(dictType)) { + // Continue to use current dictionary. + dict = mDictionaries.getSubDict(dictType); + } else { + // Start to use new dictionary. + dict = getSubDict(dictType, context, newLocale, null /* dictFile */); + } + subDicts.put(dictType, dict); } // Replace Dictionaries. - final Dictionaries newDictionaries = new Dictionaries(newLocale, newMainDict, - newContactsDict, newUserDictionary, newUserHistoryDict, newPersonalizationDict); + final Dictionaries newDictionaries = new Dictionaries(newLocale, newMainDict, subDicts); final Dictionaries oldDictionaries; synchronized (mLock) { oldDictionaries = mDictionaries; mDictionaries = newDictionaries; + mIsUserDictEnabled = UserBinaryDictionary.isEnabled(context); if (reloadMainDictionary) { asyncReloadMainDictionary(context, newLocale, listener); } @@ -219,24 +246,15 @@ public class DictionaryFacilitatorForSuggest { if (listener != null) { listener.onUpdateMainDictionaryAvailability(hasInitializedMainDictionary()); } - // Clean up old dictionaries. if (reloadMainDictionary) { oldDictionaries.closeDict(Dictionary.TYPE_MAIN); } - if (closeContactsDictionary) { - oldDictionaries.closeDict(Dictionary.TYPE_CONTACTS); - } - if (closeUserDictionary) { - oldDictionaries.closeDict(Dictionary.TYPE_USER); - } - if (closeUserHistoryDictionary) { - oldDictionaries.closeDict(Dictionary.TYPE_USER_HISTORY); - } - if (closePersonalizationDictionary) { - oldDictionaries.closeDict(Dictionary.TYPE_PERSONALIZATION); + for (final String dictType : SUB_DICT_TYPES) { + if (localeHasBeenChanged || !subDictTypesToUse.contains(dictType)) { + oldDictionaries.closeDict(dictType); + } } - oldDictionaries.mDictMap.clear(); oldDictionaries.mSubDictMap.clear(); } @@ -270,52 +288,28 @@ public class DictionaryFacilitatorForSuggest { final ArrayList<String> dictionaryTypes, final HashMap<String, File> dictionaryFiles, final Map<String, Map<String, String>> additionalDictAttributes) { Dictionary mainDictionary = null; - ContactsBinaryDictionary contactsDictionary = null; - UserBinaryDictionary userDictionary = null; - UserHistoryDictionary userHistoryDictionary = null; - PersonalizationDictionary personalizationDictionary = null; + final Map<String, ExpandableBinaryDictionary> subDicts = CollectionUtils.newHashMap(); for (final String dictType : dictionaryTypes) { if (dictType.equals(Dictionary.TYPE_MAIN)) { mainDictionary = DictionaryFactory.createMainDictionaryFromManager(context, locale); - } else if (dictType.equals(Dictionary.TYPE_USER_HISTORY)) { - userHistoryDictionary = - PersonalizationHelper.getUserHistoryDictionary(context, locale); - // Staring with an empty user history dictionary for testing. - // Testing program may populate this dictionary before actual testing. - userHistoryDictionary.reloadDictionaryIfRequired(); - userHistoryDictionary.waitAllTasksForTests(); + } else { + final File dictFile = dictionaryFiles.get(dictType); + final ExpandableBinaryDictionary dict = getSubDict( + dictType, context, locale, dictFile); if (additionalDictAttributes.containsKey(dictType)) { - userHistoryDictionary.clearAndFlushDictionaryWithAdditionalAttributes( + dict.clearAndFlushDictionaryWithAdditionalAttributes( additionalDictAttributes.get(dictType)); } - } else if (dictType.equals(Dictionary.TYPE_PERSONALIZATION)) { - personalizationDictionary = - PersonalizationHelper.getPersonalizationDictionary(context, locale); - // Staring with an empty personalization dictionary for testing. - // Testing program may populate this dictionary before actual testing. - personalizationDictionary.reloadDictionaryIfRequired(); - personalizationDictionary.waitAllTasksForTests(); - if (additionalDictAttributes.containsKey(dictType)) { - personalizationDictionary.clearAndFlushDictionaryWithAdditionalAttributes( - additionalDictAttributes.get(dictType)); + if (dict == null) { + throw new RuntimeException("Unknown dictionary type: " + dictType); } - } else if (dictType.equals(Dictionary.TYPE_USER)) { - final File file = dictionaryFiles.get(dictType); - userDictionary = new UserBinaryDictionary(context, locale, file); - userDictionary.reloadDictionaryIfRequired(); - userDictionary.waitAllTasksForTests(); - } else if (dictType.equals(Dictionary.TYPE_CONTACTS)) { - final File file = dictionaryFiles.get(dictType); - contactsDictionary = new ContactsBinaryDictionary(context, locale, file); - contactsDictionary.reloadDictionaryIfRequired(); - contactsDictionary.waitAllTasksForTests(); - } else { - throw new RuntimeException("Unknown dictionary type: " + dictType); + dict.reloadDictionaryIfRequired(); + dict.waitAllTasksForTests(); + subDicts.put(dictType, dict); } } - mDictionaries = new Dictionaries(locale, mainDictionary, contactsDictionary, - userDictionary, userHistoryDictionary, personalizationDictionary); + mDictionaries = new Dictionaries(locale, mainDictionary, subDicts); } public void closeDictionaries() { @@ -324,15 +318,15 @@ public class DictionaryFacilitatorForSuggest { dictionaries = mDictionaries; mDictionaries = new Dictionaries(); } - for (final Dictionary dict : dictionaries.mDictMap.values()) { - dict.close(); + for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTION) { + dictionaries.closeDict(dictType); } } // The main dictionary could have been loaded asynchronously. Don't cache the return value // of this method. public boolean hasInitializedMainDictionary() { - final Dictionary mainDict = mDictionaries.getMainDict(); + final Dictionary mainDict = mDictionaries.getDict(Dictionary.TYPE_MAIN); return mainDict != null && mainDict.isInitialized(); } @@ -364,48 +358,58 @@ public class DictionaryFacilitatorForSuggest { } public boolean isUserDictionaryEnabled() { - final UserBinaryDictionary userDictionary = mDictionaries.mUserDictionary; - if (userDictionary == null) { - return false; - } - return userDictionary.mEnabled; + return mIsUserDictEnabled; } - public void addWordToUserDictionary(String word) { - final UserBinaryDictionary userDictionary = mDictionaries.mUserDictionary; - if (userDictionary == null) { + public void addWordToUserDictionary(final Context context, final String word) { + final Locale locale = getLocale(); + if (locale == null) { return; } - userDictionary.addWordToUserDictionary(word); + UserBinaryDictionary.addWordToUserDictionary(context, locale, word); } public void addToUserHistory(final String suggestion, final boolean wasAutoCapitalized, - final String previousWord, final int timeStampInSeconds) { + final String previousWord, final int timeStampInSeconds, + final boolean blockPotentiallyOffensive) { final Dictionaries dictionaries = mDictionaries; + final String[] words = suggestion.split(Constants.WORD_SEPARATOR); + for (int i = 0; i < words.length; i++) { + final String currentWord = words[i]; + final String prevWord = (i == 0) ? previousWord : words[i - 1]; + final boolean wasCurrentWordAutoCapitalized = (i == 0) ? wasAutoCapitalized : false; + addWordToUserHistory(dictionaries, prevWord, currentWord, + wasCurrentWordAutoCapitalized, timeStampInSeconds, blockPotentiallyOffensive); + } + } + + private void addWordToUserHistory(final Dictionaries dictionaries, final String prevWord, + final String word, final boolean wasAutoCapitalized, final int timeStampInSeconds, + final boolean blockPotentiallyOffensive) { final ExpandableBinaryDictionary userHistoryDictionary = dictionaries.getSubDict(Dictionary.TYPE_USER_HISTORY); if (userHistoryDictionary == null) { return; } - final int maxFreq = getMaxFrequency(suggestion); - if (maxFreq == 0) { + final int maxFreq = getMaxFrequency(word); + if (maxFreq == 0 && blockPotentiallyOffensive) { return; } - final String suggestionLowerCase = suggestion.toLowerCase(dictionaries.mLocale); + final String lowerCasedWord = word.toLowerCase(dictionaries.mLocale); final String secondWord; if (wasAutoCapitalized) { - if (isValidWord(suggestion, false /* ignoreCase */) - && !isValidWord(suggestionLowerCase, false /* ignoreCase */)) { + if (isValidWord(word, false /* ignoreCase */) + && !isValidWord(lowerCasedWord, false /* ignoreCase */)) { // If the word was auto-capitalized and exists only as a capitalized word in the // dictionary, then we must not downcase it before registering it. For example, // the name of the contacts in start-of-sentence position would come here with the // wasAutoCapitalized flag: if we downcase it, we'd register a lower-case version // of that contact's name which would end up popping in suggestions. - secondWord = suggestion; + secondWord = word; } else { // If however the word is not in the dictionary, or exists as a lower-case word // only, then we consider that was a lower-case word that had been auto-capitalized. - secondWord = suggestionLowerCase; + secondWord = lowerCasedWord; } } else { // HACK: We'd like to avoid adding the capitalized form of common words to the User @@ -413,20 +417,20 @@ public class DictionaryFacilitatorForSuggest { // consolidation is done. // TODO: Remove this hack when ready. final int lowerCaseFreqInMainDict = dictionaries.hasDict(Dictionary.TYPE_MAIN) ? - dictionaries.getMainDict().getFrequency(suggestionLowerCase) : + dictionaries.getDict(Dictionary.TYPE_MAIN).getFrequency(lowerCasedWord) : Dictionary.NOT_A_PROBABILITY; if (maxFreq < lowerCaseFreqInMainDict && lowerCaseFreqInMainDict >= CAPITALIZED_FORM_MAX_PROBABILITY_FOR_INSERT) { // Use lower cased word as the word can be a distracter of the popular word. - secondWord = suggestionLowerCase; + secondWord = lowerCasedWord; } else { - secondWord = suggestion; + secondWord = word; } } // We demote unrecognized words (frequency < 0, below) by specifying them as "invalid". // We don't add words with 0-frequency (assuming they would be profanity etc.). final boolean isValid = maxFreq > 0; - UserHistoryDictionary.addToDictionary(userHistoryDictionary, previousWord, secondWord, + UserHistoryDictionary.addToDictionary(userHistoryDictionary, prevWord, secondWord, isValid, timeStampInSeconds); } @@ -444,12 +448,11 @@ public class DictionaryFacilitatorForSuggest { final boolean blockOffensiveWords, final int[] additionalFeaturesOptions, final int sessionId, final ArrayList<SuggestedWordInfo> rawSuggestions) { final Dictionaries dictionaries = mDictionaries; - final Map<String, Dictionary> dictMap = dictionaries.mDictMap; final SuggestionResults suggestionResults = new SuggestionResults(dictionaries.mLocale, SuggestedWords.MAX_SUGGESTIONS); final float[] languageWeight = new float[] { Dictionary.NOT_A_LANGUAGE_WEIGHT }; - for (final String dictType : dictTypesOrderedToGetSuggestion) { - final Dictionary dictionary = dictMap.get(dictType); + for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTION) { + final Dictionary dictionary = dictionaries.getDict(dictType); if (null == dictionary) continue; final ArrayList<SuggestedWordInfo> dictionarySuggestions = dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo, @@ -465,11 +468,11 @@ public class DictionaryFacilitatorForSuggest { } public boolean isValidMainDictWord(final String word) { - final Dictionaries dictionaries = mDictionaries; - if (TextUtils.isEmpty(word) || !dictionaries.hasDict(Dictionary.TYPE_MAIN)) { + final Dictionary mainDict = mDictionaries.getDict(Dictionary.TYPE_MAIN); + if (TextUtils.isEmpty(word) || mainDict == null) { return false; } - return dictionaries.getMainDict().isValidWord(word); + return mainDict.isValidWord(word); } public boolean isValidWord(final String word, final boolean ignoreCase) { @@ -481,8 +484,8 @@ public class DictionaryFacilitatorForSuggest { return false; } final String lowerCasedWord = word.toLowerCase(dictionaries.mLocale); - final Map<String, Dictionary> dictMap = dictionaries.mDictMap; - for (final Dictionary dictionary : dictMap.values()) { + for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTION) { + final Dictionary dictionary = dictionaries.getDict(dictType); // Ideally the passed map would come out of a {@link java.util.concurrent.Future} and // would be immutable once it's finished initializing, but concretely a null test is // probably good enough for the time being. @@ -500,8 +503,10 @@ public class DictionaryFacilitatorForSuggest { return Dictionary.NOT_A_PROBABILITY; } int maxFreq = -1; - final Map<String, Dictionary> dictMap = mDictionaries.mDictMap; - for (final Dictionary dictionary : dictMap.values()) { + final Dictionaries dictionaries = mDictionaries; + for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTION) { + final Dictionary dictionary = dictionaries.getDict(dictType); + if (dictionary == null) continue; final int tempFreq = dictionary.getFrequency(word); if (tempFreq >= maxFreq) { maxFreq = tempFreq; diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 08f3c63a3..6818c156e 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -92,11 +92,13 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { /** Indicates whether a task for reloading the dictionary has been scheduled. */ private final AtomicBoolean mIsReloading; - /** Indicates whether the current dictionary needs to be reloaded. */ - private boolean mNeedsToReload; + /** Indicates whether the current dictionary needs to be recreated. */ + private boolean mNeedsToRecreate; private final ReentrantReadWriteLock mLock; + private Map<String, String> mAdditionalAttributeMap = null; + /* A extension for a binary dictionary file. */ protected static final String DICT_FILE_EXTENSION = ".dict"; @@ -105,20 +107,14 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { */ protected abstract void loadInitialContentsLocked(); - /** - * Indicates that the source dictionary contents have changed and a rebuild of the binary file - * is required. If it returns false, the next reload will only read the current binary - * dictionary from file. - */ - protected abstract boolean haveContentsChanged(); - private boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) { return formatVersion == FormatSpec.VERSION4; } private boolean needsToMigrateDictionary(final int formatVersion) { - // TODO: Check version. - return false; + // When we bump up the dictionary format version, the old version should be added to here + // for supporting migration. Note that native code has to support reading such formats. + return formatVersion == FormatSpec.VERSION4_ONLY_FOR_TESTING; } public boolean isValidDictionaryLocked() { @@ -145,7 +141,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { mDictFile = getDictFile(context, dictName, dictFile); mBinaryDictionary = null; mIsReloading = new AtomicBoolean(); - mNeedsToReload = false; + mNeedsToRecreate = false; mLock = new ReentrantReadWriteLock(); } @@ -196,6 +192,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { protected Map<String, String> getHeaderAttributeMap() { HashMap<String, String> attributeMap = new HashMap<String, String>(); + if (mAdditionalAttributeMap != null) { + attributeMap.putAll(mAdditionalAttributeMap); + } attributeMap.put(DictionaryHeader.DICTIONARY_ID_KEY, mDictName); attributeMap.put(DictionaryHeader.DICTIONARY_LOCALE_KEY, mLocale.toString()); attributeMap.put(DictionaryHeader.DICTIONARY_VERSION_KEY, @@ -465,7 +464,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } if (mBinaryDictionary.isValidDictionary() && needsToMigrateDictionary(mBinaryDictionary.getFormatVersion())) { - mBinaryDictionary.migrateTo(DICTIONARY_FORMAT_VERSION); + if (!mBinaryDictionary.migrateTo(DICTIONARY_FORMAT_VERSION)) { + Log.e(TAG, "Dictionary migration failed: " + mDictName); + removeBinaryDictionaryLocked(); + } } } @@ -481,11 +483,11 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } /** - * Marks that the dictionary needs to be reloaded. + * Marks that the dictionary needs to be recreated. * */ - protected void setNeedsToReload() { - mNeedsToReload = true; + protected void setNeedsToRecreate() { + mNeedsToRecreate = true; } /** @@ -503,7 +505,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { * Returns whether a dictionary reload is required. */ private boolean isReloadRequired() { - return mBinaryDictionary == null || mNeedsToReload; + return mBinaryDictionary == null || mNeedsToRecreate; } /** @@ -511,28 +513,28 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { */ private final void asyncReloadDictionary() { if (mIsReloading.compareAndSet(false, true)) { - mNeedsToReload = false; asyncExecuteTaskWithWriteLock(new Runnable() { @Override public void run() { try { - if (!mDictFile.exists() || haveContentsChanged()) { + if (!mDictFile.exists() || mNeedsToRecreate) { // If the dictionary file does not exist or contents have been updated, // generate a new one. createNewDictionaryLocked(); } else if (mBinaryDictionary == null) { // Otherwise, load the existing dictionary. loadBinaryDictionaryLocked(); + if (mBinaryDictionary != null && !(isValidDictionaryLocked() + // TODO: remove the check below + && matchesExpectedBinaryDictFormatVersionForThisType( + mBinaryDictionary.getFormatVersion()))) { + // Binary dictionary or its format version is not valid. Regenerate + // the dictionary file. createNewDictionaryLocked will remove the + // existing files if appropriate. + createNewDictionaryLocked(); + } } - if (mBinaryDictionary != null && !(isValidDictionaryLocked() - // TODO: remove the check below - && matchesExpectedBinaryDictFormatVersionForThisType( - mBinaryDictionary.getFormatVersion()))) { - // Binary dictionary or its format version is not valid. Regenerate - // the dictionary file. writeBinaryDictionary will remove the - // existing files if appropriate. - createNewDictionaryLocked(); - } + mNeedsToRecreate = false; } finally { mIsReloading.set(false); } @@ -591,6 +593,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } @UsedForTesting + public void clearAndFlushDictionaryWithAdditionalAttributes( + final Map<String, String> attributeMap) { + mAdditionalAttributeMap = attributeMap; + clear(); + } + public void dumpAllWordsForDebug() { reloadDictionaryIfRequired(); asyncExecuteTaskWithLock(mLock.readLock(), new Runnable() { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f1b1b8db2..8a2ed1088 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -55,7 +55,6 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.accessibility.AccessibilityUtils; -import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.dictionarypack.DictionaryPackConstants; @@ -541,18 +540,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen refreshPersonalizationDictionarySession(); } - private DistracterFilter createDistracterFilter() { - final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); - // TODO: Create Keyboard when mainKeyboardView is null. - // TODO: Figure out the most reasonable keyboard for the filter. Refer to the - // spellchecker's logic. - final Keyboard keyboard = (mainKeyboardView != null) ? - mainKeyboardView.getKeyboard() : null; - final DistracterFilter distracterFilter = new DistracterFilter(mInputLogic.mSuggest, - keyboard); - return distracterFilter; - } - private void refreshPersonalizationDictionarySession() { final DictionaryFacilitatorForSuggest dictionaryFacilitator = mInputLogic.mSuggest.mDictionaryFacilitator; @@ -734,6 +721,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged() // is not guaranteed. It may even be called at the same time on a different thread. mSubtypeSwitcher.onSubtypeChanged(subtype); + mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype)); loadKeyboard(); } @@ -809,7 +797,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // The app calling setText() has the effect of clearing the composing // span, so we should reset our state unconditionally, even if restarting is true. - mInputLogic.startInput(restarting, editorInfo); + // We also tell the input logic about the combining rules for the current subtype, so + // it can adjust its combiners if needed. + mInputLogic.startInput(restarting, editorInfo, + mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype()); // Note: the following does a round-trip IPC on the main thread: be careful final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); @@ -1002,10 +993,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen LatinImeLogger.commit(); mKeyboardSwitcher.onHideWindow(); - if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) { - AccessibleKeyboardViewProxy.getInstance().onHideWindow(); - } - if (TRACE) Debug.stopMethodTracing(); if (isShowingOptionDialog()) { mOptionsDialog.dismiss(); @@ -1179,7 +1166,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else { wordToEdit = word; } - mInputLogic.mSuggest.mDictionaryFacilitator.addWordToUserDictionary(wordToEdit); + mInputLogic.mSuggest.mDictionaryFacilitator.addWordToUserDictionary( + this /* context */, wordToEdit); } // Callback for the {@link SuggestionStripView}, to call when the important notice strip is @@ -1596,18 +1584,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onReleaseKey(final int primaryCode, final boolean withSliding) { mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding, getCurrentAutoCapsState(), getCurrentRecapitalizeState()); - - // If accessibility is on, ensure the user receives keyboard state updates. - if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - switch (primaryCode) { - case Constants.CODE_SHIFT: - AccessibleKeyboardViewProxy.getInstance().notifyShiftState(); - break; - case Constants.CODE_SWITCH_ALPHA_SYMBOL: - AccessibleKeyboardViewProxy.getInstance().notifySymbolsState(); - break; - } - } } private HardwareEventDecoder getHardwareKeyEventDecoder(final int deviceId) { @@ -1767,6 +1743,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.mSuggest.mDictionaryFacilitator.clearPersonalizationDictionary(); } + @UsedForTesting + /* package for test */ DistracterFilter createDistracterFilter() { + return DistracterFilter.createDistracterFilter(mInputLogic.mSuggest, mKeyboardSwitcher); + } + public void dumpDictionaryForDebug(final String dictName) { final DictionaryFacilitatorForSuggest dictionaryFacilitator = mInputLogic.mSuggest.mDictionaryFacilitator; diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java index 2b0be545e..64cc562c8 100644 --- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java +++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java @@ -410,12 +410,21 @@ public final class RichInputMethodManager { public boolean shouldOfferSwitchingToNextInputMethod(final IBinder binder, boolean defaultValue) { - // Use the default value instead on Jelly Bean MR2 and previous where - // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available - // and on KitKat where the API is still just a stub to return true always. - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { + // Use the default value instead on Jelly Bean MR2 and previous, where + // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available. + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { return defaultValue; } + // Use the default value instead on KitKat as well, where + // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is still just a stub to + // return true always. + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { + // Make sure this is actually KitKat. + // TODO: Consider to remove this check once the *next* version becomes available. + if (Build.VERSION.CODENAME.equals("REL")) { + return defaultValue; + } + } return mImmWrapper.shouldOfferSwitchingToNextInputMethod(binder); } } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 021133945..c8a2fb2f9 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -52,7 +52,6 @@ public final class SubtypeSwitcher { private /* final */ RichInputMethodManager mRichImm; private /* final */ Resources mResources; - private /* final */ ConnectivityManager mConnectivityManager; private final LanguageOnSpacebarHelper mLanguageOnSpacebarHelper = new LanguageOnSpacebarHelper(); @@ -111,10 +110,10 @@ public final class SubtypeSwitcher { } mResources = context.getResources(); mRichImm = RichInputMethodManager.getInstance(); - mConnectivityManager = (ConnectivityManager) context.getSystemService( + ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE); - final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); + final NetworkInfo info = connectivityManager.getActiveNetworkInfo(); mIsNetworkConnected = (info != null && info.isConnected()); onSubtypeChanged(getCurrentSubtype()); @@ -327,4 +326,8 @@ public final class SubtypeSwitcher { + DUMMY_EMOJI_SUBTYPE); return DUMMY_EMOJI_SUBTYPE; } + + public String getCombiningRulesExtraValueOfCurrentSubtype() { + return SubtypeLocaleUtils.getCombiningRulesExtraValue(getCurrentSubtype()); + } } diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java index 9d9ce0138..c8ffbe443 100644 --- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java @@ -28,8 +28,8 @@ import android.provider.UserDictionary.Words; import android.text.TextUtils; import android.util.Log; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.compat.UserDictionaryCompatUtils; -import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.io.File; @@ -51,42 +51,24 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { // to auto-correct, so we set this to the highest frequency that won't, i.e. 14. private static final int USER_DICT_SHORTCUT_FREQUENCY = 14; - // TODO: use Words.SHORTCUT when we target JellyBean or above - final static String SHORTCUT = "shortcut"; - private static final String[] PROJECTION_QUERY; - static { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - PROJECTION_QUERY = new String[] { - Words.WORD, - SHORTCUT, - Words.FREQUENCY, - }; - } else { - PROJECTION_QUERY = new String[] { - Words.WORD, - Words.FREQUENCY, - }; - } - } + private static final String[] PROJECTION_QUERY_WITH_SHORTCUT = new String[] { + Words.WORD, + Words.SHORTCUT, + Words.FREQUENCY, + }; + private static final String[] PROJECTION_QUERY_WITHOUT_SHORTCUT = new String[] { + Words.WORD, + Words.FREQUENCY, + }; private static final String NAME = "userunigram"; private ContentObserver mObserver; final private String mLocale; final private boolean mAlsoUseMoreRestrictiveLocales; - final public boolean mEnabled; - - public UserBinaryDictionary(final Context context, final Locale locale) { - this(context, locale, false /* alsoUseMoreRestrictiveLocales */, null /* dictFile */); - } - public UserBinaryDictionary(final Context context, final Locale locale, final File dictFile) { - this(context, locale, false /* alsoUseMoreRestrictiveLocales */, dictFile); - } - - public UserBinaryDictionary(final Context context, final Locale locale, - final boolean alsoUseMoreRestrictiveLocales, final File dictFile) { - this(context, locale, alsoUseMoreRestrictiveLocales, dictFile, NAME); + private UserBinaryDictionary(final Context context, final Locale locale, final File dictFile) { + this(context, locale, false /* alsoUseMoreRestrictiveLocales */, dictFile, NAME); } protected UserBinaryDictionary(final Context context, final Locale locale, @@ -116,14 +98,19 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { // devices. On older versions of the platform, the hook above will be called instead. @Override public void onChange(final boolean self, final Uri uri) { - setNeedsToReload(); + setNeedsToRecreate(); } }; cres.registerContentObserver(Words.CONTENT_URI, true, mObserver); - mEnabled = readIsEnabled(); reloadDictionaryIfRequired(); } + @UsedForTesting + public static UserBinaryDictionary getDictionary(final Context context, final Locale locale, + final File dictFile) { + return new UserBinaryDictionary(context, locale, dictFile); + } + @Override public synchronized void close() { if (mObserver != null) { @@ -182,10 +169,29 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { } else { requestArguments = localeElements; } + final String requestString = request.toString(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + try { + addWordsFromProjectionLocked(PROJECTION_QUERY_WITH_SHORTCUT, requestString, + requestArguments); + } catch (IllegalArgumentException e) { + // This may happen on some non-compliant devices where the declared API is JB+ but + // the SHORTCUT column is not present for some reason. + addWordsFromProjectionLocked(PROJECTION_QUERY_WITHOUT_SHORTCUT, requestString, + requestArguments); + } + } else { + addWordsFromProjectionLocked(PROJECTION_QUERY_WITHOUT_SHORTCUT, requestString, + requestArguments); + } + } + + private void addWordsFromProjectionLocked(final String[] query, String request, + final String[] requestArguments) throws IllegalArgumentException { Cursor cursor = null; try { cursor = mContext.getContentResolver().query( - Words.CONTENT_URI, PROJECTION_QUERY, request.toString(), requestArguments, null); + Words.CONTENT_URI, query, request, requestArguments, null); addWordsLocked(cursor); } catch (final SQLiteException e) { Log.e(TAG, "SQLiteException in the remote User dictionary process.", e); @@ -198,8 +204,8 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { } } - private boolean readIsEnabled() { - final ContentResolver cr = mContext.getContentResolver(); + public static boolean isEnabled(final Context context) { + final ContentResolver cr = context.getContentResolver(); final ContentProviderClient client = cr.acquireContentProviderClient(Words.CONTENT_URI); if (client != null) { client.release(); @@ -212,18 +218,15 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { /** * Adds a word to the user dictionary and makes it persistent. * + * @param context the context + * @param locale the locale * @param word the word to add. If the word is capitalized, then the dictionary will * recognize it as a capitalized word when searched. */ - public synchronized void addWordToUserDictionary(final String word) { + public static void addWordToUserDictionary(final Context context, final Locale locale, + final String word) { // Update the user dictionary provider - final Locale locale; - if (USER_DICTIONARY_ALL_LANGUAGES == mLocale) { - locale = null; - } else { - locale = LocaleUtils.constructLocaleFromString(mLocale); - } - UserDictionaryCompatUtils.addWord(mContext, word, + UserDictionaryCompatUtils.addWord(context, word, HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY, null, locale); } @@ -245,7 +248,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { if (cursor == null) return; if (cursor.moveToFirst()) { final int indexWord = cursor.getColumnIndex(Words.WORD); - final int indexShortcut = hasShortcutColumn ? cursor.getColumnIndex(SHORTCUT) : 0; + final int indexShortcut = hasShortcutColumn ? cursor.getColumnIndex(Words.SHORTCUT) : 0; final int indexFrequency = cursor.getColumnIndex(Words.FREQUENCY); while (!cursor.isAfterLast()) { final String word = cursor.getString(indexWord); @@ -269,9 +272,4 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { } } } - - @Override - protected boolean haveContentsChanged() { - return true; - } } diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index d755195f2..cdee496a8 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -41,6 +41,7 @@ public final class WordComposer { public static final int CAPS_MODE_AUTO_SHIFT_LOCKED = 0x7; private CombinerChain mCombinerChain; + private String mCombiningSpec; // Memory so that we don't uselessly recreate the combiner chain // The list of events that served to compose this string. private final ArrayList<Event> mEvents; @@ -91,6 +92,21 @@ public final class WordComposer { } /** + * Restart input with a new combining spec. + * @param combiningSpec The spec string for combining. This is found in the extra value. + */ + public void restart(final String combiningSpec) { + final String nonNullCombiningSpec = null == combiningSpec ? "" : combiningSpec; + if (nonNullCombiningSpec.equals(mCombiningSpec)) { + mCombinerChain.reset(); + } else { + mCombinerChain = new CombinerChain(CombinerChain.createCombiners(nonNullCombiningSpec)); + mCombiningSpec = nonNullCombiningSpec; + } + reset(); + } + + /** * Clear out the keys registered so far. */ public void reset() { diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index d2100d415..8b795b82f 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -97,6 +97,11 @@ public final class InputLogic { private boolean mIsAutoCorrectionIndicatorOn; private long mDoubleSpacePeriodCountdownStart; + /** + * Create a new instance of the input logic. + * @param latinIME the instance of the parent LatinIME. We should remove this when we can. + * @param suggestionStripViewAccessor an object to access the suggestion strip view. + */ public InputLogic(final LatinIME latinIME, final SuggestionStripViewAccessor suggestionStripViewAccessor) { mLatinIME = latinIME; @@ -117,9 +122,12 @@ public final class InputLogic { * * @param restarting whether input is starting in the same field as before. Unused for now. * @param editorInfo the editorInfo associated with the editor. + * @param combiningSpec the combining spec string for this subtype */ - public void startInput(final boolean restarting, final EditorInfo editorInfo) { + public void startInput(final boolean restarting, final EditorInfo editorInfo, + final String combiningSpec) { mEnteredText = null; + mWordComposer.restart(combiningSpec); resetComposingState(true /* alsoResetLastComposedWord */); mDeleteCount = 0; mSpaceState = SpaceState.NONE; @@ -138,6 +146,14 @@ public final class InputLogic { } /** + * Call this when the subtype changes. + * @param combiningSpec the spec string for the combining rules + */ + public void onSubtypeChanged(final String combiningSpec) { + mWordComposer.restart(combiningSpec); + } + + /** * Clean up the input logic after input is finished. */ public void finishInput() { @@ -588,7 +604,7 @@ public final class InputLogic { if (null != candidate && mSuggestedWords.mSequenceNumber >= mAutoCommitSequenceNumber) { if (candidate.mSourceDict.shouldAutoCommit(candidate)) { - final String[] commitParts = candidate.mWord.split(" ", 2); + final String[] commitParts = candidate.mWord.split(Constants.WORD_SEPARATOR, 2); batchPointers.shift(candidate.mIndexOfTouchPointOfSecondWord); promotePhantomSpace(settingsValues); mConnection.commitText(commitParts[0], 0); @@ -784,11 +800,11 @@ public final class InputLogic { // TODO: remove this argument final LatinIME.UIHandler handler) { final int codePoint = inputTransaction.mEvent.mCodePoint; + final SettingsValues settingsValues = inputTransaction.mSettingsValues; boolean didAutoCorrect = false; // We avoid sending spaces in languages without spaces if we were composing. final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint - && !inputTransaction.mSettingsValues.mSpacingAndPunctuations - .mCurrentLanguageHasSpaces + && !settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces && mWordComposer.isComposingWord(); if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) { // If we are in the middle of a recorrection, we need to commit the recorrection @@ -798,13 +814,13 @@ public final class InputLogic { } // isComposingWord() may have changed since we stored wasComposing if (mWordComposer.isComposingWord()) { - if (inputTransaction.mSettingsValues.mCorrectionEnabled) { + if (settingsValues.mCorrectionEnabled) { final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR : StringUtils.newSingleCodePointString(codePoint); - commitCurrentAutoCorrection(inputTransaction.mSettingsValues, separator, handler); + commitCurrentAutoCorrection(settingsValues, separator, handler); didAutoCorrect = true; } else { - commitTyped(inputTransaction.mSettingsValues, + commitTyped(settingsValues, StringUtils.newSingleCodePointString(codePoint)); } } @@ -821,20 +837,23 @@ public final class InputLogic { // Double quotes behave like they are usually preceded by space iff we are // not inside a double quote or after a digit. needsPrecedingSpace = !isInsideDoubleQuoteOrAfterDigit; + } else if (settingsValues.mSpacingAndPunctuations.isClusteringSymbol(codePoint) + && settingsValues.mSpacingAndPunctuations.isClusteringSymbol( + mConnection.getCodePointBeforeCursor())) { + needsPrecedingSpace = false; } else { - needsPrecedingSpace = inputTransaction.mSettingsValues.isUsuallyPrecededBySpace( - codePoint); + needsPrecedingSpace = settingsValues.isUsuallyPrecededBySpace(codePoint); } if (needsPrecedingSpace) { - promotePhantomSpace(inputTransaction.mSettingsValues); + promotePhantomSpace(settingsValues); } if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_handleSeparator(codePoint, mWordComposer.isComposingWord()); } if (!shouldAvoidSendingCode) { - sendKeyCodePoint(inputTransaction.mSettingsValues, codePoint); + sendKeyCodePoint(settingsValues, codePoint); } if (Constants.CODE_SPACE == codePoint) { @@ -852,7 +871,7 @@ public final class InputLogic { swapSwapperAndSpace(inputTransaction); mSpaceState = SpaceState.SWAP_PUNCTUATION; } else if ((SpaceState.PHANTOM == inputTransaction.mSpaceState - && inputTransaction.mSettingsValues.isUsuallyFollowedBySpace(codePoint)) + && settingsValues.isUsuallyFollowedBySpace(codePoint)) || (Constants.CODE_DOUBLE_QUOTE == codePoint && isInsideDoubleQuoteOrAfterDigit)) { // If we are in phantom space state, and the user presses a separator, we want to @@ -1222,7 +1241,7 @@ public final class InputLogic { final int timeStampInSeconds = (int)TimeUnit.MILLISECONDS.toSeconds( System.currentTimeMillis()); mSuggest.mDictionaryFacilitator.addToUserHistory(suggestion, wasAutoCapitalized, prevWord, - timeStampInSeconds); + timeStampInSeconds, settingsValues.mBlockPotentiallyOffensive); } public void performUpdateSuggestionStripSync(final SettingsValues settingsValues) { @@ -1943,10 +1962,11 @@ public final class InputLogic { final CharSequence chosenWordWithSuggestions = SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord, suggestedWords); - mConnection.commitText(chosenWordWithSuggestions, 1); - // TODO: we pass 2 here, but would it be better to move this above and pass 1 instead? + // Use the 2nd previous word as the previous word because the 1st previous word is the word + // to be committed. final String prevWord = mConnection.getNthPreviousWord( settingsValues.mSpacingAndPunctuations, 2); + mConnection.commitText(chosenWordWithSuggestions, 1); // Add the word to the user history dictionary performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWord); // TODO: figure out here if this is an auto-correct or if the best word is actually diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java index f25503488..613ff2ba4 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java @@ -186,7 +186,12 @@ public final class FormatSpec { // From version 4 on, we use version * 100 + revision as a version number. That allows // us to change the format during development while having testing devices remove // older files with each upgrade, while still having a readable versioning scheme. + // When we bump up the dictionary format version, we should update + // ExpandableDictionary.needsToMigrateDictionary() and + // ExpandableDictionary.matchesExpectedBinaryDictFormatVersionForThisType(). public static final int VERSION2 = 2; + // Dictionary version used for testing. + public static final int VERSION4_ONLY_FOR_TESTING = 399; public static final int VERSION4 = 401; static final int MINIMUM_SUPPORTED_VERSION = VERSION2; static final int MAXIMUM_SUPPORTED_VERSION = VERSION4; diff --git a/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java b/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java new file mode 100644 index 000000000..96f03f9ff --- /dev/null +++ b/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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. + */ + +package com.android.inputmethod.latin.personalization; + +import android.content.Context; + +import com.android.inputmethod.annotations.UsedForTesting; +import com.android.inputmethod.latin.Dictionary; +import com.android.inputmethod.latin.ExpandableBinaryDictionary; + +import java.io.File; +import java.util.Locale; + +public class ContextualDictionary extends ExpandableBinaryDictionary { + /* package */ static final String NAME = PersonalizationDictionary.class.getSimpleName(); + + private ContextualDictionary(final Context context, final Locale locale, + final File dictFile) { + super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_CONTEXTUAL, + dictFile); + // Always reset the contents. + clear(); + } + @UsedForTesting + public static ContextualDictionary getDictionary(final Context context, final Locale locale, + final File dictFile) { + return new ContextualDictionary(context, locale, dictFile); + } + + @Override + public boolean isValidWord(final String word) { + // Strings out of this dictionary should not be considered existing words. + return false; + } + + @Override + protected void loadInitialContentsLocked() { + } +} diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java index 352288f8b..06bdba054 100644 --- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java +++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java @@ -18,15 +18,11 @@ package com.android.inputmethod.latin.personalization; import android.content.Context; -import com.android.inputmethod.annotations.UsedForTesting; -import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.makedict.DictionaryHeader; -import com.android.inputmethod.latin.utils.LanguageModelParam; import java.io.File; -import java.util.ArrayList; import java.util.Locale; import java.util.Map; @@ -47,8 +43,6 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB /** The locale for this dictionary. */ public final Locale mLocale; - private Map<String, String> mAdditionalAttributeMap = null; - protected DecayingExpandableBinaryDictionaryBase(final Context context, final String dictName, final Locale locale, final String dictionaryType, final File dictFile) { @@ -72,9 +66,6 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB @Override protected Map<String, String> getHeaderAttributeMap() { final Map<String, String> attributeMap = super.getHeaderAttributeMap(); - if (mAdditionalAttributeMap != null) { - attributeMap.putAll(mAdditionalAttributeMap); - } attributeMap.put(DictionaryHeader.USES_FORGETTING_CURVE_KEY, DictionaryHeader.ATTRIBUTE_VALUE_TRUE); attributeMap.put(DictionaryHeader.HAS_HISTORICAL_INFO_KEY, @@ -83,22 +74,10 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB } @Override - protected boolean haveContentsChanged() { - return false; - } - - @Override protected void loadInitialContentsLocked() { // No initial contents. } - @UsedForTesting - public void clearAndFlushDictionaryWithAdditionalAttributes( - final Map<String, String> attributeMap) { - mAdditionalAttributeMap = attributeMap; - clear(); - } - /* package */ void runGCIfRequired() { runGCIfRequired(false /* mindsBlockByGC */); } diff --git a/java/src/com/android/inputmethod/latin/personalization/DictionaryDecayBroadcastReciever.java b/java/src/com/android/inputmethod/latin/personalization/DictionaryDecayBroadcastReciever.java index de2744f29..221bb9a8f 100644 --- a/java/src/com/android/inputmethod/latin/personalization/DictionaryDecayBroadcastReciever.java +++ b/java/src/com/android/inputmethod/latin/personalization/DictionaryDecayBroadcastReciever.java @@ -61,6 +61,7 @@ public class DictionaryDecayBroadcastReciever extends BroadcastReceiver { final String action = intent.getAction(); if (action.equals(DICTIONARY_DECAY_INTENT_ACTION)) { PersonalizationHelper.runGCOnAllOpenedUserHistoryDictionaries(); + PersonalizationHelper.runGCOnAllOpenedPersonalizationDictionaries(); } } } diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java index 4afd5b4c9..1423fceff 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin.personalization; import android.content.Context; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.Dictionary; import java.io.File; @@ -26,14 +27,16 @@ import java.util.Locale; public class PersonalizationDictionary extends DecayingExpandableBinaryDictionaryBase { /* package */ static final String NAME = PersonalizationDictionary.class.getSimpleName(); + // TODO: Make this constructor private /* package */ PersonalizationDictionary(final Context context, final Locale locale) { - this(context, locale, null /* dictFile */); + super(context, getDictName(NAME, locale, null /* dictFile */), locale, + Dictionary.TYPE_PERSONALIZATION, null /* dictFile */); } - public PersonalizationDictionary(final Context context, final Locale locale, - final File dictFile) { - super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_PERSONALIZATION, - dictFile); + @UsedForTesting + public static PersonalizationDictionary getDictionary(final Context context, + final Locale locale, final File dictFile) { + return PersonalizationHelper.getPersonalizationDictionary(context, locale); } @Override diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java index 7c43182bc..afacd085b 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java @@ -16,7 +16,6 @@ package com.android.inputmethod.latin.personalization; -import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.FileUtils; @@ -66,8 +65,8 @@ public class PersonalizationHelper { if (TimeUnit.MILLISECONDS.toSeconds( DictionaryDecayBroadcastReciever.DICTIONARY_DECAY_INTERVAL) < currentTimestamp - sCurrentTimestampForTesting) { - // TODO: Run GC for both PersonalizationDictionary and UserHistoryDictionary. runGCOnAllOpenedUserHistoryDictionaries(); + runGCOnAllOpenedPersonalizationDictionaries(); } } @@ -75,7 +74,6 @@ public class PersonalizationHelper { runGCOnAllDictionariesIfRequired(sLangUserHistoryDictCache); } - @UsedForTesting public static void runGCOnAllOpenedPersonalizationDictionaries() { runGCOnAllDictionariesIfRequired(sLangPersonalizationDictCache); } diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java index 8a29c354d..818cd9a5f 100644 --- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin.personalization; import android.content.Context; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.ExpandableBinaryDictionary; @@ -32,14 +33,16 @@ import java.util.Locale; public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase { /* package */ static final String NAME = UserHistoryDictionary.class.getSimpleName(); + // TODO: Make this constructor private /* package */ UserHistoryDictionary(final Context context, final Locale locale) { - this(context, locale, null /* dictFile */); + super(context, getDictName(NAME, locale, null /* dictFile */), locale, + Dictionary.TYPE_USER_HISTORY, null /* dictFile */); } - public UserHistoryDictionary(final Context context, final Locale locale, + @UsedForTesting + public static UserHistoryDictionary getDictionary(final Context context, final Locale locale, final File dictFile) { - super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_USER_HISTORY, - dictFile); + return PersonalizationHelper.getUserHistoryDictionary(context, locale); } @Override diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index a3aae8cb3..4e4c8885c 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -64,7 +64,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang "pref_show_language_switch_key"; public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST = "pref_include_other_imes_in_language_switch_list"; - public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20110916"; + public static final String PREF_KEYBOARD_THEME = "pref_keyboard_theme"; public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles"; // TODO: consolidate key preview dismiss delay with the key preview animation parameters. public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java index 22cbd204c..e1d38e7c4 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java @@ -37,6 +37,7 @@ import android.util.Log; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.dictionarypack.DictionarySettingsActivity; +import com.android.inputmethod.keyboard.KeyboardTheme; import com.android.inputmethod.latin.AudioAndHapticFeedbackManager; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; @@ -253,11 +254,31 @@ public final class SettingsFragment extends InputMethodSettingsFragment } updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING); updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); - updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_LAYOUT); + final ListPreference keyboardThemePref = (ListPreference)findPreference( + Settings.PREF_KEYBOARD_THEME); + if (keyboardThemePref != null) { + final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs); + final String value = Integer.toString(keyboardTheme.mThemeId); + final CharSequence entries[] = keyboardThemePref.getEntries(); + final int entryIndex = keyboardThemePref.findIndexOfValue(value); + keyboardThemePref.setSummary(entryIndex < 0 ? null : entries[entryIndex]); + keyboardThemePref.setValue(value); + } updateCustomInputStylesSummary(prefs, res); } @Override + public void onPause() { + super.onPause(); + final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); + final ListPreference keyboardThemePref = (ListPreference)findPreference( + Settings.PREF_KEYBOARD_THEME); + if (keyboardThemePref != null) { + KeyboardTheme.saveKeyboardThemeId(keyboardThemePref.getValue(), prefs); + } + } + + @Override public void onDestroy() { getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener( this); @@ -287,7 +308,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment ensureConsistencyOfAutoCorrectionSettings(); updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING); updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); - updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_LAYOUT); + updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_THEME); refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources()); } diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index dde50ccaf..de2eb951e 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -205,7 +205,8 @@ public final class SettingsValues { } public boolean isWordCodePoint(final int code) { - return Character.isLetter(code) || isWordConnector(code); + return Character.isLetter(code) || isWordConnector(code) + || Character.COMBINING_SPACING_MARK == Character.getType(code); } public boolean isUsuallyPrecededBySpace(final int code) { diff --git a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java index 796921f71..b8d2a2248 100644 --- a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java +++ b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java @@ -30,6 +30,7 @@ import java.util.Locale; public final class SpacingAndPunctuations { private final int[] mSortedSymbolsPrecededBySpace; private final int[] mSortedSymbolsFollowedBySpace; + private final int[] mSortedSymbolsClusteringTogether; private final int[] mSortedWordConnectors; public final int[] mSortedWordSeparators; public final PunctuationSuggestions mSuggestPuncList; @@ -46,6 +47,8 @@ public final class SpacingAndPunctuations { // To be able to binary search the code point. See {@link #isUsuallyFollowedBySpace(int)}. mSortedSymbolsFollowedBySpace = StringUtils.toSortedCodePointArray( res.getString(R.string.symbols_followed_by_space)); + mSortedSymbolsClusteringTogether = StringUtils.toSortedCodePointArray( + res.getString(R.string.symbols_clustering_together)); // To be able to binary search the code point. See {@link #isWordConnector(int)}. mSortedWordConnectors = StringUtils.toSortedCodePointArray( res.getString(R.string.symbols_word_connectors)); @@ -85,6 +88,10 @@ public final class SpacingAndPunctuations { return Arrays.binarySearch(mSortedSymbolsFollowedBySpace, code) >= 0; } + public boolean isClusteringSymbol(final int code) { + return Arrays.binarySearch(mSortedSymbolsClusteringTogether, code) >= 0; + } + public boolean isSentenceSeparator(final int code) { return code == mSentenceSeparator; } diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java index 1d84bb59f..810bda758 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java @@ -309,9 +309,8 @@ final class SuggestionStripLayoutHelper { setupWordViewsTextAndColor(suggestedWords, mSuggestionsCountInStrip); final TextView centerWordView = mWordViews.get(mCenterPositionInStrip); - final int availableStripWidth = placerView.getWidth() - - placerView.getPaddingRight() - placerView.getPaddingLeft(); - final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, availableStripWidth); + final int stripWidth = stripView.getWidth(); + final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, stripWidth); final int countInStrip; if (suggestedWords.size() == 1 || getTextScaleX(centerWordView.getText(), centerWidth, centerWordView.getPaint()) < MIN_TEXT_XSCALE) { @@ -319,11 +318,11 @@ final class SuggestionStripLayoutHelper { // by consolidating all slots in the strip. countInStrip = 1; mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip); - layoutWord(mCenterPositionInStrip, availableStripWidth - mPadding); + layoutWord(mCenterPositionInStrip, stripWidth - mPadding); stripView.addView(centerWordView); setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT); if (SuggestionStripView.DBG) { - layoutDebugInfo(mCenterPositionInStrip, placerView, availableStripWidth); + layoutDebugInfo(mCenterPositionInStrip, placerView, stripWidth); } } else { countInStrip = mSuggestionsCountInStrip; @@ -337,7 +336,7 @@ final class SuggestionStripLayoutHelper { x += divider.getMeasuredWidth(); } - final int width = getSuggestionWidth(positionInStrip, availableStripWidth); + final int width = getSuggestionWidth(positionInStrip, stripWidth); final TextView wordView = layoutWord(positionInStrip, width); stripView.addView(wordView); setLayoutWeight(wordView, getSuggestionWeight(positionInStrip), @@ -382,6 +381,7 @@ final class SuggestionStripLayoutHelper { } // Disable this suggestion if the suggestion is null or empty. + // TODO: Fix disabled {@link TextView}'s content description. wordView.setEnabled(!TextUtils.isEmpty(word)); final CharSequence text = getEllipsizedText(word, width, wordView.getPaint()); final float scaleX = getTextScaleX(word, width, wordView.getPaint()); @@ -425,7 +425,9 @@ final class SuggestionStripLayoutHelper { final int countInStrip) { // Clear all suggestions first for (int positionInStrip = 0; positionInStrip < countInStrip; ++positionInStrip) { - mWordViews.get(positionInStrip).setText(null); + final TextView wordView = mWordViews.get(positionInStrip); + wordView.setText(null); + wordView.setTag(null); // Make this inactive for touches in {@link #layoutWord(int,int)}. if (SuggestionStripView.DBG) { mDebugInfoViews.get(positionInStrip).setText(null); @@ -474,8 +476,8 @@ final class SuggestionStripLayoutHelper { return countInStrip; } - public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip, - final int stripWidth) { + public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) { + final int stripWidth = addToDictionaryStrip.getWidth(); final int width = stripWidth - mDividerWidth - mPadding * 2; final TextView wordView = (TextView)addToDictionaryStrip.findViewById(R.id.word_to_save); diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index a0793b133..619804afa 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -18,7 +18,9 @@ package com.android.inputmethod.latin.suggestions; import android.content.Context; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.support.v4.view.ViewCompat; import android.text.TextUtils; import android.util.AttributeSet; @@ -31,6 +33,7 @@ import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.view.ViewParent; +import android.widget.ImageButton; import android.widget.RelativeLayout; import android.widget.TextView; @@ -59,12 +62,14 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick public void addWordToUserDictionary(String word); public void showImportantNoticeContents(); public void pickSuggestionManually(int index, SuggestedWordInfo word); + public void onCodeInput(int primaryCode, int x, int y, boolean isKeyRepeat); } static final boolean DBG = LatinImeLogger.sDBG; private static final float DEBUG_INFO_TEXT_SIZE_IN_DIP = 6.0f; private final ViewGroup mSuggestionsStrip; + private final ImageButton mVoiceKey; private final ViewGroup mAddToDictionaryStrip; private final View mImportantNoticeStrip; MainKeyboardView mMainKeyboardView; @@ -86,39 +91,42 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick private static class StripVisibilityGroup { private final View mSuggestionsStrip; + private final View mVoiceKey; private final View mAddToDictionaryStrip; private final View mImportantNoticeStrip; - public StripVisibilityGroup(final View suggestionsStrip, final View addToDictionaryStrip, - final View importantNoticeStrip) { + public StripVisibilityGroup(final View suggestionsStrip, final View voiceKey, + final View addToDictionaryStrip, final View importantNoticeStrip) { mSuggestionsStrip = suggestionsStrip; + mVoiceKey = voiceKey; mAddToDictionaryStrip = addToDictionaryStrip; mImportantNoticeStrip = importantNoticeStrip; - showSuggestionsStrip(); + showSuggestionsStrip(false /* voiceKeyEnabled */); } - public void setLayoutDirection(final boolean isRtlLanguage) { - final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL - : ViewCompat.LAYOUT_DIRECTION_LTR; + public void setLayoutDirection(final int layoutDirection) { ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection); ViewCompat.setLayoutDirection(mAddToDictionaryStrip, layoutDirection); ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection); } - public void showSuggestionsStrip() { + public void showSuggestionsStrip(final boolean enableVoiceKey) { mSuggestionsStrip.setVisibility(VISIBLE); + mVoiceKey.setVisibility(enableVoiceKey ? VISIBLE : INVISIBLE); mAddToDictionaryStrip.setVisibility(INVISIBLE); mImportantNoticeStrip.setVisibility(INVISIBLE); } public void showAddToDictionaryStrip() { mSuggestionsStrip.setVisibility(INVISIBLE); + mVoiceKey.setVisibility(INVISIBLE); mAddToDictionaryStrip.setVisibility(VISIBLE); mImportantNoticeStrip.setVisibility(INVISIBLE); } - public void showImportantNoticeStrip() { + public void showImportantNoticeStrip(final boolean enableVoiceKey) { mSuggestionsStrip.setVisibility(INVISIBLE); + mVoiceKey.setVisibility(enableVoiceKey ? VISIBLE : INVISIBLE); mAddToDictionaryStrip.setVisibility(INVISIBLE); mImportantNoticeStrip.setVisibility(VISIBLE); } @@ -145,10 +153,11 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick inflater.inflate(R.layout.suggestions_strip, this); mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip); + mVoiceKey = (ImageButton)findViewById(R.id.suggestions_strip_voice_key); mAddToDictionaryStrip = (ViewGroup)findViewById(R.id.add_to_dictionary_strip); mImportantNoticeStrip = findViewById(R.id.important_notice_strip); - mStripVisibilityGroup = new StripVisibilityGroup(mSuggestionsStrip, mAddToDictionaryStrip, - mImportantNoticeStrip); + mStripVisibilityGroup = new StripVisibilityGroup(mSuggestionsStrip, mVoiceKey, + mAddToDictionaryStrip, mImportantNoticeStrip); for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) { final TextView word = new TextView(context, null, R.attr.suggestionWordStyle); @@ -177,6 +186,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick R.dimen.config_more_suggestions_modal_tolerance); mMoreSuggestionsSlidingDetector = new GestureDetector( context, mMoreSuggestionsSlidingListener); + + final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs, + R.styleable.Keyboard, defStyle, R.style.SuggestionStripView); + final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey); + keyboardAttr.recycle(); + mVoiceKey.setImageDrawable(iconVoice); + mVoiceKey.setOnClickListener(this); } /** @@ -188,16 +204,30 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view); } + private boolean isVoiceKeyEnabled() { + if (mMainKeyboardView == null) { + return false; + } + final Keyboard keyboard = mMainKeyboardView.getKeyboard(); + if (keyboard == null) { + return false; + } + return keyboard.mId.mHasShortcutKey; + } + public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) { clear(); - mStripVisibilityGroup.setLayoutDirection(isRtlLanguage); + final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL + : ViewCompat.LAYOUT_DIRECTION_LTR; + setLayoutDirection(layoutDirection); + mStripVisibilityGroup.setLayoutDirection(layoutDirection); mSuggestedWords = suggestedWords; mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip( mSuggestedWords, mSuggestionsStrip, this); if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords); } - mStripVisibilityGroup.showSuggestionsStrip(); + mStripVisibilityGroup.showSuggestionsStrip(isVoiceKeyEnabled()); } public int setMoreSuggestionsHeight(final int remainingHeight) { @@ -209,7 +239,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick } public void showAddToDictionaryHint(final String word) { - mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip, getWidth()); + mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip); // {@link TextView#setTag()} is used to hold the word to be added to dictionary. The word // will be extracted at {@link #onClick(View)}. mAddToDictionaryStrip.setTag(word); @@ -244,7 +274,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick dismissMoreSuggestionsPanel(); } mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, importantNoticeTitle); - mStripVisibilityGroup.showImportantNoticeStrip(); + mStripVisibilityGroup.showImportantNoticeStrip(isVoiceKeyEnabled()); mImportantNoticeStrip.setOnClickListener(this); return true; } @@ -252,7 +282,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick public void clear() { mSuggestionsStrip.removeAllViews(); removeAllDebugInfoViews(); - mStripVisibilityGroup.showSuggestionsStrip(); + mStripVisibilityGroup.showSuggestionsStrip(false /* enableVoiceKey */); dismissMoreSuggestionsPanel(); } @@ -415,6 +445,12 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick mListener.showImportantNoticeContents(); return; } + if (view == mVoiceKey) { + mListener.onCodeInput(Constants.CODE_SHORTCUT, + Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, + false /* isKeyRepeat */); + return; + } final Object tag = view.getTag(); // {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}. if (tag instanceof String) { diff --git a/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java b/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java index f2a1e524d..55cbf79b3 100644 --- a/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java +++ b/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java @@ -17,21 +17,35 @@ package com.android.inputmethod.latin.utils; import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.KeyboardSwitcher; +import com.android.inputmethod.keyboard.MainKeyboardView; +import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Suggest; +import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback; +import com.android.inputmethod.latin.SuggestedWords; +import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import com.android.inputmethod.latin.WordComposer; /** - * This class is used to prevent distracters/misspellings being added to personalization + * This class is used to prevent distracters being added to personalization * or user history dictionaries */ public class DistracterFilter { private final Suggest mSuggest; private final Keyboard mKeyboard; + // If the score of the top suggestion exceeds this value, the tested word (e.g., + // an OOV, a misspelling, or an in-vocabulary word) would be considered as a distracter to + // words in dictionary. The greater the threshold is, the less likely the tested word would + // become a distracter, which means the tested word will be more likely to be added to + // the dictionary. + private static final float DISTRACTER_WORD_SCORE_THRESHOLD = 2.0f; + /** * Create a DistracterFilter instance. * * @param suggest an instance of Suggest which will be used to obtain a list of suggestions - * for a potential distracter/misspelling + * for a potential distracter * @param keyboard the keyboard that is currently being used. This information is needed * when calling mSuggest.getSuggestedWords(...) to obtain a list of suggestions. */ @@ -40,9 +54,79 @@ public class DistracterFilter { mKeyboard = keyboard; } - public boolean isDistractorToWordsInDictionaries(final String prevWord, - final String targetWord) { - // TODO: to be implemented + public static DistracterFilter createDistracterFilter(final Suggest suggest, + final KeyboardSwitcher keyboardSwitcher) { + final MainKeyboardView mainKeyboardView = keyboardSwitcher.getMainKeyboardView(); + // TODO: Create Keyboard when mainKeyboardView is null. + // TODO: Figure out the most reasonable keyboard for the filter. Refer to the + // spellchecker's logic. + final Keyboard keyboard = (mainKeyboardView != null) ? + mainKeyboardView.getKeyboard() : null; + final DistracterFilter distracterFilter = new DistracterFilter(suggest, keyboard); + return distracterFilter; + } + + private static boolean suggestionExceedsDistracterThreshold( + final SuggestedWordInfo suggestion, final String consideredWord, + final float distracterThreshold) { + if (null != suggestion) { + final int suggestionScore = suggestion.mScore; + final float normalizedScore = BinaryDictionaryUtils.calcNormalizedScore( + consideredWord, suggestion.mWord, suggestionScore); + if (normalizedScore > distracterThreshold) { + return true; + } + } return false; } + + /** + * Determine whether a word is a distracter to words in dictionaries. + * + * @param prevWord the previous word, or null if none. + * @param testedWord the word that will be tested to see whether it is a distracter to words + * in dictionaries. + * @return true if testedWord is a distracter, otherwise false. + */ + public boolean isDistracterToWordsInDictionaries(final String prevWord, + final String testedWord) { + if (mSuggest == null) { + return false; + } + + final WordComposer composer = new WordComposer(); + final int[] codePoints = StringUtils.toCodePointArray(testedWord); + final int[] coordinates; + if (null == mKeyboard) { + coordinates = CoordinateUtils.newCoordinateArray(codePoints.length, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); + } else { + coordinates = mKeyboard.getCoordinates(codePoints); + } + composer.setComposingWord(codePoints, coordinates, prevWord); + + final int trailingSingleQuotesCount = composer.trailingSingleQuotesCount(); + final String consideredWord = trailingSingleQuotesCount > 0 ? testedWord.substring(0, + testedWord.length() - trailingSingleQuotesCount) : testedWord; + final AsyncResultHolder<Boolean> holder = new AsyncResultHolder<Boolean>(); + final OnGetSuggestedWordsCallback callback = new OnGetSuggestedWordsCallback() { + @Override + public void onGetSuggestedWords(final SuggestedWords suggestedWords) { + if (suggestedWords != null && suggestedWords.size() > 1) { + // The suggestedWordInfo at 0 is the typed word. The 1st suggestion from + // the decoder is at index 1. + final SuggestedWordInfo firstSuggestion = suggestedWords.getInfo(1); + final boolean hasStrongDistractor = suggestionExceedsDistracterThreshold( + firstSuggestion, consideredWord, DISTRACTER_WORD_SCORE_THRESHOLD); + holder.set(hasStrongDistractor); + } + } + }; + mSuggest.getSuggestedWords(composer, prevWord, mKeyboard.getProximityInfo(), + true /* blockOffensiveWords */, true /* isCorrectionEnbaled */, + null /* additionalFeaturesOptions */, 0 /* sessionId */, + SuggestedWords.NOT_A_SEQUENCE_NUMBER, callback); + + return holder.get(false /* defaultValue */, Constants.GET_SUGGESTED_WORDS_TIMEOUT); + } } diff --git a/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java b/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java index 5ce977d5e..74e7db901 100644 --- a/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java +++ b/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java @@ -80,7 +80,8 @@ public final class LanguageModelParam { public static ArrayList<LanguageModelParam> createLanguageModelParamsFrom( final ArrayList<String> tokens, final int timestamp, final DictionaryFacilitatorForSuggest dictionaryFacilitator, - final SpacingAndPunctuations spacingAndPunctuations) { + final SpacingAndPunctuations spacingAndPunctuations, + final DistracterFilter distracterFilter) { final ArrayList<LanguageModelParam> languageModelParams = CollectionUtils.newArrayList(); final int N = tokens.size(); @@ -109,7 +110,8 @@ public final class LanguageModelParam { } final LanguageModelParam languageModelParam = detectWhetherVaildWordOrNotAndGetLanguageModelParam( - prevWord, tempWord, timestamp, dictionaryFacilitator); + prevWord, tempWord, timestamp, dictionaryFacilitator, + distracterFilter); if (languageModelParam == null) { continue; } @@ -121,27 +123,36 @@ public final class LanguageModelParam { private static LanguageModelParam detectWhetherVaildWordOrNotAndGetLanguageModelParam( final String prevWord, final String targetWord, final int timestamp, - final DictionaryFacilitatorForSuggest dictionaryFacilitator) { + final DictionaryFacilitatorForSuggest dictionaryFacilitator, + final DistracterFilter distracterFilter) { final Locale locale = dictionaryFacilitator.getLocale(); if (locale == null) { return null; } - if (!dictionaryFacilitator.isValidWord(targetWord, true /* ignoreCase */)) { - // OOV word. - return createAndGetLanguageModelParamOfWord(prevWord, targetWord, timestamp, - false /* isValidWord */, locale); - } + // TODO: Though targetWord is an IV (in-vocabulary) word, we should still apply + // distracterFilter in the following code. If targetWord is a distracter, + // it should be filtered out. if (dictionaryFacilitator.isValidWord(targetWord, false /* ignoreCase */)) { return createAndGetLanguageModelParamOfWord(prevWord, targetWord, timestamp, true /* isValidWord */, locale); } + final String lowerCaseTargetWord = targetWord.toLowerCase(locale); if (dictionaryFacilitator.isValidWord(lowerCaseTargetWord, false /* ignoreCase */)) { // Add the lower-cased word. return createAndGetLanguageModelParamOfWord(prevWord, lowerCaseTargetWord, timestamp, true /* isValidWord */, locale); } - // Treat the word as an OOV word. + + // Treat the word as an OOV word. The following statement checks whether this OOV + // is a distracter to words in dictionaries. Being a distracter means the OOV word is + // too close to a common word in dictionaries (e.g., the OOV "mot" is very close to "not"). + // Adding such a word to dictonaries would interfere with entering in-dictionary words. For + // example, adding "mot" to dictionaries might interfere with entering "not". + // This kind of OOV should be filtered out. + if (distracterFilter.isDistracterToWordsInDictionaries(prevWord, targetWord)) { + return null; + } return createAndGetLanguageModelParamOfWord(prevWord, targetWord, timestamp, false /* isValidWord */, locale); } diff --git a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java index a23b3ac79..bf38abc95 100644 --- a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java +++ b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin.utils; +import com.android.inputmethod.annotations.UsedForTesting; + import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ConcurrentLinkedQueue; @@ -74,6 +76,7 @@ public class PrioritizedSerialExecutor { * Enqueues the given task into the prioritized task queue. * @param r the enqueued task */ + @UsedForTesting public void executePrioritized(final Runnable r) { synchronized(mLock) { if (!mIsShutdown) { diff --git a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java index b37779bdc..938d27122 100644 --- a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java @@ -324,4 +324,8 @@ public final class SubtypeLocaleUtils { public static boolean isRtlLanguage(final InputMethodSubtype subtype) { return isRtlLanguage(getSubtypeLocale(subtype)); } + + public static String getCombiningRulesExtraValue(final InputMethodSubtype subtype) { + return subtype.getExtraValueOf(Constants.Subtype.ExtraValue.COMBINING_RULES); + } } |