am 4e0149c2: Merge "Remove DrawingHandler"

* commit '4e0149c22a78673f3ec7e0903f945587e12cc3b1':
  Remove DrawingHandler
main
Tadashi G. Takaoka 2014-10-29 13:46:33 +00:00 committed by Android Git Automerger
commit 9b8822defb
6 changed files with 76 additions and 111 deletions

View File

@ -39,7 +39,6 @@ import android.view.ViewGroup;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.MainKeyboardAccessibilityDelegate;
import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.keyboard.internal.DrawingHandler;
import com.android.inputmethod.keyboard.internal.DrawingPreviewPlacerView;
import com.android.inputmethod.keyboard.internal.GestureFloatingTextDrawingPreview;
import com.android.inputmethod.keyboard.internal.GestureTrailsDrawingPreview;
@ -64,6 +63,8 @@ import com.android.inputmethod.latin.utils.TypefaceUtils;
import java.util.Locale;
import java.util.WeakHashMap;
import javax.annotation.Nonnull;
/**
* A view that is responsible for detecting key presses and touch movements.
*
@ -108,7 +109,7 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
*/
public final class MainKeyboardView extends KeyboardView implements PointerTracker.DrawingProxy,
MoreKeysPanel.Controller, DrawingHandler.Callbacks, TimerHandler.Callbacks {
MoreKeysPanel.Controller, TimerHandler.Callbacks {
private static final String TAG = MainKeyboardView.class.getSimpleName();
/** Listener for {@link KeyboardActionListener}. */
@ -164,11 +165,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
private final KeyDetector mKeyDetector;
private final NonDistinctMultitouchHelper mNonDistinctMultitouchHelper;
private final TimerHandler mKeyTimerHandler;
private final TimerHandler mTimerHandler;
private final int mLanguageOnSpacebarHorizontalMargin;
private final DrawingHandler mDrawingHandler = new DrawingHandler(this);
private MainKeyboardAccessibilityDelegate mAccessibilityDelegate;
public MainKeyboardView(final Context context, final AttributeSet attrs) {
@ -186,7 +185,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
final int gestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0);
mKeyTimerHandler = new TimerHandler(
mTimerHandler = new TimerHandler(
this, ignoreAltCodeKeyTimeout, gestureRecognitionUpdateTime);
final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
@ -196,7 +195,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mKeyDetector = new KeyDetector(
keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);
PointerTracker.init(mainKeyboardViewAttr, mKeyTimerHandler, this /* DrawingProxy */);
PointerTracker.init(mainKeyboardViewAttr, mTimerHandler, this /* DrawingProxy */);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final boolean forceNonDistinctMultitouch = prefs.getBoolean(
@ -379,7 +378,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
public void setKeyboard(final Keyboard keyboard) {
// Remove any pending messages, except dismissing preview and key repeat.
mKeyTimerHandler.cancelLongPressTimers();
mTimerHandler.cancelLongPressTimers();
super.setKeyboard(keyboard);
mKeyDetector.setKeyboard(
keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
@ -473,22 +472,21 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
getWidth(), mOriginCoords, mDrawingPreviewPlacerView, isHardwareAccelerated());
}
// Implements {@link TimerHandler.Callbacks} method.
// Implements {@link TimerHandler.Callbacks#dismissKeyPreviewWithoutDelay(Key)}.
@Override
public void dismissKeyPreviewWithoutDelay(final Key key) {
mKeyPreviewChoreographer.dismissKeyPreview(key, false /* withAnimation */);
// To redraw key top letter.
invalidateKey(key);
}
@Override
public void dismissKeyPreview(final Key key) {
if (!isHardwareAccelerated()) {
// TODO: Implement preference option to control key preview method and duration.
mDrawingHandler.dismissKeyPreview(mKeyPreviewDrawParams.getLingerTimeout(), key);
return;
final KeyPreviewChoreographer keyPreviewChoreographer = mKeyPreviewChoreographer;
if (isHardwareAccelerated()) {
keyPreviewChoreographer.dismissKeyPreview(key, true /* withAnimation */);
}
mKeyPreviewChoreographer.dismissKeyPreview(key, true /* withAnimation */);
// TODO: Implement preference option to control key preview method and duration.
mTimerHandler.postDismissKeyPreview(key, mKeyPreviewDrawParams.getLingerTimeout());
}
public void setSlidingKeyInputPreviewEnabled(final boolean enabled) {
@ -512,16 +510,22 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mGestureTrailsDrawingPreview.setPreviewEnabled(isGestureTrailEnabled);
}
// Implements {@link DrawingHandler.Callbacks} method.
@Override
public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
public void showGestureFloatingPreviewText(@Nonnull final SuggestedWords suggestedWords,
final boolean dismissDelayed) {
locatePreviewPlacerView();
mGestureFloatingTextDrawingPreview.setSuggetedWords(suggestedWords);
final GestureFloatingTextDrawingPreview gestureFloatingTextDrawingPreview =
mGestureFloatingTextDrawingPreview;
gestureFloatingTextDrawingPreview.setSuggetedWords(suggestedWords);
if (dismissDelayed) {
mTimerHandler.postDismissGestureFloatingPreviewText(
mGestureFloatingPreviewTextLingerTimeout);
}
}
public void dismissGestureFloatingPreviewText() {
locatePreviewPlacerView();
mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout);
// Implements {@link TimerHandler.Callbacks#dismissGestureFloatingPreviewTextWithoutDelay()}.
@Override
public void dismissGestureFloatingPreviewTextWithoutDelay() {
mGestureFloatingTextDrawingPreview.dismissGestureFloatingPreviewText();
}
@Override
@ -653,7 +657,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
moreKeysPanel.showMoreKeysPanel(this, this, pointX, pointY, mKeyboardActionListener);
tracker.onShowMoreKeysPanel(moreKeysPanel);
// TODO: Implement zoom in animation of more keys panel.
dismissKeyPreviewWithoutDelay(key);
mKeyPreviewChoreographer.dismissKeyPreview(key, false /* withAnimation */);
}
public boolean isInDraggingFinger() {
@ -694,15 +698,15 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
public void startDoubleTapShiftKeyTimer() {
mKeyTimerHandler.startDoubleTapShiftKeyTimer();
mTimerHandler.startDoubleTapShiftKeyTimer();
}
public void cancelDoubleTapShiftKeyTimer() {
mKeyTimerHandler.cancelDoubleTapShiftKeyTimer();
mTimerHandler.cancelDoubleTapShiftKeyTimer();
}
public boolean isInDoubleTapShiftKeyTimeout() {
return mKeyTimerHandler.isInDoubleTapShiftKeyTimeout();
return mTimerHandler.isInDoubleTapShiftKeyTimeout();
}
@Override
@ -711,9 +715,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return false;
}
if (mNonDistinctMultitouchHelper != null) {
if (me.getPointerCount() > 1 && mKeyTimerHandler.isInKeyRepeat()) {
if (me.getPointerCount() > 1 && mTimerHandler.isInKeyRepeat()) {
// Key repeating timer will be canceled if 2 or more keys are in action.
mKeyTimerHandler.cancelKeyRepeatTimers();
mTimerHandler.cancelKeyRepeatTimers();
}
// Non distinct multitouch screen support
mNonDistinctMultitouchHelper.processMotionEvent(me, mKeyDetector);
@ -737,10 +741,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
public void cancelAllOngoingEvents() {
mKeyTimerHandler.cancelAllMessages();
mDrawingHandler.cancelAllMessages();
mTimerHandler.cancelAllMessages();
PointerTracker.setReleasedKeyGraphicsToAllKeys();
dismissGestureFloatingPreviewText();
mGestureFloatingTextDrawingPreview.dismissGestureFloatingPreviewText();
dismissSlidingKeyInputPreview();
PointerTracker.dismissAllMoreKeysPanels();
PointerTracker.cancelAllPointerTrackers();

View File

@ -1,69 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.keyboard.internal;
import android.os.Message;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.internal.DrawingHandler.Callbacks;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
import javax.annotation.Nonnull;
// TODO: Separate this class into KeyPreviewHandler and BatchInputPreviewHandler or so.
public class DrawingHandler extends LeakGuardHandlerWrapper<Callbacks> {
public interface Callbacks {
public void dismissKeyPreviewWithoutDelay(Key key);
public void showGestureFloatingPreviewText(SuggestedWords suggestedWords);
}
private static final int MSG_DISMISS_KEY_PREVIEW = 0;
private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
public DrawingHandler(@Nonnull final Callbacks ownerInstance) {
super(ownerInstance);
}
@Override
public void handleMessage(final Message msg) {
final Callbacks callbacks = getOwnerInstance();
if (callbacks == null) {
return;
}
switch (msg.what) {
case MSG_DISMISS_KEY_PREVIEW:
callbacks.dismissKeyPreviewWithoutDelay((Key)msg.obj);
break;
case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
callbacks.showGestureFloatingPreviewText(SuggestedWords.getEmptyInstance());
break;
}
}
public void dismissKeyPreview(final long delay, final Key key) {
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, key), delay);
}
public void dismissGestureFloatingPreviewText(final long delay) {
sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT), delay);
}
public void cancelAllMessages() {
removeMessages(MSG_DISMISS_KEY_PREVIEW);
}
}

View File

@ -29,6 +29,8 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import javax.annotation.Nonnull;
/**
* The class for single gesture preview text. The class for multiple gesture preview text will be
* derived from it.
@ -110,7 +112,11 @@ public class GestureFloatingTextDrawingPreview extends AbstractDrawingPreview {
// Nothing to do here.
}
public void setSuggetedWords(final SuggestedWords suggestedWords) {
public void dismissGestureFloatingPreviewText() {
setSuggetedWords(SuggestedWords.getEmptyInstance());
}
public void setSuggetedWords(@Nonnull final SuggestedWords suggestedWords) {
if (!isPreviewEnabled()) {
return;
}

View File

@ -35,6 +35,8 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
public void startWhileTypingFadeinAnimation();
public void startWhileTypingFadeoutAnimation();
public void onLongPress(PointerTracker tracker);
public void dismissKeyPreviewWithoutDelay(@Nonnull Key key);
public void dismissGestureFloatingPreviewTextWithoutDelay();
}
private static final int MSG_TYPING_STATE_EXPIRED = 0;
@ -43,6 +45,8 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
private static final int MSG_LONGPRESS_SHIFT_KEY = 3;
private static final int MSG_DOUBLE_TAP_SHIFT_KEY = 4;
private static final int MSG_UPDATE_BATCH_INPUT = 5;
private static final int MSG_DISMISS_KEY_PREVIEW = 6;
private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 7;
private final int mIgnoreAltCodeKeyTimeout;
private final int mGestureRecognitionUpdateTime;
@ -60,22 +64,31 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
if (callbacks == null) {
return;
}
final PointerTracker tracker = (PointerTracker) msg.obj;
switch (msg.what) {
case MSG_TYPING_STATE_EXPIRED:
callbacks.startWhileTypingFadeinAnimation();
break;
case MSG_REPEAT_KEY:
tracker.onKeyRepeat(msg.arg1 /* code */, msg.arg2 /* repeatCount */);
final PointerTracker tracker1 = (PointerTracker) msg.obj;
tracker1.onKeyRepeat(msg.arg1 /* code */, msg.arg2 /* repeatCount */);
break;
case MSG_LONGPRESS_KEY:
case MSG_LONGPRESS_SHIFT_KEY:
cancelLongPressTimers();
callbacks.onLongPress(tracker);
final PointerTracker tracker2 = (PointerTracker) msg.obj;
callbacks.onLongPress(tracker2);
break;
case MSG_UPDATE_BATCH_INPUT:
tracker.updateBatchInputByTimer(SystemClock.uptimeMillis());
startUpdateBatchInputTimer(tracker);
final PointerTracker tracker3 = (PointerTracker) msg.obj;
tracker3.updateBatchInputByTimer(SystemClock.uptimeMillis());
startUpdateBatchInputTimer(tracker3);
break;
case MSG_DISMISS_KEY_PREVIEW:
final Key key = (Key) msg.obj;
callbacks.dismissKeyPreviewWithoutDelay(key);
break;
case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
callbacks.dismissGestureFloatingPreviewTextWithoutDelay();
break;
}
}
@ -215,8 +228,18 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
removeMessages(MSG_UPDATE_BATCH_INPUT);
}
public void postDismissKeyPreview(@Nonnull final Key key, final long delay) {
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, key), delay);
}
public void postDismissGestureFloatingPreviewText(final long delay) {
sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT), delay);
}
public void cancelAllMessages() {
cancelAllKeyTimers();
cancelAllUpdateBatchInputTimers();
removeMessages(MSG_DISMISS_KEY_PREVIEW);
removeMessages(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
}
}

View File

@ -1501,14 +1501,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
// This method must run on the UI Thread.
void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
void showGesturePreviewAndSuggestionStrip(@Nonnull final SuggestedWords suggestedWords,
final boolean dismissGestureFloatingPreviewText) {
showSuggestionStrip(suggestedWords);
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
mainKeyboardView.showGestureFloatingPreviewText(suggestedWords);
if (dismissGestureFloatingPreviewText) {
mainKeyboardView.dismissGestureFloatingPreviewText();
}
mainKeyboardView.showGestureFloatingPreviewText(suggestedWords,
dismissGestureFloatingPreviewText /* dismissDelayed */);
}
// Called from PointerTracker through the KeyboardActionListener interface

View File

@ -28,6 +28,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import javax.annotation.Nonnull;
public class SuggestedWords {
public static final int INDEX_OF_TYPED_WORD = 0;
public static final int INDEX_OF_AUTO_CORRECTION = 1;
@ -46,6 +48,7 @@ public class SuggestedWords {
public static final int MAX_SUGGESTIONS = 18;
private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST = new ArrayList<>(0);
@Nonnull
private static final SuggestedWords EMPTY = new SuggestedWords(
EMPTY_WORD_INFO_LIST, null /* rawSuggestions */, false /* typedWordValid */,
false /* willAutoCorrect */, false /* isObsoleteSuggestions */, INPUT_STYLE_NONE);
@ -210,6 +213,7 @@ public class SuggestedWords {
return result;
}
@Nonnull
public static final SuggestedWords getEmptyInstance() {
return SuggestedWords.EMPTY;
}