am ca57f5ba: Move gesture preview parameters to KeyboardView attributes

* commit 'ca57f5ba40b587a7a7f8a023aca65e1b2127b2a6':
  Move gesture preview parameters to KeyboardView attributes
main
Tadashi G. Takaoka 2012-07-30 04:56:42 -07:00 committed by Android Git Automerger
commit ed754b9991
6 changed files with 91 additions and 63 deletions

View File

@ -118,6 +118,18 @@
<enum name="italic" value="2" /> <enum name="italic" value="2" />
<enum name="boldItalic" value="3" /> <enum name="boldItalic" value="3" />
</attr> </attr>
<attr name="gestureFloatingPreviewTextSize" format="dimension" />
<attr name="gestureFloatingPreviewTextColor" format="color" />
<attr name="gestureFloatingPreviewTextOffset" format="dimension" />
<attr name="gestureFloatingPreviewTextShadingColor" format="color" />
<attr name="gestureFloatingPreviewTextShadingBorder" format="dimension" />
<attr name="gestureFloatingPreviewTextShadowColor" format="color" />
<attr name="gestureFloatingPreviewTextShadowBorder" format="dimension" />
<attr name="gestureFloatingPreviewTextConnectorColor" format="color" />
<attr name="gestureFloatingPreviewTextConnectorWidth" format="dimension" />
<attr name="gesturePreviewTrailColor" format="color" />
<attr name="gesturePreviewTrailWidth" format="dimension" />
</declare-styleable> </declare-styleable>
<declare-styleable name="MainKeyboardView"> <declare-styleable name="MainKeyboardView">

View File

@ -96,9 +96,9 @@
<!-- Gesture preview parameters --> <!-- Gesture preview parameters -->
<dimen name="gesture_preview_trail_width">2.5dp</dimen> <dimen name="gesture_preview_trail_width">2.5dp</dimen>
<dimen name="gesture_preview_text_size">35dp</dimen> <dimen name="gesture_floating_preview_text_size">35dp</dimen>
<dimen name="gesture_preview_text_offset">75dp</dimen> <dimen name="gesture_floating_preview_text_offset">75dp</dimen>
<dimen name="gesture_preview_text_shadow_border">17.5dp</dimen> <dimen name="gesture_floating_preview_text_shadow_border">17.5dp</dimen>
<dimen name="gesture_preview_text_shading_border">7.5dp</dimen> <dimen name="gesture_floating_preview_text_shading_border">7.5dp</dimen>
<dimen name="gesture_preview_text_connector_width">1.0dp</dimen> <dimen name="gesture_floating_preview_text_connector_width">1.0dp</dimen>
</resources> </resources>

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
--> -->
<resources> <resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Theme "Basic" --> <!-- Theme "Basic" -->
<style name="Keyboard"> <style name="Keyboard">
<!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> <!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] -->
@ -67,6 +67,18 @@
<item name="shadowColor">#BB000000</item> <item name="shadowColor">#BB000000</item>
<item name="shadowRadius">2.75</item> <item name="shadowRadius">2.75</item>
<item name="backgroundDimAlpha">128</item> <item name="backgroundDimAlpha">128</item>
<!-- android:color/holo_blue_light=#FF33B5E5 -->
<item name="gestureFloatingPreviewTextSize">@dimen/gesture_floating_preview_text_size</item>
<item name="gestureFloatingPreviewTextColor">@android:color/white</item>
<item name="gestureFloatingPreviewTextOffset">@dimen/gesture_floating_preview_text_offset</item>
<item name="gestureFloatingPreviewTextShadingColor">@android:color/holo_blue_light</item>
<item name="gestureFloatingPreviewTextShadingBorder">@dimen/gesture_floating_preview_text_shading_border</item>
<item name="gestureFloatingPreviewTextShadowColor">#FF252525</item>
<item name="gestureFloatingPreviewTextShadowBorder">@dimen/gesture_floating_preview_text_shadow_border</item>
<item name="gestureFloatingPreviewTextConnectorColor">@android:color/white</item>
<item name="gestureFloatingPreviewTextConnectorWidth">@dimen/gesture_floating_preview_text_connector_width</item>
<item name="gesturePreviewTrailColor">@android:color/holo_blue_light</item>
<item name="gesturePreviewTrailWidth">@dimen/gesture_preview_trail_width</item>
<!-- Common attributes of MainKeyboardView --> <!-- Common attributes of MainKeyboardView -->
<item name="keyHysteresisDistance">@dimen/config_key_hysteresis_distance</item> <item name="keyHysteresisDistance">@dimen/config_key_hysteresis_distance</item>
<item name="touchNoiseThresholdTime">@integer/config_touch_noise_threshold_time</item> <item name="touchNoiseThresholdTime">@integer/config_touch_noise_threshold_time</item>

View File

@ -376,13 +376,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
R.styleable.KeyboardView_verticalCorrection, 0); R.styleable.KeyboardView_verticalCorrection, 0);
mMoreKeysLayout = a.getResourceId(R.styleable.KeyboardView_moreKeysLayout, 0); mMoreKeysLayout = a.getResourceId(R.styleable.KeyboardView_moreKeysLayout, 0);
mBackgroundDimAlpha = a.getInt(R.styleable.KeyboardView_backgroundDimAlpha, 0); mBackgroundDimAlpha = a.getInt(R.styleable.KeyboardView_backgroundDimAlpha, 0);
mPreviewPlacerView = new PreviewPlacerView(context, a);
a.recycle(); a.recycle();
mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout; mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout;
mPaint.setAntiAlias(true); mPaint.setAntiAlias(true);
mPreviewPlacerView = new PreviewPlacerView(context);
} }
// Read fraction value in TypedArray as float. // Read fraction value in TypedArray as float.
@ -903,9 +902,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
windowContentView.addView(mPreviewPlacerView); windowContentView.addView(mPreviewPlacerView);
} }
public void showGesturePreviewText(String gesturePreviewText) { public void showGestureFloatingPreviewText(String gestureFloatingPreviewText) {
locatePreviewPlacerView(); locatePreviewPlacerView();
mPreviewPlacerView.setGesturePreviewText(gesturePreviewText); mPreviewPlacerView.setGestureFloatingPreviewText(gestureFloatingPreviewText);
} }
@Override @Override

View File

@ -17,9 +17,8 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.text.TextUtils; import android.text.TextUtils;
@ -30,60 +29,65 @@ import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
public class PreviewPlacerView extends RelativeLayout { public class PreviewPlacerView extends RelativeLayout {
// TODO: Move these parameters to attributes of {@link KeyboardView}.
private final static int GESTURE_DRAWING_COLOR = 0xff33b5e5;
private static final int GESTURE_PREVIEW_TEXT_COLOR = Color.WHITE;
private static final int GESTURE_PREVIEW_TEXT_SHADING_COLOR = 0xff33b5e5;
private static final int GESTURE_PREVIEW_TEXT_SHADOW_COLOR = 0xff252525;
private static final int GESTURE_PREVIEW_CONNECTOR_COLOR = Color.WHITE;
private final Paint mGesturePaint; private final Paint mGesturePaint;
private final int mGesturePreviewTraileWidth;
private final Paint mTextPaint; private final Paint mTextPaint;
private final int mGesturePreviewTextOffset; private final int mGestureFloatingPreviewTextColor;
private final int mGesturePreviewTextShadowBorder; private final int mGestureFloatingPreviewTextOffset;
private final int mGesturePreviewTextShadingBorder; private final int mGestureFloatingPreviewTextShadowColor;
private final int mGesturePreviewTextConnectorWidth; private final int mGestureFloatingPreviewTextShadowBorder;
private final int mGestureFloatingPreviewTextShadingColor;
private final int mGestureFloatingPreviewTextShadingBorder;
private final int mGestureFloatingPreviewTextConnectorColor;
private final int mGestureFloatingPreviewTextConnectorWidth;
private int mXOrigin; private int mXOrigin;
private int mYOrigin; private int mYOrigin;
private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>(); private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>();
private String mGesturePreviewText; private String mGestureFloatingPreviewText;
private boolean mDrawsGesturePreviewTrail; private boolean mDrawsGesturePreviewTrail;
private boolean mDrawsGestureFloatingPreviewText; private boolean mDrawsGestureFloatingPreviewText;
public PreviewPlacerView(Context context) { public PreviewPlacerView(Context context, TypedArray keyboardViewAttr) {
super(context); super(context);
setWillNotDraw(false); setWillNotDraw(false);
final Resources res = getResources(); final int gestureFloatingPreviewTextSize = keyboardViewAttr.getDimensionPixelSize(
// TODO: Move these parameters to attributes of {@link KeyboardView}. R.styleable.KeyboardView_gestureFloatingPreviewTextSize, 0);
mGesturePreviewTraileWidth = res.getDimensionPixelSize( mGestureFloatingPreviewTextColor = keyboardViewAttr.getColor(
R.dimen.gesture_preview_trail_width); R.styleable.KeyboardView_gestureFloatingPreviewTextColor, 0);
final int textSize = res.getDimensionPixelSize(R.dimen.gesture_preview_text_size); mGestureFloatingPreviewTextOffset = keyboardViewAttr.getDimensionPixelOffset(
mGesturePreviewTextOffset = res.getDimensionPixelSize( R.styleable.KeyboardView_gestureFloatingPreviewTextOffset, 0);
R.dimen.gesture_preview_text_offset); mGestureFloatingPreviewTextShadowColor = keyboardViewAttr.getColor(
mGesturePreviewTextShadowBorder = res.getDimensionPixelOffset( R.styleable.KeyboardView_gestureFloatingPreviewTextShadowColor, 0);
R.dimen.gesture_preview_text_shadow_border); mGestureFloatingPreviewTextShadowBorder = keyboardViewAttr.getDimensionPixelSize(
mGesturePreviewTextShadingBorder = res.getDimensionPixelOffset( R.styleable.KeyboardView_gestureFloatingPreviewTextShadowBorder, 0);
R.dimen.gesture_preview_text_shading_border); mGestureFloatingPreviewTextShadingColor = keyboardViewAttr.getColor(
mGesturePreviewTextConnectorWidth = res.getDimensionPixelOffset( R.styleable.KeyboardView_gestureFloatingPreviewTextShadingColor, 0);
R.dimen.gesture_preview_text_connector_width); mGestureFloatingPreviewTextShadingBorder = keyboardViewAttr.getDimensionPixelSize(
R.styleable.KeyboardView_gestureFloatingPreviewTextShadingBorder, 0);
mGestureFloatingPreviewTextConnectorColor = keyboardViewAttr.getColor(
R.styleable.KeyboardView_gestureFloatingPreviewTextConnectorColor, 0);
mGestureFloatingPreviewTextConnectorWidth = keyboardViewAttr.getDimensionPixelSize(
R.styleable.KeyboardView_gestureFloatingPreviewTextConnectorWidth, 0);
final int gesturePreviewTrailColor = keyboardViewAttr.getColor(
R.styleable.KeyboardView_gesturePreviewTrailColor, 0);
final int gesturePreviewTrailWidth = keyboardViewAttr.getDimensionPixelSize(
R.styleable.KeyboardView_gesturePreviewTrailWidth, 0);
mGesturePaint = new Paint(); mGesturePaint = new Paint();
mGesturePaint.setAntiAlias(true); mGesturePaint.setAntiAlias(true);
mGesturePaint.setStyle(Paint.Style.STROKE); mGesturePaint.setStyle(Paint.Style.STROKE);
mGesturePaint.setStrokeJoin(Paint.Join.ROUND); mGesturePaint.setStrokeJoin(Paint.Join.ROUND);
mGesturePaint.setColor(GESTURE_DRAWING_COLOR); mGesturePaint.setColor(gesturePreviewTrailColor);
mGesturePaint.setStrokeWidth(mGesturePreviewTraileWidth); mGesturePaint.setStrokeWidth(gesturePreviewTrailWidth);
mTextPaint = new Paint(); mTextPaint = new Paint();
mTextPaint.setAntiAlias(true); mTextPaint.setAntiAlias(true);
mTextPaint.setStrokeJoin(Paint.Join.ROUND); mTextPaint.setStrokeJoin(Paint.Join.ROUND);
mTextPaint.setTextAlign(Align.CENTER); mTextPaint.setTextAlign(Align.CENTER);
mTextPaint.setTextSize(textSize); mTextPaint.setTextSize(gestureFloatingPreviewTextSize);
} }
public void setOrigin(int x, int y) { public void setOrigin(int x, int y) {
@ -119,7 +123,7 @@ public class PreviewPlacerView extends RelativeLayout {
} }
// TODO: Figure out more cleaner way to draw gesture preview text. // TODO: Figure out more cleaner way to draw gesture preview text.
if (mDrawsGestureFloatingPreviewText && !hasDrawnFloatingPreviewText) { if (mDrawsGestureFloatingPreviewText && !hasDrawnFloatingPreviewText) {
drawGesturePreviewText(canvas, tracker, mGesturePreviewText); drawGestureFloatingPreviewText(canvas, tracker, mGestureFloatingPreviewText);
hasDrawnFloatingPreviewText = true; hasDrawnFloatingPreviewText = true;
} }
} }
@ -127,14 +131,14 @@ public class PreviewPlacerView extends RelativeLayout {
} }
} }
public void setGesturePreviewText(String gesturePreviewText) { public void setGestureFloatingPreviewText(String gestureFloatingPreviewText) {
mGesturePreviewText = gesturePreviewText; mGestureFloatingPreviewText = gestureFloatingPreviewText;
invalidate(); invalidate();
} }
private void drawGesturePreviewText(Canvas canvas, PointerTracker tracker, private void drawGestureFloatingPreviewText(Canvas canvas, PointerTracker tracker,
String gesturePreviewText) { String gestureFloatingPreviewText) {
if (TextUtils.isEmpty(gesturePreviewText)) { if (TextUtils.isEmpty(gestureFloatingPreviewText)) {
return; return;
} }
@ -144,22 +148,22 @@ public class PreviewPlacerView extends RelativeLayout {
final int textSize = (int)paint.getTextSize(); final int textSize = (int)paint.getTextSize();
final int canvasWidth = canvas.getWidth(); final int canvasWidth = canvas.getWidth();
final int halfTextWidth = (int)paint.measureText(gesturePreviewText) / 2 + textSize; final int halfTextWidth = (int)paint.measureText(gestureFloatingPreviewText) / 2 + textSize;
final int textX = Math.min(Math.max(lastX, halfTextWidth), canvasWidth - halfTextWidth); final int textX = Math.min(Math.max(lastX, halfTextWidth), canvasWidth - halfTextWidth);
int textY = Math.max(-textSize, lastY - mGesturePreviewTextOffset); int textY = Math.max(-textSize, lastY - mGestureFloatingPreviewTextOffset);
if (textY < 0) { if (textY < 0) {
// Paint black text shadow if preview extends above keyboard region. // Paint black text shadow if preview extends above keyboard region.
paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setColor(GESTURE_PREVIEW_TEXT_SHADOW_COLOR); paint.setColor(mGestureFloatingPreviewTextShadowColor);
paint.setStrokeWidth(mGesturePreviewTextShadowBorder); paint.setStrokeWidth(mGestureFloatingPreviewTextShadowBorder);
canvas.drawText(gesturePreviewText, textX, textY, paint); canvas.drawText(gestureFloatingPreviewText, textX, textY, paint);
} }
// Paint the vertical line connecting the touch point to the preview text. // Paint the vertical line connecting the touch point to the preview text.
paint.setStyle(Paint.Style.STROKE); paint.setStyle(Paint.Style.STROKE);
paint.setColor(GESTURE_PREVIEW_CONNECTOR_COLOR); paint.setColor(mGestureFloatingPreviewTextConnectorColor);
paint.setStrokeWidth(mGesturePreviewTextConnectorWidth); paint.setStrokeWidth(mGestureFloatingPreviewTextConnectorWidth);
final int lineTopY = textY - textSize / 4; final int lineTopY = textY - textSize / 4;
canvas.drawLine(lastX, lastY, lastX, lineTopY, paint); canvas.drawLine(lastX, lastY, lastX, lineTopY, paint);
if (lastX != textX) { if (lastX != textX) {
@ -169,13 +173,13 @@ public class PreviewPlacerView extends RelativeLayout {
// Paint the shading for the text preview // Paint the shading for the text preview
paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setColor(GESTURE_PREVIEW_TEXT_SHADING_COLOR); paint.setColor(mGestureFloatingPreviewTextShadingColor);
paint.setStrokeWidth(mGesturePreviewTextShadingBorder); paint.setStrokeWidth(mGestureFloatingPreviewTextShadingBorder);
canvas.drawText(gesturePreviewText, textX, textY, paint); canvas.drawText(gestureFloatingPreviewText, textX, textY, paint);
// Paint the text preview // Paint the text preview
paint.setColor(GESTURE_PREVIEW_TEXT_COLOR); paint.setColor(mGestureFloatingPreviewTextColor);
paint.setStyle(Paint.Style.FILL); paint.setStyle(Paint.Style.FILL);
canvas.drawText(gesturePreviewText, textX, textY, paint); canvas.drawText(gestureFloatingPreviewText, textX, textY, paint);
} }
} }

View File

@ -1363,9 +1363,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mWordComposer.setBatchInputPointers(batchPointers); mWordComposer.setBatchInputPointers(batchPointers);
final SuggestedWords suggestedWords = getSuggestedWords(); final SuggestedWords suggestedWords = getSuggestedWords();
showSuggestionStrip(suggestedWords, null); showSuggestionStrip(suggestedWords, null);
final String gesturePreviewText = (suggestedWords.size() > 0) final String gestureFloatingPreviewText = (suggestedWords.size() > 0)
? suggestedWords.getWord(0) : null; ? suggestedWords.getWord(0) : null;
mKeyboardSwitcher.getKeyboardView().showGesturePreviewText(gesturePreviewText); mKeyboardSwitcher.getKeyboardView()
.showGestureFloatingPreviewText(gestureFloatingPreviewText);
} }
@Override @Override
@ -1373,7 +1374,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mWordComposer.setBatchInputPointers(batchPointers); mWordComposer.setBatchInputPointers(batchPointers);
final SuggestedWords suggestedWords = getSuggestedWords(); final SuggestedWords suggestedWords = getSuggestedWords();
showSuggestionStrip(suggestedWords, null); showSuggestionStrip(suggestedWords, null);
mKeyboardSwitcher.getKeyboardView().showGesturePreviewText(null); mKeyboardSwitcher.getKeyboardView().showGestureFloatingPreviewText(null);
if (suggestedWords == null || suggestedWords.size() == 0) { if (suggestedWords == null || suggestedWords.size() == 0) {
return; return;
} }