2010-08-20 05:35:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 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.
|
|
|
|
*/
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
package com.android.inputmethod.keyboard;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Canvas;
|
2011-02-20 05:44:59 +00:00
|
|
|
import android.graphics.Color;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.graphics.Paint;
|
2010-08-24 13:46:36 +00:00
|
|
|
import android.graphics.Paint.Align;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.Rect;
|
2012-08-02 06:10:59 +00:00
|
|
|
import android.graphics.Region;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
|
2012-08-30 07:18:53 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
|
2012-08-30 08:42:49 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
|
2012-07-19 08:20:54 +00:00
|
|
|
import com.android.inputmethod.latin.Constants;
|
2011-06-15 04:38:58 +00:00
|
|
|
import com.android.inputmethod.latin.LatinImeLogger;
|
|
|
|
import com.android.inputmethod.latin.R;
|
2012-07-19 02:21:54 +00:00
|
|
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
2013-07-05 09:57:07 +00:00
|
|
|
import com.android.inputmethod.latin.utils.TypefaceUtils;
|
2012-07-19 02:21:54 +00:00
|
|
|
import com.android.inputmethod.research.ResearchLogger;
|
2011-06-15 04:38:58 +00:00
|
|
|
|
2012-03-13 08:28:52 +00:00
|
|
|
import java.util.HashSet;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
/**
|
2011-07-01 04:07:59 +00:00
|
|
|
* A view that renders a virtual {@link Keyboard}.
|
2010-08-20 05:35:02 +00:00
|
|
|
*
|
2010-12-02 09:46:21 +00:00
|
|
|
* @attr ref R.styleable#KeyboardView_keyBackground
|
2011-06-28 07:32:39 +00:00
|
|
|
* @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding
|
|
|
|
* @attr ref R.styleable#KeyboardView_keyHintLetterPadding
|
2011-09-07 12:56:42 +00:00
|
|
|
* @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding
|
2012-01-26 09:03:30 +00:00
|
|
|
* @attr ref R.styleable#KeyboardView_keyShiftedLetterHintPadding
|
2012-08-30 08:42:49 +00:00
|
|
|
* @attr ref R.styleable#KeyboardView_keyTextShadowRadius
|
2012-08-31 01:09:43 +00:00
|
|
|
* @attr ref R.styleable#KeyboardView_verticalCorrection
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyTypeface
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyLetterSize
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyLabelSize
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyLargeLetterRatio
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyLargeLabelRatio
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyHintLetterRatio
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintRatio
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyHintLabelRatio
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyPreviewTextRatio
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyTextColor
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyTextColorDisabled
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyTextShadowColor
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyHintLetterColor
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyHintLabelColor
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintInactivatedColor
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintActivatedColor
|
|
|
|
* @attr ref R.styleable#Keyboard_Key_keyPreviewTextColor
|
2010-08-20 05:35:02 +00:00
|
|
|
*/
|
2013-01-21 06:23:32 +00:00
|
|
|
public class KeyboardView extends View {
|
2011-08-31 05:22:53 +00:00
|
|
|
// XML attributes
|
2013-04-11 03:08:36 +00:00
|
|
|
private final KeyVisualAttributes mKeyVisualAttributes;
|
2012-08-31 01:09:43 +00:00
|
|
|
private final int mKeyLabelHorizontalPadding;
|
|
|
|
private final float mKeyHintLetterPadding;
|
|
|
|
private final float mKeyPopupHintLetterPadding;
|
|
|
|
private final float mKeyShiftedLetterHintPadding;
|
2012-08-30 08:42:49 +00:00
|
|
|
private final float mKeyTextShadowRadius;
|
2013-04-11 03:08:36 +00:00
|
|
|
private final float mVerticalCorrection;
|
|
|
|
private final Drawable mKeyBackground;
|
|
|
|
private final Rect mKeyBackgroundPadding = new Rect();
|
2010-08-27 12:23:51 +00:00
|
|
|
|
2011-06-27 15:54:14 +00:00
|
|
|
// HORIZONTAL ELLIPSIS "...", character for popup hint.
|
2011-09-23 21:59:33 +00:00
|
|
|
private static final String POPUP_HINT_CHAR = "\u2026";
|
2011-06-27 15:54:14 +00:00
|
|
|
|
2011-08-15 11:43:00 +00:00
|
|
|
// Margin between the label and the icon on a key that has both of them.
|
|
|
|
// Specified by the fraction of the key width.
|
|
|
|
// TODO: Use resource parameter for this value.
|
|
|
|
private static final float LABEL_ICON_MARGIN = 0.05f;
|
|
|
|
|
2011-09-12 07:29:24 +00:00
|
|
|
// The maximum key label width in the proportion to the key width.
|
|
|
|
private static final float MAX_LABEL_RATIO = 0.90f;
|
|
|
|
|
2010-08-27 12:23:51 +00:00
|
|
|
// Main keyboard
|
2010-12-02 09:46:21 +00:00
|
|
|
private Keyboard mKeyboard;
|
2012-08-30 08:42:49 +00:00
|
|
|
protected final KeyDrawParams mKeyDrawParams = new KeyDrawParams();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-08-27 12:23:51 +00:00
|
|
|
// Drawing
|
2012-03-13 08:28:52 +00:00
|
|
|
/** True if all keys should be drawn */
|
|
|
|
private boolean mInvalidateAllKeys;
|
|
|
|
/** The keys that should be drawn */
|
2012-08-21 07:34:55 +00:00
|
|
|
private final HashSet<Key> mInvalidatedKeys = CollectionUtils.newHashSet();
|
2012-08-02 06:10:59 +00:00
|
|
|
/** The working rectangle variable */
|
|
|
|
private final Rect mWorkingRect = new Rect();
|
2011-07-21 06:57:00 +00:00
|
|
|
/** The keyboard bitmap buffer for faster updates */
|
2012-08-02 07:39:27 +00:00
|
|
|
/** The clip region to draw keys */
|
|
|
|
private final Region mClipRegion = new Region();
|
2012-08-02 06:10:59 +00:00
|
|
|
private Bitmap mOffscreenBuffer;
|
2010-08-20 05:35:02 +00:00
|
|
|
/** The canvas for the above mutable keyboard bitmap */
|
2012-09-12 07:28:54 +00:00
|
|
|
private final Canvas mOffscreenCanvas = new Canvas();
|
2011-06-15 03:36:53 +00:00
|
|
|
private final Paint mPaint = new Paint();
|
2012-03-27 08:47:33 +00:00
|
|
|
private final Paint.FontMetrics mFontMetrics = new Paint.FontMetrics();
|
2011-09-07 03:07:56 +00:00
|
|
|
private static final char[] KEY_LABEL_REFERENCE_CHAR = { 'M' };
|
|
|
|
private static final char[] KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR = { '8' };
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
public KeyboardView(final Context context, final AttributeSet attrs) {
|
2010-08-20 05:35:02 +00:00
|
|
|
this(context, attrs, R.attr.keyboardViewStyle);
|
|
|
|
}
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
public KeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
|
2010-08-20 05:35:02 +00:00
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
2012-08-30 07:05:40 +00:00
|
|
|
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
|
|
|
|
R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
|
2012-08-30 08:42:49 +00:00
|
|
|
mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground);
|
|
|
|
mKeyBackground.getPadding(mKeyBackgroundPadding);
|
2012-08-31 10:57:25 +00:00
|
|
|
mKeyLabelHorizontalPadding = keyboardViewAttr.getDimensionPixelOffset(
|
2012-08-31 01:09:43 +00:00
|
|
|
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
|
2012-08-31 10:57:25 +00:00
|
|
|
mKeyHintLetterPadding = keyboardViewAttr.getDimension(
|
2013-04-11 03:08:36 +00:00
|
|
|
R.styleable.KeyboardView_keyHintLetterPadding, 0.0f);
|
2012-08-31 10:57:25 +00:00
|
|
|
mKeyPopupHintLetterPadding = keyboardViewAttr.getDimension(
|
2013-04-11 03:08:36 +00:00
|
|
|
R.styleable.KeyboardView_keyPopupHintLetterPadding, 0.0f);
|
2012-08-31 10:57:25 +00:00
|
|
|
mKeyShiftedLetterHintPadding = keyboardViewAttr.getDimension(
|
2013-04-11 03:08:36 +00:00
|
|
|
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0.0f);
|
2012-08-30 08:42:49 +00:00
|
|
|
mKeyTextShadowRadius = keyboardViewAttr.getFloat(
|
|
|
|
R.styleable.KeyboardView_keyTextShadowRadius, 0.0f);
|
|
|
|
mVerticalCorrection = keyboardViewAttr.getDimension(
|
2013-04-11 03:08:36 +00:00
|
|
|
R.styleable.KeyboardView_verticalCorrection, 0.0f);
|
2012-08-30 07:05:40 +00:00
|
|
|
keyboardViewAttr.recycle();
|
2012-08-30 08:42:49 +00:00
|
|
|
|
|
|
|
final TypedArray keyAttr = context.obtainStyledAttributes(attrs,
|
|
|
|
R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView);
|
|
|
|
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
|
2012-08-30 07:05:40 +00:00
|
|
|
keyAttr.recycle();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
mPaint.setAntiAlias(true);
|
|
|
|
}
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
private static void blendAlpha(final Paint paint, final int alpha) {
|
|
|
|
final int color = paint.getColor();
|
|
|
|
paint.setARGB((paint.getAlpha() * alpha) / Constants.Color.ALPHA_OPAQUE,
|
|
|
|
Color.red(color), Color.green(color), Color.blue(color));
|
|
|
|
}
|
|
|
|
|
2013-08-01 15:25:05 +00:00
|
|
|
public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
|
|
|
|
if (!enabled) return;
|
|
|
|
// TODO: Should use LAYER_TYPE_SOFTWARE when hardware acceleration is off?
|
2013-08-02 11:22:51 +00:00
|
|
|
setLayerType(LAYER_TYPE_HARDWARE, null);
|
2013-08-01 15:25:05 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/**
|
|
|
|
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
|
|
|
|
* view will re-layout itself to accommodate the keyboard.
|
2010-12-02 09:46:21 +00:00
|
|
|
* @see Keyboard
|
2010-08-20 05:35:02 +00:00
|
|
|
* @see #getKeyboard()
|
|
|
|
* @param keyboard the keyboard to display in this view
|
|
|
|
*/
|
2012-08-30 08:42:49 +00:00
|
|
|
public void setKeyboard(final Keyboard keyboard) {
|
2010-08-20 05:35:02 +00:00
|
|
|
mKeyboard = keyboard;
|
2010-09-01 14:18:39 +00:00
|
|
|
LatinImeLogger.onSetKeyboard(keyboard);
|
2012-08-30 08:42:49 +00:00
|
|
|
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
|
|
|
mKeyDrawParams.updateParams(keyHeight, mKeyVisualAttributes);
|
|
|
|
mKeyDrawParams.updateParams(keyHeight, keyboard.mKeyVisualAttributes);
|
2013-01-22 05:32:47 +00:00
|
|
|
invalidateAllKeys();
|
|
|
|
requestLayout();
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current keyboard being displayed by this view.
|
|
|
|
* @return the currently attached keyboard
|
2010-12-02 09:46:21 +00:00
|
|
|
* @see #setKeyboard(Keyboard)
|
2010-08-20 05:35:02 +00:00
|
|
|
*/
|
2010-12-02 09:46:21 +00:00
|
|
|
public Keyboard getKeyboard() {
|
2010-08-20 05:35:02 +00:00
|
|
|
return mKeyboard;
|
|
|
|
}
|
|
|
|
|
2013-04-11 03:08:36 +00:00
|
|
|
protected float getVerticalCorrection() {
|
|
|
|
return mVerticalCorrection;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateKeyDrawParams(final int keyHeight) {
|
|
|
|
mKeyDrawParams.updateParams(keyHeight, mKeyVisualAttributes);
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
@Override
|
2012-08-30 08:42:49 +00:00
|
|
|
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
|
2013-08-08 10:14:55 +00:00
|
|
|
if (mKeyboard == null) {
|
2011-07-21 06:57:00 +00:00
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
2013-08-08 10:14:55 +00:00
|
|
|
return;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2013-08-08 10:14:55 +00:00
|
|
|
// The main keyboard expands to the entire this {@link KeyboardView}.
|
|
|
|
final int width = mKeyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight();
|
|
|
|
final int height = mKeyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom();
|
|
|
|
setMeasuredDimension(width, height);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-01-21 07:36:25 +00:00
|
|
|
protected void onDraw(final Canvas canvas) {
|
2010-08-20 05:35:02 +00:00
|
|
|
super.onDraw(canvas);
|
2012-08-02 07:39:27 +00:00
|
|
|
if (canvas.isHardwareAccelerated()) {
|
|
|
|
onDrawKeyboard(canvas);
|
|
|
|
return;
|
|
|
|
}
|
2012-08-09 06:25:01 +00:00
|
|
|
|
|
|
|
final boolean bufferNeedsUpdates = mInvalidateAllKeys || !mInvalidatedKeys.isEmpty();
|
|
|
|
if (bufferNeedsUpdates || mOffscreenBuffer == null) {
|
2012-08-02 06:10:59 +00:00
|
|
|
if (maybeAllocateOffscreenBuffer()) {
|
|
|
|
mInvalidateAllKeys = true;
|
2012-09-12 07:28:54 +00:00
|
|
|
// TODO: Stop using the offscreen canvas even when in software rendering
|
|
|
|
mOffscreenCanvas.setBitmap(mOffscreenBuffer);
|
2012-08-02 06:10:59 +00:00
|
|
|
}
|
|
|
|
onDrawKeyboard(mOffscreenCanvas);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2013-04-11 03:08:36 +00:00
|
|
|
canvas.drawBitmap(mOffscreenBuffer, 0.0f, 0.0f, null);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 06:10:59 +00:00
|
|
|
private boolean maybeAllocateOffscreenBuffer() {
|
2011-02-01 05:02:22 +00:00
|
|
|
final int width = getWidth();
|
|
|
|
final int height = getHeight();
|
2012-08-02 06:10:59 +00:00
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mOffscreenBuffer != null && mOffscreenBuffer.getWidth() == width
|
|
|
|
&& mOffscreenBuffer.getHeight() == height) {
|
|
|
|
return false;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2012-08-02 06:10:59 +00:00
|
|
|
freeOffscreenBuffer();
|
|
|
|
mOffscreenBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2012-08-02 06:10:59 +00:00
|
|
|
private void freeOffscreenBuffer() {
|
|
|
|
if (mOffscreenBuffer != null) {
|
|
|
|
mOffscreenBuffer.recycle();
|
|
|
|
mOffscreenBuffer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onDrawKeyboard(final Canvas canvas) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboard == null) return;
|
|
|
|
|
2012-08-02 06:10:59 +00:00
|
|
|
final int width = getWidth();
|
|
|
|
final int height = getHeight();
|
2012-03-13 08:28:52 +00:00
|
|
|
final Paint paint = mPaint;
|
|
|
|
|
2012-08-02 07:39:27 +00:00
|
|
|
// Calculate clip region and set.
|
|
|
|
final boolean drawAllKeys = mInvalidateAllKeys || mInvalidatedKeys.isEmpty();
|
|
|
|
final boolean isHardwareAccelerated = canvas.isHardwareAccelerated();
|
|
|
|
// TODO: Confirm if it's really required to draw all keys when hardware acceleration is on.
|
|
|
|
if (drawAllKeys || isHardwareAccelerated) {
|
|
|
|
mClipRegion.set(0, 0, width, height);
|
|
|
|
} else {
|
|
|
|
mClipRegion.setEmpty();
|
|
|
|
for (final Key key : mInvalidatedKeys) {
|
|
|
|
if (mKeyboard.hasKey(key)) {
|
2013-08-12 09:05:11 +00:00
|
|
|
final int x = key.getX() + getPaddingLeft();
|
|
|
|
final int y = key.getY() + getPaddingTop();
|
|
|
|
mWorkingRect.set(x, y, x + key.getWidth(), y + key.getHeight());
|
2012-08-02 07:39:27 +00:00
|
|
|
mClipRegion.union(mWorkingRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isHardwareAccelerated) {
|
|
|
|
canvas.clipRegion(mClipRegion, Region.Op.REPLACE);
|
2012-08-09 06:25:01 +00:00
|
|
|
// Draw keyboard background.
|
|
|
|
canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
|
|
|
|
final Drawable background = getBackground();
|
|
|
|
if (background != null) {
|
|
|
|
background.draw(canvas);
|
|
|
|
}
|
2012-08-02 07:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Confirm if it's really required to draw all keys when hardware acceleration is on.
|
|
|
|
if (drawAllKeys || isHardwareAccelerated) {
|
2011-04-15 04:05:58 +00:00
|
|
|
// Draw all keys.
|
2013-08-22 09:51:32 +00:00
|
|
|
for (final Key key : mKeyboard.getKeys()) {
|
2012-08-30 08:42:49 +00:00
|
|
|
onDrawKey(key, canvas, paint);
|
2012-03-13 08:28:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Draw invalidated keys.
|
|
|
|
for (final Key key : mInvalidatedKeys) {
|
2012-08-02 07:39:27 +00:00
|
|
|
if (mKeyboard.hasKey(key)) {
|
2012-08-30 08:42:49 +00:00
|
|
|
onDrawKey(key, canvas, paint);
|
2012-04-18 05:54:40 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-05 09:41:12 +00:00
|
|
|
|
2013-03-18 09:21:18 +00:00
|
|
|
// Research Logging (Development Only Diagnostics) indicator.
|
2012-07-19 02:21:54 +00:00
|
|
|
// TODO: Reimplement using a keyboard background image specific to the ResearchLogger,
|
|
|
|
// and remove this call.
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-07-19 02:21:54 +00:00
|
|
|
ResearchLogger.getInstance().paintIndicator(this, paint, canvas, width, height);
|
|
|
|
}
|
|
|
|
|
2012-03-13 08:28:52 +00:00
|
|
|
mInvalidatedKeys.clear();
|
|
|
|
mInvalidateAllKeys = false;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
private void onDrawKey(final Key key, final Canvas canvas, final Paint paint) {
|
2012-08-28 08:19:49 +00:00
|
|
|
final int keyDrawX = key.getDrawX() + getPaddingLeft();
|
2013-08-12 09:05:11 +00:00
|
|
|
final int keyDrawY = key.getY() + getPaddingTop();
|
2012-03-13 08:28:52 +00:00
|
|
|
canvas.translate(keyDrawX, keyDrawY);
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
final int keyHeight = mKeyboard.mMostCommonKeyHeight - mKeyboard.mVerticalGap;
|
2013-08-12 09:05:11 +00:00
|
|
|
final KeyVisualAttributes attr = key.getVisualAttributes();
|
2012-08-30 08:42:49 +00:00
|
|
|
final KeyDrawParams params = mKeyDrawParams.mayCloneAndUpdateParams(keyHeight, attr);
|
2012-07-19 08:20:54 +00:00
|
|
|
params.mAnimAlpha = Constants.Color.ALPHA_OPAQUE;
|
2012-08-30 08:42:49 +00:00
|
|
|
|
2012-02-02 15:18:47 +00:00
|
|
|
if (!key.isSpacer()) {
|
2012-08-30 08:42:49 +00:00
|
|
|
onDrawKeyBackground(key, canvas);
|
2012-02-02 15:18:47 +00:00
|
|
|
}
|
2011-12-17 17:58:13 +00:00
|
|
|
onDrawKeyTopVisuals(key, canvas, paint, params);
|
2012-03-13 08:28:52 +00:00
|
|
|
|
|
|
|
canvas.translate(-keyDrawX, -keyDrawY);
|
2011-12-17 17:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw key background.
|
2012-09-05 06:34:51 +00:00
|
|
|
protected void onDrawKeyBackground(final Key key, final Canvas canvas) {
|
2012-08-30 08:42:49 +00:00
|
|
|
final Rect padding = mKeyBackgroundPadding;
|
|
|
|
final int bgWidth = key.getDrawWidth() + padding.left + padding.right;
|
2013-08-12 09:05:11 +00:00
|
|
|
final int bgHeight = key.getHeight() + padding.top + padding.bottom;
|
2012-08-30 08:42:49 +00:00
|
|
|
final int bgX = -padding.left;
|
|
|
|
final int bgY = -padding.top;
|
2011-12-17 17:58:13 +00:00
|
|
|
final int[] drawableState = key.getCurrentDrawableState();
|
2012-08-30 08:42:49 +00:00
|
|
|
final Drawable background = mKeyBackground;
|
2011-12-17 17:58:13 +00:00
|
|
|
background.setState(drawableState);
|
|
|
|
final Rect bounds = background.getBounds();
|
|
|
|
if (bgWidth != bounds.right || bgHeight != bounds.bottom) {
|
|
|
|
background.setBounds(0, 0, bgWidth, bgHeight);
|
2011-06-28 07:32:39 +00:00
|
|
|
}
|
2011-12-17 17:58:13 +00:00
|
|
|
canvas.translate(bgX, bgY);
|
|
|
|
background.draw(canvas);
|
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
2013-04-11 03:08:36 +00:00
|
|
|
drawRectangle(canvas, 0.0f, 0.0f, bgWidth, bgHeight, 0x80c00000, new Paint());
|
2011-12-17 17:58:13 +00:00
|
|
|
}
|
|
|
|
canvas.translate(-bgX, -bgY);
|
|
|
|
}
|
2011-06-28 07:32:39 +00:00
|
|
|
|
2011-12-17 17:58:13 +00:00
|
|
|
// Draw key top visuals.
|
2012-09-05 06:34:51 +00:00
|
|
|
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
|
|
|
|
final KeyDrawParams params) {
|
2012-08-28 08:19:49 +00:00
|
|
|
final int keyWidth = key.getDrawWidth();
|
2013-08-12 09:05:11 +00:00
|
|
|
final int keyHeight = key.getHeight();
|
2011-06-28 07:32:39 +00:00
|
|
|
final float centerX = keyWidth * 0.5f;
|
|
|
|
final float centerY = keyHeight * 0.5f;
|
|
|
|
|
2011-12-17 17:58:13 +00:00
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
2013-04-11 03:08:36 +00:00
|
|
|
drawRectangle(canvas, 0.0f, 0.0f, keyWidth, keyHeight, 0x800000c0, new Paint());
|
2011-04-15 04:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw key label.
|
2012-05-16 08:41:56 +00:00
|
|
|
final Drawable icon = key.getIcon(mKeyboard.mIconsSet, params.mAnimAlpha);
|
2011-06-28 07:32:39 +00:00
|
|
|
float positionX = centerX;
|
2013-08-12 09:05:11 +00:00
|
|
|
final String label = key.getLabel();
|
|
|
|
if (label != null) {
|
2012-08-30 08:42:49 +00:00
|
|
|
paint.setTypeface(key.selectTypeface(params));
|
|
|
|
paint.setTextSize(key.selectTextSize(params));
|
2013-04-11 03:08:36 +00:00
|
|
|
final float labelCharHeight = TypefaceUtils.getCharHeight(
|
|
|
|
KEY_LABEL_REFERENCE_CHAR, paint);
|
|
|
|
final float labelCharWidth = TypefaceUtils.getCharWidth(
|
|
|
|
KEY_LABEL_REFERENCE_CHAR, paint);
|
2011-04-15 04:05:58 +00:00
|
|
|
|
|
|
|
// Vertical label text alignment.
|
2013-04-11 03:08:36 +00:00
|
|
|
final float baseline = centerY + labelCharHeight / 2.0f;
|
2011-06-25 10:38:55 +00:00
|
|
|
|
2011-04-15 04:05:58 +00:00
|
|
|
// Horizontal label text alignment
|
2013-04-11 03:08:36 +00:00
|
|
|
float labelWidth = 0.0f;
|
2011-08-03 04:29:24 +00:00
|
|
|
if (key.isAlignLeft()) {
|
2012-08-31 01:09:43 +00:00
|
|
|
positionX = mKeyLabelHorizontalPadding;
|
2011-04-15 04:05:58 +00:00
|
|
|
paint.setTextAlign(Align.LEFT);
|
2011-08-03 04:29:24 +00:00
|
|
|
} else if (key.isAlignRight()) {
|
2012-08-31 01:09:43 +00:00
|
|
|
positionX = keyWidth - mKeyLabelHorizontalPadding;
|
2011-04-15 04:05:58 +00:00
|
|
|
paint.setTextAlign(Align.RIGHT);
|
2011-08-03 04:29:24 +00:00
|
|
|
} else if (key.isAlignLeftOfCenter()) {
|
2011-06-25 10:38:55 +00:00
|
|
|
// TODO: Parameterise this?
|
2013-04-11 03:08:36 +00:00
|
|
|
positionX = centerX - labelCharWidth * 7.0f / 4.0f;
|
2011-06-25 10:38:55 +00:00
|
|
|
paint.setTextAlign(Align.LEFT);
|
2011-08-03 04:29:24 +00:00
|
|
|
} else if (key.hasLabelWithIconLeft() && icon != null) {
|
2013-04-11 03:08:36 +00:00
|
|
|
labelWidth = TypefaceUtils.getLabelWidth(label, paint) + icon.getIntrinsicWidth()
|
2011-09-12 07:29:24 +00:00
|
|
|
+ LABEL_ICON_MARGIN * keyWidth;
|
2013-04-11 03:08:36 +00:00
|
|
|
positionX = centerX + labelWidth / 2.0f;
|
2011-08-03 04:29:24 +00:00
|
|
|
paint.setTextAlign(Align.RIGHT);
|
|
|
|
} else if (key.hasLabelWithIconRight() && icon != null) {
|
2013-04-11 03:08:36 +00:00
|
|
|
labelWidth = TypefaceUtils.getLabelWidth(label, paint) + icon.getIntrinsicWidth()
|
2011-09-12 07:29:24 +00:00
|
|
|
+ LABEL_ICON_MARGIN * keyWidth;
|
2013-04-11 03:08:36 +00:00
|
|
|
positionX = centerX - labelWidth / 2.0f;
|
2011-08-03 04:29:24 +00:00
|
|
|
paint.setTextAlign(Align.LEFT);
|
2011-04-15 04:05:58 +00:00
|
|
|
} else {
|
2011-06-25 10:38:55 +00:00
|
|
|
positionX = centerX;
|
2011-04-15 04:05:58 +00:00
|
|
|
paint.setTextAlign(Align.CENTER);
|
|
|
|
}
|
2011-09-12 07:29:24 +00:00
|
|
|
if (key.needsXScale()) {
|
2013-04-11 03:08:36 +00:00
|
|
|
paint.setTextScaleX(Math.min(1.0f,
|
|
|
|
(keyWidth * MAX_LABEL_RATIO) / TypefaceUtils.getLabelWidth(label, paint)));
|
2011-09-12 07:29:24 +00:00
|
|
|
}
|
2011-06-25 10:38:55 +00:00
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
paint.setColor(key.selectTextColor(params));
|
2011-06-23 12:23:44 +00:00
|
|
|
if (key.isEnabled()) {
|
2011-04-15 04:05:58 +00:00
|
|
|
// Set a drop shadow for the text
|
2013-04-11 03:08:36 +00:00
|
|
|
paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor);
|
2011-04-15 04:05:58 +00:00
|
|
|
} else {
|
|
|
|
// Make label invisible
|
|
|
|
paint.setColor(Color.TRANSPARENT);
|
|
|
|
}
|
2012-08-30 08:42:49 +00:00
|
|
|
blendAlpha(paint, params.mAnimAlpha);
|
2011-06-25 10:38:55 +00:00
|
|
|
canvas.drawText(label, 0, label.length(), positionX, baseline, paint);
|
2011-09-12 07:29:24 +00:00
|
|
|
// Turn off drop shadow and reset x-scale.
|
2013-04-11 03:08:36 +00:00
|
|
|
paint.setShadowLayer(0.0f, 0.0f, 0.0f, Color.TRANSPARENT);
|
2011-09-12 07:29:24 +00:00
|
|
|
paint.setTextScaleX(1.0f);
|
2011-06-25 10:38:55 +00:00
|
|
|
|
2011-08-03 04:29:24 +00:00
|
|
|
if (icon != null) {
|
|
|
|
final int iconWidth = icon.getIntrinsicWidth();
|
|
|
|
final int iconHeight = icon.getIntrinsicHeight();
|
|
|
|
final int iconY = (keyHeight - iconHeight) / 2;
|
|
|
|
if (key.hasLabelWithIconLeft()) {
|
2013-04-11 03:08:36 +00:00
|
|
|
final int iconX = (int)(centerX - labelWidth / 2.0f);
|
2011-08-03 04:29:24 +00:00
|
|
|
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
|
|
|
|
} else if (key.hasLabelWithIconRight()) {
|
2013-04-11 03:08:36 +00:00
|
|
|
final int iconX = (int)(centerX + labelWidth / 2.0f - iconWidth);
|
2011-08-03 04:29:24 +00:00
|
|
|
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 17:58:13 +00:00
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
2011-06-28 07:32:39 +00:00
|
|
|
final Paint line = new Paint();
|
|
|
|
drawHorizontalLine(canvas, baseline, keyWidth, 0xc0008000, line);
|
|
|
|
drawVerticalLine(canvas, positionX, keyHeight, 0xc0800080, line);
|
|
|
|
}
|
2011-04-15 04:05:58 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 10:38:55 +00:00
|
|
|
// Draw hint label.
|
2013-08-12 09:05:11 +00:00
|
|
|
final String hintLabel = key.getHintLabel();
|
|
|
|
if (hintLabel != null) {
|
2012-08-30 08:42:49 +00:00
|
|
|
paint.setTextSize(key.selectHintTextSize(params));
|
|
|
|
paint.setColor(key.selectHintTextColor(params));
|
|
|
|
blendAlpha(paint, params.mAnimAlpha);
|
2011-06-25 10:38:55 +00:00
|
|
|
final float hintX, hintY;
|
|
|
|
if (key.hasHintLabel()) {
|
2011-09-07 03:07:56 +00:00
|
|
|
// The hint label is placed just right of the key label. Used mainly on
|
|
|
|
// "phone number" layout.
|
2011-06-25 10:38:55 +00:00
|
|
|
// TODO: Generalize the following calculations.
|
2013-04-11 03:08:36 +00:00
|
|
|
hintX = positionX
|
|
|
|
+ TypefaceUtils.getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) * 2.0f;
|
|
|
|
hintY = centerY
|
|
|
|
+ TypefaceUtils.getCharHeight(KEY_LABEL_REFERENCE_CHAR, paint) / 2.0f;
|
2011-06-28 07:32:39 +00:00
|
|
|
paint.setTextAlign(Align.LEFT);
|
2012-01-26 09:03:30 +00:00
|
|
|
} else if (key.hasShiftedLetterHint()) {
|
2011-09-07 03:07:56 +00:00
|
|
|
// The hint label is placed at top-right corner of the key. Used mainly on tablet.
|
2012-08-31 01:09:43 +00:00
|
|
|
hintX = keyWidth - mKeyShiftedLetterHintPadding
|
2013-04-11 03:08:36 +00:00
|
|
|
- TypefaceUtils.getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2.0f;
|
2012-03-27 08:47:33 +00:00
|
|
|
paint.getFontMetrics(mFontMetrics);
|
2012-05-01 10:33:22 +00:00
|
|
|
hintY = -mFontMetrics.top;
|
2011-06-28 07:32:39 +00:00
|
|
|
paint.setTextAlign(Align.CENTER);
|
|
|
|
} else { // key.hasHintLetter()
|
2012-04-24 03:59:33 +00:00
|
|
|
// The hint letter is placed at top-right corner of the key. Used mainly on phone.
|
2012-08-31 01:09:43 +00:00
|
|
|
hintX = keyWidth - mKeyHintLetterPadding
|
2013-04-11 03:08:36 +00:00
|
|
|
- TypefaceUtils.getCharWidth(KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR, paint)
|
|
|
|
/ 2.0f;
|
2012-04-24 03:59:33 +00:00
|
|
|
hintY = -paint.ascent();
|
2011-06-28 07:32:39 +00:00
|
|
|
paint.setTextAlign(Align.CENTER);
|
2011-06-25 10:38:55 +00:00
|
|
|
}
|
2012-08-30 08:42:49 +00:00
|
|
|
canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintY, paint);
|
2011-06-28 07:32:39 +00:00
|
|
|
|
2011-12-17 17:58:13 +00:00
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
2011-06-28 07:32:39 +00:00
|
|
|
final Paint line = new Paint();
|
|
|
|
drawHorizontalLine(canvas, (int)hintY, keyWidth, 0xc0808000, line);
|
|
|
|
drawVerticalLine(canvas, (int)hintX, keyHeight, 0xc0808000, line);
|
|
|
|
}
|
2011-06-15 03:36:53 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 04:05:58 +00:00
|
|
|
// Draw key icon.
|
2013-08-12 09:05:11 +00:00
|
|
|
if (label == null && icon != null) {
|
2012-09-03 02:26:45 +00:00
|
|
|
final int iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth);
|
2011-06-25 10:38:55 +00:00
|
|
|
final int iconHeight = icon.getIntrinsicHeight();
|
|
|
|
final int iconX, alignX;
|
2011-06-28 07:32:39 +00:00
|
|
|
final int iconY = (keyHeight - iconHeight) / 2;
|
2011-08-03 04:29:24 +00:00
|
|
|
if (key.isAlignLeft()) {
|
2012-08-31 01:09:43 +00:00
|
|
|
iconX = mKeyLabelHorizontalPadding;
|
2011-06-25 10:38:55 +00:00
|
|
|
alignX = iconX;
|
2011-08-03 04:29:24 +00:00
|
|
|
} else if (key.isAlignRight()) {
|
2012-08-31 01:09:43 +00:00
|
|
|
iconX = keyWidth - mKeyLabelHorizontalPadding - iconWidth;
|
2011-06-25 10:38:55 +00:00
|
|
|
alignX = iconX + iconWidth;
|
2011-04-15 04:05:58 +00:00
|
|
|
} else { // Align center
|
2011-06-28 07:32:39 +00:00
|
|
|
iconX = (keyWidth - iconWidth) / 2;
|
2011-06-25 10:38:55 +00:00
|
|
|
alignX = iconX + iconWidth / 2;
|
|
|
|
}
|
|
|
|
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
|
2011-06-28 07:32:39 +00:00
|
|
|
|
2011-12-17 17:58:13 +00:00
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
2011-06-25 10:38:55 +00:00
|
|
|
final Paint line = new Paint();
|
2011-06-28 07:32:39 +00:00
|
|
|
drawVerticalLine(canvas, alignX, keyHeight, 0xc0800080, line);
|
2011-06-25 10:38:55 +00:00
|
|
|
drawRectangle(canvas, iconX, iconY, iconWidth, iconHeight, 0x80c00000, line);
|
2011-04-15 04:05:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-12 09:05:11 +00:00
|
|
|
if (key.hasPopupHint() && key.getMoreKeys() != null) {
|
2011-12-17 17:58:13 +00:00
|
|
|
drawKeyPopupHint(key, canvas, paint, params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw popup hint "..." at the bottom right corner of the key.
|
2012-09-05 06:34:51 +00:00
|
|
|
protected void drawKeyPopupHint(final Key key, final Canvas canvas, final Paint paint,
|
|
|
|
final KeyDrawParams params) {
|
2012-08-28 08:19:49 +00:00
|
|
|
final int keyWidth = key.getDrawWidth();
|
2013-08-12 09:05:11 +00:00
|
|
|
final int keyHeight = key.getHeight();
|
2011-12-17 17:58:13 +00:00
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
paint.setTypeface(params.mTypeface);
|
|
|
|
paint.setTextSize(params.mHintLetterSize);
|
|
|
|
paint.setColor(params.mHintLabelColor);
|
2011-12-17 17:58:13 +00:00
|
|
|
paint.setTextAlign(Align.CENTER);
|
2012-08-31 01:09:43 +00:00
|
|
|
final float hintX = keyWidth - mKeyHintLetterPadding
|
2013-04-11 03:08:36 +00:00
|
|
|
- TypefaceUtils.getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2.0f;
|
2012-08-31 01:09:43 +00:00
|
|
|
final float hintY = keyHeight - mKeyPopupHintLetterPadding;
|
2011-12-17 17:58:13 +00:00
|
|
|
canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint);
|
|
|
|
|
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
|
|
|
final Paint line = new Paint();
|
|
|
|
drawHorizontalLine(canvas, (int)hintY, keyWidth, 0xc0808000, line);
|
|
|
|
drawVerticalLine(canvas, (int)hintX, keyHeight, 0xc0808000, line);
|
2011-06-28 07:32:39 +00:00
|
|
|
}
|
2011-04-15 04:05:58 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 06:34:51 +00:00
|
|
|
protected static void drawIcon(final Canvas canvas, final Drawable icon, final int x,
|
|
|
|
final int y, final int width, final int height) {
|
2010-10-19 15:18:50 +00:00
|
|
|
canvas.translate(x, y);
|
|
|
|
icon.setBounds(0, 0, width, height);
|
|
|
|
icon.draw(canvas);
|
|
|
|
canvas.translate(-x, -y);
|
|
|
|
}
|
|
|
|
|
2012-09-05 06:34:51 +00:00
|
|
|
private static void drawHorizontalLine(final Canvas canvas, final float y, final float w,
|
|
|
|
final int color, final Paint paint) {
|
2010-11-24 07:59:56 +00:00
|
|
|
paint.setStyle(Paint.Style.STROKE);
|
|
|
|
paint.setStrokeWidth(1.0f);
|
|
|
|
paint.setColor(color);
|
2013-04-11 03:08:36 +00:00
|
|
|
canvas.drawLine(0.0f, y, w, y, paint);
|
2010-11-24 07:59:56 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 06:34:51 +00:00
|
|
|
private static void drawVerticalLine(final Canvas canvas, final float x, final float h,
|
|
|
|
final int color, final Paint paint) {
|
2010-11-24 07:59:56 +00:00
|
|
|
paint.setStyle(Paint.Style.STROKE);
|
|
|
|
paint.setStrokeWidth(1.0f);
|
|
|
|
paint.setColor(color);
|
2013-04-11 03:08:36 +00:00
|
|
|
canvas.drawLine(x, 0.0f, x, h, paint);
|
2010-11-24 07:59:56 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 06:34:51 +00:00
|
|
|
private static void drawRectangle(final Canvas canvas, final float x, final float y,
|
|
|
|
final float w, final float h, final int color, final Paint paint) {
|
2010-11-24 07:59:56 +00:00
|
|
|
paint.setStyle(Paint.Style.STROKE);
|
|
|
|
paint.setStrokeWidth(1.0f);
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas.translate(x, y);
|
2013-04-11 03:08:36 +00:00
|
|
|
canvas.drawRect(0.0f, 0.0f, w, h, paint);
|
2010-11-24 07:59:56 +00:00
|
|
|
canvas.translate(-x, -y);
|
|
|
|
}
|
|
|
|
|
2013-04-11 03:08:36 +00:00
|
|
|
public Paint newLabelPaint(final Key key) {
|
2012-03-16 07:41:18 +00:00
|
|
|
final Paint paint = new Paint();
|
|
|
|
paint.setAntiAlias(true);
|
2013-04-11 03:08:36 +00:00
|
|
|
if (key == null) {
|
|
|
|
paint.setTypeface(mKeyDrawParams.mTypeface);
|
|
|
|
paint.setTextSize(mKeyDrawParams.mLabelSize);
|
|
|
|
} else {
|
|
|
|
paint.setTypeface(key.selectTypeface(mKeyDrawParams));
|
|
|
|
paint.setTextSize(key.selectTextSize(mKeyDrawParams));
|
|
|
|
}
|
2012-03-16 07:41:18 +00:00
|
|
|
return paint;
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/**
|
|
|
|
* Requests a redraw of the entire keyboard. Calling {@link #invalidate} is not sufficient
|
|
|
|
* because the keyboard renders the keys to an off-screen buffer and an invalidate() only
|
|
|
|
* draws the cached buffer.
|
2010-08-31 11:21:45 +00:00
|
|
|
* @see #invalidateKey(Key)
|
2010-08-20 05:35:02 +00:00
|
|
|
*/
|
|
|
|
public void invalidateAllKeys() {
|
2012-03-13 08:28:52 +00:00
|
|
|
mInvalidatedKeys.clear();
|
|
|
|
mInvalidateAllKeys = true;
|
2010-08-20 05:35:02 +00:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidates a key so that it will be redrawn on the next repaint. Use this method if only
|
|
|
|
* one key is changing it's content. Any changes that affect the position or size of the key
|
|
|
|
* may not be honored.
|
2010-12-02 09:46:21 +00:00
|
|
|
* @param key key in the attached {@link Keyboard}.
|
2010-08-20 05:35:02 +00:00
|
|
|
* @see #invalidateAllKeys
|
|
|
|
*/
|
2012-09-05 06:34:51 +00:00
|
|
|
public void invalidateKey(final Key key) {
|
2012-03-13 08:28:52 +00:00
|
|
|
if (mInvalidateAllKeys) return;
|
|
|
|
if (key == null) return;
|
|
|
|
mInvalidatedKeys.add(key);
|
2013-08-12 09:05:11 +00:00
|
|
|
final int x = key.getX() + getPaddingLeft();
|
|
|
|
final int y = key.getY() + getPaddingTop();
|
|
|
|
invalidate(x, y, x + key.getWidth(), y + key.getHeight());
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-09-27 06:18:02 +00:00
|
|
|
protected void onDetachedFromWindow() {
|
2010-08-20 05:35:02 +00:00
|
|
|
super.onDetachedFromWindow();
|
2012-08-02 06:10:59 +00:00
|
|
|
freeOffscreenBuffer();
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2013-08-01 09:01:48 +00:00
|
|
|
|
|
|
|
public void deallocateMemory() {
|
|
|
|
freeOffscreenBuffer();
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|