am 49d8af8a: Separate inner classes of KeyboardView out under internal package
* commit '49d8af8a4e900f3c68c333aba7fde0a11fd368b1': Separate inner classes of KeyboardView out under internal packagemain
commit
92a2c9b644
|
@ -38,12 +38,13 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
|
||||||
|
import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
|
||||||
import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
|
import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
|
||||||
import com.android.inputmethod.latin.CollectionUtils;
|
import com.android.inputmethod.latin.CollectionUtils;
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.ResourceUtils;
|
|
||||||
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
||||||
import com.android.inputmethod.latin.StringUtils;
|
import com.android.inputmethod.latin.StringUtils;
|
||||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||||
|
@ -179,224 +180,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move this class to internal package
|
|
||||||
protected static class KeyDrawParams {
|
|
||||||
// XML attributes
|
|
||||||
public final int mKeyTextColor;
|
|
||||||
public final int mKeyTextInactivatedColor;
|
|
||||||
public final float mKeyLabelHorizontalPadding;
|
|
||||||
public final float mKeyHintLetterPadding;
|
|
||||||
public final float mKeyPopupHintLetterPadding;
|
|
||||||
public final float mKeyShiftedLetterHintPadding;
|
|
||||||
public final int mKeyTextShadowColor;
|
|
||||||
public final float mKeyTextShadowRadius;
|
|
||||||
public final Drawable mKeyBackground;
|
|
||||||
public final int mKeyHintLetterColor;
|
|
||||||
public final int mKeyHintLabelColor;
|
|
||||||
public final int mKeyShiftedLetterHintInactivatedColor;
|
|
||||||
public final int mKeyShiftedLetterHintActivatedColor;
|
|
||||||
|
|
||||||
private final Typeface mKeyTypefaceFromKeyboardView;
|
|
||||||
private final float mKeyLetterRatio;
|
|
||||||
private final int mKeyLetterSizeFromKeyboardView;
|
|
||||||
private final float mKeyLargeLetterRatio;
|
|
||||||
private final float mKeyLabelRatio;
|
|
||||||
private final float mKeyLargeLabelRatio;
|
|
||||||
private final float mKeyHintLetterRatio;
|
|
||||||
private final float mKeyShiftedLetterHintRatio;
|
|
||||||
private final float mKeyHintLabelRatio;
|
|
||||||
|
|
||||||
public final Rect mPadding = new Rect();
|
|
||||||
public Typeface mKeyTypeface;
|
|
||||||
public int mKeyLetterSize;
|
|
||||||
public int mKeyLargeLetterSize;
|
|
||||||
public int mKeyLabelSize;
|
|
||||||
public int mKeyLargeLabelSize;
|
|
||||||
public int mKeyHintLetterSize;
|
|
||||||
public int mKeyShiftedLetterHintSize;
|
|
||||||
public int mKeyHintLabelSize;
|
|
||||||
public int mAnimAlpha;
|
|
||||||
|
|
||||||
public KeyDrawParams(final TypedArray keyboardViewAttr, final TypedArray keyAttr) {
|
|
||||||
mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground);
|
|
||||||
mKeyBackground.getPadding(mPadding);
|
|
||||||
|
|
||||||
mKeyLetterRatio = ResourceUtils.getFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyLetterSize);
|
|
||||||
mKeyLetterSizeFromKeyboardView = ResourceUtils.getDimensionPixelSize(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyLetterSize);
|
|
||||||
mKeyLabelRatio = ResourceUtils.getFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyLabelSize);
|
|
||||||
mKeyLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyLabelSize);
|
|
||||||
mKeyLargeLabelRatio = ResourceUtils.getFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyLargeLabelRatio);
|
|
||||||
mKeyLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyLargeLetterRatio);
|
|
||||||
mKeyHintLetterRatio = ResourceUtils.getFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyHintLetterRatio);
|
|
||||||
mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
|
|
||||||
mKeyHintLabelRatio = ResourceUtils.getFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyHintLabelRatio);
|
|
||||||
mKeyLabelHorizontalPadding = keyAttr.getDimension(
|
|
||||||
R.styleable.Keyboard_Key_keyLabelHorizontalPadding, 0);
|
|
||||||
mKeyHintLetterPadding = keyAttr.getDimension(
|
|
||||||
R.styleable.Keyboard_Key_keyHintLetterPadding, 0);
|
|
||||||
mKeyPopupHintLetterPadding = keyAttr.getDimension(
|
|
||||||
R.styleable.Keyboard_Key_keyPopupHintLetterPadding, 0);
|
|
||||||
mKeyShiftedLetterHintPadding = keyAttr.getDimension(
|
|
||||||
R.styleable.Keyboard_Key_keyShiftedLetterHintPadding, 0);
|
|
||||||
mKeyTextColor = keyAttr.getColor(
|
|
||||||
R.styleable.Keyboard_Key_keyTextColor, Color.WHITE);
|
|
||||||
mKeyTextInactivatedColor = keyAttr.getColor(
|
|
||||||
R.styleable.Keyboard_Key_keyTextInactivatedColor, Color.WHITE);
|
|
||||||
mKeyHintLetterColor = keyAttr.getColor(
|
|
||||||
R.styleable.Keyboard_Key_keyHintLetterColor, Color.TRANSPARENT);
|
|
||||||
mKeyHintLabelColor = keyAttr.getColor(
|
|
||||||
R.styleable.Keyboard_Key_keyHintLabelColor, Color.TRANSPARENT);
|
|
||||||
mKeyShiftedLetterHintInactivatedColor = keyAttr.getColor(
|
|
||||||
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor,
|
|
||||||
Color.TRANSPARENT);
|
|
||||||
mKeyShiftedLetterHintActivatedColor = keyAttr.getColor(
|
|
||||||
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, Color.TRANSPARENT);
|
|
||||||
mKeyTypefaceFromKeyboardView = Typeface.defaultFromStyle(
|
|
||||||
keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
|
|
||||||
mKeyTextShadowColor = keyAttr.getColor(
|
|
||||||
R.styleable.Keyboard_Key_keyTextShadowColor, Color.TRANSPARENT);
|
|
||||||
mKeyTextShadowRadius = keyAttr.getFloat(
|
|
||||||
R.styleable.Keyboard_Key_keyTextShadowRadius, 0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateParams(final Keyboard keyboard) {
|
|
||||||
mKeyTypeface = (keyboard.mKeyTypeface != null)
|
|
||||||
? keyboard.mKeyTypeface : mKeyTypefaceFromKeyboardView;
|
|
||||||
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
|
||||||
mKeyLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight,
|
|
||||||
mKeyLetterSizeFromKeyboardView, mKeyLetterRatio,
|
|
||||||
mKeyLetterSizeFromKeyboardView);
|
|
||||||
// Override if size/ratio is specified in Keyboard.
|
|
||||||
mKeyLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight, keyboard.mKeyLetterSize,
|
|
||||||
keyboard.mKeyLetterRatio, mKeyLetterSize);
|
|
||||||
if (ResourceUtils.isValidFraction(mKeyLabelRatio)) {
|
|
||||||
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
|
|
||||||
}
|
|
||||||
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
|
|
||||||
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio);
|
|
||||||
mKeyHintLetterSize = selectTextSizeFromKeyboardOrView(keyHeight,
|
|
||||||
keyboard.mKeyHintLetterRatio, mKeyHintLetterRatio);
|
|
||||||
mKeyShiftedLetterHintSize = selectTextSizeFromKeyboardOrView(keyHeight,
|
|
||||||
keyboard.mKeyShiftedLetterHintRatio, mKeyShiftedLetterHintRatio);
|
|
||||||
mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int selectTextSizeFromDimensionOrRatio(final int keyHeight,
|
|
||||||
final int dimens, final float ratio, final int defaultDimens) {
|
|
||||||
if (ResourceUtils.isValidDimensionPixelSize(dimens)) {
|
|
||||||
return dimens;
|
|
||||||
}
|
|
||||||
if (ResourceUtils.isValidFraction(ratio)) {
|
|
||||||
return (int)(keyHeight * ratio);
|
|
||||||
}
|
|
||||||
return defaultDimens;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int selectTextSizeFromKeyboardOrView(final int keyHeight,
|
|
||||||
final float ratioFromKeyboard, final float ratioFromView) {
|
|
||||||
final float ratio = ResourceUtils.isValidFraction(ratioFromKeyboard)
|
|
||||||
? ratioFromKeyboard : ratioFromView;
|
|
||||||
return (int)(keyHeight * ratio);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void blendAlpha(final Paint paint) {
|
|
||||||
final int color = paint.getColor();
|
|
||||||
paint.setARGB((paint.getAlpha() * mAnimAlpha) / Constants.Color.ALPHA_OPAQUE,
|
|
||||||
Color.red(color), Color.green(color), Color.blue(color));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Move this class to internal package.
|
|
||||||
/* package */ static class KeyPreviewDrawParams {
|
|
||||||
// XML attributes.
|
|
||||||
public final Drawable mPreviewBackground;
|
|
||||||
public final Drawable mPreviewLeftBackground;
|
|
||||||
public final Drawable mPreviewRightBackground;
|
|
||||||
public final int mPreviewTextColor;
|
|
||||||
public final int mPreviewOffset;
|
|
||||||
public final int mPreviewHeight;
|
|
||||||
public final int mLingerTimeout;
|
|
||||||
|
|
||||||
private final float mPreviewTextRatio;
|
|
||||||
|
|
||||||
// The graphical geometry of the key preview.
|
|
||||||
// <-width->
|
|
||||||
// +-------+ ^
|
|
||||||
// | | |
|
|
||||||
// |preview| height (visible)
|
|
||||||
// | | |
|
|
||||||
// + + ^ v
|
|
||||||
// \ / |offset
|
|
||||||
// +-\ /-+ v
|
|
||||||
// | +-+ |
|
|
||||||
// |parent |
|
|
||||||
// | key|
|
|
||||||
// +-------+
|
|
||||||
// The background of a {@link TextView} being used for a key preview may have invisible
|
|
||||||
// paddings. To align the more keys keyboard panel's visible part with the visible part of
|
|
||||||
// the background, we need to record the width and height of key preview that don't include
|
|
||||||
// invisible paddings.
|
|
||||||
public int mPreviewVisibleWidth;
|
|
||||||
public int mPreviewVisibleHeight;
|
|
||||||
// The key preview may have an arbitrary offset and its background that may have a bottom
|
|
||||||
// padding. To align the more keys keyboard and the key preview we also need to record the
|
|
||||||
// offset between the top edge of parent key and the bottom of the visible part of key
|
|
||||||
// preview background.
|
|
||||||
public int mPreviewVisibleOffset;
|
|
||||||
|
|
||||||
public Typeface mKeyTypeface;
|
|
||||||
public int mPreviewTextSize;
|
|
||||||
public int mKeyLetterSize;
|
|
||||||
public final int[] mCoordinates = new int[2];
|
|
||||||
|
|
||||||
private static final int PREVIEW_ALPHA = 240;
|
|
||||||
|
|
||||||
public KeyPreviewDrawParams(final TypedArray keyboardViewAttr, final TypedArray keyAttr) {
|
|
||||||
mPreviewBackground = keyboardViewAttr.getDrawable(
|
|
||||||
R.styleable.KeyboardView_keyPreviewBackground);
|
|
||||||
mPreviewLeftBackground = keyboardViewAttr.getDrawable(
|
|
||||||
R.styleable.KeyboardView_keyPreviewLeftBackground);
|
|
||||||
mPreviewRightBackground = keyboardViewAttr.getDrawable(
|
|
||||||
R.styleable.KeyboardView_keyPreviewRightBackground);
|
|
||||||
setAlpha(mPreviewBackground, PREVIEW_ALPHA);
|
|
||||||
setAlpha(mPreviewLeftBackground, PREVIEW_ALPHA);
|
|
||||||
setAlpha(mPreviewRightBackground, PREVIEW_ALPHA);
|
|
||||||
mPreviewOffset = keyboardViewAttr.getDimensionPixelOffset(
|
|
||||||
R.styleable.KeyboardView_keyPreviewOffset, 0);
|
|
||||||
mPreviewHeight = keyboardViewAttr.getDimensionPixelSize(
|
|
||||||
R.styleable.KeyboardView_keyPreviewHeight, 80);
|
|
||||||
mLingerTimeout = keyboardViewAttr.getInt(
|
|
||||||
R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
|
|
||||||
|
|
||||||
mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyPreviewTextRatio);
|
|
||||||
mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateParams(final Keyboard keyboard, final KeyDrawParams keyDrawParams) {
|
|
||||||
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
|
||||||
if (ResourceUtils.isValidFraction(mPreviewTextRatio)) {
|
|
||||||
mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio);
|
|
||||||
}
|
|
||||||
mKeyLetterSize = keyDrawParams.mKeyLetterSize;
|
|
||||||
mKeyTypeface = keyDrawParams.mKeyTypeface;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setAlpha(final Drawable drawable, final int alpha) {
|
|
||||||
if (drawable == null) return;
|
|
||||||
drawable.setAlpha(alpha);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public KeyboardView(Context context, AttributeSet attrs) {
|
public KeyboardView(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, R.attr.keyboardViewStyle);
|
this(context, attrs, R.attr.keyboardViewStyle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import com.android.inputmethod.accessibility.AccessibilityUtils;
|
||||||
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
||||||
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
|
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
|
||||||
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
||||||
|
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
|
||||||
import com.android.inputmethod.keyboard.internal.SuddenJumpingTouchEventHandler;
|
import com.android.inputmethod.keyboard.internal.SuddenJumpingTouchEventHandler;
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
import com.android.inputmethod.latin.LatinIME;
|
import com.android.inputmethod.latin.LatinIME;
|
||||||
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 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.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
|
import com.android.inputmethod.latin.Constants;
|
||||||
|
import com.android.inputmethod.latin.R;
|
||||||
|
import com.android.inputmethod.latin.ResourceUtils;
|
||||||
|
|
||||||
|
public class KeyDrawParams {
|
||||||
|
// XML attributes
|
||||||
|
public final int mKeyTextColor;
|
||||||
|
public final int mKeyTextInactivatedColor;
|
||||||
|
public final float mKeyLabelHorizontalPadding;
|
||||||
|
public final float mKeyHintLetterPadding;
|
||||||
|
public final float mKeyPopupHintLetterPadding;
|
||||||
|
public final float mKeyShiftedLetterHintPadding;
|
||||||
|
public final int mKeyTextShadowColor;
|
||||||
|
public final float mKeyTextShadowRadius;
|
||||||
|
public final Drawable mKeyBackground;
|
||||||
|
public final int mKeyHintLetterColor;
|
||||||
|
public final int mKeyHintLabelColor;
|
||||||
|
public final int mKeyShiftedLetterHintInactivatedColor;
|
||||||
|
public final int mKeyShiftedLetterHintActivatedColor;
|
||||||
|
|
||||||
|
private final Typeface mKeyTypefaceFromKeyboardView;
|
||||||
|
private final float mKeyLetterRatio;
|
||||||
|
private final int mKeyLetterSizeFromKeyboardView;
|
||||||
|
private final float mKeyLargeLetterRatio;
|
||||||
|
private final float mKeyLabelRatio;
|
||||||
|
private final float mKeyLargeLabelRatio;
|
||||||
|
private final float mKeyHintLetterRatio;
|
||||||
|
private final float mKeyShiftedLetterHintRatio;
|
||||||
|
private final float mKeyHintLabelRatio;
|
||||||
|
|
||||||
|
public final Rect mPadding = new Rect();
|
||||||
|
public Typeface mKeyTypeface;
|
||||||
|
public int mKeyLetterSize;
|
||||||
|
public int mKeyLargeLetterSize;
|
||||||
|
public int mKeyLabelSize;
|
||||||
|
public int mKeyLargeLabelSize;
|
||||||
|
public int mKeyHintLetterSize;
|
||||||
|
public int mKeyShiftedLetterHintSize;
|
||||||
|
public int mKeyHintLabelSize;
|
||||||
|
public int mAnimAlpha;
|
||||||
|
|
||||||
|
public KeyDrawParams(final TypedArray keyboardViewAttr, final TypedArray keyAttr) {
|
||||||
|
mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground);
|
||||||
|
mKeyBackground.getPadding(mPadding);
|
||||||
|
|
||||||
|
mKeyLetterRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyLetterSize);
|
||||||
|
mKeyLetterSizeFromKeyboardView = ResourceUtils.getDimensionPixelSize(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyLetterSize);
|
||||||
|
mKeyLabelRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyLabelSize);
|
||||||
|
mKeyLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyLabelSize);
|
||||||
|
mKeyLargeLabelRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyLargeLabelRatio);
|
||||||
|
mKeyLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyLargeLetterRatio);
|
||||||
|
mKeyHintLetterRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyHintLetterRatio);
|
||||||
|
mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
|
||||||
|
mKeyHintLabelRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyHintLabelRatio);
|
||||||
|
mKeyLabelHorizontalPadding = keyAttr.getDimension(
|
||||||
|
R.styleable.Keyboard_Key_keyLabelHorizontalPadding, 0);
|
||||||
|
mKeyHintLetterPadding = keyAttr.getDimension(
|
||||||
|
R.styleable.Keyboard_Key_keyHintLetterPadding, 0);
|
||||||
|
mKeyPopupHintLetterPadding = keyAttr.getDimension(
|
||||||
|
R.styleable.Keyboard_Key_keyPopupHintLetterPadding, 0);
|
||||||
|
mKeyShiftedLetterHintPadding = keyAttr.getDimension(
|
||||||
|
R.styleable.Keyboard_Key_keyShiftedLetterHintPadding, 0);
|
||||||
|
mKeyTextColor = keyAttr.getColor(
|
||||||
|
R.styleable.Keyboard_Key_keyTextColor, Color.WHITE);
|
||||||
|
mKeyTextInactivatedColor = keyAttr.getColor(
|
||||||
|
R.styleable.Keyboard_Key_keyTextInactivatedColor, Color.WHITE);
|
||||||
|
mKeyHintLetterColor = keyAttr.getColor(
|
||||||
|
R.styleable.Keyboard_Key_keyHintLetterColor, Color.TRANSPARENT);
|
||||||
|
mKeyHintLabelColor = keyAttr.getColor(
|
||||||
|
R.styleable.Keyboard_Key_keyHintLabelColor, Color.TRANSPARENT);
|
||||||
|
mKeyShiftedLetterHintInactivatedColor = keyAttr.getColor(
|
||||||
|
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, Color.TRANSPARENT);
|
||||||
|
mKeyShiftedLetterHintActivatedColor = keyAttr.getColor(
|
||||||
|
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, Color.TRANSPARENT);
|
||||||
|
mKeyTypefaceFromKeyboardView = Typeface.defaultFromStyle(
|
||||||
|
keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
|
||||||
|
mKeyTextShadowColor = keyAttr.getColor(
|
||||||
|
R.styleable.Keyboard_Key_keyTextShadowColor, Color.TRANSPARENT);
|
||||||
|
mKeyTextShadowRadius = keyAttr.getFloat(
|
||||||
|
R.styleable.Keyboard_Key_keyTextShadowRadius, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateParams(final Keyboard keyboard) {
|
||||||
|
mKeyTypeface = (keyboard.mKeyTypeface != null)
|
||||||
|
? keyboard.mKeyTypeface : mKeyTypefaceFromKeyboardView;
|
||||||
|
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
||||||
|
mKeyLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight,
|
||||||
|
mKeyLetterSizeFromKeyboardView, mKeyLetterRatio,
|
||||||
|
mKeyLetterSizeFromKeyboardView);
|
||||||
|
// Override if size/ratio is specified in Keyboard.
|
||||||
|
mKeyLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight, keyboard.mKeyLetterSize,
|
||||||
|
keyboard.mKeyLetterRatio, mKeyLetterSize);
|
||||||
|
if (ResourceUtils.isValidFraction(mKeyLabelRatio)) {
|
||||||
|
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
|
||||||
|
}
|
||||||
|
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
|
||||||
|
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio);
|
||||||
|
mKeyHintLetterSize = selectTextSizeFromKeyboardOrView(keyHeight,
|
||||||
|
keyboard.mKeyHintLetterRatio, mKeyHintLetterRatio);
|
||||||
|
mKeyShiftedLetterHintSize = selectTextSizeFromKeyboardOrView(keyHeight,
|
||||||
|
keyboard.mKeyShiftedLetterHintRatio, mKeyShiftedLetterHintRatio);
|
||||||
|
mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int selectTextSizeFromDimensionOrRatio(final int keyHeight,
|
||||||
|
final int dimens, final float ratio, final int defaultDimens) {
|
||||||
|
if (ResourceUtils.isValidDimensionPixelSize(dimens)) {
|
||||||
|
return dimens;
|
||||||
|
}
|
||||||
|
if (ResourceUtils.isValidFraction(ratio)) {
|
||||||
|
return (int)(keyHeight * ratio);
|
||||||
|
}
|
||||||
|
return defaultDimens;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int selectTextSizeFromKeyboardOrView(final int keyHeight,
|
||||||
|
final float ratioFromKeyboard, final float ratioFromView) {
|
||||||
|
final float ratio = ResourceUtils.isValidFraction(ratioFromKeyboard)
|
||||||
|
? ratioFromKeyboard : ratioFromView;
|
||||||
|
return (int)(keyHeight * ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void blendAlpha(final Paint paint) {
|
||||||
|
final int color = paint.getColor();
|
||||||
|
paint.setARGB((paint.getAlpha() * mAnimAlpha) / Constants.Color.ALPHA_OPAQUE,
|
||||||
|
Color.red(color), Color.green(color), Color.blue(color));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 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.Typeface;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
|
import com.android.inputmethod.latin.R;
|
||||||
|
import com.android.inputmethod.latin.ResourceUtils;
|
||||||
|
|
||||||
|
public class KeyPreviewDrawParams {
|
||||||
|
// XML attributes.
|
||||||
|
public final Drawable mPreviewBackground;
|
||||||
|
public final Drawable mPreviewLeftBackground;
|
||||||
|
public final Drawable mPreviewRightBackground;
|
||||||
|
public final int mPreviewTextColor;
|
||||||
|
public final int mPreviewOffset;
|
||||||
|
public final int mPreviewHeight;
|
||||||
|
public final int mLingerTimeout;
|
||||||
|
|
||||||
|
private final float mPreviewTextRatio;
|
||||||
|
|
||||||
|
// The graphical geometry of the key preview.
|
||||||
|
// <-width->
|
||||||
|
// +-------+ ^
|
||||||
|
// | | |
|
||||||
|
// |preview| height (visible)
|
||||||
|
// | | |
|
||||||
|
// + + ^ v
|
||||||
|
// \ / |offset
|
||||||
|
// +-\ /-+ v
|
||||||
|
// | +-+ |
|
||||||
|
// |parent |
|
||||||
|
// | key|
|
||||||
|
// +-------+
|
||||||
|
// The background of a {@link TextView} being used for a key preview may have invisible
|
||||||
|
// paddings. To align the more keys keyboard panel's visible part with the visible part of
|
||||||
|
// the background, we need to record the width and height of key preview that don't include
|
||||||
|
// invisible paddings.
|
||||||
|
public int mPreviewVisibleWidth;
|
||||||
|
public int mPreviewVisibleHeight;
|
||||||
|
// The key preview may have an arbitrary offset and its background that may have a bottom
|
||||||
|
// padding. To align the more keys keyboard and the key preview we also need to record the
|
||||||
|
// offset between the top edge of parent key and the bottom of the visible part of key
|
||||||
|
// preview background.
|
||||||
|
public int mPreviewVisibleOffset;
|
||||||
|
|
||||||
|
public Typeface mKeyTypeface;
|
||||||
|
public int mPreviewTextSize;
|
||||||
|
public int mKeyLetterSize;
|
||||||
|
public final int[] mCoordinates = new int[2];
|
||||||
|
|
||||||
|
private static final int PREVIEW_ALPHA = 240;
|
||||||
|
|
||||||
|
public KeyPreviewDrawParams(final TypedArray keyboardViewAttr, final TypedArray keyAttr) {
|
||||||
|
mPreviewBackground = keyboardViewAttr.getDrawable(
|
||||||
|
R.styleable.KeyboardView_keyPreviewBackground);
|
||||||
|
mPreviewLeftBackground = keyboardViewAttr.getDrawable(
|
||||||
|
R.styleable.KeyboardView_keyPreviewLeftBackground);
|
||||||
|
mPreviewRightBackground = keyboardViewAttr.getDrawable(
|
||||||
|
R.styleable.KeyboardView_keyPreviewRightBackground);
|
||||||
|
setAlpha(mPreviewBackground, PREVIEW_ALPHA);
|
||||||
|
setAlpha(mPreviewLeftBackground, PREVIEW_ALPHA);
|
||||||
|
setAlpha(mPreviewRightBackground, PREVIEW_ALPHA);
|
||||||
|
mPreviewOffset = keyboardViewAttr.getDimensionPixelOffset(
|
||||||
|
R.styleable.KeyboardView_keyPreviewOffset, 0);
|
||||||
|
mPreviewHeight = keyboardViewAttr.getDimensionPixelSize(
|
||||||
|
R.styleable.KeyboardView_keyPreviewHeight, 80);
|
||||||
|
mLingerTimeout = keyboardViewAttr.getInt(
|
||||||
|
R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
|
||||||
|
|
||||||
|
mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyPreviewTextRatio);
|
||||||
|
mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateParams(final Keyboard keyboard, final KeyDrawParams keyDrawParams) {
|
||||||
|
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
||||||
|
if (ResourceUtils.isValidFraction(mPreviewTextRatio)) {
|
||||||
|
mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio);
|
||||||
|
}
|
||||||
|
mKeyLetterSize = keyDrawParams.mKeyLetterSize;
|
||||||
|
mKeyTypeface = keyDrawParams.mKeyTypeface;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setAlpha(final Drawable drawable, final int alpha) {
|
||||||
|
if (drawable == null) return;
|
||||||
|
drawable.setAlpha(alpha);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue