From ecfbf4625c8afd9cde7b79e0c7846b87e20f79e9 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 22 Aug 2012 14:22:20 +0900 Subject: [PATCH] Add static construct method for SparseArray Change-Id: I6da97f6ea23578318f403bb5d64c30b1663c69ee --- .../accessibility/AccessibilityEntityProvider.java | 3 ++- java/src/com/android/inputmethod/keyboard/Keyboard.java | 2 +- .../com/android/inputmethod/keyboard/KeyboardLayoutSet.java | 2 +- java/src/com/android/inputmethod/keyboard/KeyboardView.java | 4 ++-- .../android/inputmethod/keyboard/internal/KeyStyles.java | 2 +- .../inputmethod/keyboard/internal/PreviewPlacerView.java | 3 ++- .../src/com/android/inputmethod/latin/BinaryDictionary.java | 2 +- java/src/com/android/inputmethod/latin/CollectionUtils.java | 6 ++++++ 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java index 70e38fdb0..039c77b9c 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java @@ -35,6 +35,7 @@ import android.view.inputmethod.EditorInfo; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardView; +import com.android.inputmethod.latin.CollectionUtils; /** * Exposes a virtual view sub-tree for {@link KeyboardView} and generates @@ -55,7 +56,7 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat private final AccessibilityUtils mAccessibilityUtils; /** A map of integer IDs to {@link Key}s. */ - private final SparseArray mVirtualViewIdToKey = new SparseArray(); + private final SparseArray mVirtualViewIdToKey = CollectionUtils.newSparseArray(); /** Temporary rect used to calculate in-screen bounds. */ private final Rect mTempBoundsInScreen = new Rect(); diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index a5429e98c..e37868b3f 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -135,7 +135,7 @@ public class Keyboard { public final Key[] mAltCodeKeysWhileTyping; public final KeyboardIconsSet mIconsSet; - private final SparseArray mKeyCache = new SparseArray(); + private final SparseArray mKeyCache = CollectionUtils.newSparseArray(); private final ProximityInfo mProximityInfo; private final boolean mProximityCharsCorrectionEnabled; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index 0cb8d869f..76ac3de22 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -117,7 +117,7 @@ public class KeyboardLayoutSet { int mWidth; // Sparse array of KeyboardLayoutSet element parameters indexed by element's id. final SparseArray mKeyboardLayoutSetElementIdToParamsMap = - new SparseArray(); + CollectionUtils.newSparseArray(); static class ElementParams { int mKeyboardXmlId; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index c8f30e2c9..ff428ac85 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -130,9 +130,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { private final Paint mPaint = new Paint(); private final Paint.FontMetrics mFontMetrics = new Paint.FontMetrics(); // This sparse array caches key label text height in pixel indexed by key label text size. - private static final SparseArray sTextHeightCache = new SparseArray(); + private static final SparseArray sTextHeightCache = CollectionUtils.newSparseArray(); // This sparse array caches key label text width in pixel indexed by key label text size. - private static final SparseArray sTextWidthCache = new SparseArray(); + private static final SparseArray sTextWidthCache = CollectionUtils.newSparseArray(); private static final char[] KEY_LABEL_REFERENCE_CHAR = { 'M' }; private static final char[] KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR = { '8' }; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java index 16fd715df..e40cf45cc 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java @@ -91,7 +91,7 @@ public class KeyStyles { private class DeclaredKeyStyle extends KeyStyle { private final String mParentStyleName; - private final SparseArray mStyleAttributes = new SparseArray(); + private final SparseArray mStyleAttributes = CollectionUtils.newSparseArray(); public DeclaredKeyStyle(String parentStyleName) { mParentStyleName = parentStyleName; diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java index 59a92d625..3f33aee5a 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java +++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java @@ -28,6 +28,7 @@ import android.util.SparseArray; import android.widget.RelativeLayout; import com.android.inputmethod.keyboard.PointerTracker; +import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; @@ -47,7 +48,7 @@ public class PreviewPlacerView extends RelativeLayout { private int mXOrigin; private int mYOrigin; - private final SparseArray mPointers = new SparseArray(); + private final SparseArray mPointers = CollectionUtils.newSparseArray(); private String mGestureFloatingPreviewText; private int mLastPointerX; diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index c04a99b6a..8909526d8 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -63,7 +63,7 @@ public class BinaryDictionary extends Dictionary { private final boolean mUseFullEditDistance; private final SparseArray mDicTraverseSessions = - new SparseArray(); + CollectionUtils.newSparseArray(); // TODO: There should be a way to remove used DicTraverseSession objects from // {@code mDicTraverseSessions}. diff --git a/java/src/com/android/inputmethod/latin/CollectionUtils.java b/java/src/com/android/inputmethod/latin/CollectionUtils.java index 789b79a0a..baa2ee1cd 100644 --- a/java/src/com/android/inputmethod/latin/CollectionUtils.java +++ b/java/src/com/android/inputmethod/latin/CollectionUtils.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import android.util.SparseArray; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -86,4 +88,8 @@ public class CollectionUtils { public static CopyOnWriteArrayList newCopyOnWriteArrayList(final E[] array) { return new CopyOnWriteArrayList(array); } + + public static SparseArray newSparseArray() { + return new SparseArray(); + } }