Make sure PointerTrackerQueue is non-null

Change-Id: I2106cf64bed1472fb39d24e7e5bdee7238a30bfe
main
Tadashi G. Takaoka 2012-11-01 13:24:18 +09:00
parent 2db1ea79e6
commit 93b5c2ce63
2 changed files with 23 additions and 44 deletions

View File

@ -374,7 +374,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean( final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
ResourceUtils.getDeviceOverrideValue(res, ResourceUtils.getDeviceOverrideValue(res,
R.array.phantom_sudden_move_event_device_list, "false")); R.array.phantom_sudden_move_event_device_list, "false"));
PointerTracker.init(mHasDistinctMultitouch, needsPhantomSuddenMoveEventHack); PointerTracker.init(needsPhantomSuddenMoveEventHack);
final TypedArray a = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView); attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);

View File

@ -157,7 +157,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private static final boolean sNeedsProximateBogusDownMoveUpEventHack = true; private static final boolean sNeedsProximateBogusDownMoveUpEventHack = true;
private static final ArrayList<PointerTracker> sTrackers = CollectionUtils.newArrayList(); private static final ArrayList<PointerTracker> sTrackers = CollectionUtils.newArrayList();
private static PointerTrackerQueue sPointerTrackerQueue; private static final PointerTrackerQueue sPointerTrackerQueue = new PointerTrackerQueue();
public final int mPointerId; public final int mPointerId;
@ -326,13 +326,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private final GestureStrokeWithPreviewPoints mGestureStrokeWithPreviewPoints; private final GestureStrokeWithPreviewPoints mGestureStrokeWithPreviewPoints;
public static void init(boolean hasDistinctMultitouch, public static void init(final boolean needsPhantomSuddenMoveEventHack) {
boolean needsPhantomSuddenMoveEventHack) {
if (hasDistinctMultitouch) {
sPointerTrackerQueue = new PointerTrackerQueue();
} else {
sPointerTrackerQueue = null;
}
sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack; sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack;
sParams = PointerTrackerParams.DEFAULT; sParams = PointerTrackerParams.DEFAULT;
sGestureStrokeParams = GestureStrokeParams.DEFAULT; sGestureStrokeParams = GestureStrokeParams.DEFAULT;
@ -376,7 +370,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
public static boolean isAnyInSlidingKeyInput() { public static boolean isAnyInSlidingKeyInput() {
return sPointerTrackerQueue != null ? sPointerTrackerQueue.isAnyInSlidingKeyInput() : false; return sPointerTrackerQueue.isAnyInSlidingKeyInput();
} }
public static void setKeyboardActionListener(final KeyboardActionListener listener) { public static void setKeyboardActionListener(final KeyboardActionListener listener) {
@ -683,12 +677,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
private static int getActivePointerTrackerCount() { private static int getActivePointerTrackerCount() {
return (sPointerTrackerQueue == null) ? 1 : sPointerTrackerQueue.size(); return sPointerTrackerQueue.size();
} }
private static boolean isOldestTrackerInQueue(final PointerTracker tracker) { private static boolean isOldestTrackerInQueue(final PointerTracker tracker) {
return sPointerTrackerQueue == null return sPointerTrackerQueue.getOldestElement() == tracker;
|| sPointerTrackerQueue.getOldestElement() == tracker;
} }
private void mayStartBatchInput(final Key key) { private void mayStartBatchInput(final Key key) {
@ -798,15 +791,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final Key key = getKeyOn(x, y); final Key key = getKeyOn(x, y);
mBogusMoveEventDetector.onActualDownEvent(x, y); mBogusMoveEventDetector.onActualDownEvent(x, y);
final PointerTrackerQueue queue = sPointerTrackerQueue; if (key != null && key.isModifier()) {
if (queue != null) { // Before processing a down event of modifier key, all pointers already being
if (key != null && key.isModifier()) { // tracked should be released.
// Before processing a down event of modifier key, all pointers already being sPointerTrackerQueue.releaseAllPointers(eventTime);
// tracked should be released.
queue.releaseAllPointers(eventTime);
}
queue.add(this);
} }
sPointerTrackerQueue.add(this);
onDownEventInternal(x, y, eventTime); onDownEventInternal(x, y, eventTime);
if (!sShouldHandleGesture) { if (!sShouldHandleGesture) {
return; return;
@ -982,7 +972,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// slides off the key. This defends against noise from some touch panels when there are // slides off the key. This defends against noise from some touch panels when there are
// close multiple touches. // close multiple touches.
// Caveat: When in chording input mode with a modifier key, we don't use this hack. // Caveat: When in chording input mode with a modifier key, we don't use this hack.
else if (getActivePointerTrackerCount() > 1 && sPointerTrackerQueue != null else if (getActivePointerTrackerCount() > 1
&& !sPointerTrackerQueue.hasModifierKeyOlderThan(this)) { && !sPointerTrackerQueue.hasModifierKeyOlderThan(this)) {
if (DEBUG_MODE) { if (DEBUG_MODE) {
Log.w(TAG, String.format("[%d] onMoveEvent:" Log.w(TAG, String.format("[%d] onMoveEvent:"
@ -1048,22 +1038,17 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
printTouchEvent("onUpEvent :", x, y, eventTime); printTouchEvent("onUpEvent :", x, y, eventTime);
} }
final PointerTrackerQueue queue = sPointerTrackerQueue; if (!sInGesture) {
if (queue != null) { if (mCurrentKey != null && mCurrentKey.isModifier()) {
if (!sInGesture) { // Before processing an up event of modifier key, all pointers already being
if (mCurrentKey != null && mCurrentKey.isModifier()) { // tracked should be released.
// Before processing an up event of modifier key, all pointers already being sPointerTrackerQueue.releaseAllPointersExcept(this, eventTime);
// tracked should be released. } else {
queue.releaseAllPointersExcept(this, eventTime); sPointerTrackerQueue.releaseAllPointersOlderThan(this, eventTime);
} else {
queue.releaseAllPointersOlderThan(this, eventTime);
}
} }
} }
onUpEventInternal(eventTime); onUpEventInternal(eventTime);
if (queue != null) { sPointerTrackerQueue.remove(this);
queue.remove(this);
}
} }
// Let this pointer tracker know that one of newer-than-this pointer trackers got an up event. // Let this pointer tracker know that one of newer-than-this pointer trackers got an up event.
@ -1116,10 +1101,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public void onLongPressed() { public void onLongPressed() {
mKeyAlreadyProcessed = true; mKeyAlreadyProcessed = true;
setReleasedKeyGraphics(mCurrentKey); setReleasedKeyGraphics(mCurrentKey);
final PointerTrackerQueue queue = sPointerTrackerQueue; sPointerTrackerQueue.remove(this);
if (queue != null) {
queue.remove(this);
}
} }
public void onCancelEvent(final int x, final int y, final long eventTime) { public void onCancelEvent(final int x, final int y, final long eventTime) {
@ -1127,11 +1109,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
printTouchEvent("onCancelEvt:", x, y, eventTime); printTouchEvent("onCancelEvt:", x, y, eventTime);
} }
final PointerTrackerQueue queue = sPointerTrackerQueue; sPointerTrackerQueue.releaseAllPointersExcept(this, eventTime);
if (queue != null) { sPointerTrackerQueue.remove(this);
queue.releaseAllPointersExcept(this, eventTime);
queue.remove(this);
}
onCancelEventInternal(); onCancelEventInternal();
} }