public T repair(final T line) {
      final T standard = get(line.getID(), false);
      if (standard != null) {
        final boolean badCountType = line.getCountType() != standard.getCountType();
        final boolean badCount =
            line.isFixedCount() && !badCountType && line.getCount() != standard.getCount();
        final boolean badType = line.getType() != standard.getType();
        final boolean badDesc = !line.getDescription().equals(standard.getDescription());
        final boolean needsRepair =
            badCountType || badCount || badType || (REPAIR_BAD_DESCRIPTIONS && badDesc);

        if (needsRepair) {
          if (GeneralUtils.DEBUG_MODE_ENABLED) {
            System.err.println(
                "Repairing standard header line for field "
                    + line.getID()
                    + " because"
                    + (badCountType
                        ? " -- count types disagree; header has "
                            + line.getCountType()
                            + " but standard is "
                            + standard.getCountType()
                        : "")
                    + (badType
                        ? " -- type disagree; header has "
                            + line.getType()
                            + " but standard is "
                            + standard.getType()
                        : "")
                    + (badCount
                        ? " -- counts disagree; header has "
                            + line.getCount()
                            + " but standard is "
                            + standard.getCount()
                        : "")
                    + (badDesc
                        ? " -- descriptions disagree; header has '"
                            + line.getDescription()
                            + "' but standard is '"
                            + standard.getDescription()
                            + "'"
                        : ""));
          }
          return standard;
        } else {
          return line;
        }
      } else {
        return line;
      }
    }
 /** Remember enough information to restore the screen state when the data has changed. */
 void rememberSyncState() {
   if (getChildCount() > 0) {
     mNeedSync = true;
     mSyncHeight = mLayoutHeight;
     if (mSelectedPosition >= 0) {
       // Sync the selection state
       View v = getChildAt(mSelectedPosition - mFirstPosition);
       mSyncRowId = mNextSelectedRowId;
       mSyncPosition = mNextSelectedPosition;
       if (v != null) {
         mSpecificTop = v.getTop();
       }
       mSyncMode = SYNC_SELECTED_POSITION;
     } else {
       // Sync the based on the offset of the first view
       View v = getChildAt(0);
       T adapter = getAdapter();
       if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) {
         mSyncRowId = adapter.getItemId(mFirstPosition);
       } else {
         mSyncRowId = NO_ID;
       }
       mSyncPosition = mFirstPosition;
       if (v != null) {
         mSpecificTop = v.getTop();
       }
       mSyncMode = SYNC_FIRST_POSITION;
     }
   }
 }
 private boolean isScrollableForAccessibility() {
   T adapter = getAdapter();
   if (adapter != null) {
     final int itemCount = adapter.getCount();
     return itemCount > 0
         && (getFirstVisiblePosition() > 0 || getLastVisiblePosition() < itemCount - 1);
   }
   return false;
 }
 /**
  * @return The data corresponding to the currently selected item, or null if there is nothing
  *     selected.
  */
 public Object getSelectedItem() {
   T adapter = getAdapter();
   int selection = getSelectedItemPosition();
   if (adapter != null && adapter.getCount() > 0 && selection >= 0) {
     return adapter.getItem(selection);
   } else {
     return null;
   }
 }
 @Override
 public void setFocusable(boolean focusable) {
   final T adapter = getAdapter();
   final boolean empty = adapter == null || adapter.getCount() == 0;
   mDesiredFocusableState = focusable;
   if (!focusable) {
     mDesiredFocusableInTouchModeState = false;
   }
   super.setFocusable(focusable && (!empty || isInFilterMode()));
 }
 void checkFocus() {
   final T adapter = getAdapter();
   final boolean empty = adapter == null || adapter.getCount() == 0;
   final boolean focusable = !empty || isInFilterMode();
   super.setFocusableInTouchMode(focusable && mDesiredFocusableInTouchModeState);
   super.setFocusable(focusable && mDesiredFocusableState);
   if (mEmptyView != null) {
     updateEmptyStatus(adapter == null || adapter.isEmpty());
   }
 }
 private void populate() {
   if (mAdapter != null) {
     for (int i = 0; i < mAdapter.getCount(); i++) {
       addView(
           itemBuilder(i)
               .setBody(mAdapter.getBodyForPos(i, this))
               .setPos(i)
               .setListener(this)
               .build());
     }
   }
 }
Example #8
0
  /**
   * Scrolls a list.
   *
   * @param absListView the list to be scrolled
   * @param direction the direction to be scrolled
   * @param allTheWay {@code true} to scroll the view all the way up or down, {@code false} to
   *     scroll one page up or down
   * @return {@code true} if more scrolling can be done
   */
  public <T extends AbsListView> boolean scrollList(
      T absListView, int direction, boolean allTheWay) {

    if (absListView == null) {
      return false;
    }

    if (direction == DOWN) {

      int listCount = absListView.getCount();
      int lastVisiblePosition = absListView.getLastVisiblePosition();

      if (allTheWay) {
        scrollListToLine(absListView, listCount - 1);
        return false;
      }

      if (lastVisiblePosition >= listCount - 1) {
        if (lastVisiblePosition > 0) {
          scrollListToLine(absListView, lastVisiblePosition);
        }
        return false;
      }

      int firstVisiblePosition = absListView.getFirstVisiblePosition();

      if (firstVisiblePosition != lastVisiblePosition)
        scrollListToLine(absListView, lastVisiblePosition);
      else scrollListToLine(absListView, firstVisiblePosition + 1);

    } else if (direction == UP) {
      int firstVisiblePosition = absListView.getFirstVisiblePosition();

      if (allTheWay || firstVisiblePosition < 2) {
        scrollListToLine(absListView, 0);
        return false;
      }
      int lastVisiblePosition = absListView.getLastVisiblePosition();

      final int lines = lastVisiblePosition - firstVisiblePosition;

      int lineToScrollTo = firstVisiblePosition - lines;

      if (lineToScrollTo == lastVisiblePosition) lineToScrollTo--;

      if (lineToScrollTo < 0) lineToScrollTo = 0;

      scrollListToLine(absListView, lineToScrollTo);
    }
    sleeper.sleep();
    return true;
  }
 void checkFocus() {
   final T adapter = getAdapter();
   final boolean empty = adapter == null || adapter.getCount() == 0;
   final boolean focusable = !empty || isInFilterMode();
   // The order in which we set focusable in touch mode/focusable may matter
   // for the client, see View.setFocusableInTouchMode() comments for more
   // details
   super.setFocusableInTouchMode(focusable && mDesiredFocusableInTouchModeState);
   super.setFocusable(focusable && mDesiredFocusableState);
   if (mEmptyView != null) {
     updateEmptyStatus((adapter == null) || adapter.isEmpty());
   }
 }