();
}
/**
* Creates a blank keyboard from the given resource file and populates it with the specified
* characters in left-to-right, top-to-bottom fashion, using the specified number of columns.
*
*
*
*
If the specified number of columns is -1, then the keyboard will fit as many keys as
* possible in each row.
*
* @param context the application or service context
* @param characters the list of characters to display on the keyboard. One key will be created
* for each character.
* @param columns the number of columns of keys to display. If this number is greater than the
* number of keys that can fit in a row, it will be ignored. If this number is -1, the
* keyboard will fit as many keys as possible in each row.
* @param horizontalPadding 按鍵水平間距
*/
public Keyboard(Context context, CharSequence characters, int columns, int horizontalPadding) {
this(context);
int x = 0;
int y = 0;
int column = 0;
mTotalWidth = 0;
final int maxColumns = columns == -1 ? Integer.MAX_VALUE : columns;
for (int i = 0; i < characters.length(); i++) {
char c = characters.charAt(i);
if (column >= maxColumns || x + mDefaultWidth + horizontalPadding > mDisplayWidth) {
x = 0;
y += mDefaultVerticalGap + mDefaultHeight;
column = 0;
}
final Key key = new Key(this);
key.setX(x);
key.setY(y);
key.setWidth(mDefaultWidth);
key.setHeight(mDefaultHeight);
key.setGap(mDefaultHorizontalGap);
key.events[0] = new Event(this, String.valueOf(c));
column++;
x += key.getWidth() + key.getGap();
mKeys.add(key);
if (x > mTotalWidth) {
mTotalWidth = x;
}
}
mTotalHeight = y + mDefaultHeight;
}
public Keyboard(Context context, String name) {
this(context);
Map m = Config.get().getKeyboard(name);
mLabelTransform = Config.getString(m, "label_transform", "none");
mAsciiMode = Config.getInt(m, "ascii_mode", 1);
if (mAsciiMode == 0) mAsciiKeyboard = Config.getString(m, "ascii_keyboard");
mLock = Config.getBoolean(m, "lock", false);
int columns = Config.getInt(m, "columns", 30);
int defaultWidth = (int) (Config.getDouble(m, "width", 0) * mDisplayWidth / 100);
if (defaultWidth == 0) defaultWidth = mDefaultWidth;
int height = Config.getPixel(m, "height", 0);
int defaultHeight = (height > 0) ? height : mDefaultHeight;
int rowHeight = defaultHeight;
List