@Test public void testNavigate() { addElementsToGrid(); Actionable lastActionable = null; for(int x = 0; x <= COLUMNS; x++) { lastActionable = navigation.navigate(Keys.RIGHT); } Assert.assertEquals(elements[2][0], lastActionable); for(int y = 0; y <= ROWS; y++) { lastActionable = navigation.navigate(Keys.DOWN); } Assert.assertEquals(elements[2][2], lastActionable); for(int x = 0; x <= COLUMNS; x++) { lastActionable = navigation.navigate(Keys.LEFT); } Assert.assertEquals(elements[0][2], lastActionable); for(int y = 0; y <= ROWS; y++) { lastActionable = navigation.navigate(Keys.UP); } Assert.assertEquals(elements[0][0], lastActionable); }
@Override public Actionable navigate(int keycode) { if (navigation.size == 0) { return null; } switch (keycode) { case Keys.W: case Keys.UP: if (cursorY > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY--; } break; case Keys.S: case Keys.DOWN: if (getIndex(cursorX, cursorY + 1) >= navigation.size){ navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorY < getTotalRows() - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY = getTotalRows() - 1; } break; case Keys.A: case Keys.LEFT: if (cursorX > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX--; } break; case Keys.D: case Keys.RIGHT: if (getIndex(cursorX + 1, cursorY) >= navigation.size) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorX < columns - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX = columns - 1; } break; } return navigation.get(getIndex(cursorX, cursorY)); }
GridUiNavigation implements UiNavigation { @Override public Actionable navigate(int keycode) { if (navigation.size == 0) { return null; } switch (keycode) { case Keys.W: case Keys.UP: if (cursorY > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY--; } break; case Keys.S: case Keys.DOWN: if (getIndex(cursorX, cursorY + 1) >= navigation.size){ navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorY < getTotalRows() - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY = getTotalRows() - 1; } break; case Keys.A: case Keys.LEFT: if (cursorX > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX--; } break; case Keys.D: case Keys.RIGHT: if (getIndex(cursorX + 1, cursorY) >= navigation.size) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorX < columns - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX = columns - 1; } break; } return navigation.get(getIndex(cursorX, cursorY)); } }
GridUiNavigation implements UiNavigation { @Override public Actionable navigate(int keycode) { if (navigation.size == 0) { return null; } switch (keycode) { case Keys.W: case Keys.UP: if (cursorY > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY--; } break; case Keys.S: case Keys.DOWN: if (getIndex(cursorX, cursorY + 1) >= navigation.size){ navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorY < getTotalRows() - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY = getTotalRows() - 1; } break; case Keys.A: case Keys.LEFT: if (cursorX > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX--; } break; case Keys.D: case Keys.RIGHT: if (getIndex(cursorX + 1, cursorY) >= navigation.size) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorX < columns - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX = columns - 1; } break; } return navigation.get(getIndex(cursorX, cursorY)); } GridUiNavigation(int xsColumns); }
GridUiNavigation implements UiNavigation { @Override public Actionable navigate(int keycode) { if (navigation.size == 0) { return null; } switch (keycode) { case Keys.W: case Keys.UP: if (cursorY > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY--; } break; case Keys.S: case Keys.DOWN: if (getIndex(cursorX, cursorY + 1) >= navigation.size){ navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorY < getTotalRows() - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY = getTotalRows() - 1; } break; case Keys.A: case Keys.LEFT: if (cursorX > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX--; } break; case Keys.D: case Keys.RIGHT: if (getIndex(cursorX + 1, cursorY) >= navigation.size) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorX < columns - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX = columns - 1; } break; } return navigation.get(getIndex(cursorX, cursorY)); } GridUiNavigation(int xsColumns); @Override void layout(ScreenSize screenSize); @Override void add(Actionable actionable); @Override void remove(Actionable actionable); @Override void removeAll(); @Override void set(int index, Actionable actionable); Actionable get(int x, int y); void set(int x, int y, Actionable actionable); @Override Actionable navigate(int keycode); @Override Actionable getCursor(); @Override Actionable resetCursor(); @Override Actionable resetCursor(boolean triggerHoverEvent); void setWidth(ScreenSize screenSize, int columns); int getTotalColumns(); int getTotalRows(); @Override String toString(); @Override void onHoverBegin(Hoverable source); @Override void onHoverEnd(Hoverable source); }
GridUiNavigation implements UiNavigation { @Override public Actionable navigate(int keycode) { if (navigation.size == 0) { return null; } switch (keycode) { case Keys.W: case Keys.UP: if (cursorY > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY--; } break; case Keys.S: case Keys.DOWN: if (getIndex(cursorX, cursorY + 1) >= navigation.size){ navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorY < getTotalRows() - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorY = getTotalRows() - 1; } break; case Keys.A: case Keys.LEFT: if (cursorX > 0) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX--; } break; case Keys.D: case Keys.RIGHT: if (getIndex(cursorX + 1, cursorY) >= navigation.size) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); }else if (cursorX < columns - 1) { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX++; } else { navigation.get(getIndex(cursorX, cursorY)).invokeEndHover(); cursorX = columns - 1; } break; } return navigation.get(getIndex(cursorX, cursorY)); } GridUiNavigation(int xsColumns); @Override void layout(ScreenSize screenSize); @Override void add(Actionable actionable); @Override void remove(Actionable actionable); @Override void removeAll(); @Override void set(int index, Actionable actionable); Actionable get(int x, int y); void set(int x, int y, Actionable actionable); @Override Actionable navigate(int keycode); @Override Actionable getCursor(); @Override Actionable resetCursor(); @Override Actionable resetCursor(boolean triggerHoverEvent); void setWidth(ScreenSize screenSize, int columns); int getTotalColumns(); int getTotalRows(); @Override String toString(); @Override void onHoverBegin(Hoverable source); @Override void onHoverEnd(Hoverable source);  }