No need to specify dimensions for AbstractKeyboardBuilder
Bug: 13017434 Change-Id: I1cce6d9f072dff8ce2a53b8089f09105ba812a2bmain
parent
746f94c671
commit
cd15cfdaab
|
@ -35,7 +35,7 @@ public final class Qwerty extends LayoutBase {
|
||||||
@Override
|
@Override
|
||||||
ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; }
|
ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; }
|
||||||
|
|
||||||
private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder(10, 9, 7, 3)
|
private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder()
|
||||||
.setLabelsOfRow(1, "q", "w", "e", "r", "t", "y", "u", "i", "o", "p")
|
.setLabelsOfRow(1, "q", "w", "e", "r", "t", "y", "u", "i", "o", "p")
|
||||||
.setMoreKeysOf("q", "1")
|
.setMoreKeysOf("q", "1")
|
||||||
.setMoreKeysOf("w", "2")
|
.setMoreKeysOf("w", "2")
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class Symbols extends AbstractLayoutBase {
|
||||||
public static ExpectedKey[] SINGLE_ANGLE_QUOTES_RL = { SAQUOTE_RIGHT, SAQUOTE_LEFT };
|
public static ExpectedKey[] SINGLE_ANGLE_QUOTES_RL = { SAQUOTE_RIGHT, SAQUOTE_LEFT };
|
||||||
|
|
||||||
// Common symbols keyboard layout.
|
// Common symbols keyboard layout.
|
||||||
private static final ExpectedKey[][] SYMBOLS_COMMON = new ExpectedKeyboardBuilder(10, 9, 7, 5)
|
private static final ExpectedKey[][] SYMBOLS_COMMON = new ExpectedKeyboardBuilder()
|
||||||
.setKeysOfRow(1,
|
.setKeysOfRow(1,
|
||||||
// U+00B9: "¹" SUPERSCRIPT ONE
|
// U+00B9: "¹" SUPERSCRIPT ONE
|
||||||
// U+00BD: "½" VULGAR FRACTION ONE HALF
|
// U+00BD: "½" VULGAR FRACTION ONE HALF
|
||||||
|
|
|
@ -70,8 +70,7 @@ public class SymbolsShifted extends AbstractLayoutBase {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Common symbols shifted keyboard layout.
|
// Common symbols shifted keyboard layout.
|
||||||
private static final ExpectedKey[][] SYMBOLS_SHIFTED_COMMON = new ExpectedKeyboardBuilder(
|
private static final ExpectedKey[][] SYMBOLS_SHIFTED_COMMON = new ExpectedKeyboardBuilder()
|
||||||
10, 1 /* other_currencies */+ 5, 7, 5)
|
|
||||||
.setKeysOfRow(1,
|
.setKeysOfRow(1,
|
||||||
key("~"),
|
key("~"),
|
||||||
// U+0060: "`" GRAVE ACCENT
|
// U+0060: "`" GRAVE ACCENT
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.util.Arrays;
|
||||||
*/
|
*/
|
||||||
abstract class AbstractKeyboardBuilder<E> {
|
abstract class AbstractKeyboardBuilder<E> {
|
||||||
// A building array of rows.
|
// A building array of rows.
|
||||||
private final E[][] mRows;
|
private E[][] mRows;
|
||||||
|
|
||||||
// Returns an instance of default element.
|
// Returns an instance of default element.
|
||||||
abstract E defaultElement();
|
abstract E defaultElement();
|
||||||
|
@ -42,12 +42,8 @@ abstract class AbstractKeyboardBuilder<E> {
|
||||||
* Construct a builder filled with the default element.
|
* Construct a builder filled with the default element.
|
||||||
* @param dimensions the integer array of each row's size.
|
* @param dimensions the integer array of each row's size.
|
||||||
*/
|
*/
|
||||||
AbstractKeyboardBuilder(final int ... dimensions) {
|
AbstractKeyboardBuilder() {
|
||||||
mRows = newArrayOfArray(dimensions.length);
|
mRows = newArrayOfArray(0);
|
||||||
for (int rowIndex = 0; rowIndex < dimensions.length; rowIndex++) {
|
|
||||||
mRows[rowIndex] = newArray(dimensions[rowIndex]);
|
|
||||||
Arrays.fill(mRows[rowIndex], defaultElement());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,10 +98,13 @@ abstract class AbstractKeyboardBuilder<E> {
|
||||||
*/
|
*/
|
||||||
void setRowAt(final int row, final E[] elements) {
|
void setRowAt(final int row, final E[] elements) {
|
||||||
final int rowIndex = row - 1;
|
final int rowIndex = row - 1;
|
||||||
if (rowIndex < 0 || rowIndex >= mRows.length) {
|
if (rowIndex < 0) {
|
||||||
throw new RuntimeException("Illegal row number: " + row);
|
throw new RuntimeException("Illegal row number: " + row);
|
||||||
}
|
}
|
||||||
mRows[rowIndex] = elements;
|
final E[][] newRows = (rowIndex < mRows.length) ? mRows
|
||||||
|
: Arrays.copyOf(mRows, rowIndex + 1);
|
||||||
|
newRows[rowIndex] = elements;
|
||||||
|
mRows = newRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,8 +119,11 @@ abstract class AbstractKeyboardBuilder<E> {
|
||||||
void setElementAt(final int row, final int column, final E element, final boolean insert) {
|
void setElementAt(final int row, final int column, final E element, final boolean insert) {
|
||||||
final E[] elements = getRowAt(row);
|
final E[] elements = getRowAt(row);
|
||||||
final int columnIndex = column - 1;
|
final int columnIndex = column - 1;
|
||||||
|
if (columnIndex < 0) {
|
||||||
|
throw new RuntimeException("Illegal column number: " + column);
|
||||||
|
}
|
||||||
if (insert) {
|
if (insert) {
|
||||||
if (columnIndex < 0 || columnIndex >= elements.length + 1) {
|
if (columnIndex >= elements.length + 1) {
|
||||||
throw new RuntimeException("Illegal column number: " + column);
|
throw new RuntimeException("Illegal column number: " + column);
|
||||||
}
|
}
|
||||||
final E[] newElements = Arrays.copyOf(elements, elements.length + 1);
|
final E[] newElements = Arrays.copyOf(elements, elements.length + 1);
|
||||||
|
@ -134,9 +136,9 @@ abstract class AbstractKeyboardBuilder<E> {
|
||||||
setRowAt(row, newElements);
|
setRowAt(row, newElements);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (columnIndex < 0 || columnIndex >= elements.length) {
|
final E[] newElements = (columnIndex < elements.length) ? elements
|
||||||
throw new RuntimeException("Illegal column number: " + column);
|
: Arrays.copyOf(elements, columnIndex + 1);
|
||||||
}
|
newElements[columnIndex] = element;
|
||||||
elements[columnIndex] = element;
|
setRowAt(row, newElements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> {
|
||||||
for (int rowIndex = 0; rowIndex < dimensions.length; rowIndex++) {
|
for (int rowIndex = 0; rowIndex < dimensions.length; rowIndex++) {
|
||||||
dimensions[rowIndex] = rows.get(rowIndex).size();
|
dimensions[rowIndex] = rows.get(rowIndex).size();
|
||||||
}
|
}
|
||||||
final ActualKeyboardBuilder builder = new ActualKeyboardBuilder(dimensions);
|
final ActualKeyboardBuilder builder = new ActualKeyboardBuilder();
|
||||||
|
|
||||||
for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
|
for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
|
||||||
final int row = rowIndex + 1;
|
final int row = rowIndex + 1;
|
||||||
|
@ -95,10 +95,6 @@ public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActualKeyboardBuilder(final int ... dimensions) {
|
|
||||||
super(dimensions);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Key defaultElement() { return null; }
|
Key defaultElement() { return null; }
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ import java.util.Locale;
|
||||||
* This class builds an expected keyboard for unit test.
|
* This class builds an expected keyboard for unit test.
|
||||||
*/
|
*/
|
||||||
public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<ExpectedKey> {
|
public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<ExpectedKey> {
|
||||||
public ExpectedKeyboardBuilder(final int ... dimensions) {
|
public ExpectedKeyboardBuilder() {
|
||||||
super(dimensions);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpectedKeyboardBuilder(final ExpectedKey[][] rows) {
|
public ExpectedKeyboardBuilder(final ExpectedKey[][] rows) {
|
||||||
|
|
Loading…
Reference in New Issue