am 86735948: Merge "Add SlidingKeyInputPreview class"

* commit '86735948306765d60dee811b31fabc1796129303':
  Add SlidingKeyInputPreview class
main
Tadashi G. Takaoka 2013-01-21 05:45:30 -08:00 committed by Android Git Automerger
commit f0b99e446a
2 changed files with 79 additions and 19 deletions

View File

@ -57,9 +57,7 @@ public final class PreviewPlacerView extends RelativeLayout {
private final Rect mGesturePreviewTrailBoundsRect = new Rect(); // per trail
// TODO: Move these AbstractDrawingPvreiew objects to MainKeyboardView.
private final GestureFloatingPreviewText mGestureFloatingPreviewText;
private boolean mShowSlidingKeyInputPreview;
private final int[] mRubberBandFrom = CoordinateUtils.newInstance();
private final int[] mRubberBandTo = CoordinateUtils.newInstance();
private final SlidingKeyInputPreview mSlidingKeyInputPreview;
private final DrawingHandler mDrawingHandler;
@ -107,6 +105,7 @@ public final class PreviewPlacerView extends RelativeLayout {
// MultiGesturePreviewText, depending on the user's choice in the settings.
mGestureFloatingPreviewText = new GestureFloatingPreviewText(this, mainKeyboardViewAttr);
mGesturePreviewTrailParams = new Params(mainKeyboardViewAttr);
mSlidingKeyInputPreview = new SlidingKeyInputPreview(this, mainKeyboardViewAttr);
mainKeyboardViewAttr.recycle();
mDrawingHandler = new DrawingHandler(this, mGesturePreviewTrailParams);
@ -125,6 +124,7 @@ public final class PreviewPlacerView extends RelativeLayout {
final int height) {
CoordinateUtils.copy(mKeyboardViewOrigin, originCoords);
mGestureFloatingPreviewText.setKeyboardGeometry(originCoords, width, height);
mSlidingKeyInputPreview.setKeyboardGeometry(originCoords, width, height);
mOffscreenOffsetY = (int)(
height * GestureStroke.EXTRA_GESTURE_TRAIL_AREA_ABOVE_KEYBOARD_RATIO);
mOffscreenWidth = width;
@ -156,25 +156,21 @@ public final class PreviewPlacerView extends RelativeLayout {
}
}
// TODO: Move this method to MainKeyboardView
public void showSlidingKeyInputPreview(final PointerTracker tracker) {
if (!tracker.isInSlidingKeyInputFromModifier()) {
mShowSlidingKeyInputPreview = false;
return;
}
tracker.getDownCoordinates(mRubberBandFrom);
tracker.getLastCoordinates(mRubberBandTo);
mShowSlidingKeyInputPreview = true;
invalidate();
mSlidingKeyInputPreview.setPreviewPosition(tracker);
}
// TODO: Move this method to MainKeyboardView
public void dismissSlidingKeyInputPreview() {
mShowSlidingKeyInputPreview = false;
mSlidingKeyInputPreview.dismissSlidingKeyInputPreview();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mGestureFloatingPreviewText.onDetachFromWindow();
mSlidingKeyInputPreview.onDetachFromWindow();
freeOffscreenBuffer();
}
@ -221,9 +217,7 @@ public final class PreviewPlacerView extends RelativeLayout {
}
}
mGestureFloatingPreviewText.drawPreview(canvas);
if (mShowSlidingKeyInputPreview) {
drawSlidingKeyInputPreview(canvas);
}
mSlidingKeyInputPreview.drawPreview(canvas);
canvas.translate(-originX, -originY);
}
@ -253,11 +247,8 @@ public final class PreviewPlacerView extends RelativeLayout {
return needsUpdatingGesturePreviewTrail;
}
// TODO: Move this method to MainKeyboardView.
public void setGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
mGestureFloatingPreviewText.setSuggetedWords(suggestedWords);
}
private void drawSlidingKeyInputPreview(final Canvas canvas) {
// TODO: Implement rubber band preview
}
}

View File

@ -0,0 +1,69 @@
/*
* 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.content.res.TypedArray;
import android.graphics.Canvas;
import android.view.View;
import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.latin.CoordinateUtils;
/**
* Draw rubber band preview graphics during sliding key input.
*/
public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
private boolean mShowSlidingKeyInputPreview;
private final int[] mRubberBandFrom = CoordinateUtils.newInstance();
private final int[] mRubberBandTo = CoordinateUtils.newInstance();
public SlidingKeyInputPreview(final View drawingView, final TypedArray mainKeyboardViewAttr) {
super(drawingView);
}
public void dismissSlidingKeyInputPreview() {
mShowSlidingKeyInputPreview = false;
}
/**
* Draws the preview
* @param canvas The canvas where the preview is drawn.
*/
@Override
public void drawPreview(final Canvas canvas) {
if (!isPreviewEnabled() || mShowSlidingKeyInputPreview == false) {
return;
}
// TODO: Implement rubber band preview
}
/**
* Set the position of the preview.
* @param tracker The new location of the preview is based on the points in PointerTracker.
*/
@Override
public void setPreviewPosition(final PointerTracker tracker) {
if (!tracker.isInSlidingKeyInputFromModifier()) {
mShowSlidingKeyInputPreview = false;
return;
}
tracker.getDownCoordinates(mRubberBandFrom);
tracker.getLastCoordinates(mRubberBandTo);
mShowSlidingKeyInputPreview = true;
getDrawingView().invalidate();
}
}