Add static construct method for SparseArray

Change-Id: I6da97f6ea23578318f403bb5d64c30b1663c69ee
main
Tadashi G. Takaoka 2012-08-22 14:22:20 +09:00
parent 1f05cf6dab
commit ecfbf4625c
8 changed files with 16 additions and 8 deletions

View File

@ -35,6 +35,7 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.latin.CollectionUtils;
/** /**
* Exposes a virtual view sub-tree for {@link KeyboardView} and generates * Exposes a virtual view sub-tree for {@link KeyboardView} and generates
@ -55,7 +56,7 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
private final AccessibilityUtils mAccessibilityUtils; private final AccessibilityUtils mAccessibilityUtils;
/** A map of integer IDs to {@link Key}s. */ /** A map of integer IDs to {@link Key}s. */
private final SparseArray<Key> mVirtualViewIdToKey = new SparseArray<Key>(); private final SparseArray<Key> mVirtualViewIdToKey = CollectionUtils.newSparseArray();
/** Temporary rect used to calculate in-screen bounds. */ /** Temporary rect used to calculate in-screen bounds. */
private final Rect mTempBoundsInScreen = new Rect(); private final Rect mTempBoundsInScreen = new Rect();

View File

@ -135,7 +135,7 @@ public class Keyboard {
public final Key[] mAltCodeKeysWhileTyping; public final Key[] mAltCodeKeysWhileTyping;
public final KeyboardIconsSet mIconsSet; public final KeyboardIconsSet mIconsSet;
private final SparseArray<Key> mKeyCache = new SparseArray<Key>(); private final SparseArray<Key> mKeyCache = CollectionUtils.newSparseArray();
private final ProximityInfo mProximityInfo; private final ProximityInfo mProximityInfo;
private final boolean mProximityCharsCorrectionEnabled; private final boolean mProximityCharsCorrectionEnabled;

View File

@ -117,7 +117,7 @@ public class KeyboardLayoutSet {
int mWidth; int mWidth;
// Sparse array of KeyboardLayoutSet element parameters indexed by element's id. // Sparse array of KeyboardLayoutSet element parameters indexed by element's id.
final SparseArray<ElementParams> mKeyboardLayoutSetElementIdToParamsMap = final SparseArray<ElementParams> mKeyboardLayoutSetElementIdToParamsMap =
new SparseArray<ElementParams>(); CollectionUtils.newSparseArray();
static class ElementParams { static class ElementParams {
int mKeyboardXmlId; int mKeyboardXmlId;

View File

@ -130,9 +130,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private final Paint mPaint = new Paint(); private final Paint mPaint = new Paint();
private final Paint.FontMetrics mFontMetrics = new Paint.FontMetrics(); private final Paint.FontMetrics mFontMetrics = new Paint.FontMetrics();
// This sparse array caches key label text height in pixel indexed by key label text size. // This sparse array caches key label text height in pixel indexed by key label text size.
private static final SparseArray<Float> sTextHeightCache = new SparseArray<Float>(); private static final SparseArray<Float> sTextHeightCache = CollectionUtils.newSparseArray();
// This sparse array caches key label text width in pixel indexed by key label text size. // This sparse array caches key label text width in pixel indexed by key label text size.
private static final SparseArray<Float> sTextWidthCache = new SparseArray<Float>(); private static final SparseArray<Float> sTextWidthCache = CollectionUtils.newSparseArray();
private static final char[] KEY_LABEL_REFERENCE_CHAR = { 'M' }; private static final char[] KEY_LABEL_REFERENCE_CHAR = { 'M' };
private static final char[] KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR = { '8' }; private static final char[] KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR = { '8' };

View File

@ -91,7 +91,7 @@ public class KeyStyles {
private class DeclaredKeyStyle extends KeyStyle { private class DeclaredKeyStyle extends KeyStyle {
private final String mParentStyleName; private final String mParentStyleName;
private final SparseArray<Object> mStyleAttributes = new SparseArray<Object>(); private final SparseArray<Object> mStyleAttributes = CollectionUtils.newSparseArray();
public DeclaredKeyStyle(String parentStyleName) { public DeclaredKeyStyle(String parentStyleName) {
mParentStyleName = parentStyleName; mParentStyleName = parentStyleName;

View File

@ -28,6 +28,7 @@ import android.util.SparseArray;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@ -47,7 +48,7 @@ public class PreviewPlacerView extends RelativeLayout {
private int mXOrigin; private int mXOrigin;
private int mYOrigin; private int mYOrigin;
private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>(); private final SparseArray<PointerTracker> mPointers = CollectionUtils.newSparseArray();
private String mGestureFloatingPreviewText; private String mGestureFloatingPreviewText;
private int mLastPointerX; private int mLastPointerX;

View File

@ -63,7 +63,7 @@ public class BinaryDictionary extends Dictionary {
private final boolean mUseFullEditDistance; private final boolean mUseFullEditDistance;
private final SparseArray<DicTraverseSession> mDicTraverseSessions = private final SparseArray<DicTraverseSession> mDicTraverseSessions =
new SparseArray<DicTraverseSession>(); CollectionUtils.newSparseArray();
// TODO: There should be a way to remove used DicTraverseSession objects from // TODO: There should be a way to remove used DicTraverseSession objects from
// {@code mDicTraverseSessions}. // {@code mDicTraverseSessions}.

View File

@ -16,6 +16,8 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.util.SparseArray;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -86,4 +88,8 @@ public class CollectionUtils {
public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final E[] array) { public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final E[] array) {
return new CopyOnWriteArrayList<E>(array); return new CopyOnWriteArrayList<E>(array);
} }
public static <E> SparseArray<E> newSparseArray() {
return new SparseArray<E>();
}
} }