Beispiel #1
0
  @Override
  public int getLineCount() {
    final int emptyCountTop = flags.contains(Flags.EMPTY_LINE_TOP) ? 1 : 0;
    final int emptyCountBottom = flags.contains(Flags.EMPTY_LINE_BOTTOM) ? 1 : 0;

    final int res = model.getItemCount() + emptyCountTop + emptyCountBottom;
    return res >= 1 ? res : 1;
  }
Beispiel #2
0
 /**
  * Selects the item by its index. Given the non-negative integer value as an index, this method
  * sets the hot point on the item addressed with this index, checking only that index is in
  * appropriate bounds. Index must address the object as a number in the model, ignoring any empty
  * lines.
  *
  * @param index The item index to select
  * @param announce Must be true, if it is necessary to announce the item , once it has been
  *     selected
  * @return True if the index is valid and the item gets hot point on it
  */
 public boolean select(int index, boolean announce) {
   if (index < 0 || index >= model.getItemCount()) return false;
   final int emptyCountAbove = flags.contains(Flags.EMPTY_LINE_TOP) ? 1 : 0;
   hotPointY = index + emptyCountAbove;
   final Object item = model.getItem(index);
   if (item != null) {
     hotPointX = appearance.getObservableLeftBound(item);
     if (announce) appearance.announceItem(item, NONE_APPEARANCE_FLAGS);
   } else {
     hotPointX = 0;
     if (announce) environment.hint(Hints.EMPTY_LINE);
   }
   environment.onAreaNewHotPoint(this);
   return true;
 }
Beispiel #3
0
 protected boolean onTransition(Transition.Type type, int hint, boolean briefAnnouncement) {
   NullCheck.notNull(type, "type");
   //	NullCheck.notNull(hint, "hint");
   if (noContent()) return true;
   final int index = selectedIndex();
   final int count = model.getItemCount();
   final int emptyCountTop = flags.contains(Flags.EMPTY_LINE_TOP) ? 1 : 0;
   final Transition.State current;
   if (index >= 0) current = new Transition.State(index);
   else if (flags.contains(Flags.EMPTY_LINE_TOP) && hotPointY == 0)
     current = new Transition.State(Transition.State.Type.EMPTY_LINE_TOP);
   else if (flags.contains(Flags.EMPTY_LINE_BOTTOM) && hotPointY == count + emptyCountTop)
     current = new Transition.State(Transition.State.Type.EMPTY_LINE_BOTTOM);
   else return false;
   final Transition.State newState =
       transition.transition(
           type,
           current,
           count,
           flags.contains(Flags.EMPTY_LINE_TOP),
           flags.contains(Flags.EMPTY_LINE_BOTTOM));
   NullCheck.notNull(newState, "newState");
   Log.debug("list", "newState=" + newState.type);
   switch (newState.type) {
     case NO_TRANSITION:
       environment.hint(hint);
       return true;
     case EMPTY_LINE_TOP:
       if (!flags.contains(Flags.EMPTY_LINE_TOP)) return false;
       hotPointY = 0;
       break;
     case EMPTY_LINE_BOTTOM:
       if (!flags.contains(Flags.EMPTY_LINE_BOTTOM)) return false;
       hotPointY = count + emptyCountTop;
       break;
     case ITEM_INDEX:
       if (newState.itemIndex < 0 || newState.itemIndex >= count) return false;
       hotPointY = newState.itemIndex + emptyCountTop;
       break;
     default:
       return false;
   }
   onNewHotPointY(briefAnnouncement);
   return true;
 }
Beispiel #4
0
 public int getLineIndexByItemIndex(int index) {
   final int count = model.getItemCount();
   if (index < 0 || index >= count) return -1;
   final int linesTop = flags.contains(Flags.EMPTY_LINE_TOP) ? 1 : 0;
   return index + linesTop;
 }
Beispiel #5
0
 public int getItemIndexOnLine(int index) {
   final int linesTop = flags.contains(Flags.EMPTY_LINE_TOP) ? 1 : 0;
   if (index < linesTop) return -1;
   if (index - linesTop < model.getItemCount()) return index - linesTop;
   return -1;
 }