am 38d6a188: Use String instaed of CharSequence in Key class
* commit '38d6a18821794dc733760b55fd2a896626f784e2': Use String instaed of CharSequence in Key classmain
commit
71aba3d2fb
|
@ -52,9 +52,9 @@ public class Key {
|
||||||
public final int mAltCode;
|
public final int mAltCode;
|
||||||
|
|
||||||
/** Label to display */
|
/** Label to display */
|
||||||
public final CharSequence mLabel;
|
public final String mLabel;
|
||||||
/** Hint label to display on the key in conjunction with the label */
|
/** Hint label to display on the key in conjunction with the label */
|
||||||
public final CharSequence mHintLabel;
|
public final String mHintLabel;
|
||||||
/** Flags of the label */
|
/** Flags of the label */
|
||||||
private final int mLabelFlags;
|
private final int mLabelFlags;
|
||||||
private static final int LABEL_FLAGS_ALIGN_LEFT = 0x01;
|
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.
|
* 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) {
|
int code, CharSequence outputText, int x, int y, int width, int height) {
|
||||||
mHeight = height - params.mVerticalGap;
|
mHeight = height - params.mVerticalGap;
|
||||||
mHorizontalGap = params.mHorizontalGap;
|
mHorizontalGap = params.mHorizontalGap;
|
||||||
|
@ -260,7 +260,7 @@ public class Key {
|
||||||
// Update row to have current x coordinate.
|
// Update row to have current x coordinate.
|
||||||
row.setXPos(keyXPos + keyWidth);
|
row.setXPos(keyXPos + keyWidth);
|
||||||
|
|
||||||
final String[] moreKeys = style.getTextArray(keyAttr,
|
final String[] moreKeys = style.getStringArray(keyAttr,
|
||||||
R.styleable.Keyboard_Key_moreKeys);
|
R.styleable.Keyboard_Key_moreKeys);
|
||||||
// In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
|
// In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
|
||||||
// config_digit_more_keys_enabled.
|
// config_digit_more_keys_enabled.
|
||||||
|
@ -291,11 +291,11 @@ public class Key {
|
||||||
final int disabledIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
|
final int disabledIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED));
|
R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED));
|
||||||
mDisabledIcon = iconsSet.getIconByAttrId(disabledIconAttrId);
|
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);
|
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
|
// Choose the first letter of the label as primary code if not
|
||||||
// specified.
|
// specified.
|
||||||
final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code,
|
final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code,
|
||||||
|
|
|
@ -245,10 +245,10 @@ public class Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method.
|
// TODO: Remove this method.
|
||||||
public CharSequence adjustLabelCase(CharSequence label) {
|
public String adjustLabelCase(String label) {
|
||||||
if (mId.isAlphabetKeyboard() && isShiftedOrShiftLocked() && !TextUtils.isEmpty(label)
|
if (mId.isAlphabetKeyboard() && isShiftedOrShiftLocked() && !TextUtils.isEmpty(label)
|
||||||
&& label.length() < 3 && Character.isLowerCase(label.charAt(0))) {
|
&& label.length() < 3 && Character.isLowerCase(label.charAt(0))) {
|
||||||
return label.toString().toUpperCase(mId.mLocale);
|
return label.toUpperCase(mId.mLocale);
|
||||||
}
|
}
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
|
@ -557,7 +557,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
float positionX = centerX;
|
float positionX = centerX;
|
||||||
if (key.mLabel != null) {
|
if (key.mLabel != null) {
|
||||||
// Switch the character to uppercase if shift is pressed
|
// 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.
|
// For characters, use large font. For labels like "Done", use smaller font.
|
||||||
paint.setTypeface(key.selectTypeface(params.mKeyTextStyle));
|
paint.setTypeface(key.selectTypeface(params.mKeyTextStyle));
|
||||||
final int labelSize = key.selectTextSize(params.mKeyLetterSize,
|
final int labelSize = key.selectTextSize(params.mKeyLetterSize,
|
||||||
|
@ -639,7 +639,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
|
|
||||||
// Draw hint label.
|
// Draw hint label.
|
||||||
if (key.mHintLabel != null) {
|
if (key.mHintLabel != null) {
|
||||||
final CharSequence hint = key.mHintLabel;
|
final String hint = key.mHintLabel;
|
||||||
final int hintColor;
|
final int hintColor;
|
||||||
final int hintSize;
|
final int hintSize;
|
||||||
if (key.hasHintLabel()) {
|
if (key.hasHintLabel()) {
|
||||||
|
@ -778,12 +778,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
return width;
|
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);
|
paint.getTextBounds(label.toString(), 0, label.length(), sTextBounds);
|
||||||
return sTextBounds.width();
|
return sTextBounds.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDefaultLabelWidth(CharSequence label, Paint paint) {
|
public float getDefaultLabelWidth(String label, Paint paint) {
|
||||||
paint.setTextSize(mKeyDrawParams.mKeyLabelSize);
|
paint.setTextSize(mKeyDrawParams.mKeyLabelSize);
|
||||||
paint.setTypeface(mKeyDrawParams.mKeyTextStyle);
|
paint.setTypeface(mKeyDrawParams.mKeyTextStyle);
|
||||||
return getLabelWidth(label, paint);
|
return getLabelWidth(label, paint);
|
||||||
|
|
|
@ -40,8 +40,8 @@ public class KeyStyles {
|
||||||
private static final KeyStyle EMPTY_KEY_STYLE = new EmptyKeyStyle();
|
private static final KeyStyle EMPTY_KEY_STYLE = new EmptyKeyStyle();
|
||||||
|
|
||||||
public interface KeyStyle {
|
public interface KeyStyle {
|
||||||
public String[] getTextArray(TypedArray a, int index);
|
public String[] getStringArray(TypedArray a, int index);
|
||||||
public CharSequence getText(TypedArray a, int index);
|
public String getString(TypedArray a, int index);
|
||||||
public int getInt(TypedArray a, int index, int defaultValue);
|
public int getInt(TypedArray a, int index, int defaultValue);
|
||||||
public int getFlag(TypedArray a, int index, int defaultValue);
|
public int getFlag(TypedArray a, int index, int defaultValue);
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,13 @@ public class KeyStyles {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getTextArray(TypedArray a, int index) {
|
public String[] getStringArray(TypedArray a, int index) {
|
||||||
return parseTextArray(a, index);
|
return parseStringArray(a, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getText(TypedArray a, int index) {
|
public String getString(TypedArray a, int index) {
|
||||||
return a.getText(index);
|
return a.getString(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,16 +71,15 @@ public class KeyStyles {
|
||||||
return a.getInt(index, defaultValue);
|
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))
|
if (!a.hasValue(index))
|
||||||
return null;
|
return null;
|
||||||
final CharSequence text = a.getText(index);
|
return parseCsvString(a.getString(index), a.getResources(), R.string.english_ime_name);
|
||||||
return parseCsvText(text.toString(), a.getResources(), R.string.english_ime_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package for test */
|
/* 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 String text = Utils.resolveStringResource(rawText, res, packageNameResId);
|
||||||
final int size = text.length();
|
final int size = text.length();
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
|
@ -139,15 +138,15 @@ public class KeyStyles {
|
||||||
private final HashMap<Integer, Object> mAttributes = new HashMap<Integer, Object>();
|
private final HashMap<Integer, Object> mAttributes = new HashMap<Integer, Object>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getTextArray(TypedArray a, int index) {
|
public String[] getStringArray(TypedArray a, int index) {
|
||||||
return a.hasValue(index)
|
return a.hasValue(index)
|
||||||
? super.getTextArray(a, index) : (String[])mAttributes.get(index);
|
? super.getStringArray(a, index) : (String[])mAttributes.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getText(TypedArray a, int index) {
|
public String getString(TypedArray a, int index) {
|
||||||
return a.hasValue(index)
|
return a.hasValue(index)
|
||||||
? super.getText(a, index) : (CharSequence)mAttributes.get(index);
|
? super.getString(a, index) : (String)mAttributes.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -170,10 +169,10 @@ public class KeyStyles {
|
||||||
// TODO: Currently not all Key attributes can be declared as style.
|
// TODO: Currently not all Key attributes can be declared as style.
|
||||||
readInt(keyAttr, R.styleable.Keyboard_Key_code);
|
readInt(keyAttr, R.styleable.Keyboard_Key_code);
|
||||||
readInt(keyAttr, R.styleable.Keyboard_Key_altCode);
|
readInt(keyAttr, R.styleable.Keyboard_Key_altCode);
|
||||||
readText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
|
readString(keyAttr, R.styleable.Keyboard_Key_keyLabel);
|
||||||
readText(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
|
readString(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
|
||||||
readText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
|
readString(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
|
||||||
readTextArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
|
readStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
|
||||||
readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags);
|
readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags);
|
||||||
readInt(keyAttr, R.styleable.Keyboard_Key_keyIcon);
|
readInt(keyAttr, R.styleable.Keyboard_Key_keyIcon);
|
||||||
readInt(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled);
|
readInt(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled);
|
||||||
|
@ -183,9 +182,9 @@ public class KeyStyles {
|
||||||
readFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags);
|
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))
|
if (a.hasValue(index))
|
||||||
mAttributes.put(index, a.getText(index));
|
mAttributes.put(index, a.getString(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readInt(TypedArray a, int 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));
|
mAttributes.put(index, a.getInt(index, 0) | (value != null ? value : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readTextArray(TypedArray a, int index) {
|
private void readStringArray(TypedArray a, int index) {
|
||||||
final CharSequence[] value = parseTextArray(a, index);
|
final String[] value = parseStringArray(a, index);
|
||||||
if (value != null)
|
if (value != null)
|
||||||
mAttributes.put(index, value);
|
mAttributes.put(index, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class MoreSuggestions extends Keyboard {
|
||||||
int pos = fromPos, rowStartPos = fromPos;
|
int pos = fromPos, rowStartPos = fromPos;
|
||||||
final int size = Math.min(suggestions.size(), SuggestionsView.MAX_SUGGESTIONS);
|
final int size = Math.min(suggestions.size(), SuggestionsView.MAX_SUGGESTIONS);
|
||||||
while (pos < size) {
|
while (pos < size) {
|
||||||
final CharSequence word = suggestions.getWord(pos);
|
final String word = suggestions.getWord(pos).toString();
|
||||||
// TODO: Should take care of text x-scaling.
|
// TODO: Should take care of text x-scaling.
|
||||||
mWidths[pos] = (int)view.getDefaultLabelWidth(word, paint) + padding;
|
mWidths[pos] = (int)view.getDefaultLabelWidth(word, paint) + padding;
|
||||||
final int numColumn = pos - rowStartPos + 1;
|
final int numColumn = pos - rowStartPos + 1;
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class KeyStylesTests extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertTextArray(String message, String value, String ... expected) {
|
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);
|
R.string.empty_string);
|
||||||
if (expected.length == 0) {
|
if (expected.length == 0) {
|
||||||
assertNull(message, actual);
|
assertNull(message, actual);
|
||||||
|
|
Loading…
Reference in New Issue