am 38d6a188: Use String instaed of CharSequence in Key class

* commit '38d6a18821794dc733760b55fd2a896626f784e2':
  Use String instaed of CharSequence in Key class
main
Tadashi G. Takaoka 2012-01-25 00:13:40 -08:00 committed by Android Git Automerger
commit 71aba3d2fb
6 changed files with 36 additions and 37 deletions

View File

@ -52,9 +52,9 @@ public class Key {
public final int mAltCode;
/** Label to display */
public final CharSequence mLabel;
public final String mLabel;
/** Hint label to display on the key in conjunction with the label */
public final CharSequence mHintLabel;
public final String mHintLabel;
/** Flags of the label */
private final int mLabelFlags;
private static final int LABEL_FLAGS_ALIGN_LEFT = 0x01;
@ -187,7 +187,7 @@ public class Key {
/**
* This constructor is being used only for key in popup suggestions pane.
*/
public Key(Keyboard.Params params, CharSequence label, CharSequence hintLabel, Drawable icon,
public Key(Keyboard.Params params, String label, String hintLabel, Drawable icon,
int code, CharSequence outputText, int x, int y, int width, int height) {
mHeight = height - params.mVerticalGap;
mHorizontalGap = params.mHorizontalGap;
@ -260,7 +260,7 @@ public class Key {
// Update row to have current x coordinate.
row.setXPos(keyXPos + keyWidth);
final String[] moreKeys = style.getTextArray(keyAttr,
final String[] moreKeys = style.getStringArray(keyAttr,
R.styleable.Keyboard_Key_moreKeys);
// In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
// config_digit_more_keys_enabled.
@ -291,11 +291,11 @@ public class Key {
final int disabledIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED));
mDisabledIcon = iconsSet.getIconByAttrId(disabledIconAttrId);
mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
mHintLabel = style.getString(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
mLabel = style.getString(keyAttr, R.styleable.Keyboard_Key_keyLabel);
mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags, 0);
mOutputText = style.getText(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
mOutputText = style.getString(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
// Choose the first letter of the label as primary code if not
// specified.
final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code,

View File

@ -245,10 +245,10 @@ public class Keyboard {
}
// TODO: Remove this method.
public CharSequence adjustLabelCase(CharSequence label) {
public String adjustLabelCase(String label) {
if (mId.isAlphabetKeyboard() && isShiftedOrShiftLocked() && !TextUtils.isEmpty(label)
&& label.length() < 3 && Character.isLowerCase(label.charAt(0))) {
return label.toString().toUpperCase(mId.mLocale);
return label.toUpperCase(mId.mLocale);
}
return label;
}

View File

@ -557,7 +557,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
float positionX = centerX;
if (key.mLabel != null) {
// Switch the character to uppercase if shift is pressed
final CharSequence label = mKeyboard.adjustLabelCase(key.mLabel);
final String label = mKeyboard.adjustLabelCase(key.mLabel);
// For characters, use large font. For labels like "Done", use smaller font.
paint.setTypeface(key.selectTypeface(params.mKeyTextStyle));
final int labelSize = key.selectTextSize(params.mKeyLetterSize,
@ -639,7 +639,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
// Draw hint label.
if (key.mHintLabel != null) {
final CharSequence hint = key.mHintLabel;
final String hint = key.mHintLabel;
final int hintColor;
final int hintSize;
if (key.hasHintLabel()) {
@ -778,12 +778,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
return width;
}
private static float getLabelWidth(CharSequence label, Paint paint) {
private static float getLabelWidth(String label, Paint paint) {
paint.getTextBounds(label.toString(), 0, label.length(), sTextBounds);
return sTextBounds.width();
}
public float getDefaultLabelWidth(CharSequence label, Paint paint) {
public float getDefaultLabelWidth(String label, Paint paint) {
paint.setTextSize(mKeyDrawParams.mKeyLabelSize);
paint.setTypeface(mKeyDrawParams.mKeyTextStyle);
return getLabelWidth(label, paint);

View File

@ -40,8 +40,8 @@ public class KeyStyles {
private static final KeyStyle EMPTY_KEY_STYLE = new EmptyKeyStyle();
public interface KeyStyle {
public String[] getTextArray(TypedArray a, int index);
public CharSequence getText(TypedArray a, int index);
public String[] getStringArray(TypedArray a, int index);
public String getString(TypedArray a, int index);
public int getInt(TypedArray a, int index, int defaultValue);
public int getFlag(TypedArray a, int index, int defaultValue);
}
@ -52,13 +52,13 @@ public class KeyStyles {
}
@Override
public String[] getTextArray(TypedArray a, int index) {
return parseTextArray(a, index);
public String[] getStringArray(TypedArray a, int index) {
return parseStringArray(a, index);
}
@Override
public CharSequence getText(TypedArray a, int index) {
return a.getText(index);
public String getString(TypedArray a, int index) {
return a.getString(index);
}
@Override
@ -71,16 +71,15 @@ public class KeyStyles {
return a.getInt(index, defaultValue);
}
protected static String[] parseTextArray(TypedArray a, int index) {
protected static String[] parseStringArray(TypedArray a, int index) {
if (!a.hasValue(index))
return null;
final CharSequence text = a.getText(index);
return parseCsvText(text.toString(), a.getResources(), R.string.english_ime_name);
return parseCsvString(a.getString(index), a.getResources(), R.string.english_ime_name);
}
}
/* package for test */
static String[] parseCsvText(String rawText, Resources res, int packageNameResId) {
static String[] parseCsvString(String rawText, Resources res, int packageNameResId) {
final String text = Utils.resolveStringResource(rawText, res, packageNameResId);
final int size = text.length();
if (size == 0) {
@ -139,15 +138,15 @@ public class KeyStyles {
private final HashMap<Integer, Object> mAttributes = new HashMap<Integer, Object>();
@Override
public String[] getTextArray(TypedArray a, int index) {
public String[] getStringArray(TypedArray a, int index) {
return a.hasValue(index)
? super.getTextArray(a, index) : (String[])mAttributes.get(index);
? super.getStringArray(a, index) : (String[])mAttributes.get(index);
}
@Override
public CharSequence getText(TypedArray a, int index) {
public String getString(TypedArray a, int index) {
return a.hasValue(index)
? super.getText(a, index) : (CharSequence)mAttributes.get(index);
? super.getString(a, index) : (String)mAttributes.get(index);
}
@Override
@ -170,10 +169,10 @@ public class KeyStyles {
// TODO: Currently not all Key attributes can be declared as style.
readInt(keyAttr, R.styleable.Keyboard_Key_code);
readInt(keyAttr, R.styleable.Keyboard_Key_altCode);
readText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
readText(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
readText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
readTextArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
readString(keyAttr, R.styleable.Keyboard_Key_keyLabel);
readString(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
readString(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
readStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIcon);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled);
@ -183,9 +182,9 @@ public class KeyStyles {
readFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags);
}
private void readText(TypedArray a, int index) {
private void readString(TypedArray a, int index) {
if (a.hasValue(index))
mAttributes.put(index, a.getText(index));
mAttributes.put(index, a.getString(index));
}
private void readInt(TypedArray a, int index) {
@ -199,8 +198,8 @@ public class KeyStyles {
mAttributes.put(index, a.getInt(index, 0) | (value != null ? value : 0));
}
private void readTextArray(TypedArray a, int index) {
final CharSequence[] value = parseTextArray(a, index);
private void readStringArray(TypedArray a, int index) {
final String[] value = parseStringArray(a, index);
if (value != null)
mAttributes.put(index, value);
}

View File

@ -72,7 +72,7 @@ public class MoreSuggestions extends Keyboard {
int pos = fromPos, rowStartPos = fromPos;
final int size = Math.min(suggestions.size(), SuggestionsView.MAX_SUGGESTIONS);
while (pos < size) {
final CharSequence word = suggestions.getWord(pos);
final String word = suggestions.getWord(pos).toString();
// TODO: Should take care of text x-scaling.
mWidths[pos] = (int)view.getDefaultLabelWidth(word, paint) + padding;
final int numColumn = pos - rowStartPos + 1;

View File

@ -39,7 +39,7 @@ public class KeyStylesTests extends AndroidTestCase {
}
private void assertTextArray(String message, String value, String ... expected) {
final String actual[] = KeyStyles.parseCsvText(value, mTestResources,
final String actual[] = KeyStyles.parseCsvString(value, mTestResources,
R.string.empty_string);
if (expected.length == 0) {
assertNull(message, actual);