I am trying to create another input method editor. I create and add the keyboard with the following code.
keyboardView = (KeyboardView)findViewById(R.id.myKeboardView);
Keyboard keyboard = new Keyboard(this, R.xml.key_layout, "abcdefghigjklmnopqrstuvwxyz", 10, 0);
keyboardView.setKeyboard(keyboard);
Upon checking the source code for the keyboard constructor, I saw that it is not adding new rows. The keyboard generated contains just one very long row and when the column limit is reached, instead of adding new row, it just increases the y value with the key height and continues off the same old row.
from the android source code for Keyboard class
public Keyboard(Context context, int layoutTemplateResId,
CharSequence characters, int columns, int horizontalPadding) {
this(context, layoutTemplateResId);
int x = 0;
int y = 0;
int column = 0;
mTotalWidth = 0;
Row row = new Row(this);
row.defaultHeight = mDefaultHeight;
row.defaultWidth = mDefaultWidth;
row.defaultHorizontalGap = mDefaultHorizontalGap;
row.verticalGap = mDefaultVerticalGap;
row.rowEdgeFlags = EDGE_TOP | EDGE_BOTTOM;
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(row);
key.x = x;
key.y = y;
key.label = String.valueOf(c);
key.codes = new int[] { c };
column++;
x += key.width + key.gap;
mKeys.add(key);
row.mKeys.add(key);
if (x > mTotalWidth) {
mTotalWidth = x;
}
}
mTotalHeight = y + mDefaultHeight;
rows.add(row);
}
Instead of just one row, i want as many rows as needed and the keys not squashed. Any work around for this issue?