aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java32
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java4
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java51
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java7
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java12
5 files changed, 86 insertions, 20 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
index 8bc789317..9986f6ec0 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
@@ -29,7 +29,6 @@ import android.util.Log;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;
-import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.accessibility.AccessibilityEvent;
import android.view.inputmethod.EditorInfo;
@@ -51,7 +50,6 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
private static final String TAG = AccessibilityEntityProvider.class.getSimpleName();
private static final int UNDEFINED = Integer.MIN_VALUE;
- private final KeyboardView mKeyboardView;
private final InputMethodService mInputMethodService;
private final KeyCodeDescriptionMapper mKeyCodeDescriptionMapper;
private final AccessibilityUtils mAccessibilityUtils;
@@ -68,18 +66,28 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
/** The virtual view identifier for the focused node. */
private int mAccessibilityFocusedView = UNDEFINED;
+ /** The current keyboard view. */
+ private KeyboardView mKeyboardView;
+
public AccessibilityEntityProvider(KeyboardView keyboardView, InputMethodService inputMethod) {
- mKeyboardView = keyboardView;
mInputMethodService = inputMethod;
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(KeyboardView keyboardView) {
+ mKeyboardView = keyboardView;
+
assignVirtualViewIds();
updateParentLocation();
-
- // Ensure that the on-screen bounds are cleared when the layout changes.
- mKeyboardView.getViewTreeObserver().addOnGlobalLayoutListener(mGlobalLayoutListener);
}
/**
@@ -196,8 +204,8 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
* @param key The key to press.
*/
void simulateKeyPress(Key key) {
- final int x = key.mX + (key.mWidth / 2);
- final int y = key.mY + (key.mHeight / 2);
+ final int x = key.mHitBox.centerX();
+ final int y = key.mHitBox.centerY();
final long downTime = SystemClock.uptimeMillis();
final MotionEvent downEvent = MotionEvent.obtain(
downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0);
@@ -331,12 +339,4 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
// left-half of the integer and OR'ing with the y-coordinate.
return ((0xFFFF & key.mX) << (Integer.SIZE / 2)) | (0xFFFF & key.mY);
}
-
- private final OnGlobalLayoutListener mGlobalLayoutListener = new OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- assignVirtualViewIds();
- updateParentLocation();
- }
- };
}
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
index 2623dcc03..59f1eec04 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
@@ -80,6 +80,10 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
// Ensure that the view has an accessibility delegate.
ViewCompat.setAccessibilityDelegate(view, this);
+
+ if (mAccessibilityNodeProvider != null) {
+ mAccessibilityNodeProvider.setView(view);
+ }
}
/**
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index 7e1889a74..23acb8b74 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.accessibility;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
+import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
@@ -104,6 +105,10 @@ public class KeyCodeDescriptionMapper {
return getDescriptionForShiftKey(context, keyboard);
}
+ if (code == Keyboard.CODE_ACTION_ENTER) {
+ return getDescriptionForActionKey(context, keyboard, key);
+ }
+
if (!TextUtils.isEmpty(key.mLabel)) {
final String label = key.mLabel.toString().trim();
@@ -192,6 +197,52 @@ public class KeyCodeDescriptionMapper {
}
/**
+ * Returns a context-sensitive description of the "Enter" action key.
+ *
+ * @param context The package's context.
+ * @param keyboard The keyboard on which the key resides.
+ * @param key The key to describe.
+ * @return Returns a context-sensitive description of the "Enter" action
+ * key.
+ */
+ private String getDescriptionForActionKey(Context context, Keyboard keyboard, Key key) {
+ final KeyboardId keyboardId = keyboard.mId;
+ final int actionId = keyboardId.imeActionId();
+ final int resId;
+
+ // Always use the label, if available.
+ if (!TextUtils.isEmpty(key.mLabel)) {
+ return key.mLabel.toString().trim();
+ }
+
+ // Otherwise, use the action ID.
+ switch (actionId) {
+ case EditorInfo.IME_ACTION_SEARCH:
+ resId = R.string.spoken_description_search;
+ break;
+ case EditorInfo.IME_ACTION_GO:
+ resId = R.string.label_go_key;
+ break;
+ case EditorInfo.IME_ACTION_SEND:
+ resId = R.string.label_send_key;
+ break;
+ case EditorInfo.IME_ACTION_NEXT:
+ resId = R.string.label_next_key;
+ break;
+ case EditorInfo.IME_ACTION_DONE:
+ resId = R.string.label_done_key;
+ break;
+ case EditorInfo.IME_ACTION_PREVIOUS:
+ resId = R.string.label_previous_key;
+ break;
+ default:
+ resId = R.string.spoken_description_return;
+ }
+
+ return context.getString(resId);
+ }
+
+ /**
* Returns a localized character sequence describing what will happen when
* the specified key is pressed based on its key code.
* <p>
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 38549436b..695bf8dce 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -454,6 +454,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Has to be package-visible for unit tests
/* package */ void loadSettings() {
+ // 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.
if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
@Override
@@ -495,6 +497,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
resetContactsDictionary(oldContactsDictionary);
+ // 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.
+ if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mUserHistoryDictionary = new UserHistoryDictionary(
this, localeStr, Suggest.DIC_USER_HISTORY, mPrefs);
mSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
@@ -624,6 +629,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
+ // 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.updateSubtype(subtype);
}
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index b3e46baf5..4178955bc 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -126,8 +126,9 @@ public class Utils {
}
public static RingCharBuffer init(InputMethodService context, boolean enabled,
boolean usabilityStudy) {
+ if (!(enabled || usabilityStudy)) return null;
sRingCharBuffer.mContext = context;
- sRingCharBuffer.mEnabled = enabled || usabilityStudy;
+ sRingCharBuffer.mEnabled = true;
UsabilityStudyLogUtils.getInstance().init(context);
return sRingCharBuffer;
}
@@ -221,8 +222,6 @@ public class Utils {
// TODO: remove code duplication with ResearchLog class
private static final String USABILITY_TAG = UsabilityStudyLogUtils.class.getSimpleName();
private static final String FILENAME = "log.txt";
- private static final UsabilityStudyLogUtils sInstance =
- new UsabilityStudyLogUtils();
private final Handler mLoggingHandler;
private File mFile;
private File mDirectory;
@@ -241,8 +240,13 @@ public class Utils {
mLoggingHandler = new Handler(handlerThread.getLooper());
}
+ // Initialization-on-demand holder
+ private static class OnDemandInitializationHolder {
+ public static final UsabilityStudyLogUtils sInstance = new UsabilityStudyLogUtils();
+ }
+
public static UsabilityStudyLogUtils getInstance() {
- return sInstance;
+ return OnDemandInitializationHolder.sInstance;
}
public void init(InputMethodService ims) {