am aee147e2: Revert "Make KeyDrawParams and KeyPreviewDrawParams to top level class"

* commit 'aee147e2167b9d5147ec9fc315723bdf2a70eb2c':
  Revert "Make KeyDrawParams and KeyPreviewDrawParams to top level class"
main
Tadashi Takaoka 2012-05-18 01:05:52 -07:00 committed by Android Git Automerger
commit 8906f91550
5 changed files with 185 additions and 245 deletions

View File

@ -31,7 +31,6 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.Xml;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.keyboard.internal.KeySpecParser.MoreKeySpec;
import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
@ -494,7 +493,7 @@ public class Key {
}
}
public int selectTextSize(KeyDrawParams params) {
public int selectTextSize(KeyboardView.KeyDrawParams params) {
switch (mLabelFlags & LABEL_FLAGS_FOLLOW_KEY_TEXT_RATIO_MASK) {
case LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO:
return params.mKeyLargeLetterSize;

View File

@ -37,8 +37,6 @@ import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@ -96,7 +94,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
// The maximum key label width in the proportion to the key width.
private static final float MAX_LABEL_RATIO = 0.90f;
private static final int ALPHA_OPAQUE = 255;
private final static int ALPHA_OPAQUE = 255;
// Main keyboard
private Keyboard mKeyboard;
@ -173,6 +171,184 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
}
protected static class KeyDrawParams {
// XML attributes
public final int mKeyTextColor;
public final int mKeyTextInactivatedColor;
public final Typeface mKeyTextStyle;
public final float mKeyLabelHorizontalPadding;
public final float mKeyHintLetterPadding;
public final float mKeyPopupHintLetterPadding;
public final float mKeyShiftedLetterHintPadding;
public final int mShadowColor;
public final float mShadowRadius;
public final Drawable mKeyBackground;
public final int mKeyHintLetterColor;
public final int mKeyHintLabelColor;
public final int mKeyShiftedLetterHintInactivatedColor;
public final int mKeyShiftedLetterHintActivatedColor;
/* package */ final float mKeyLetterRatio;
private final float mKeyLargeLetterRatio;
private final float mKeyLabelRatio;
private final float mKeyLargeLabelRatio;
private final float mKeyHintLetterRatio;
private final float mKeyShiftedLetterHintRatio;
private final float mKeyHintLabelRatio;
private static final float UNDEFINED_RATIO = -1.0f;
public final Rect mPadding = new Rect();
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(TypedArray a) {
mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground);
if (a.hasValue(R.styleable.KeyboardView_keyLetterSize)) {
mKeyLetterRatio = UNDEFINED_RATIO;
mKeyLetterSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLetterSize, 0);
} else {
mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio);
}
if (a.hasValue(R.styleable.KeyboardView_keyLabelSize)) {
mKeyLabelRatio = UNDEFINED_RATIO;
mKeyLabelSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLabelSize, 0);
} else {
mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio);
}
mKeyLargeLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLabelRatio);
mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio);
mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio);
mKeyShiftedLetterHintRatio = getRatio(a,
R.styleable.KeyboardView_keyShiftedLetterHintRatio);
mKeyHintLabelRatio = getRatio(a, R.styleable.KeyboardView_keyHintLabelRatio);
mKeyLabelHorizontalPadding = a.getDimension(
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
mKeyHintLetterPadding = a.getDimension(
R.styleable.KeyboardView_keyHintLetterPadding, 0);
mKeyPopupHintLetterPadding = a.getDimension(
R.styleable.KeyboardView_keyPopupHintLetterPadding, 0);
mKeyShiftedLetterHintPadding = a.getDimension(
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000);
mKeyTextInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyTextInactivatedColor, 0xFF000000);
mKeyHintLetterColor = a.getColor(R.styleable.KeyboardView_keyHintLetterColor, 0);
mKeyHintLabelColor = a.getColor(R.styleable.KeyboardView_keyHintLabelColor, 0);
mKeyShiftedLetterHintInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyShiftedLetterHintInactivatedColor, 0);
mKeyShiftedLetterHintActivatedColor = a.getColor(
R.styleable.KeyboardView_keyShiftedLetterHintActivatedColor, 0);
mKeyTextStyle = Typeface.defaultFromStyle(
a.getInt(R.styleable.KeyboardView_keyTextStyle, Typeface.NORMAL));
mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, 0);
mShadowRadius = a.getFloat(R.styleable.KeyboardView_shadowRadius, 0f);
mKeyBackground.getPadding(mPadding);
}
public void updateKeyHeight(int keyHeight) {
if (mKeyLetterRatio >= 0.0f)
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
if (mKeyLabelRatio >= 0.0f)
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio);
mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio);
mKeyShiftedLetterHintSize = (int)(keyHeight * mKeyShiftedLetterHintRatio);
mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio);
}
public void blendAlpha(Paint paint) {
final int color = paint.getColor();
paint.setARGB((paint.getAlpha() * mAnimAlpha) / ALPHA_OPAQUE,
Color.red(color), Color.green(color), Color.blue(color));
}
}
/* 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 Typeface mKeyTextStyle;
public final int mLingerTimeout;
private final float mPreviewTextRatio;
private final float mKeyLetterRatio;
// 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 int mPreviewTextSize;
public int mKeyLetterSize;
public final int[] mCoordinates = new int[2];
private static final int PREVIEW_ALPHA = 240;
public KeyPreviewDrawParams(TypedArray a, KeyDrawParams keyDrawParams) {
mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground);
mPreviewLeftBackground = a.getDrawable(
R.styleable.KeyboardView_keyPreviewLeftBackground);
mPreviewRightBackground = a.getDrawable(
R.styleable.KeyboardView_keyPreviewRightBackground);
setAlpha(mPreviewBackground, PREVIEW_ALPHA);
setAlpha(mPreviewLeftBackground, PREVIEW_ALPHA);
setAlpha(mPreviewRightBackground, PREVIEW_ALPHA);
mPreviewOffset = a.getDimensionPixelOffset(
R.styleable.KeyboardView_keyPreviewOffset, 0);
mPreviewHeight = a.getDimensionPixelSize(
R.styleable.KeyboardView_keyPreviewHeight, 80);
mPreviewTextRatio = getRatio(a, R.styleable.KeyboardView_keyPreviewTextRatio);
mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
mLingerTimeout = a.getInt(R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
mKeyLetterRatio = keyDrawParams.mKeyLetterRatio;
mKeyTextStyle = keyDrawParams.mKeyTextStyle;
}
public void updateKeyHeight(int keyHeight) {
mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio);
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
}
private static void setAlpha(Drawable drawable, int alpha) {
if (drawable == null)
return;
drawable.setAlpha(alpha);
}
}
public KeyboardView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.keyboardViewStyle);
}
@ -200,6 +376,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mPaint.setAntiAlias(true);
}
// Read fraction value in TypedArray as float.
/* package */ static float getRatio(TypedArray a, int index) {
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
}
/**
* 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.

View File

@ -43,7 +43,6 @@ import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.latin.ImfUtils;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;

View File

@ -1,133 +0,0 @@
/*
* 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.latin.R;
public class KeyDrawParams {
// XML attributes
public final int mKeyTextColor;
public final int mKeyTextInactivatedColor;
public final Typeface mKeyTextStyle;
public final float mKeyLabelHorizontalPadding;
public final float mKeyHintLetterPadding;
public final float mKeyPopupHintLetterPadding;
public final float mKeyShiftedLetterHintPadding;
public final int mShadowColor;
public final float mShadowRadius;
public final Drawable mKeyBackground;
public final int mKeyHintLetterColor;
public final int mKeyHintLabelColor;
public final int mKeyShiftedLetterHintInactivatedColor;
public final int mKeyShiftedLetterHintActivatedColor;
public final float mKeyLetterRatio;
private final float mKeyLargeLetterRatio;
private final float mKeyLabelRatio;
private final float mKeyLargeLabelRatio;
private final float mKeyHintLetterRatio;
private final float mKeyShiftedLetterHintRatio;
private final float mKeyHintLabelRatio;
private static final float UNDEFINED_RATIO = -1.0f;
public final Rect mPadding = new Rect();
public int mKeyLetterSize;
public int mKeyLargeLetterSize;
public int mKeyLabelSize;
public int mKeyLargeLabelSize;
public int mKeyHintLetterSize;
public int mKeyShiftedLetterHintSize;
public int mKeyHintLabelSize;
public int mAnimAlpha;
private static final int ALPHA_OPAQUE = 255;
public KeyDrawParams(TypedArray a) {
mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground);
if (a.hasValue(R.styleable.KeyboardView_keyLetterSize)) {
mKeyLetterRatio = UNDEFINED_RATIO;
mKeyLetterSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLetterSize, 0);
} else {
mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio);
}
if (a.hasValue(R.styleable.KeyboardView_keyLabelSize)) {
mKeyLabelRatio = UNDEFINED_RATIO;
mKeyLabelSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLabelSize, 0);
} else {
mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio);
}
mKeyLargeLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLabelRatio);
mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio);
mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio);
mKeyShiftedLetterHintRatio = getRatio(a,
R.styleable.KeyboardView_keyShiftedLetterHintRatio);
mKeyHintLabelRatio = getRatio(a, R.styleable.KeyboardView_keyHintLabelRatio);
mKeyLabelHorizontalPadding = a.getDimension(
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
mKeyHintLetterPadding = a.getDimension(
R.styleable.KeyboardView_keyHintLetterPadding, 0);
mKeyPopupHintLetterPadding = a.getDimension(
R.styleable.KeyboardView_keyPopupHintLetterPadding, 0);
mKeyShiftedLetterHintPadding = a.getDimension(
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000);
mKeyTextInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyTextInactivatedColor, 0xFF000000);
mKeyHintLetterColor = a.getColor(R.styleable.KeyboardView_keyHintLetterColor, 0);
mKeyHintLabelColor = a.getColor(R.styleable.KeyboardView_keyHintLabelColor, 0);
mKeyShiftedLetterHintInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyShiftedLetterHintInactivatedColor, 0);
mKeyShiftedLetterHintActivatedColor = a.getColor(
R.styleable.KeyboardView_keyShiftedLetterHintActivatedColor, 0);
mKeyTextStyle = Typeface.defaultFromStyle(
a.getInt(R.styleable.KeyboardView_keyTextStyle, Typeface.NORMAL));
mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, 0);
mShadowRadius = a.getFloat(R.styleable.KeyboardView_shadowRadius, 0f);
mKeyBackground.getPadding(mPadding);
}
public void updateKeyHeight(int keyHeight) {
if (mKeyLetterRatio >= 0.0f)
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
if (mKeyLabelRatio >= 0.0f)
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio);
mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio);
mKeyShiftedLetterHintSize = (int)(keyHeight * mKeyShiftedLetterHintRatio);
mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio);
}
public void blendAlpha(Paint paint) {
final int color = paint.getColor();
paint.setARGB((paint.getAlpha() * mAnimAlpha) / ALPHA_OPAQUE,
Color.red(color), Color.green(color), Color.blue(color));
}
// Read fraction value in TypedArray as float.
private static float getRatio(TypedArray a, int index) {
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
}
}

View File

@ -1,106 +0,0 @@
/*
* 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.latin.R;
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 Typeface mKeyTextStyle;
public final int mLingerTimeout;
private final float mPreviewTextRatio;
private final float mKeyLetterRatio;
// 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 int mPreviewTextSize;
public int mKeyLetterSize;
public final int[] mCoordinates = new int[2];
private static final int PREVIEW_ALPHA = 240;
public KeyPreviewDrawParams(TypedArray a, KeyDrawParams keyDrawParams) {
mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground);
mPreviewLeftBackground = a.getDrawable(
R.styleable.KeyboardView_keyPreviewLeftBackground);
mPreviewRightBackground = a.getDrawable(
R.styleable.KeyboardView_keyPreviewRightBackground);
setAlpha(mPreviewBackground, PREVIEW_ALPHA);
setAlpha(mPreviewLeftBackground, PREVIEW_ALPHA);
setAlpha(mPreviewRightBackground, PREVIEW_ALPHA);
mPreviewOffset = a.getDimensionPixelOffset(
R.styleable.KeyboardView_keyPreviewOffset, 0);
mPreviewHeight = a.getDimensionPixelSize(
R.styleable.KeyboardView_keyPreviewHeight, 80);
mPreviewTextRatio = getRatio(a, R.styleable.KeyboardView_keyPreviewTextRatio);
mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
mLingerTimeout = a.getInt(R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
mKeyLetterRatio = keyDrawParams.mKeyLetterRatio;
mKeyTextStyle = keyDrawParams.mKeyTextStyle;
}
public void updateKeyHeight(int keyHeight) {
mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio);
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
}
private static void setAlpha(Drawable drawable, int alpha) {
if (drawable == null)
return;
drawable.setAlpha(alpha);
}
// Read fraction value in TypedArray as float.
private static float getRatio(TypedArray a, int index) {
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
}
}