aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/MainKeyboardView.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java198
1 files changed, 101 insertions, 97 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 2b16785c2..cba7ff2a2 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -28,19 +28,19 @@ import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
-import android.view.inputmethod.InputMethodSubtype;
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.DrawingProxy;
import com.android.inputmethod.keyboard.internal.GestureFloatingTextDrawingPreview;
import com.android.inputmethod.keyboard.internal.GestureTrailsDrawingPreview;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
@@ -52,16 +52,21 @@ import com.android.inputmethod.keyboard.internal.MoreKeySpec;
import com.android.inputmethod.keyboard.internal.NonDistinctMultitouchHelper;
import com.android.inputmethod.keyboard.internal.SlidingKeyInputDrawingPreview;
import com.android.inputmethod.keyboard.internal.TimerHandler;
-import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.RichInputMethodSubtype;
import com.android.inputmethod.latin.SuggestedWords;
+import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.CoordinateUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.settings.DebugSettings;
-import com.android.inputmethod.latin.utils.CoordinateUtils;
-import com.android.inputmethod.latin.utils.SpacebarLanguageUtils;
import com.android.inputmethod.latin.utils.TypefaceUtils;
+import java.util.Locale;
import java.util.WeakHashMap;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* A view that is responsible for detecting key presses and touch movements.
*
@@ -105,8 +110,8 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_gestureRecognitionSpeedThreshold
* @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
*/
-public final class MainKeyboardView extends KeyboardView implements PointerTracker.DrawingProxy,
- MoreKeysPanel.Controller, DrawingHandler.Callbacks, TimerHandler.Callbacks {
+public final class MainKeyboardView extends KeyboardView implements DrawingProxy,
+ MoreKeysPanel.Controller {
private static final String TAG = MainKeyboardView.class.getSimpleName();
/** Listener for {@link KeyboardActionListener}. */
@@ -147,7 +152,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// More keys keyboard
private final Paint mBackgroundDimAlphaPaint = new Paint();
- private boolean mNeedsToDimEntireKeyboard;
private final View mMoreKeysKeyboardContainer;
private final View mMoreKeysKeyboardForActionContainer;
private final WeakHashMap<Key, Keyboard> mMoreKeysKeyboardCache = new WeakHashMap<>();
@@ -163,11 +167,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) {
@@ -177,7 +179,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
- mDrawingPreviewPlacerView = new DrawingPreviewPlacerView(context, attrs);
+ final DrawingPreviewPlacerView drawingPreviewPlacerView =
+ new DrawingPreviewPlacerView(context, attrs);
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
@@ -185,7 +188,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(
@@ -195,7 +198,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(
@@ -245,15 +248,17 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mGestureFloatingTextDrawingPreview = new GestureFloatingTextDrawingPreview(
mainKeyboardViewAttr);
- mGestureFloatingTextDrawingPreview.setDrawingView(mDrawingPreviewPlacerView);
+ mGestureFloatingTextDrawingPreview.setDrawingView(drawingPreviewPlacerView);
mGestureTrailsDrawingPreview = new GestureTrailsDrawingPreview(mainKeyboardViewAttr);
- mGestureTrailsDrawingPreview.setDrawingView(mDrawingPreviewPlacerView);
+ mGestureTrailsDrawingPreview.setDrawingView(drawingPreviewPlacerView);
mSlidingKeyInputDrawingPreview = new SlidingKeyInputDrawingPreview(mainKeyboardViewAttr);
- mSlidingKeyInputDrawingPreview.setDrawingView(mDrawingPreviewPlacerView);
+ mSlidingKeyInputDrawingPreview.setDrawingView(drawingPreviewPlacerView);
mainKeyboardViewAttr.recycle();
+ mDrawingPreviewPlacerView = drawingPreviewPlacerView;
+
final LayoutInflater inflater = LayoutInflater.from(getContext());
mMoreKeysKeyboardContainer = inflater.inflate(moreKeysKeyboardLayoutId, null);
mMoreKeysKeyboardForActionContainer = inflater.inflate(
@@ -306,17 +311,24 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
animatorToStart.setCurrentPlayTime(startTime);
}
- // Implements {@link TimerHander.Callbacks} method.
- @Override
- public void startWhileTypingFadeinAnimation() {
- cancelAndStartAnimators(
- mAltCodeKeyWhileTypingFadeoutAnimator, mAltCodeKeyWhileTypingFadeinAnimator);
- }
-
+ // Implements {@link DrawingProxy#startWhileTypingAnimation(int)}.
+ /**
+ * Called when a while-typing-animation should be started.
+ * @param fadeInOrOut {@link DrawingProxy#FADE_IN} starts while-typing-fade-in animation.
+ * {@link DrawingProxy#FADE_OUT} starts while-typing-fade-out animation.
+ */
@Override
- public void startWhileTypingFadeoutAnimation() {
- cancelAndStartAnimators(
- mAltCodeKeyWhileTypingFadeinAnimator, mAltCodeKeyWhileTypingFadeoutAnimator);
+ public void startWhileTypingAnimation(final int fadeInOrOut) {
+ switch (fadeInOrOut) {
+ case DrawingProxy.FADE_IN:
+ cancelAndStartAnimators(
+ mAltCodeKeyWhileTypingFadeoutAnimator, mAltCodeKeyWhileTypingFadeinAnimator);
+ break;
+ case DrawingProxy.FADE_OUT:
+ cancelAndStartAnimators(
+ mAltCodeKeyWhileTypingFadeinAnimator, mAltCodeKeyWhileTypingFadeoutAnimator);
+ break;
+ }
}
@ExternallyReferenced
@@ -378,7 +390,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());
@@ -450,17 +462,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
windowContentView.addView(mDrawingPreviewPlacerView);
}
- // Implements {@link DrawingHandler.Callbacks} method.
- @Override
- public void dismissAllKeyPreviews() {
- mKeyPreviewChoreographer.dismissAllKeyPreviews();
- PointerTracker.setReleasedKeyGraphicsToAllKeys();
- }
-
@Override
- public void showKeyPreview(final Key key) {
+ public void showKeyPreview(@Nonnull final Key key) {
// If the key is invalid or has no key preview, we must not show key preview.
- if (key == null || key.noKeyPreview()) {
+ if (key.noKeyPreview()) {
return;
}
final Keyboard keyboard = getKeyboard();
@@ -479,22 +484,21 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
getWidth(), mOriginCoords, mDrawingPreviewPlacerView, isHardwareAccelerated());
}
- // Implements {@link TimerHandler.Callbacks} method.
+ // Implements {@link DrawingProxy#dismissKeyPreviewWithoutDelay(Key)}.
@Override
- public void dismissKeyPreviewWithoutDelay(final Key key) {
+ public void dismissKeyPreviewWithoutDelay(@Nonnull 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);
+ public void dismissKeyPreview(@Nonnull final Key key) {
+ if (isHardwareAccelerated()) {
+ mKeyPreviewChoreographer.dismissKeyPreview(key, true /* withAnimation */);
return;
}
- 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) {
@@ -502,14 +506,13 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
@Override
- public void showSlidingKeyInputPreview(final PointerTracker tracker) {
+ public void showSlidingKeyInputPreview(@Nullable final PointerTracker tracker) {
locatePreviewPlacerView();
- mSlidingKeyInputDrawingPreview.setPreviewPosition(tracker);
- }
-
- @Override
- public void dismissSlidingKeyInputPreview() {
- mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview();
+ if (tracker != null) {
+ mSlidingKeyInputDrawingPreview.setPreviewPosition(tracker);
+ } else {
+ mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview();
+ }
}
private void setGesturePreviewMode(final boolean isGestureTrailEnabled,
@@ -518,20 +521,26 @@ 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 DrawingProxy#dismissGestureFloatingPreviewTextWithoutDelay()}.
+ @Override
+ public void dismissGestureFloatingPreviewTextWithoutDelay() {
+ mGestureFloatingTextDrawingPreview.dismissGestureFloatingPreviewText();
}
@Override
- public void showGestureTrail(final PointerTracker tracker,
+ public void showGestureTrail(@Nonnull final PointerTracker tracker,
final boolean showsFloatingPreviewText) {
locatePreviewPlacerView();
if (showsFloatingPreviewText) {
@@ -598,13 +607,13 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return moreKeysKeyboardView;
}
- // Implements {@link TimerHandler.Callbacks} method.
+ // Implements {@link DrawingProxy@onLongPress(PointerTracker)}.
/**
* Called when a key is long pressed.
* @param tracker the pointer tracker which pressed the parent key
*/
@Override
- public void onLongPress(final PointerTracker tracker) {
+ public void onLongPress(@Nonnull final PointerTracker tracker) {
if (isShowingMoreKeysPanel()) {
return;
}
@@ -659,7 +668,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() {
@@ -672,9 +681,14 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
locatePreviewPlacerView();
+ // Dismiss another {@link MoreKeysPanel} that may be being showed.
+ onDismissMoreKeysPanel();
+ // Dismiss all key previews that may be being showed.
+ PointerTracker.setReleasedKeyGraphicsToAllKeys();
+ // Dismiss sliding key input preview that may be being showed.
+ mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview();
panel.showInParent(mDrawingPreviewPlacerView);
mMoreKeysPanel = panel;
- dimEntireKeyboard(true /* dimmed */);
}
public boolean isShowingMoreKeysPanel() {
@@ -688,7 +702,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
public void onDismissMoreKeysPanel() {
- dimEntireKeyboard(false /* dimmed */);
if (isShowingMoreKeysPanel()) {
mMoreKeysPanel.removeFromParent();
mMoreKeysPanel = null;
@@ -696,15 +709,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
@@ -713,9 +726,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);
@@ -739,11 +752,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
public void cancelAllOngoingEvents() {
- mKeyTimerHandler.cancelAllMessages();
- mDrawingHandler.cancelAllMessages();
- dismissAllKeyPreviews();
- dismissGestureFloatingPreviewText();
- dismissSlidingKeyInputPreview();
+ mTimerHandler.cancelAllMessages();
+ PointerTracker.setReleasedKeyGraphicsToAllKeys();
+ mGestureFloatingTextDrawingPreview.dismissGestureFloatingPreviewText();
+ mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview();
PointerTracker.dismissAllMoreKeysPanels();
PointerTracker.cancelAllPointerTrackers();
}
@@ -816,24 +828,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
invalidateKey(mSpaceKey);
}
- private void dimEntireKeyboard(final boolean dimmed) {
- final boolean needsRedrawing = mNeedsToDimEntireKeyboard != dimmed;
- mNeedsToDimEntireKeyboard = dimmed;
- if (needsRedrawing) {
- invalidateAllKeys();
- }
- }
-
- @Override
- protected void onDraw(final Canvas canvas) {
- super.onDraw(canvas);
-
- // Overlay a dark rectangle to dim.
- if (mNeedsToDimEntireKeyboard) {
- canvas.drawRect(0.0f, 0.0f, getWidth(), getHeight(), mBackgroundDimAlphaPaint);
- }
- }
-
@Override
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
final KeyDrawParams params) {
@@ -875,16 +869,26 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// Layout language name on spacebar.
private String layoutLanguageOnSpacebar(final Paint paint,
- final InputMethodSubtype subtype, final int width) {
+ final RichInputMethodSubtype subtype, final int width) {
+ if (mLanguageOnSpacebarFormatType == LanguageOnSpacebarHelper.FORMAT_TYPE_MULTIPLE) {
+ final Locale[] locales = subtype.getLocales();
+ final String[] languages = new String[locales.length];
+ for (int i = 0; i < locales.length; ++i) {
+ languages[i] = StringUtils.toUpperCaseOfStringForLocale(
+ locales[i].getLanguage(), true /* needsToUpperCase */, Locale.ROOT);
+ }
+ return TextUtils.join(" / ", languages);
+ }
+
// Choose appropriate language name to fit into the width.
if (mLanguageOnSpacebarFormatType == LanguageOnSpacebarHelper.FORMAT_TYPE_FULL_LOCALE) {
- final String fullText = SpacebarLanguageUtils.getFullDisplayName(subtype);
+ final String fullText = subtype.getFullDisplayName();
if (fitsTextIntoWidth(width, fullText, paint)) {
return fullText;
}
}
- final String middleText = SpacebarLanguageUtils.getMiddleDisplayName(subtype);
+ final String middleText = subtype.getMiddleDisplayName();
if (fitsTextIntoWidth(width, middleText, paint)) {
return middleText;
}
@@ -898,7 +902,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
paint.setTextAlign(Align.CENTER);
paint.setTypeface(Typeface.DEFAULT);
paint.setTextSize(mLanguageOnSpacebarTextSize);
- final InputMethodSubtype subtype = getKeyboard().mId.mSubtype;
+ final RichInputMethodSubtype subtype = getKeyboard().mId.mSubtype;
final String language = layoutLanguageOnSpacebar(paint, subtype, width);
// Draw language text with shadow
final float descent = paint.descent();