am d9b1327c: Merge "Consolidate similar methods"

* commit 'd9b1327c218c813e5556d5894621c82bd0a99297':
  Consolidate similar methods
main
Tadashi G. Takaoka 2014-10-30 03:00:34 +00:00 committed by Android Git Automerger
commit 3dcb5d3462
5 changed files with 50 additions and 37 deletions

View File

@ -64,6 +64,7 @@ import java.util.Locale;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/** /**
* A view that is responsible for detecting key presses and touch movements. * A view that is responsible for detecting key presses and touch movements.
@ -306,17 +307,24 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
animatorToStart.setCurrentPlayTime(startTime); animatorToStart.setCurrentPlayTime(startTime);
} }
// Implements {@link TimerHander.Callbacks} method. // Implements {@link TimerHander.Callbacks#startWhileTypingAnimation(int)}.
/**
* Called when a while-typing-animation should be started.
* @param fadeInOrOut {@link TimerHandler.Callbacks#FADE_IN} starts while-typing-fade-in
* animation. {@link TimerHandler.Callbacks#FADE_OUT} starts while-typing-fade-out animation.
*/
@Override @Override
public void startWhileTypingFadeinAnimation() { public void startWhileTypingAnimation(final int fadeInOrOut) {
switch (fadeInOrOut) {
case TimerHandler.Callbacks.FADE_IN:
cancelAndStartAnimators( cancelAndStartAnimators(
mAltCodeKeyWhileTypingFadeoutAnimator, mAltCodeKeyWhileTypingFadeinAnimator); mAltCodeKeyWhileTypingFadeoutAnimator, mAltCodeKeyWhileTypingFadeinAnimator);
} break;
case TimerHandler.Callbacks.FADE_OUT:
@Override
public void startWhileTypingFadeoutAnimation() {
cancelAndStartAnimators( cancelAndStartAnimators(
mAltCodeKeyWhileTypingFadeinAnimator, mAltCodeKeyWhileTypingFadeoutAnimator); mAltCodeKeyWhileTypingFadeinAnimator, mAltCodeKeyWhileTypingFadeoutAnimator);
break;
}
} }
@ExternallyReferenced @ExternallyReferenced
@ -474,7 +482,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// Implements {@link TimerHandler.Callbacks#dismissKeyPreviewWithoutDelay(Key)}. // Implements {@link TimerHandler.Callbacks#dismissKeyPreviewWithoutDelay(Key)}.
@Override @Override
public void dismissKeyPreviewWithoutDelay(final Key key) { public void dismissKeyPreviewWithoutDelay(@Nonnull final Key key) {
mKeyPreviewChoreographer.dismissKeyPreview(key, false /* withAnimation */); mKeyPreviewChoreographer.dismissKeyPreview(key, false /* withAnimation */);
invalidateKey(key); invalidateKey(key);
} }
@ -496,13 +504,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override @Override
public void showSlidingKeyInputPreview(final PointerTracker tracker) { public void showSlidingKeyInputPreview(final PointerTracker tracker) {
locatePreviewPlacerView(); locatePreviewPlacerView();
if (tracker != null) {
mSlidingKeyInputDrawingPreview.setPreviewPosition(tracker); mSlidingKeyInputDrawingPreview.setPreviewPosition(tracker);
} } else {
@Override
public void dismissSlidingKeyInputPreview() {
mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview(); mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview();
} }
}
private void setGesturePreviewMode(final boolean isGestureTrailEnabled, private void setGesturePreviewMode(final boolean isGestureTrailEnabled,
final boolean isGestureFloatingPreviewTextEnabled) { final boolean isGestureFloatingPreviewTextEnabled) {
@ -596,13 +603,13 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return moreKeysKeyboardView; return moreKeysKeyboardView;
} }
// Implements {@link TimerHandler.Callbacks} method. // Implements {@link TimerHandler.Callbacks#onLongPress(PointerTracker)}.
/** /**
* Called when a key is long pressed. * Called when a key is long pressed.
* @param tracker the pointer tracker which pressed the parent key * @param tracker the pointer tracker which pressed the parent key
*/ */
@Override @Override
public void onLongPress(final PointerTracker tracker) { public void onLongPress(@Nonnull final PointerTracker tracker) {
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
return; return;
} }
@ -675,7 +682,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// Dismiss all key previews that may be being showed. // Dismiss all key previews that may be being showed.
PointerTracker.setReleasedKeyGraphicsToAllKeys(); PointerTracker.setReleasedKeyGraphicsToAllKeys();
// Dismiss sliding key input preview that may be being showed. // Dismiss sliding key input preview that may be being showed.
dismissSlidingKeyInputPreview(); mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview();
panel.showInParent(mDrawingPreviewPlacerView); panel.showInParent(mDrawingPreviewPlacerView);
mMoreKeysPanel = panel; mMoreKeysPanel = panel;
} }
@ -744,7 +751,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mTimerHandler.cancelAllMessages(); mTimerHandler.cancelAllMessages();
PointerTracker.setReleasedKeyGraphicsToAllKeys(); PointerTracker.setReleasedKeyGraphicsToAllKeys();
mGestureFloatingTextDrawingPreview.dismissGestureFloatingPreviewText(); mGestureFloatingTextDrawingPreview.dismissGestureFloatingPreviewText();
dismissSlidingKeyInputPreview(); mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview();
PointerTracker.dismissAllMoreKeysPanels(); PointerTracker.dismissAllMoreKeysPanels();
PointerTracker.cancelAllPointerTrackers(); PointerTracker.cancelAllPointerTrackers();
} }

View File

@ -41,6 +41,9 @@ import com.android.inputmethod.latin.utils.ResourceUtils;
import java.util.ArrayList; import java.util.ArrayList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class PointerTracker implements PointerTrackerQueue.Element, public final class PointerTracker implements PointerTrackerQueue.Element,
BatchInputArbiterListener { BatchInputArbiterListener {
private static final String TAG = PointerTracker.class.getSimpleName(); private static final String TAG = PointerTracker.class.getSimpleName();
@ -53,9 +56,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
public void invalidateKey(Key key); public void invalidateKey(Key key);
public void showKeyPreview(Key key); public void showKeyPreview(Key key);
public void dismissKeyPreview(Key key); public void dismissKeyPreview(Key key);
public void showSlidingKeyInputPreview(PointerTracker tracker); public void showSlidingKeyInputPreview(@Nullable PointerTracker tracker);
public void dismissSlidingKeyInputPreview(); public void showGestureTrail(@Nonnull PointerTracker tracker,
public void showGestureTrail(PointerTracker tracker, boolean showsFloatingPreviewText); boolean showsFloatingPreviewText);
} }
public interface TimerProxy { public interface TimerProxy {
@ -416,6 +419,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
return mIsInDraggingFinger; return mIsInDraggingFinger;
} }
@Nullable
public Key getKey() { public Key getKey() {
return mCurrentKey; return mCurrentKey;
} }
@ -765,7 +769,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
private void resetKeySelectionByDraggingFinger() { private void resetKeySelectionByDraggingFinger() {
mIsInDraggingFinger = false; mIsInDraggingFinger = false;
mIsInSlidingKeyInput = false; mIsInSlidingKeyInput = false;
sDrawingProxy.dismissSlidingKeyInputPreview(); sDrawingProxy.showSlidingKeyInputPreview(null /* tracker */);
} }
private void onGestureMoveEvent(final int x, final int y, final long eventTime, private void onGestureMoveEvent(final int x, final int y, final long eventTime,

View File

@ -22,6 +22,8 @@ import android.view.View;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.PointerTracker;
import javax.annotation.Nonnull;
/** /**
* Abstract base class for previews that are drawn on DrawingPreviewPlacerView, e.g., * Abstract base class for previews that are drawn on DrawingPreviewPlacerView, e.g.,
* GestureFloatingTextDrawingPreview, GestureTrailsDrawingPreview, and * GestureFloatingTextDrawingPreview, GestureTrailsDrawingPreview, and
@ -32,7 +34,7 @@ public abstract class AbstractDrawingPreview {
private boolean mPreviewEnabled; private boolean mPreviewEnabled;
private boolean mHasValidGeometry; private boolean mHasValidGeometry;
public void setDrawingView(final DrawingPreviewPlacerView drawingView) { public void setDrawingView(@Nonnull final DrawingPreviewPlacerView drawingView) {
mDrawingView = drawingView; mDrawingView = drawingView;
drawingView.addPreview(this); drawingView.addPreview(this);
} }
@ -61,7 +63,7 @@ public abstract class AbstractDrawingPreview {
* @param width the width of {@link MainKeyboardView}. * @param width the width of {@link MainKeyboardView}.
* @param height the height of {@link MainKeyboardView}. * @param height the height of {@link MainKeyboardView}.
*/ */
public void setKeyboardViewGeometry(final int[] originCoords, final int width, public void setKeyboardViewGeometry(@Nonnull final int[] originCoords, final int width,
final int height) { final int height) {
mHasValidGeometry = (width > 0 && height > 0); mHasValidGeometry = (width > 0 && height > 0);
} }
@ -72,11 +74,11 @@ public abstract class AbstractDrawingPreview {
* Draws the preview * Draws the preview
* @param canvas The canvas where the preview is drawn. * @param canvas The canvas where the preview is drawn.
*/ */
public abstract void drawPreview(final Canvas canvas); public abstract void drawPreview(@Nonnull final Canvas canvas);
/** /**
* Set the position of the preview. * Set the position of the preview.
* @param tracker The new location of the preview is based on the points in PointerTracker. * @param tracker The new location of the preview is based on the points in PointerTracker.
*/ */
public abstract void setPreviewPosition(final PointerTracker tracker); public abstract void setPreviewPosition(@Nonnull final PointerTracker tracker);
} }

View File

@ -32,9 +32,10 @@ import javax.annotation.Nonnull;
// TODO: Separate this class into KeyTimerHandler and BatchInputTimerHandler or so. // TODO: Separate this class into KeyTimerHandler and BatchInputTimerHandler or so.
public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> implements TimerProxy { public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> implements TimerProxy {
public interface Callbacks { public interface Callbacks {
public void startWhileTypingFadeinAnimation(); public static final int FADE_IN = 0;
public void startWhileTypingFadeoutAnimation(); public static final int FADE_OUT = 1;
public void onLongPress(PointerTracker tracker); public void startWhileTypingAnimation(final int fadeInOrOut);
public void onLongPress(@Nonnull PointerTracker tracker);
public void dismissKeyPreviewWithoutDelay(@Nonnull Key key); public void dismissKeyPreviewWithoutDelay(@Nonnull Key key);
public void dismissGestureFloatingPreviewTextWithoutDelay(); public void dismissGestureFloatingPreviewTextWithoutDelay();
} }
@ -66,7 +67,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
} }
switch (msg.what) { switch (msg.what) {
case MSG_TYPING_STATE_EXPIRED: case MSG_TYPING_STATE_EXPIRED:
callbacks.startWhileTypingFadeinAnimation(); callbacks.startWhileTypingAnimation(Callbacks.FADE_IN);
break; break;
case MSG_REPEAT_KEY: case MSG_REPEAT_KEY:
final PointerTracker tracker1 = (PointerTracker) msg.obj; final PointerTracker tracker1 = (PointerTracker) msg.obj;
@ -163,7 +164,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
final int typedCode = typedKey.getCode(); final int typedCode = typedKey.getCode();
if (typedCode == Constants.CODE_SPACE || typedCode == Constants.CODE_ENTER) { if (typedCode == Constants.CODE_SPACE || typedCode == Constants.CODE_ENTER) {
if (isTyping) { if (isTyping) {
callbacks.startWhileTypingFadeinAnimation(); callbacks.startWhileTypingAnimation(Callbacks.FADE_IN);
} }
return; return;
} }
@ -173,7 +174,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
if (isTyping) { if (isTyping) {
return; return;
} }
callbacks.startWhileTypingFadeoutAnimation(); callbacks.startWhileTypingAnimation(Callbacks.FADE_OUT);
} }
@Override @Override

View File

@ -282,7 +282,6 @@ public class UserDictionarySettings extends ListFragment {
} }
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer { private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
private AlphabetIndexer mIndexer; private AlphabetIndexer mIndexer;
private ViewBinder mViewBinder = new ViewBinder() { private ViewBinder mViewBinder = new ViewBinder() {