Exemplo n.º 1
0
    /**
     * Creates a row of views that will fit within the layout span of the row. This is called by the
     * layout method. This is implemented to fill the row by repeatedly calling the createView
     * method until the available span has been exhausted, a forced break was encountered, or the
     * createView method returned null. If the remaining span was exhaused, the adjustRow method
     * will be called to perform adjustments to the row to try and make it fit into the given span.
     *
     * @param rowIndex the index of the row to fill in with views. The row is assumed to be empty on
     *     entry.
     * @param pos The current position in the children of this views element from which to start.
     * @return the position to start the next row
     */
    protected int layoutRow(FlowView fv, int rowIndex, int pos) {
      View row = fv.getView(rowIndex);
      int x = fv.getFlowStart(rowIndex);
      int spanLeft = fv.getFlowSpan(rowIndex);
      int end = fv.getEndOffset();
      TabExpander te = (fv instanceof TabExpander) ? (TabExpander) fv : null;

      // Indentation.
      int preX = x;
      int availableSpan = spanLeft;
      preX = x;

      final int flowAxis = fv.getFlowAxis();
      boolean forcedBreak = false;
      while (pos < end && spanLeft > 0) {
        View v = createView(fv, pos, spanLeft, rowIndex);
        if (v == null) {
          break;
        }

        int chunkSpan;
        if ((flowAxis == X_AXIS) && (v instanceof TabableView)) {
          chunkSpan = (int) ((TabableView) v).getTabbedSpan(x, te);
        } else {
          chunkSpan = (int) v.getPreferredSpan(flowAxis);
        }

        // If a forced break is necessary, break
        if (v.getBreakWeight(flowAxis, pos, spanLeft) >= ForcedBreakWeight) {
          int n = row.getViewCount();
          if (n > 0) {
            /* If this is a forced break and it's not the only view
             * the view should be replaced with a call to breakView.
             * If it's it only view, it should be used directly.  In
             * either case no more children should be added beyond this
             * view.
             */
            v = v.breakView(flowAxis, pos, x, spanLeft);
            if (v != null) {
              if ((flowAxis == X_AXIS) && (v instanceof TabableView)) {
                chunkSpan = (int) ((TabableView) v).getTabbedSpan(x, te);
              } else {
                chunkSpan = (int) v.getPreferredSpan(flowAxis);
              }
            } else {
              chunkSpan = 0;
            }
          }
          forcedBreak = true;
        }

        spanLeft -= chunkSpan;
        x += chunkSpan;
        if (v != null) {
          row.append(v);
          pos = v.getEndOffset();
        }
        if (forcedBreak) {
          break;
        }
      }
      if (spanLeft < 0) {
        // This row is too long and needs to be adjusted.
        adjustRow(fv, rowIndex, availableSpan, preX);
      } else if (row.getViewCount() == 0) {
        // Impossible spec... put in whatever is left.
        View v = createView(fv, pos, Integer.MAX_VALUE, rowIndex);
        row.append(v);
      }
      return row.getEndOffset();
    }