@SuppressWarnings("unchecked")
  public void appendItems(List<T> newItems) {
    items.addAll(newItems);

    RowInfo<T> rowInfo = null;
    final int lastRow = getRowCount() - 1;
    if (lastRow >= 0) rowInfo = itemsPerRow.get(lastRow);

    if (rowInfo != null) {
      final float spaceLeftInLastRow = rowInfo.getSpaceLeft();

      if (listView.isDebugging()) Log.d(TAG, "Space left in last row: " + spaceLeftInLastRow);

      // Try to add new items into the last row, if there is any space left
      if (spaceLeftInLastRow > 0) {

        for (final T i : rowInfo.getItems()) newItems.add(0, i);

        final RowInfo<T> stuffThatFit = calculateItemsForRow(newItems);
        final List<T> itemsThatFit = stuffThatFit.getItems();

        if (!itemsThatFit.isEmpty()) {
          for (T anItemsThatFit : itemsThatFit) newItems.remove(anItemsThatFit);

          itemsPerRow.put(lastRow, stuffThatFit);
          notifyDataSetChanged();
        }
      }
    }

    new ProcessRowsTask().executeSerially(newItems);
  }
 /**
  * Marks the current row as the first day that has events after "yesterday". Used to mark the
  * separation between the past and the present/future
  *
  * @param position in the adapter
  */
 public void setAsFirstDayAfterYesterday(int position) {
   if (mRowInfo == null || position < 0 || position > mRowInfo.size()) {
     return;
   }
   RowInfo row = mRowInfo.get(position);
   row.mFirstDayAfterYesterday = true;
 }
Example #3
0
 public List<RowInfo> initRowInfo(List<JSONObject> _list, boolean isRed) {
   List<RowInfo> list = new ArrayList<RowInfo>();
   for (int i = 0; i < _list.size(); i++) {
     RowInfo info = new RowInfo();
     try {
       info.setIssue(_list.get(i).getString("batchCode"));
       info.setBallNum(parseStr(_list.get(i).getString("winCode"), isRed));
       if (iGameType.equals("fc3d")) {
         info.setTrycode(parseStrtrycode(_list.get(i).getString("tryCode")));
       }
     } catch (JSONException e) {
       e.printStackTrace();
     }
     list.add(info);
   }
   return list;
 }
    private List<RowInfo<T>> calculateItemsPerRow(int currentRow, final List<T> itemsToAdd) {
      List<RowInfo<T>> rows = new ArrayList<>();

      while (!itemsToAdd.isEmpty()) {
        final RowInfo<T> stuffThatFit = calculateItemsForRow(itemsToAdd);

        final List<T> itemsThatFit = stuffThatFit.getItems();
        if (itemsThatFit.isEmpty()) {
          // we can't fit a single item inside a row.
          // bail out.
          break;
        }

        for (T anItemsThatFit : itemsThatFit) itemsToAdd.remove(anItemsThatFit);

        rows.add(stuffThatFit);
        currentRow++;
      }

      return rows;
    }
  private VcsLogHighlighter.VcsCommitStyle getStyle(
      int row, int column, String text, boolean hasFocus, final boolean selected) {
    Component dummyRendererComponent =
        myDummyRenderer.getTableCellRendererComponent(this, text, selected, hasFocus, row, column);

    VisibleGraph<Integer> visibleGraph = getVisibleGraph();
    if (row < 0 || row >= visibleGraph.getVisibleCommitCount()) {
      LOG.error(
          "Visible graph has "
              + visibleGraph.getVisibleCommitCount()
              + " commits, yet we want row "
              + row);
      return VcsCommitStyleFactory.createStyle(
          dummyRendererComponent.getForeground(),
          dummyRendererComponent.getBackground(),
          VcsLogHighlighter.TextStyle.NORMAL);
    }

    final RowInfo<Integer> rowInfo = visibleGraph.getRowInfo(row);

    VcsLogHighlighter.VcsCommitStyle defaultStyle =
        VcsCommitStyleFactory.createStyle(
            rowInfo.getRowType() == RowType.UNMATCHED
                ? JBColor.GRAY
                : dummyRendererComponent.getForeground(),
            dummyRendererComponent.getBackground(),
            VcsLogHighlighter.TextStyle.NORMAL);

    List<VcsLogHighlighter.VcsCommitStyle> styles =
        ContainerUtil.map(
            myHighlighters,
            new Function<VcsLogHighlighter, VcsLogHighlighter.VcsCommitStyle>() {
              @Override
              public VcsLogHighlighter.VcsCommitStyle fun(VcsLogHighlighter highlighter) {
                return highlighter.getStyle(rowInfo.getCommit(), selected);
              }
            });

    return VcsCommitStyleFactory.combine(ContainerUtil.append(styles, defaultStyle));
  }
  @Override
  public View getView(final int position, final View convertView, final ViewGroup parent) {
    LinearLayout layout = findOrInitializeLayout(convertView);

    final RowInfo<T> rowInfo = itemsPerRow.get(position);
    final List<T> rowItems = new ArrayList<>();
    rowItems.addAll(rowInfo.getItems());

    // Index to control the current position
    // of the current column in this row
    int columnIndex = 0;

    // Index to control the current position
    // in the array of all the items available for this row
    int currentIndex = 0;

    int spaceLeftInColumn = rowInfo.getRowHeight();

    while (!rowItems.isEmpty() && columnIndex < listView.getNumColumns()) {
      final T currentItem = rowItems.get(currentIndex);

      if (spaceLeftInColumn == 0) {
        // No more space in this column. Move to next one
        columnIndex++;
        currentIndex = 0;
        spaceLeftInColumn = rowInfo.getRowHeight();
        continue;
      }

      // Is there enough space in this column to accommodate currentItem?
      if (spaceLeftInColumn >= currentItem.getRowSpan()) {
        rowItems.remove(currentItem);

        int index = items.indexOf(currentItem);
        final LinearLayout childLayout = findOrInitializeChildLayout(layout, columnIndex);
        final View childConvertView = viewPool.get();
        final View v = getActualView(index, childConvertView, parent);
        v.setTag(currentItem);
        v.setOnClickListener(this);
        v.setOnLongClickListener(this);

        spaceLeftInColumn -= currentItem.getRowSpan();
        currentIndex = 0;

        v.setLayoutParams(
            new LinearLayout.LayoutParams(getRowWidth(currentItem), getRowHeight(currentItem)));

        childLayout.addView(v);
      } else if (currentIndex < rowItems.size() - 1) {
        // Try again with next item
        currentIndex++;
      } else {
        break;
      }
    }

    if (listView.isDebugging() && position % 20 == 0) {
      Log.d(TAG, linearLayoutPool.getStats("LinearLayout"));
      Log.d(TAG, viewPool.getStats("Views"));
    }

    return layout;
  }
Example #7
0
  protected Row analyzeRow(Row originalRow) {
    KnittingEngine engine = renderingContext.getEngine();
    // can't handle short rows
    if (originalRow.isShortRow()) {
      return null;
    }
    // can't handle colors (right now)
    if (originalRow.getYarnIdRef() != null) {
      return null;
    }

    List<InlineOperation> newOperations = new ArrayList<InlineOperation>();
    Row newRow = new Row(originalRow, newOperations);
    this.currentRowInfo = new RowInfo();

    // Begin the row for the engine
    if (dynamicFirstRowCastOn) {
      // if this is an instruction definition, infer the intended shape
      // from what is specified by the first row's shape.
      // If nothing is specified, flat knitting is assumed.
      if (originalRow.getType() != null) {
        this.shape = originalRow.getType();
      }
      // cast on one stitch so that we can start a new row below
      engine.castOn(1, false);
    }
    engine.startNewRow();
    if (this.startingSide == null) {
      this.startingSide = Side.RIGHT;
      if (dynamicFirstRowCastOn && originalRow.getSide() == Side.WRONG) {
        this.startingSide = Side.WRONG;
        engine.knit();
        engine.endRow();
        engine.startNewRow();
      } else if (engine.getDirection() == Direction.BACKWARDS) {
        this.startingSide = Side.WRONG;
      }
    }

    // Walk through all of the row's operations and see how it affects the
    // counts
    for (InlineOperation operation : originalRow.getOperations()) {
      InlineOperation newOperation = handle(operation);
      // if null is returned, we cannot chart, so return null up the chain
      if (newOperation == null) {
        return null;
      }
      newOperations.add(newOperation);
    }

    // End the row for the engine
    if (dynamicFirstRowCastOn) {
      // remove the "extra" stitch we created in order to start the row.
      engine.reverseSlip(1);
      // don't swallow the real stitch's nature
      StitchNature stitchNature = engine.peekAtNextStitch().getCurrentNature();
      if (stitchNature == StitchNature.PURL) {
        engine.purlTwoTogether();
      } else {
        engine.knitTwoTogether();
      }
      // now pretend like all is normal
      dynamicFirstRowCastOn = false;
    }
    engine.endRow();

    // if this row pushed the bounds of the previously recorded maximum
    // width, record the new max width
    if (currentRowInfo.getRowWidth() > maxWidth) {
      maxWidth = currentRowInfo.getRowWidth();
    }

    // if (!repeatInCurrentRow) {
    // resetGlobalRepeatTracker();
    // }

    this.rowInfos.add(currentRowInfo);
    return newRow;
  }