aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java377
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java11
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java164
-rw-r--r--java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java5
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java18
-rw-r--r--java/src/com/android/inputmethod/compat/AccessibilityEventCompatUtils.java22
-rw-r--r--java/src/com/android/inputmethod/compat/AccessibilityManagerCompatUtils.java (renamed from java/src/com/android/inputmethod/compat/AccessibilityManagerCompatWrapper.java)12
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java5
-rw-r--r--java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java2
-rw-r--r--java/src/com/android/inputmethod/compat/ViewParentCompatUtils.java51
-rw-r--r--java/src/com/android/inputmethod/deprecated/VoiceProxy.java38
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java23
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyDetector.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java17
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardId.java31
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSet.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java19
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java64
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java7
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java53
-rw-r--r--java/src/com/android/inputmethod/latin/ComposingStateManager.java7
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java73
-rw-r--r--java/src/com/android/inputmethod/latin/LatinImeLogger.java2
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java7
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java66
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java47
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java4
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java76
30 files changed, 830 insertions, 380 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
new file mode 100644
index 000000000..dc7c12ba6
--- /dev/null
+++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
@@ -0,0 +1,377 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.accessibility;
+
+import android.graphics.Rect;
+import android.inputmethodservice.InputMethodService;
+import android.support.v4.view.ViewCompat;
+import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
+import android.support.v4.view.accessibility.AccessibilityNodeProviderCompat;
+import android.support.v4.view.accessibility.AccessibilityRecordCompat;
+import android.util.Log;
+import android.util.SparseArray;
+import android.view.View;
+import android.view.ViewTreeObserver.OnGlobalLayoutListener;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.inputmethod.EditorInfo;
+
+import com.android.inputmethod.keyboard.Key;
+import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.keyboard.KeyboardView;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Exposes a virtual view sub-tree for {@link KeyboardView} and generates
+ * {@link AccessibilityEvent}s for individual {@link Key}s.
+ * <p>
+ * A virtual sub-tree is composed of imaginary {@link View}s that are reported
+ * as a part of the view hierarchy for accessibility purposes. This enables
+ * custom views that draw complex content to report them selves as a tree of
+ * virtual views, thus conveying their logical structure.
+ * </p>
+ */
+public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat {
+ private static final String TAG = AccessibilityEntityProvider.class.getSimpleName();
+
+ private final KeyboardView mKeyboardView;
+ private final InputMethodService mInputMethodService;
+ private final KeyCodeDescriptionMapper mKeyCodeDescriptionMapper;
+ private final AccessibilityUtils mAccessibilityUtils;
+
+ /** A map of integer IDs to {@link Key}s. */
+ private final SparseArray<Key> mVirtualViewIdToKey = new SparseArray<Key>();
+
+ /** Temporary rect used to calculate in-screen bounds. */
+ private final Rect mTempBoundsInScreen = new Rect();
+
+ /** The parent view's cached on-screen location. */
+ private final int[] mParentLocation = new int[2];
+
+ public AccessibilityEntityProvider(KeyboardView keyboardView, InputMethodService inputMethod) {
+ mKeyboardView = keyboardView;
+ mInputMethodService = inputMethod;
+
+ mKeyCodeDescriptionMapper = KeyCodeDescriptionMapper.getInstance();
+ mAccessibilityUtils = AccessibilityUtils.getInstance();
+
+ assignVirtualViewIds();
+ updateParentLocation();
+
+ // Ensure that the on-screen bounds are cleared when the layout changes.
+ mKeyboardView.getViewTreeObserver().addOnGlobalLayoutListener(mGlobalLayoutListener);
+ }
+
+ /**
+ * Creates and populates an {@link AccessibilityEvent} for the specified key
+ * and event type.
+ *
+ * @param key A key on the host keyboard view.
+ * @param eventType The event type to create.
+ * @return A populated {@link AccessibilityEvent} for the key.
+ * @see AccessibilityEvent
+ */
+ public AccessibilityEvent createAccessibilityEvent(Key key, int eventType) {
+ final int virtualViewId = generateVirtualViewIdForKey(key);
+ final String keyDescription = getKeyDescription(key);
+
+ final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
+ event.setPackageName(mKeyboardView.getContext().getPackageName());
+ event.setClassName(key.getClass().getName());
+ event.getText().add(keyDescription);
+
+ final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
+ record.setSource(mKeyboardView, virtualViewId);
+
+ return event;
+ }
+
+ /**
+ * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
+ * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
+ * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}.
+ * <p>
+ * A virtual descendant is an imaginary View that is reported as a part of
+ * the view hierarchy for accessibility purposes. This enables custom views
+ * that draw complex content to report them selves as a tree of virtual
+ * views, thus conveying their logical structure.
+ * </p>
+ * <p>
+ * The implementer is responsible for obtaining an accessibility node info
+ * from the pool of reusable instances and setting the desired properties of
+ * the node info before returning it.
+ * </p>
+ *
+ * @param virtualViewId A client defined virtual view id.
+ * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual
+ * descendant or the host View.
+ * @see AccessibilityNodeInfoCompat
+ */
+ @Override
+ public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId) {
+ AccessibilityNodeInfoCompat info = null;
+
+ if (virtualViewId == View.NO_ID) {
+ // We are requested to create an AccessibilityNodeInfo describing
+ // this View, i.e. the root of the virtual sub-tree.
+ info = AccessibilityNodeInfoCompat.obtain(mKeyboardView);
+ ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, info);
+
+ // Add the virtual children of the root View.
+ // TODO(alanv): Need to assign a unique ID to each key.
+ final Keyboard keyboard = mKeyboardView.getKeyboard();
+ final Set<Key> keys = keyboard.mKeys;
+ for (Key key : keys) {
+ final int childVirtualViewId = generateVirtualViewIdForKey(key);
+ info.addChild(mKeyboardView, childVirtualViewId);
+ }
+ } else {
+ // Find the view that corresponds to the given id.
+ final Key key = mVirtualViewIdToKey.get(virtualViewId);
+ if (key == null) {
+ Log.e(TAG, "Invalid virtual view ID: " + virtualViewId);
+ return null;
+ }
+
+ final String keyDescription = getKeyDescription(key);
+ final Rect boundsInParent = key.mHitBox;
+
+ // Calculate the key's in-screen bounds.
+ mTempBoundsInScreen.set(boundsInParent);
+ mTempBoundsInScreen.offset(mParentLocation[0], mParentLocation[1]);
+
+ final Rect boundsInScreen = mTempBoundsInScreen;
+
+ // Obtain and initialize an AccessibilityNodeInfo with
+ // information about the virtual view.
+ info = AccessibilityNodeInfoCompat.obtain();
+ info.addAction(AccessibilityNodeInfoCompat.ACTION_SELECT);
+ info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION);
+ info.setPackageName(mKeyboardView.getContext().getPackageName());
+ info.setClassName(key.getClass().getName());
+ info.setBoundsInParent(boundsInParent);
+ info.setBoundsInScreen(boundsInScreen);
+ info.setParent(mKeyboardView);
+ info.setSource(mKeyboardView, virtualViewId);
+ info.setBoundsInScreen(boundsInScreen);
+ info.setText(keyDescription);
+ }
+
+ return info;
+ }
+
+ /**
+ * Performs an accessibility action on a virtual view, i.e. a descendant of
+ * the host View, with the given <code>virtualViewId</code> or the host View itself if
+ * <code>virtualViewId</code> equals to {@link View#NO_ID}.
+ *
+ * @param action The action to perform.
+ * @param virtualViewId A client defined virtual view id.
+ * @return True if the action was performed.
+ * @see #createAccessibilityNodeInfo(int)
+ * @see AccessibilityNodeInfoCompat
+ */
+ @Override
+ public boolean performAccessibilityAction(int action, int virtualViewId) {
+ if (virtualViewId == View.NO_ID) {
+ // Perform the action on the host View.
+ switch (action) {
+ case AccessibilityNodeInfoCompat.ACTION_SELECT:
+ if (!mKeyboardView.isSelected()) {
+ mKeyboardView.setSelected(true);
+ return mKeyboardView.isSelected();
+ }
+ break;
+ case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION:
+ if (mKeyboardView.isSelected()) {
+ mKeyboardView.setSelected(false);
+ return !mKeyboardView.isSelected();
+ }
+ break;
+ }
+ } else {
+ // Find the view that corresponds to the given id.
+ final Key child = mVirtualViewIdToKey.get(virtualViewId);
+ if (child == null)
+ return false;
+
+ // Perform the action on a virtual view.
+ switch (action) {
+ case AccessibilityNodeInfoCompat.ACTION_SELECT:
+ // TODO: Provide some focus indicator.
+ return true;
+ case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION:
+ // TODO: Provide some clear focus indicator.
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Finds {@link AccessibilityNodeInfoCompat}s by text. The match is case
+ * insensitive containment. The search is relative to the virtual view, i.e.
+ * a descendant of the host View, with the given <code>virtualViewId</code> or the host
+ * View itself <code>virtualViewId</code> equals to {@link View#NO_ID}.
+ *
+ * @param virtualViewId A client defined virtual view id which defined the
+ * root of the tree in which to perform the search.
+ * @param text The searched text.
+ * @return A list of node info.
+ * @see #createAccessibilityNodeInfo(int)
+ * @see AccessibilityNodeInfoCompat
+ */
+ @Override
+ public List<AccessibilityNodeInfoCompat> findAccessibilityNodeInfosByText(
+ String text, int virtualViewId) {
+ final String searchedLowerCase = text.toLowerCase();
+ final Keyboard keyboard = mKeyboardView.getKeyboard();
+
+ List<AccessibilityNodeInfoCompat> results = null;
+
+ if (virtualViewId == View.NO_ID) {
+ for (Key key : keyboard.mKeys) {
+ results = findByTextAndPopulate(searchedLowerCase, key, results);
+ }
+ } else {
+ final Key key = mVirtualViewIdToKey.get(virtualViewId);
+
+ results = findByTextAndPopulate(searchedLowerCase, key, results);
+ }
+
+ if (results == null) {
+ return Collections.emptyList();
+ }
+
+ return results;
+ }
+
+ /**
+ * Helper method for {@link #findAccessibilityNodeInfosByText(String, int)}.
+ * Takes a current set of results and matches a specified key against a
+ * lower-case search string. Returns an updated list of results.
+ *
+ * @param searchedLowerCase The lower-case search string.
+ * @param key The key to compare against.
+ * @param results The current list of results, or {@code null} if no results
+ * found.
+ * @return An updated list of results, or {@code null} if no results found.
+ */
+ private List<AccessibilityNodeInfoCompat> findByTextAndPopulate(String searchedLowerCase,
+ Key key, List<AccessibilityNodeInfoCompat> results) {
+ if (!keyContainsText(key, searchedLowerCase)) {
+ return results;
+ }
+
+ final int childVirtualViewId = generateVirtualViewIdForKey(key);
+ final AccessibilityNodeInfoCompat nodeInfo = createAccessibilityNodeInfo(
+ childVirtualViewId);
+
+ if (results == null) {
+ results = new LinkedList<AccessibilityNodeInfoCompat>();
+ }
+
+ results.add(nodeInfo);
+
+ return results;
+ }
+
+ /**
+ * Returns whether a key's current description contains the lower-case
+ * search text.
+ *
+ * @param key The key to compare against.
+ * @param textLowerCase The lower-case search string.
+ * @return {@code true} if the key contains the search text.
+ */
+ private boolean keyContainsText(Key key, String textLowerCase) {
+ if (key == null) {
+ return false;
+ }
+
+ final String description = getKeyDescription(key);
+
+ if (description == null) {
+ return false;
+ }
+
+ return description.toLowerCase().contains(textLowerCase);
+ }
+
+ /**
+ * Returns the context-specific description for a {@link Key}.
+ *
+ * @param key The key to describe.
+ * @return The context-specific description of the key.
+ */
+ private String getKeyDescription(Key key) {
+ final EditorInfo editorInfo = mInputMethodService.getCurrentInputEditorInfo();
+ final boolean shouldObscure = mAccessibilityUtils.shouldObscureInput(editorInfo);
+ final String keyDescription = mKeyCodeDescriptionMapper.getDescriptionForKey(
+ mKeyboardView.getContext(), mKeyboardView.getKeyboard(), key, shouldObscure);
+
+ return keyDescription;
+ }
+
+ /**
+ * Assigns virtual view IDs to keyboard keys and populates the related maps.
+ */
+ private void assignVirtualViewIds() {
+ final Keyboard keyboard = mKeyboardView.getKeyboard();
+ if (keyboard == null) {
+ return;
+ }
+
+ mVirtualViewIdToKey.clear();
+
+ final Set<Key> keySet = keyboard.mKeys;
+ for (Key key : keySet) {
+ final int virtualViewId = generateVirtualViewIdForKey(key);
+ mVirtualViewIdToKey.put(virtualViewId, key);
+ }
+ }
+
+ /**
+ * Updates the parent's on-screen location.
+ */
+ private void updateParentLocation() {
+ mKeyboardView.getLocationOnScreen(mParentLocation);
+ }
+
+ /**
+ * Generates a virtual view identifier for the specified key.
+ *
+ * @param key The key to identify.
+ * @return A virtual view identifier.
+ */
+ private static int generateVirtualViewIdForKey(Key key) {
+ // The key code is unique within an instance of a Keyboard.
+ return key.mCode;
+ }
+
+ private final OnGlobalLayoutListener mGlobalLayoutListener = new OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ assignVirtualViewIds();
+ updateParentLocation();
+ }
+ };
+}
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
index 9caed00c9..41da2aa4c 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
@@ -21,13 +21,14 @@ import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
import android.os.SystemClock;
import android.provider.Settings;
+import android.support.v4.view.MotionEventCompat;
import android.util.Log;
import android.view.MotionEvent;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.EditorInfo;
-import com.android.inputmethod.compat.AccessibilityManagerCompatWrapper;
+import com.android.inputmethod.compat.AccessibilityManagerCompatUtils;
import com.android.inputmethod.compat.AudioManagerCompatWrapper;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.MotionEventCompatUtils;
@@ -44,7 +45,6 @@ public class AccessibilityUtils {
private Context mContext;
private AccessibilityManager mAccessibilityManager;
- private AccessibilityManagerCompatWrapper mCompatManager;
private AudioManagerCompatWrapper mAudioManager;
/*
@@ -77,7 +77,6 @@ public class AccessibilityUtils {
mContext = context;
mAccessibilityManager = (AccessibilityManager) context
.getSystemService(Context.ACCESSIBILITY_SERVICE);
- mCompatManager = new AccessibilityManagerCompatWrapper(mAccessibilityManager);
final AudioManager audioManager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
@@ -94,7 +93,7 @@ public class AccessibilityUtils {
public boolean isTouchExplorationEnabled() {
return ENABLE_ACCESSIBILITY
&& mAccessibilityManager.isEnabled()
- && mCompatManager.isTouchExplorationEnabled();
+ && AccessibilityManagerCompatUtils.isTouchExplorationEnabled(mAccessibilityManager);
}
/**
@@ -110,13 +109,13 @@ public class AccessibilityUtils {
return action == MotionEventCompatUtils.ACTION_HOVER_ENTER
|| action == MotionEventCompatUtils.ACTION_HOVER_EXIT
- || action == MotionEventCompatUtils.ACTION_HOVER_MOVE;
+ || action == MotionEventCompat.ACTION_HOVER_MOVE;
}
/**
* Returns whether the device should obscure typed password characters.
* Typically this means speaking "dot" in place of non-control characters.
- *
+ *
* @return {@code true} if the device should obscure password characters.
*/
public boolean shouldObscureInput(EditorInfo editorInfo) {
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
index 2294a18a0..2401d93c6 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
@@ -20,13 +20,16 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.inputmethodservice.InputMethodService;
-import android.util.Log;
+import android.support.v4.view.AccessibilityDelegateCompat;
+import android.support.v4.view.MotionEventCompat;
+import android.support.v4.view.ViewCompat;
+import android.support.v4.view.accessibility.AccessibilityEventCompat;
import android.view.MotionEvent;
+import android.view.View;
import android.view.accessibility.AccessibilityEvent;
-import android.view.inputmethod.EditorInfo;
-import com.android.inputmethod.compat.AccessibilityEventCompatUtils;
import com.android.inputmethod.compat.MotionEventCompatUtils;
+import com.android.inputmethod.compat.ViewParentCompatUtils;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
@@ -34,14 +37,14 @@ import com.android.inputmethod.keyboard.LatinKeyboardView;
import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.latin.R;
-public class AccessibleKeyboardViewProxy {
- private static final String TAG = AccessibleKeyboardViewProxy.class.getSimpleName();
+public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
private static final AccessibleKeyboardViewProxy sInstance = new AccessibleKeyboardViewProxy();
private InputMethodService mInputMethod;
private FlickGestureDetector mGestureDetector;
private LatinKeyboardView mView;
private AccessibleKeyboardActionListener mListener;
+ private AccessibilityEntityProvider mAccessibilityNodeProvider;
private Key mLastHoverKey = null;
@@ -54,10 +57,6 @@ public class AccessibleKeyboardViewProxy {
return sInstance;
}
- public static void setView(LatinKeyboardView view) {
- sInstance.mView = view;
- }
-
private AccessibleKeyboardViewProxy() {
// Not publicly instantiable.
}
@@ -73,34 +72,39 @@ public class AccessibleKeyboardViewProxy {
mGestureDetector = new KeyboardFlickGestureDetector(inputMethod);
}
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
- if (mView == null) {
- Log.e(TAG, "No keyboard view set!");
- return false;
+ /**
+ * Sets the view wrapped by this proxy.
+ *
+ * @param view The view to wrap.
+ */
+ public void setView(LatinKeyboardView view) {
+ if (view == null) {
+ // Ignore null views.
+ return;
}
- switch (event.getEventType()) {
- case AccessibilityEventCompatUtils.TYPE_VIEW_HOVER_ENTER:
- final Key key = mLastHoverKey;
+ mView = view;
- if (key == null)
- break;
-
- final EditorInfo info = mInputMethod.getCurrentInputEditorInfo();
- final boolean shouldObscure = AccessibilityUtils.getInstance().shouldObscureInput(info);
- final CharSequence description = KeyCodeDescriptionMapper.getInstance()
- .getDescriptionForKey(mView.getContext(), mView.getKeyboard(), key,
- shouldObscure);
-
- if (description == null)
- return false;
-
- event.getText().add(description);
+ // Ensure that the view has an accessibility delegate.
+ ViewCompat.setAccessibilityDelegate(view, this);
+ }
- break;
+ /**
+ * Proxy method for View.getAccessibilityNodeProvider(). This method is
+ * called in SDK version 15 and higher to obtain the virtual node hierarchy
+ * provider.
+ *
+ * @return The accessibility node provider for the current keyboard.
+ */
+ @Override
+ public AccessibilityEntityProvider getAccessibilityNodeProvider(View host) {
+ // 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, mInputMethod);
}
-
- return true;
+ return mAccessibilityNodeProvider;
}
/**
@@ -123,46 +127,94 @@ public class AccessibleKeyboardViewProxy {
* @param event The touch exploration hover event.
* @return {@code true} if the event was handled
*/
- /*package*/ boolean onHoverEventInternal(MotionEvent event, PointerTracker tracker) {
+ /* package */boolean onHoverEventInternal(MotionEvent event, PointerTracker tracker) {
final int x = (int) event.getX();
final int y = (int) event.getY();
+ final Key key = tracker.getKeyOn(x, y);
+ final Key previousKey = mLastHoverKey;
+
+ mLastHoverKey = key;
switch (event.getAction()) {
case MotionEventCompatUtils.ACTION_HOVER_ENTER:
- case MotionEventCompatUtils.ACTION_HOVER_MOVE:
- final Key key = tracker.getKeyOn(x, y);
-
- if (key != mLastHoverKey) {
- fireKeyHoverEvent(mLastHoverKey, false);
- mLastHoverKey = key;
- fireKeyHoverEvent(mLastHoverKey, true);
+ case MotionEventCompatUtils.ACTION_HOVER_EXIT:
+ return onHoverKey(key, event);
+ case MotionEventCompat.ACTION_HOVER_MOVE:
+ if (key != previousKey) {
+ return onTransitionKey(key, previousKey, event);
+ } else {
+ return onHoverKey(key, event);
}
-
- return true;
}
return false;
}
- private void fireKeyHoverEvent(Key key, boolean entering) {
- if (mListener == null) {
- Log.e(TAG, "No accessible keyboard action listener set!");
- return;
+ /**
+ * Simulates a transition between two {@link Key}s by sending a HOVER_EXIT
+ * on the previous key, a HOVER_ENTER on the current key, and a HOVER_MOVE
+ * on the current key.
+ *
+ * @param currentKey The currently hovered key.
+ * @param previousKey The previously hovered key.
+ * @param event The event that triggered the transition.
+ * @return {@code true} if the event was handled.
+ */
+ private boolean onTransitionKey(Key currentKey, Key previousKey, MotionEvent event) {
+ final int savedAction = event.getAction();
+
+ event.setAction(MotionEventCompatUtils.ACTION_HOVER_EXIT);
+ onHoverKey(previousKey, event);
+
+ event.setAction(MotionEventCompatUtils.ACTION_HOVER_ENTER);
+ onHoverKey(currentKey, event);
+
+ event.setAction(MotionEventCompat.ACTION_HOVER_MOVE);
+ final boolean handled = onHoverKey(currentKey, event);
+
+ event.setAction(savedAction);
+
+ return handled;
+ }
+
+ /**
+ * Handles a hover event on a key. If {@link Key} extended View, this would
+ * be analogous to calling View.onHoverEvent(MotionEvent).
+ *
+ * @param key The currently hovered key.
+ * @param event The hover event.
+ * @return {@code true} if the event was handled.
+ */
+ private boolean onHoverKey(Key key, MotionEvent event) {
+ // Null keys can't receive events.
+ if (key == null) {
+ return false;
}
- if (mView == null) {
- Log.e(TAG, "No keyboard view set!");
- return;
+ switch (event.getAction()) {
+ case MotionEventCompatUtils.ACTION_HOVER_ENTER:
+ sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
+ break;
+ case MotionEventCompatUtils.ACTION_HOVER_EXIT:
+ sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
+ break;
}
- if (key == null)
- return;
+ return true;
+ }
- if (entering) {
- mView.sendAccessibilityEvent(AccessibilityEventCompatUtils.TYPE_VIEW_HOVER_ENTER);
- } else {
- mView.sendAccessibilityEvent(AccessibilityEventCompatUtils.TYPE_VIEW_HOVER_EXIT);
- }
+ /**
+ * Populates and sends an {@link AccessibilityEvent} for the specified key.
+ *
+ * @param key The key to send an event for.
+ * @param eventType The type of event to send.
+ */
+ private void sendAccessibilityEventForKey(Key key, int eventType) {
+ final AccessibilityEntityProvider nodeProvider = getAccessibilityNodeProvider(null);
+ final AccessibilityEvent event = nodeProvider.createAccessibilityEvent(key, eventType);
+
+ // Propagates the event up the view hierarchy.
+ ViewParentCompatUtils.requestSendAccessibilityEvent(mView.getParent(), mView, event);
}
private class KeyboardFlickGestureDetector extends FlickGestureDetector {
diff --git a/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java b/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java
index db12f76ad..eaa4ddff6 100644
--- a/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java
+++ b/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.accessibility;
import android.content.Context;
import android.os.Message;
+import android.support.v4.view.MotionEventCompat;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
@@ -32,7 +33,7 @@ import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
* properties:
* <ul>
* <li>Begins with a {@link MotionEventCompatUtils#ACTION_HOVER_ENTER} event
- * <li>Contains any number of {@link MotionEventCompatUtils#ACTION_HOVER_MOVE}
+ * <li>Contains any number of {@link MotionEventCompat#ACTION_HOVER_MOVE}
* events
* <li>Ends with a {@link MotionEventCompatUtils#ACTION_HOVER_EXIT} event
* <li>Maximum duration of 250 milliseconds
@@ -128,7 +129,7 @@ public abstract class FlickGestureDetector {
final float distanceSquare = calculateDistanceSquare(mCachedHoverEnter, event);
switch (event.getAction()) {
- case MotionEventCompatUtils.ACTION_HOVER_MOVE:
+ case MotionEventCompat.ACTION_HOVER_MOVE:
// Consume all valid move events before timeout.
return true;
case MotionEventCompatUtils.ACTION_HOVER_EXIT:
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index f0dba4a02..3d861c231 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.accessibility;
import android.content.Context;
import android.text.TextUtils;
+import android.util.Log;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
@@ -27,6 +28,8 @@ import com.android.inputmethod.latin.R;
import java.util.HashMap;
public class KeyCodeDescriptionMapper {
+ private static final String TAG = KeyCodeDescriptionMapper.class.getSimpleName();
+
// The resource ID of the string spoken for obscured keys
private static final int OBSCURED_KEY_RES_ID = R.string.spoken_description_dot;
@@ -87,12 +90,12 @@ public class KeyCodeDescriptionMapper {
* @return a character sequence describing the action performed by pressing
* the key
*/
- public CharSequence getDescriptionForKey(Context context, Keyboard keyboard, Key key,
+ public String getDescriptionForKey(Context context, Keyboard keyboard, Key key,
boolean shouldObscure) {
final int code = key.mCode;
if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
- final CharSequence description = getDescriptionForSwitchAlphaSymbol(context, keyboard);
+ final String description = getDescriptionForSwitchAlphaSymbol(context, keyboard);
if (description != null)
return description;
}
@@ -128,7 +131,7 @@ public class KeyCodeDescriptionMapper {
* @return a character sequence describing the action performed by pressing
* the key
*/
- private CharSequence getDescriptionForSwitchAlphaSymbol(Context context, Keyboard keyboard) {
+ private String getDescriptionForSwitchAlphaSymbol(Context context, Keyboard keyboard) {
final KeyboardId keyboardId = keyboard.mId;
final int elementId = keyboardId.mElementId;
final int resId;
@@ -152,10 +155,7 @@ public class KeyCodeDescriptionMapper {
resId = R.string.spoken_description_to_numeric;
break;
default:
- resId = -1;
- }
-
- if (resId < 0) {
+ Log.e(TAG, "Missing description for keyboard element ID:" + elementId);
return null;
}
@@ -169,7 +169,7 @@ public class KeyCodeDescriptionMapper {
* @param keyboard The keyboard on which the key resides.
* @return A context-sensitive description of the "Shift" key.
*/
- private CharSequence getDescriptionForShiftKey(Context context, Keyboard keyboard) {
+ private String getDescriptionForShiftKey(Context context, Keyboard keyboard) {
final KeyboardId keyboardId = keyboard.mId;
final int elementId = keyboardId.mElementId;
final int resId;
@@ -212,7 +212,7 @@ public class KeyCodeDescriptionMapper {
* @return a character sequence describing the action performed by pressing
* the key
*/
- private CharSequence getDescriptionForKeyCode(Context context, Keyboard keyboard, Key key,
+ private String getDescriptionForKeyCode(Context context, Keyboard keyboard, Key key,
boolean shouldObscure) {
final int code = key.mCode;
diff --git a/java/src/com/android/inputmethod/compat/AccessibilityEventCompatUtils.java b/java/src/com/android/inputmethod/compat/AccessibilityEventCompatUtils.java
deleted file mode 100644
index 2fa9d87d8..000000000
--- a/java/src/com/android/inputmethod/compat/AccessibilityEventCompatUtils.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2011 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.compat;
-
-public class AccessibilityEventCompatUtils {
- public static final int TYPE_VIEW_HOVER_ENTER = 0x80;
- public static final int TYPE_VIEW_HOVER_EXIT = 0x100;
-}
diff --git a/java/src/com/android/inputmethod/compat/AccessibilityManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/AccessibilityManagerCompatUtils.java
index a30af0faf..41b6a074d 100644
--- a/java/src/com/android/inputmethod/compat/AccessibilityManagerCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/AccessibilityManagerCompatUtils.java
@@ -20,17 +20,15 @@ import android.view.accessibility.AccessibilityManager;
import java.lang.reflect.Method;
-public class AccessibilityManagerCompatWrapper {
+public class AccessibilityManagerCompatUtils {
private static final Method METHOD_isTouchExplorationEnabled = CompatUtils.getMethod(
AccessibilityManager.class, "isTouchExplorationEnabled");
- private final AccessibilityManager mManager;
-
- public AccessibilityManagerCompatWrapper(AccessibilityManager manager) {
- mManager = manager;
+ private AccessibilityManagerCompatUtils() {
+ // This class is non-instantiable.
}
- public boolean isTouchExplorationEnabled() {
- return (Boolean) CompatUtils.invoke(mManager, false, METHOD_isTouchExplorationEnabled);
+ public static boolean isTouchExplorationEnabled(AccessibilityManager receiver) {
+ return (Boolean) CompatUtils.invoke(receiver, false, METHOD_isTouchExplorationEnabled);
}
}
diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
index 0e5f8c80a..7e216e5c8 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
@@ -150,7 +150,7 @@ public class InputMethodManagerCompatWrapper {
private InputMethodInfoCompatWrapper getLatinImeInputMethodInfo() {
if (TextUtils.isEmpty(mLatinImePackageName))
return null;
- return Utils.getInputMethodInfo(this, mLatinImePackageName);
+ return Utils.getInputMethodInfo(mLatinImePackageName);
}
private static InputMethodSubtypeCompatWrapper getLastResortSubtype(String mode) {
@@ -239,8 +239,7 @@ public class InputMethodManagerCompatWrapper {
// The code below are based on {@link InputMethodManager#showInputMethodMenuInternal}.
- final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo(
- this, mLatinImePackageName);
+ final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo(mLatinImePackageName);
final List<InputMethodSubtypeCompatWrapper> myImsList = getEnabledInputMethodSubtypeList(
myImi, true);
final InputMethodSubtypeCompatWrapper currentIms = getCurrentInputMethodSubtype();
diff --git a/java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java b/java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java
index 8518a4a78..eca922e68 100644
--- a/java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java
@@ -17,7 +17,7 @@
package com.android.inputmethod.compat;
public class MotionEventCompatUtils {
- public static final int ACTION_HOVER_MOVE = 0x7;
+ // TODO(alanv): Remove after these are added to MotionEventCompat.
public static final int ACTION_HOVER_ENTER = 0x9;
public static final int ACTION_HOVER_EXIT = 0xA;
}
diff --git a/java/src/com/android/inputmethod/compat/ViewParentCompatUtils.java b/java/src/com/android/inputmethod/compat/ViewParentCompatUtils.java
new file mode 100644
index 000000000..d19bc3af1
--- /dev/null
+++ b/java/src/com/android/inputmethod/compat/ViewParentCompatUtils.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.compat;
+
+import android.view.View;
+import android.view.ViewParent;
+import android.view.accessibility.AccessibilityEvent;
+
+import java.lang.reflect.Method;
+
+public class ViewParentCompatUtils {
+ private static final Method METHOD_requestSendAccessibilityEvent = CompatUtils.getMethod(
+ ViewParent.class, "requestSendAccessibilityEvent", View.class,
+ AccessibilityEvent.class);
+
+ /**
+ * Called by a child to request from its parent to send an {@link AccessibilityEvent}.
+ * The child has already populated a record for itself in the event and is delegating
+ * to its parent to send the event. The parent can optionally add a record for itself.
+ * <p>
+ * Note: An accessibility event is fired by an individual view which populates the
+ * event with a record for its state and requests from its parent to perform
+ * the sending. The parent can optionally add a record for itself before
+ * dispatching the request to its parent. A parent can also choose not to
+ * respect the request for sending the event. The accessibility event is sent
+ * by the topmost view in the view tree.</p>
+ *
+ * @param child The child which requests sending the event.
+ * @param event The event to be sent.
+ * @return True if the event was sent.
+ */
+ public static boolean requestSendAccessibilityEvent(
+ ViewParent receiver, View child, AccessibilityEvent event) {
+ return (Boolean) CompatUtils.invoke(
+ receiver, false, METHOD_requestSendAccessibilityEvent, child, event);
+ }
+}
diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
index 5c4e9af68..700709d50 100644
--- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
+++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
@@ -435,44 +435,6 @@ public class VoiceProxy implements VoiceInput.UiListener {
}
}
- /**
- * Tries to apply any voice alternatives for the word if this was a spoken word and
- * there are voice alternatives.
- * @param touching The word that the cursor is touching, with position information
- * @return true if an alternative was found, false otherwise.
- */
- public boolean applyVoiceAlternatives(EditingUtils.SelectedWord touching) {
- if (!VOICE_INSTALLED) {
- return false;
- }
- // Search for result in spoken word alternatives
- String selectedWord = touching.mWord.toString().trim();
- if (!mWordToSuggestions.containsKey(selectedWord)) {
- selectedWord = selectedWord.toLowerCase();
- }
- if (mWordToSuggestions.containsKey(selectedWord)) {
- mShowingVoiceSuggestions = true;
- List<CharSequence> suggestions = mWordToSuggestions.get(selectedWord);
- SuggestedWords.Builder builder = new SuggestedWords.Builder();
- // If the first letter of touching is capitalized, make all the suggestions
- // start with a capital letter.
- if (Character.isUpperCase(touching.mWord.charAt(0))) {
- for (CharSequence word : suggestions) {
- String str = word.toString();
- word = Character.toUpperCase(str.charAt(0)) + str.substring(1);
- builder.addWord(word);
- }
- } else {
- builder.addWords(suggestions, null);
- }
- builder.setTypedWordValid(true).setHasMinimalSuggestion(true);
- mService.setSuggestions(builder.build());
-// mService.setCandidatesViewShown(true);
- return true;
- }
- return false;
- }
-
public void handleBackspace() {
if (!VOICE_INSTALLED) {
return;
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index f1611d9ee..79c7ce0fd 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -108,9 +108,13 @@ public class Key {
private static final int MORE_KEYS_COLUMN_MASK = 0x000000ff;
private static final int MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER = 0x80000000;
private static final int MORE_KEYS_FLAGS_HAS_LABELS = 0x40000000;
+ private static final int MORE_KEYS_FLAGS_NEEDS_DIVIDERS = 0x40000000;
+ private static final int MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY = 0x20000000;
private static final String MORE_KEYS_AUTO_COLUMN_ORDER = "!autoColumnOrder!";
private static final String MORE_KEYS_FIXED_COLUMN_ORDER = "!fixedColumnOrder!";
private static final String MORE_KEYS_HAS_LABELS = "!hasLabels!";
+ private static final String MORE_KEYS_NEEDS_DIVIDERS = "!needsDividers!";
+ private static final String MORE_KEYS_EMBEDDED_MORE_KEY = "!embeddedMoreKey!";
/** Background type that represents different key background visual than normal one. */
public final int mBackgroundType;
@@ -253,6 +257,12 @@ public class Key {
if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_HAS_LABELS)) {
moreKeysColumn |= MORE_KEYS_FLAGS_HAS_LABELS;
}
+ if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_NEEDS_DIVIDERS)) {
+ moreKeysColumn |= MORE_KEYS_FLAGS_NEEDS_DIVIDERS;
+ }
+ if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_EMBEDDED_MORE_KEY)) {
+ moreKeysColumn |= MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY;
+ }
mMoreKeysColumnAndFlags = moreKeysColumn;
final String[] additionalMoreKeys = style.getStringArray(
@@ -539,12 +549,17 @@ public class Key {
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_HAS_LABELS) != 0;
}
- public Drawable getIcon(KeyboardIconsSet iconSet) {
- return iconSet.getIconDrawable(mIconId);
+ public boolean needsDividersInMoreKeys() {
+ return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_NEEDS_DIVIDERS) != 0;
}
- public Drawable getDisabledIcon(KeyboardIconsSet iconSet) {
- return iconSet.getIconDrawable(mDisabledIconId);
+ public boolean hasEmbeddedMoreKey() {
+ return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY) != 0;
+ }
+
+ public Drawable getIcon(KeyboardIconsSet iconSet) {
+ final int iconId = mEnabled ? mIconId : mDisabledIconId;
+ return iconSet.getIconDrawable(iconId);
}
public Drawable getPreviewIcon(KeyboardIconsSet iconSet) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
index 0ce98d2f1..10cf1d1f4 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
@@ -267,7 +267,7 @@ public class KeyDetector {
addDelimiter = false;
} else {
if (addDelimiter) sb.append(", ");
- sb.append(code);
+ sb.append(Keyboard.printableCode(code));
addDelimiter = true;
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 30ed59e18..c6cdf7986 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -85,8 +85,6 @@ public class Keyboard {
public static final int CODE_CLOSING_SQUARE_BRACKET = ']';
public static final int CODE_CLOSING_CURLY_BRACKET = '}';
public static final int CODE_CLOSING_ANGLE_BRACKET = '>';
- public static final int CODE_DIGIT0 = '0';
- public static final int CODE_PLUS = '+';
private static final int MINIMUM_LETTER_CODE = CODE_TAB;
/** Special keys code. Must be negative.
@@ -185,18 +183,11 @@ public class Keyboard {
}
// TODO: Remove this method.
- public boolean isShiftLocked() {
- return mId.isAlphabetShiftLockedKeyboard();
- }
-
- // TODO: Remove this method.
public boolean isShiftedOrShiftLocked() {
- return mId.isAlphabetShiftedOrShiftLockedKeyboard();
- }
-
- // TODO: Remove this method.
- public boolean isManualShifted() {
- return mId.isAlphabetManualShiftedKeyboard();
+ // Alphabet mode have unshifted, manual shifted, automatic shifted, shift locked, and
+ // shift lock shifted element. So that unshifed element is the only one that is NOT in
+ // shifted or shift locked state.
+ return mId.isAlphabetKeyboard() && mId.mElementId != KeyboardId.ELEMENT_ALPHABET;
}
public static boolean isLetterCode(int code) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index ed4a89e0f..f5752962e 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -36,6 +36,9 @@ public class KeyboardId {
public static final int MODE_IM = 3;
public static final int MODE_PHONE = 4;
public static final int MODE_NUMBER = 5;
+ public static final int MODE_DATE = 6;
+ public static final int MODE_TIME = 7;
+ public static final int MODE_DATETIME = 8;
public static final int ELEMENT_ALPHABET = 0;
public static final int ELEMENT_ALPHABET_MANUAL_SHIFTED = 1;
@@ -123,31 +126,6 @@ public class KeyboardId {
return mElementId < ELEMENT_SYMBOLS;
}
- public boolean isAlphabetShiftLockedKeyboard() {
- return mElementId == ELEMENT_ALPHABET_SHIFT_LOCKED
- || mElementId == ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED;
- }
-
- public boolean isAlphabetShiftedOrShiftLockedKeyboard() {
- return isAlphabetKeyboard() && mElementId != ELEMENT_ALPHABET;
- }
-
- public boolean isAlphabetManualShiftedKeyboard() {
- return mElementId == ELEMENT_ALPHABET_MANUAL_SHIFTED;
- }
-
- public boolean isSymbolsKeyboard() {
- return mElementId == ELEMENT_SYMBOLS || mElementId == ELEMENT_SYMBOLS_SHIFTED;
- }
-
- public boolean isPhoneKeyboard() {
- return mElementId == ELEMENT_PHONE || mElementId == ELEMENT_PHONE_SYMBOLS;
- }
-
- public boolean isPhoneShiftKeyboard() {
- return mElementId == ELEMENT_PHONE_SYMBOLS;
- }
-
public boolean navigateNext() {
return EditorInfoCompatUtils.hasFlagNavigateNext(mEditorInfo.imeOptions);
}
@@ -242,6 +220,9 @@ public class KeyboardId {
case MODE_IM: return "im";
case MODE_PHONE: return "phone";
case MODE_NUMBER: return "number";
+ case MODE_DATE: return "date";
+ case MODE_TIME: return "time";
+ case MODE_DATETIME: return "datetime";
default: return null;
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
index 6e62f743b..ee882edc0 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
@@ -131,6 +131,9 @@ public class KeyboardSet {
}
break;
case KeyboardId.MODE_NUMBER:
+ case KeyboardId.MODE_DATE:
+ case KeyboardId.MODE_TIME:
+ case KeyboardId.MODE_DATETIME:
keyboardSetElementId = KeyboardId.ELEMENT_NUMBER;
break;
default:
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 622e5831f..e1c6f2604 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -379,7 +379,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
// This always needs to be set since the accessibility state can
// potentially change without the input view being re-created.
- AccessibleKeyboardViewProxy.setView(mKeyboardView);
+ AccessibleKeyboardViewProxy.getInstance().setView(mKeyboardView);
return mCurrentInputView;
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index d65253ede..78e0ee230 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -849,7 +849,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final KeyPreviewDrawParams params = mKeyPreviewDrawParams;
final int keyDrawX = key.mX + key.mVisualInsetsLeft;
final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
- // What we show as preview should match what we show on key top in onBufferDraw().
+ // What we show as preview should match what we show on a key top in onBufferDraw().
if (key.mLabel != null) {
// TODO Should take care of temporaryShiftLabel here.
previewText.setCompoundDrawables(null, null, null, null);
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index 432959508..8a2f89257 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -34,7 +34,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
-import android.view.accessibility.AccessibilityEvent;
import android.widget.PopupWindow;
import com.android.inputmethod.accessibility.AccessibilityUtils;
@@ -42,6 +41,7 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
+import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
@@ -481,11 +481,10 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
*/
protected boolean onLongPress(Key parentKey, PointerTracker tracker) {
final int primaryCode = parentKey.mCode;
- final Keyboard keyboard = getKeyboard();
- if (primaryCode == Keyboard.CODE_DIGIT0 && keyboard.mId.isPhoneKeyboard()) {
+ if (parentKey.hasEmbeddedMoreKey()) {
+ final int embeddedCode = KeySpecParser.getCode(getResources(), parentKey.mMoreKeys[0]);
tracker.onLongPressed();
- // Long pressing on 0 in phone number keypad gives you a '+'.
- invokeCodeInput(Keyboard.CODE_PLUS);
+ invokeCodeInput(embeddedCode);
invokeReleaseKey(primaryCode);
KeyboardSwitcher.getInstance().hapticAndAudioFeedback(primaryCode);
return true;
@@ -732,16 +731,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
VoiceProxy.getInstance().onAttachedToWindow();
}
- @Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
- if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
- return AccessibleKeyboardViewProxy.getInstance().dispatchPopulateAccessibilityEvent(
- event) || super.dispatchPopulateAccessibilityEvent(event);
- }
-
- return super.dispatchPopulateAccessibilityEvent(event);
- }
-
/**
* Receives hover events from the input framework. This method overrides
* View.dispatchHoverEvent(MotionEvent) on SDK version ICS or higher. On
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
index abbdfddfe..9f735cff7 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
@@ -17,8 +17,10 @@
package com.android.inputmethod.keyboard;
import android.graphics.Paint;
+import android.graphics.drawable.Drawable;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
+import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
@@ -36,8 +38,10 @@ public class MoreKeysKeyboard extends Keyboard {
public static class Builder extends Keyboard.Builder<Builder.MoreKeysKeyboardParams> {
private final Key mParentKey;
+ private final Drawable mDivider;
private static final float LABEL_PADDING_RATIO = 0.2f;
+ private static final float DIVIDER_RATIO = 0.2f;
public static class MoreKeysKeyboardParams extends Keyboard.Params {
public boolean mIsFixedOrder;
@@ -47,6 +51,8 @@ public class MoreKeysKeyboard extends Keyboard {
public int mTopKeys;
public int mLeftKeys;
public int mRightKeys; // includes default key.
+ public int mDividerWidth;
+ public int mColumnWidth;
public MoreKeysKeyboardParams() {
super();
@@ -62,9 +68,11 @@ public class MoreKeysKeyboard extends Keyboard {
* @param coordXInParent coordinate x of the key preview in parent keyboard.
* @param parentKeyboardWidth parent keyboard width in pixel.
* @param isFixedColumnOrder if true, more keys should be laid out in fixed order.
+ * @param dividerWidth width of divider, zero for no dividers.
*/
public void setParameters(int numKeys, int maxColumns, int keyWidth, int rowHeight,
- int coordXInParent, int parentKeyboardWidth, boolean isFixedColumnOrder) {
+ int coordXInParent, int parentKeyboardWidth, boolean isFixedColumnOrder,
+ int dividerWidth) {
mIsFixedOrder = isFixedColumnOrder;
if (parentKeyboardWidth / keyWidth < maxColumns) {
throw new IllegalArgumentException(
@@ -116,7 +124,9 @@ public class MoreKeysKeyboard extends Keyboard {
// Adjustment of the top row.
mTopRowAdjustment = mIsFixedOrder ? getFixedOrderTopRowAdjustment()
: getAutoOrderTopRowAdjustment();
- mBaseWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth;
+ mDividerWidth = dividerWidth;
+ mColumnWidth = mDefaultKeyWidth + mDividerWidth;
+ mBaseWidth = mOccupiedWidth = mNumColumns * mColumnWidth - mDividerWidth;
// Need to subtract the bottom row's gutter only.
mBaseHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight - mVerticalGap
+ mTopPadding + mBottomPadding;
@@ -214,13 +224,13 @@ public class MoreKeysKeyboard extends Keyboard {
}
public int getDefaultKeyCoordX() {
- return mLeftKeys * mDefaultKeyWidth;
+ return mLeftKeys * mColumnWidth;
}
public int getX(int n, int row) {
- final int x = getColumnPos(n) * mDefaultKeyWidth + getDefaultKeyCoordX();
+ final int x = getColumnPos(n) * mColumnWidth + getDefaultKeyCoordX();
if (isTopRow(row)) {
- return x + mTopRowAdjustment * (mDefaultKeyWidth / 2);
+ return x + mTopRowAdjustment * (mColumnWidth / 2);
}
return x;
}
@@ -267,9 +277,19 @@ public class MoreKeysKeyboard extends Keyboard {
width = getMaxKeyWidth(view, parentKey, mParams.mDefaultKeyWidth);
height = parentKeyboard.mMostCommonKeyHeight;
}
+ final int dividerWidth;
+ if (parentKey.needsDividersInMoreKeys()) {
+ mDivider = mResources.getDrawable(R.drawable.more_keys_divider);
+ // TODO: Drawable itself should have an alpha value.
+ mDivider.setAlpha(128);
+ dividerWidth = (int)(width * DIVIDER_RATIO);
+ } else {
+ mDivider = null;
+ dividerWidth = 0;
+ }
mParams.setParameters(parentKey.mMoreKeys.length, parentKey.getMoreKeysColumn(),
width, height, parentKey.mX + parentKey.mWidth / 2, view.getMeasuredWidth(),
- parentKey.isFixedColumnOrderMoreKeys());
+ parentKey.isFixedColumnOrderMoreKeys(), dividerWidth);
}
private static int getMaxKeyWidth(KeyboardView view, Key parentKey, int minKeyWidth) {
@@ -295,6 +315,21 @@ public class MoreKeysKeyboard extends Keyboard {
return maxWidth;
}
+ private static class MoreKeyDivider extends Key.Spacer {
+ private final Drawable mIcon;
+
+ public MoreKeyDivider(MoreKeysKeyboardParams params, Drawable icon, int x, int y) {
+ super(params, x, y, params.mDividerWidth, params.mDefaultRowHeight);
+ mIcon = icon;
+ }
+
+ @Override
+ public Drawable getIcon(KeyboardIconsSet iconSet) {
+ // KeyboardIconsSet is unused. Use the icon that has been passed to the constructor.
+ return mIcon;
+ }
+ }
+
@Override
public MoreKeysKeyboard build() {
final MoreKeysKeyboardParams params = mParams;
@@ -306,11 +341,22 @@ public class MoreKeysKeyboard extends Keyboard {
for (int n = 0; n < moreKeys.length; n++) {
final String moreKeySpec = moreKeys[n];
final int row = n / params.mNumColumns;
- final Key key = new Key(mResources, params, moreKeySpec, params.getX(n, row),
- params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight,
- moreKeyFlags);
+ final int x = params.getX(n, row);
+ final int y = params.getY(row);
+ final Key key = new Key(mResources, params, moreKeySpec, x, y,
+ params.mDefaultKeyWidth, params.mDefaultRowHeight, moreKeyFlags);
params.markAsEdgeKey(key, row);
params.onAddKey(key);
+
+ final int pos = params.getColumnPos(n);
+ // The "pos" value represents the offset from the default position. Negative means
+ // left of the default position.
+ if (params.mDividerWidth > 0 && pos != 0) {
+ final int dividerX = (pos > 0) ? x - params.mDividerWidth
+ : x + params.mDefaultKeyWidth;
+ final Key divider = new MoreKeyDivider(params, mDivider, dividerX, y);
+ params.onAddKey(divider);
+ }
}
return new MoreKeysKeyboard(params);
}
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index c45308419..f8f17bdd9 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -722,13 +722,6 @@ public class PointerTracker {
final int[] codes = mKeyDetector.newCodeArray();
mKeyDetector.getKeyAndNearbyCodes(x, y, codes);
- // Swap the first and second values in the codes array if the primary code is not the
- // first value but the second value in the array. This happens when key debouncing is
- // in effect.
- if (codes.length >= 2 && codes[0] != code && codes[1] == code) {
- codes[1] = codes[0];
- codes[0] = code;
- }
callListenerOnCodeInput(key, code, codes, x, y);
callListenerOnRelease(key, code, false);
}
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index 41e7ef435..f96f71e8a 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -119,38 +119,37 @@ public class ProximityInfo {
sweetSpotCenterYs = new float[keyCount];
sweetSpotRadii = new float[keyCount];
calculateSweetSpotParams = true;
+ int i = 0;
+ for (final Key key : keys) {
+ keyXCoordinates[i] = key.mX;
+ keyYCoordinates[i] = key.mY;
+ keyWidths[i] = key.mWidth;
+ keyHeights[i] = key.mHeight;
+ keyCharCodes[i] = key.mCode;
+ if (calculateSweetSpotParams) {
+ final Rect hitBox = key.mHitBox;
+ final int row = hitBox.top / mKeyHeight;
+ if (row < touchPositionCorrection.mRadii.length) {
+ final float hitBoxCenterX = (hitBox.left + hitBox.right) * 0.5f;
+ final float hitBoxCenterY = (hitBox.top + hitBox.bottom) * 0.5f;
+ final float hitBoxWidth = hitBox.right - hitBox.left;
+ final float hitBoxHeight = hitBox.bottom - hitBox.top;
+ final float x = touchPositionCorrection.mXs[row];
+ final float y = touchPositionCorrection.mYs[row];
+ final float radius = touchPositionCorrection.mRadii[row];
+ sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth;
+ sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight;
+ sweetSpotRadii[i] = radius * (float) Math.sqrt(
+ hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
+ }
+ }
+ i++;
+ }
} else {
sweetSpotCenterXs = sweetSpotCenterYs = sweetSpotRadii = null;
calculateSweetSpotParams = false;
}
- int i = 0;
- for (final Key key : keys) {
- keyXCoordinates[i] = key.mX;
- keyYCoordinates[i] = key.mY;
- keyWidths[i] = key.mWidth;
- keyHeights[i] = key.mHeight;
- keyCharCodes[i] = key.mCode;
- if (calculateSweetSpotParams) {
- final Rect hitBox = key.mHitBox;
- final int row = hitBox.top / mKeyHeight;
- if (row < touchPositionCorrection.mRadii.length) {
- final float hitBoxCenterX = (hitBox.left + hitBox.right) * 0.5f;
- final float hitBoxCenterY = (hitBox.top + hitBox.bottom) * 0.5f;
- final float hitBoxWidth = hitBox.right - hitBox.left;
- final float hitBoxHeight = hitBox.bottom - hitBox.top;
- final float x = touchPositionCorrection.mXs[row];
- final float y = touchPositionCorrection.mYs[row];
- final float radius = touchPositionCorrection.mRadii[row];
- sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth;
- sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight;
- sweetSpotRadii[i] = radius * (float) Math.sqrt(
- hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
- }
- }
- i++;
- }
-
mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE,
keyboardWidth, keyboardHeight, mGridWidth, mGridHeight, proximityCharsArray,
keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
diff --git a/java/src/com/android/inputmethod/latin/ComposingStateManager.java b/java/src/com/android/inputmethod/latin/ComposingStateManager.java
index 27f509a29..8811f2023 100644
--- a/java/src/com/android/inputmethod/latin/ComposingStateManager.java
+++ b/java/src/com/android/inputmethod/latin/ComposingStateManager.java
@@ -53,13 +53,6 @@ public class ComposingStateManager {
}
}
- public synchronized boolean isComposing() {
- // TODO: use the composing flag in WordComposer instead of maintaining it
- // here separately. Even better, do away with this class and manage the auto
- // correction indicator in the same place as the suggestions.
- return mIsComposing;
- }
-
public synchronized boolean isAutoCorrectionIndicatorOn() {
return mAutoCorrectionIndicatorOn;
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 953d87beb..64b9f3364 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -979,7 +979,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
.setTypedWordValid(false)
.setHasMinimalSuggestion(false);
// When in fullscreen mode, show completions generated by the application
- setSuggestions(builder.build());
+ final SuggestedWords words = builder.build();
+ final boolean isAutoCorrection = false;
+ setSuggestions(words, isAutoCorrection);
+ setAutoCorrectionIndicator(isAutoCorrection);
// TODO: is this the right thing to do? What should we auto-correct to in
// this case? This says to keep whatever the user typed.
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
@@ -1111,12 +1114,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// and the composingStateManager about it.
private void resetEntireInputState() {
resetComposingState(true /* alsoResetLastComposedWord */);
+ mComposingStateManager.onFinishComposingText();
updateSuggestions();
final InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.finishComposingText();
}
- mComposingStateManager.onFinishComposingText();
mVoiceProxy.setVoiceInputHighlighted(false);
}
@@ -1533,8 +1536,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// it entirely and resume suggestions on the previous word, we'd like to still
// have touch coordinates for it.
resetComposingState(false /* alsoResetLastComposedWord */);
- clearSuggestions();
mComposingStateManager.onFinishComposingText();
+ clearSuggestions();
}
}
if (isComposingWord) {
@@ -1712,35 +1715,32 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
public void clearSuggestions() {
- setSuggestions(SuggestedWords.EMPTY);
+ setSuggestions(SuggestedWords.EMPTY, false);
+ setAutoCorrectionIndicator(false);
}
- public void setSuggestions(SuggestedWords words) {
+ public void setSuggestions(final SuggestedWords words, final boolean isAutoCorrection) {
if (mSuggestionsView != null) {
mSuggestionsView.setSuggestions(words);
- mKeyboardSwitcher.onAutoCorrectionStateChanged(
- words.hasWordAboveAutoCorrectionScoreThreshold());
+ mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection);
}
+ }
+ private void setAutoCorrectionIndicator(final boolean newAutoCorrectionIndicator) {
// Put a blue underline to a word in TextView which will be auto-corrected.
final InputConnection ic = getCurrentInputConnection();
if (ic != null) {
final boolean oldAutoCorrectionIndicator =
mComposingStateManager.isAutoCorrectionIndicatorOn();
- final boolean newAutoCorrectionIndicator = Utils.willAutoCorrect(words);
if (oldAutoCorrectionIndicator != newAutoCorrectionIndicator) {
mComposingStateManager.setAutoCorrectionIndicatorOn(newAutoCorrectionIndicator);
if (DEBUG) {
Log.d(TAG, "Flip the indicator. " + oldAutoCorrectionIndicator
+ " -> " + newAutoCorrectionIndicator);
- if (mComposingStateManager.isComposing() && newAutoCorrectionIndicator
- != mComposingStateManager.isAutoCorrectionIndicatorOn()) {
- throw new RuntimeException("Couldn't flip the indicator!");
- }
}
- final CharSequence textWithUnderline =
- getTextWithUnderline(mWordComposer.getTypedWord());
- if (!TextUtils.isEmpty(textWithUnderline)) {
+ if (mWordComposer.isComposingWord()) {
+ final CharSequence textWithUnderline =
+ getTextWithUnderline(mWordComposer.getTypedWord());
ic.setComposingText(textWithUnderline, 1);
}
}
@@ -1827,28 +1827,28 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
}
}
+ if (Utils.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) {
+ builder.setShouldBlockAutoCorrectionBySafetyNet();
+ }
showSuggestions(builder.build(), typedWord);
}
- public void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
- final boolean shouldBlockAutoCorrectionBySafetyNet =
- Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest);
- if (shouldBlockAutoCorrectionBySafetyNet) {
- suggestedWords.setShouldBlockAutoCorrection();
- }
- setSuggestions(suggestedWords);
+ public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) {
+ final CharSequence autoCorrection;
if (suggestedWords.size() > 0) {
- if (shouldBlockAutoCorrectionBySafetyNet) {
- mWordComposer.setAutoCorrection(typedWord);
- } else if (suggestedWords.hasAutoCorrectionWord()) {
- mWordComposer.setAutoCorrection(suggestedWords.getWord(1));
+ if (!suggestedWords.mShouldBlockAutoCorrectionBySafetyNet
+ && suggestedWords.hasAutoCorrectionWord()) {
+ autoCorrection = suggestedWords.getWord(1);
} else {
- mWordComposer.setAutoCorrection(typedWord);
+ autoCorrection = typedWord;
}
} else {
- // TODO: replace with mWordComposer.deleteAutoCorrection()?
- mWordComposer.setAutoCorrection(null);
+ autoCorrection = null;
}
+ mWordComposer.setAutoCorrection(autoCorrection);
+ final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
+ setSuggestions(suggestedWords, isAutoCorrection);
+ setAutoCorrectionIndicator(isAutoCorrection);
setSuggestionStripShown(isSuggestionsStripVisible());
}
@@ -1885,7 +1885,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void pickSuggestionManually(final int index, final CharSequence suggestion) {
mComposingStateManager.onFinishComposingText();
- final SuggestedWords suggestions = mSuggestionsView.getSuggestions();
+ final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion,
mSettingsValues.mWordSeparators);
@@ -1896,12 +1896,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSuggestionsView.clear();
}
mKeyboardSwitcher.updateShiftState();
+ resetComposingState(true /* alsoResetLastComposedWord */);
final InputConnection ic = getCurrentInputConnection();
if (ic != null) {
- ic.beginBatchEdit();
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
ic.commitCompletion(completionInfo);
- ic.endBatchEdit();
}
return;
}
@@ -1910,8 +1909,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (suggestion.length() == 1 && isShowingPunctuationList()) {
// Word separators are suggested before the user inputs something.
// So, LatinImeLogger logs "" as a user's input.
- LatinImeLogger.logOnManualSuggestion(
- "", suggestion.toString(), index, suggestions.mWords);
+ LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords);
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
final int primaryCode = suggestion.charAt(0);
onCodeInput(primaryCode, new int[] { primaryCode },
@@ -1922,7 +1920,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// We need to log before we commit, because the word composer will store away the user
// typed word.
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
- suggestion.toString(), index, suggestions.mWords);
+ suggestion.toString(), index, suggestedWords);
mExpectingUpdateSelection = true;
commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
LastComposedWord.NOT_A_SEPARATOR);
@@ -2021,7 +2019,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
public void setPunctuationSuggestions() {
- setSuggestions(mSettingsValues.mSuggestPuncList);
+ setSuggestions(mSettingsValues.mSuggestPuncList, false);
+ setAutoCorrectionIndicator(false);
setSuggestionStripShown(isSuggestionsStripVisible());
}
@@ -2414,7 +2413,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
switch (position) {
case 0:
Intent intent = CompatUtils.getInputLanguageSelectionIntent(
- Utils.getInputMethodId(mImm, getPackageName()),
+ Utils.getInputMethodId(getPackageName()),
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
index e3dadf250..5390ee39e 100644
--- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java
+++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
@@ -44,7 +44,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
}
public static void logOnManualSuggestion(
- String before, String after, int position, List<CharSequence> suggestions) {
+ String before, String after, int position, SuggestedWords suggestedWords) {
}
public static void logOnAutoCorrection(String before, String after, int separatorCode) {
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index dfcb6450e..3029057be 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -329,10 +329,9 @@ public class Settings extends InputMethodSettingsActivity
@Override
public boolean onPreferenceClick(Preference pref) {
if (pref == mInputLanguageSelection) {
- startActivity(CompatUtils.getInputLanguageSelectionIntent(
- Utils.getInputMethodId(
- InputMethodManagerCompatWrapper.getInstance(),
- getActivityInternal().getApplicationInfo().packageName), 0));
+ final String imeId = Utils.getInputMethodId(
+ getActivityInternal().getApplicationInfo().packageName);
+ startActivity(CompatUtils.getInputLanguageSelectionIntent(imeId, 0));
return true;
}
return false;
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index ed6359cfa..aad975e46 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -20,22 +20,25 @@ import android.text.TextUtils;
import android.view.inputmethod.CompletionInfo;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class SuggestedWords {
- public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, null);
+ public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, false,
+ null);
- public final List<CharSequence> mWords;
+ private final List<CharSequence> mWords;
public final boolean mTypedWordValid;
public final boolean mHasAutoCorrectionCandidate;
public final boolean mIsPunctuationSuggestions;
+ public final boolean mShouldBlockAutoCorrectionBySafetyNet;
private final List<SuggestedWordInfo> mSuggestedWordInfoList;
- private boolean mShouldBlockAutoCorrection;
- private SuggestedWords(List<CharSequence> words, boolean typedWordValid,
+ SuggestedWords(List<CharSequence> words, boolean typedWordValid,
boolean hasAutoCorrectionCandidate, boolean isPunctuationSuggestions,
+ boolean shouldBlockAutoCorrectionBySafetyNet,
List<SuggestedWordInfo> suggestedWordInfoList) {
if (words != null) {
mWords = words;
@@ -45,8 +48,8 @@ public class SuggestedWords {
mTypedWordValid = typedWordValid;
mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate;
mIsPunctuationSuggestions = isPunctuationSuggestions;
+ mShouldBlockAutoCorrectionBySafetyNet = shouldBlockAutoCorrectionBySafetyNet;
mSuggestedWordInfoList = suggestedWordInfoList;
- mShouldBlockAutoCorrection = false;
}
public int size() {
@@ -65,20 +68,20 @@ public class SuggestedWords {
return mHasAutoCorrectionCandidate && size() > 1 && !mTypedWordValid;
}
- public boolean hasWordAboveAutoCorrectionScoreThreshold() {
- return mHasAutoCorrectionCandidate && ((size() > 1 && !mTypedWordValid) || mTypedWordValid);
+ public boolean willAutoCorrect() {
+ return !mTypedWordValid && mHasAutoCorrectionCandidate
+ && !mShouldBlockAutoCorrectionBySafetyNet;
}
- public boolean isPunctuationSuggestions() {
- return mIsPunctuationSuggestions;
- }
-
- public void setShouldBlockAutoCorrection() {
- mShouldBlockAutoCorrection = true;
- }
-
- public boolean shouldBlockAutoCorrection() {
- return mShouldBlockAutoCorrection;
+ @Override
+ public String toString() {
+ // Pretty-print method to help debug
+ return "SuggestedWords:"
+ + " mTypedWordValid=" + mTypedWordValid
+ + " mHasAutoCorrectionCandidate=" + mHasAutoCorrectionCandidate
+ + " mIsPunctuationSuggestions=" + mIsPunctuationSuggestions
+ + " mShouldBlockAutoCorrectionBySafetyNet=" + mShouldBlockAutoCorrectionBySafetyNet
+ + " mWords=" + Arrays.toString(mWords.toArray());
}
public static class Builder {
@@ -86,6 +89,7 @@ public class SuggestedWords {
private boolean mTypedWordValid;
private boolean mHasMinimalSuggestion;
private boolean mIsPunctuationSuggestions;
+ private boolean mShouldBlockAutoCorrectionBySafetyNet;
private List<SuggestedWordInfo> mSuggestedWordInfoList =
new ArrayList<SuggestedWordInfo>();
@@ -150,6 +154,11 @@ public class SuggestedWords {
return this;
}
+ public Builder setShouldBlockAutoCorrectionBySafetyNet() {
+ mShouldBlockAutoCorrectionBySafetyNet = true;
+ return this;
+ }
+
// Should get rid of the first one (what the user typed previously) from suggestions
// and replace it with what the user currently typed.
public Builder addTypedWordAndPreviousSuggestions(CharSequence typedWord,
@@ -175,7 +184,8 @@ public class SuggestedWords {
public SuggestedWords build() {
return new SuggestedWords(mWords, mTypedWordValid, mHasMinimalSuggestion,
- mIsPunctuationSuggestions, mSuggestedWordInfoList);
+ mIsPunctuationSuggestions, mShouldBlockAutoCorrectionBySafetyNet,
+ mSuggestedWordInfoList);
}
public int size() {
@@ -186,18 +196,20 @@ public class SuggestedWords {
return mWords.get(pos);
}
+ public boolean isTypedWordValid() {
+ return mTypedWordValid;
+ }
+
@Override
public String toString() {
// Pretty-print method to help debug
- final StringBuilder sb = new StringBuilder("StringBuilder: mTypedWordValid = "
- + mTypedWordValid + " ; mHasMinimalSuggestion = " + mHasMinimalSuggestion
- + " ; mIsPunctuationSuggestions = " + mIsPunctuationSuggestions
- + " --- ");
- for (CharSequence s : mWords) {
- sb.append(s);
- sb.append(" ; ");
- }
- return sb.toString();
+ return "SuggestedWords.Builder:"
+ + " mTypedWordValid=" + mTypedWordValid
+ + " mHasMinimalSuggestion=" + mHasMinimalSuggestion
+ + " mIsPunctuationSuggestions=" + mIsPunctuationSuggestions
+ + " mShouldBlockAutoCorrectionBySafetyNet="
+ + mShouldBlockAutoCorrectionBySafetyNet
+ + " mWords=" + Arrays.toString(mWords.toArray());
}
}
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 6d63e95f6..33d4b877e 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -171,12 +171,16 @@ public class Utils {
return keyboardCount > 1;
}
- public static String getInputMethodId(InputMethodManagerCompatWrapper imm, String packageName) {
- return getInputMethodInfo(imm, packageName).getId();
+ public static String getInputMethodId(String packageName) {
+ return getInputMethodInfo(packageName).getId();
}
- public static InputMethodInfoCompatWrapper getInputMethodInfo(
- InputMethodManagerCompatWrapper imm, String packageName) {
+ public static InputMethodInfoCompatWrapper getInputMethodInfo(String packageName) {
+ final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
+ if (imm == null) {
+ throw new RuntimeException("Input method manager not found");
+ }
+
for (final InputMethodInfoCompatWrapper imi : imm.getEnabledInputMethodList()) {
if (imi.getPackageName().equals(packageName))
return imi;
@@ -186,19 +190,25 @@ public class Utils {
// TODO: Resolve the inconsistencies between the native auto correction algorithms and
// this safety net
- public static boolean shouldBlockAutoCorrectionBySafetyNet(SuggestedWords suggestions,
- Suggest suggest) {
+ public static boolean shouldBlockAutoCorrectionBySafetyNet(
+ SuggestedWords.Builder suggestedWordsBuilder, Suggest suggest) {
// Safety net for auto correction.
// Actually if we hit this safety net, it's actually a bug.
- if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false;
+ if (suggestedWordsBuilder.size() <= 1 || suggestedWordsBuilder.isTypedWordValid()) {
+ return false;
+ }
// If user selected aggressive auto correction mode, there is no need to use the safety
// net.
- if (suggest.isAggressiveAutoCorrectionMode()) return false;
- final CharSequence typedWord = suggestions.getWord(0);
+ if (suggest.isAggressiveAutoCorrectionMode()) {
+ return false;
+ }
+ final CharSequence typedWord = suggestedWordsBuilder.getWord(0);
// If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH,
// we should not use net because relatively edit distance can be big.
- if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false;
- final CharSequence suggestionWord = suggestions.getWord(1);
+ if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) {
+ return false;
+ }
+ final CharSequence suggestionWord = suggestedWordsBuilder.getWord(1);
final int typedWordLength = typedWord.length();
final int maxEditDistanceOfNativeDictionary =
(typedWordLength < 5 ? 2 : typedWordLength / 2) + 1;
@@ -563,8 +573,16 @@ public class Utils {
switch (inputType & InputType.TYPE_MASK_CLASS) {
case InputType.TYPE_CLASS_NUMBER:
- case InputType.TYPE_CLASS_DATETIME:
return KeyboardId.MODE_NUMBER;
+ case InputType.TYPE_CLASS_DATETIME:
+ switch (variation) {
+ case InputType.TYPE_DATETIME_VARIATION_DATE:
+ return KeyboardId.MODE_DATE;
+ case InputType.TYPE_DATETIME_VARIATION_TIME:
+ return KeyboardId.MODE_TIME;
+ default: // InputType.TYPE_DATETIME_VARIATION_NORMAL
+ return KeyboardId.MODE_DATETIME;
+ }
case InputType.TYPE_CLASS_PHONE:
return KeyboardId.MODE_PHONE;
case InputType.TYPE_CLASS_TEXT:
@@ -766,11 +784,6 @@ public class Utils {
return s.toUpperCase(locale).charAt(0) + s.substring(1);
}
- public static boolean willAutoCorrect(SuggestedWords suggestions) {
- return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate
- && !suggestions.shouldBlockAutoCorrection();
- }
-
public static class Stats {
public static void onNonSeparator(final char code, final int x,
final int y) {
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
index 0bd6abe09..cb1b49c67 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
@@ -34,7 +34,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
public class MoreSuggestions extends Keyboard {
public static final int SUGGESTION_CODE_BASE = 1024;
- private MoreSuggestions(Builder.MoreSuggestionsParam params) {
+ MoreSuggestions(Builder.MoreSuggestionsParam params) {
super(params);
}
@@ -63,7 +63,7 @@ public class MoreSuggestions extends Keyboard {
paint.setAntiAlias(true);
final Resources res = view.getContext().getResources();
mDivider = res.getDrawable(R.drawable.more_suggestions_divider);
- // TODO: Drawable itself should has an alpha value.
+ // TODO: Drawable itself should have an alpha value.
mDivider.setAlpha(128);
mDividerWidth = mDivider.getIntrinsicWidth();
final int padding = (int) res.getDimension(
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
index 40d782640..d3362940f 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
@@ -62,7 +62,6 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
-import com.android.inputmethod.latin.Utils;
import java.util.ArrayList;
import java.util.List;
@@ -95,7 +94,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private final TextView mPreviewText;
private Listener mListener;
- private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
+ private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
private final SuggestionsViewParams mParams;
private static final float MIN_TEXT_XSCALE = 0.70f;
@@ -259,10 +258,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
}
- private CharSequence getStyledSuggestionWord(SuggestedWords suggestions, int pos) {
- final CharSequence word = suggestions.getWord(pos);
- final boolean isAutoCorrect = pos == 1 && Utils.willAutoCorrect(suggestions);
- final boolean isTypedWordValid = pos == 0 && suggestions.mTypedWordValid;
+ private CharSequence getStyledSuggestionWord(SuggestedWords suggestedWords, int pos) {
+ final CharSequence word = suggestedWords.getWord(pos);
+ final boolean isAutoCorrect = pos == 1 && suggestedWords.willAutoCorrect();
+ final boolean isTypedWordValid = pos == 0 && suggestedWords.mTypedWordValid;
if (!isAutoCorrect && !isTypedWordValid)
return word;
@@ -279,10 +278,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
return spannedWord;
}
- private int getWordPosition(int index, SuggestedWords suggestions) {
+ private int getWordPosition(int index, SuggestedWords suggestedWords) {
// TODO: This works for 3 suggestions. Revisit this algorithm when there are 5 or more
// suggestions.
- final int centerPos = Utils.willAutoCorrect(suggestions) ? 1 : 0;
+ final int centerPos = suggestedWords.willAutoCorrect() ? 1 : 0;
if (index == mCenterSuggestionIndex) {
return centerPos;
} else if (index == centerPos) {
@@ -292,14 +291,14 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
}
- private int getSuggestionTextColor(int index, SuggestedWords suggestions, int pos) {
+ private int getSuggestionTextColor(int index, SuggestedWords suggestedWords, int pos) {
// TODO: Need to revisit this logic with bigram suggestions
final boolean isSuggested = (pos != 0);
final int color;
- if (index == mCenterSuggestionIndex && Utils.willAutoCorrect(suggestions)) {
+ if (index == mCenterSuggestionIndex && suggestedWords.willAutoCorrect()) {
color = mColorAutoCorrect;
- } else if (index == mCenterSuggestionIndex && suggestions.mTypedWordValid) {
+ } else if (index == mCenterSuggestionIndex && suggestedWords.mTypedWordValid) {
color = mColorValidTypedWord;
} else if (isSuggested) {
color = mColorSuggested;
@@ -307,14 +306,14 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
color = mColorTypedWord;
}
if (LatinImeLogger.sDBG) {
- if (index == mCenterSuggestionIndex && suggestions.mHasAutoCorrectionCandidate
- && suggestions.shouldBlockAutoCorrection()) {
+ if (index == mCenterSuggestionIndex && suggestedWords.mHasAutoCorrectionCandidate
+ && suggestedWords.mShouldBlockAutoCorrectionBySafetyNet) {
return 0xFFFF0000;
}
}
- final SuggestedWordInfo info = (pos < suggestions.size())
- ? suggestions.getInfo(pos) : null;
+ final SuggestedWordInfo info = (pos < suggestedWords.size())
+ ? suggestedWords.getInfo(pos) : null;
if (info != null && info.isObsoleteSuggestedWord()) {
return applyAlpha(color, mAlphaObsoleted);
} else {
@@ -334,19 +333,19 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
params.gravity = Gravity.CENTER;
}
- public void layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer,
+ public void layout(SuggestedWords suggestedWords, ViewGroup stripView, ViewGroup placer,
int stripWidth) {
- if (suggestions.isPunctuationSuggestions()) {
- layoutPunctuationSuggestions(suggestions, stripView);
+ if (suggestedWords.mIsPunctuationSuggestions) {
+ layoutPunctuationSuggestions(suggestedWords, stripView);
return;
}
final int countInStrip = mSuggestionsCountInStrip;
- setupTexts(suggestions, countInStrip);
- mMoreSuggestionsAvailable = (suggestions.size() > countInStrip);
+ setupTexts(suggestedWords, countInStrip);
+ mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
int x = 0;
for (int index = 0; index < countInStrip; index++) {
- final int pos = getWordPosition(index, suggestions);
+ final int pos = getWordPosition(index, suggestedWords);
if (index != 0) {
final View divider = mDividers.get(pos);
@@ -369,7 +368,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
// Disable this suggestion if the suggestion is null or empty.
word.setEnabled(!TextUtils.isEmpty(styled));
- word.setTextColor(getSuggestionTextColor(index, suggestions, pos));
+ word.setTextColor(getSuggestionTextColor(index, suggestedWords, pos));
final int width = getSuggestionWidth(index, stripWidth);
final CharSequence text = getEllipsizedText(styled, width, word.getPaint());
final float scaleX = word.getTextScaleX();
@@ -381,7 +380,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
x += word.getMeasuredWidth();
if (DBG) {
- final CharSequence debugInfo = getDebugInfo(suggestions, pos);
+ final CharSequence debugInfo = getDebugInfo(suggestedWords, pos);
if (debugInfo != null) {
final TextView info = mInfos.get(pos);
info.setText(debugInfo);
@@ -413,11 +412,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
}
- private void setupTexts(SuggestedWords suggestions, int countInStrip) {
+ private void setupTexts(SuggestedWords suggestedWords, int countInStrip) {
mTexts.clear();
- final int count = Math.min(suggestions.size(), countInStrip);
+ final int count = Math.min(suggestedWords.size(), countInStrip);
for (int pos = 0; pos < count; pos++) {
- final CharSequence styled = getStyledSuggestionWord(suggestions, pos);
+ final CharSequence styled = getStyledSuggestionWord(suggestedWords, pos);
mTexts.add(styled);
}
for (int pos = count; pos < countInStrip; pos++) {
@@ -426,8 +425,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
}
- private void layoutPunctuationSuggestions(SuggestedWords suggestions, ViewGroup stripView) {
- final int countInStrip = Math.min(suggestions.size(), PUNCTUATIONS_IN_STRIP);
+ private void layoutPunctuationSuggestions(SuggestedWords suggestedWords,
+ ViewGroup stripView) {
+ final int countInStrip = Math.min(suggestedWords.size(), PUNCTUATIONS_IN_STRIP);
for (int index = 0; index < countInStrip; index++) {
if (index != 0) {
// Add divider if this isn't the left most suggestion in suggestions strip.
@@ -437,7 +437,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final TextView word = mWords.get(index);
word.setEnabled(true);
word.setTextColor(mColorAutoCorrect);
- final CharSequence text = suggestions.getWord(index);
+ final CharSequence text = suggestedWords.getWord(index);
word.setText(text);
word.setTextScaleX(1.0f);
word.setCompoundDrawables(null, null, null, null);
@@ -636,13 +636,13 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mKeyboardView = (KeyboardView)inputView.findViewById(R.id.keyboard_view);
}
- public void setSuggestions(SuggestedWords suggestions) {
- if (suggestions == null || suggestions.size() == 0)
+ public void setSuggestions(SuggestedWords suggestedWords) {
+ if (suggestedWords == null || suggestedWords.size() == 0)
return;
clear();
- mSuggestions = suggestions;
- mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth());
+ mSuggestedWords = suggestedWords;
+ mParams.layout(mSuggestedWords, mSuggestionsStrip, this, getWidth());
}
@@ -665,7 +665,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
public SuggestedWords getSuggestions() {
- return mSuggestions;
+ return mSuggestedWords;
}
public void clear() {
@@ -688,7 +688,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
@Override
public boolean onCustomRequest(int requestCode) {
final int index = requestCode;
- final CharSequence word = mSuggestions.getWord(index);
+ final CharSequence word = mSuggestedWords.getWord(index);
mListener.pickSuggestionManually(index, word);
dismissMoreSuggestions();
return true;
@@ -733,7 +733,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final int maxWidth = stripWidth - container.getPaddingLeft()
- container.getPaddingRight();
final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder;
- builder.layout(mSuggestions, params.mSuggestionsCountInStrip, maxWidth,
+ builder.layout(mSuggestedWords, params.mSuggestionsCountInStrip, maxWidth,
(int)(maxWidth * params.mMinMoreSuggestionsWidth),
params.mMaxMoreSuggestionsRow);
mMoreSuggestionsView.setKeyboard(builder.build());
@@ -835,10 +835,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
if (!(tag instanceof Integer))
return;
final int index = (Integer) tag;
- if (index >= mSuggestions.size())
+ if (index >= mSuggestedWords.size())
return;
- final CharSequence word = mSuggestions.getWord(index);
+ final CharSequence word = mSuggestedWords.getWord(index);
mListener.pickSuggestionManually(index, word);
}