Esempio n. 1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // log.dbg (2, "onMeasure", "widthMeasureSpec = " + MeasureSpec.toString(widthMeasureSpec));
    // log.dbg (2, "onMeasure", "heightMeasureSpec = " + MeasureSpec.toString(heightMeasureSpec));

    int specWidth = MeasureSpec.getSize(widthMeasureSpec);
    int specHeight = MeasureSpec.getSize(heightMeasureSpec);

    // log.dbg (2, "onMeasure", "widthMeasureSpec, height = " + widthMeasureSpec + ", " +
    // heightMeasureSpec);

    int maxHeight = 0;
    int maxWidth = 0;

    // Find out how big everyone wants to be
    measureChildren(widthMeasureSpec, heightMeasureSpec);

    Dimensio mini = minimumLayoutSize(0, 0, specWidth, specHeight);
    Dimensio maxi = preferredLayoutSize(0, 0, specWidth, specHeight);

    // Check against minimum height and width
    maxHeight = Math.max(maxi.height, mini.height);
    maxWidth = Math.max(maxi.width, mini.width);

    setMeasuredDimension(
        resolveSize(maxWidth, widthMeasureSpec), resolveSize(maxHeight, heightMeasureSpec));
  }
Esempio n. 2
0
  protected int nColumns() {
    //      OLD
    //      return Math.max(0, lay.cols(1) - 1);
    if (mnCols != -1) return mnCols;

    // has to be calculated,
    // the maximum n of cols of header or rows
    //
    for (int ii = 1; ii < lay.rows(); ii++)
      if (mnCols < Math.max(0, lay.cols(ii) - 1)) mnCols = Math.max(0, lay.cols(ii) - 1);

    mnCols = Math.max(0, mnCols);
    return mnCols;
  }
Esempio n. 3
0
  protected int nRows() {
    //      OLD
    //      return Math.max(0, lay.rows() - 2);

    if (mnRows != -1) return mnRows;

    mnRows = Math.max(0, lay.rows() - 2);
    return mnRows;
  }
Esempio n. 4
0
  private int minHeightOfRow(int nrow, boolean preferred) {
    // el componente ma's alto de la columna
    int maxheight = 0;

    for (int ii = 0; ii < getChildCount(); ii++) {
      View vi = getChildAt(ii);
      LayoutParams lp = (EvaLayout.LayoutParams) vi.getLayoutParams();

      // buscar al pavo en la row nrow
      int col = 0;
      for (col = 0; col < nColumns(); col++) {
        String nam = widgetAt(nrow, col);
        if (nam.equals(lp.name)) break;
      }
      if (col >= nColumns()) continue;
      if (widgetAt(nrow + 1, col).equals(EXPAND_VERTICAL))
        continue; // widget occupies more rows so do not compute it

      int height = (vi instanceof izWidget) ? ((izWidget) vi).getDefaultHeight() : 400;
      maxheight = Math.max(maxheight, height);
    }
    return maxheight > 200 ? 200 : maxheight;
  }
Esempio n. 5
0
  private int minWidthOfColumn(int ncol, boolean preferred) {
    // el componente ma's ancho de la columna
    int maxwidth = 0;

    for (int ii = 0; ii < getChildCount(); ii++) {
      View vi = getChildAt(ii);
      LayoutParams lp = (EvaLayout.LayoutParams) vi.getLayoutParams();

      // buscar al pavo en la columna ncol
      int row = 0;
      for (row = 0; row < nRows(); row++) {
        String nam = widgetAt(row, ncol);
        if (nam.equals(lp.name)) break;
      }
      if (row >= nRows()) continue;
      if (widgetAt(row, ncol + 1).equals(EXPAND_HORIZONTAL))
        continue; // widget occupies more columns so even do not compute it

      int width = (vi instanceof izWidget) ? ((izWidget) vi).getDefaultWidth() : 300;
      maxwidth = Math.max(maxwidth, width);
    }
    return maxwidth > 200 ? 200 : maxwidth;
  }
Esempio n. 6
0
  private void precalculateAll() {
    if (isPrecalculated) return;
    if (!checkLayoutInfo()) {
      log.err("checkLayoutInfo", "layout [" + lay.getName() + "] is not of type EVA");
      // do not return! some variables has to be initialized anyway
    }

    log.dbg(2, "precalculateAll", "layout " + lay.getName() + " perform precalculation.");

    Hmargin = Math.max(0, stdlib.atoi(lay.getValue(0, 1)));
    Vmargin = Math.max(0, stdlib.atoi(lay.getValue(0, 2)));
    Hgap = Math.max(0, stdlib.atoi(lay.getValue(0, 3)));
    Vgap = Math.max(0, stdlib.atoi(lay.getValue(0, 4)));

    log.dbg(4, "precalculateAll", nColumns() + " columns x " + nRows() + " rows");
    log.dbg(
        4,
        "precalculateAll",
        "margins xm=" + Hmargin + ", ym=" + Vmargin + ", yg=" + Hgap + ", yg=" + Vgap);

    mnCols = -1; // reset cached number of cols
    mnRows = -1; // reset cached number of rows

    HdimMin = new int[nColumns()];
    HdimPref = new int[nColumns()];
    Hpos = new int[nColumns()];
    VdimMin = new int[nRows()];
    VdimPref = new int[nRows()];
    Vpos = new int[nRows()];

    columnsReparto = new Vector();
    rowsReparto = new Vector();

    // for all components ...
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
      View child = getChildAt(i);
      // if (child.getVisibility() != GONE)
      EvaLayout.LayoutParams lp = (EvaLayout.LayoutParams) child.getLayoutParams();
      lp.isLaidOut = false;
    }

    // compute Vdim (Note: it might be precalculated if needed)
    fijoV = Vmargin;
    for (int rr = 0; rr < nRows(); rr++) {
      String heaRow = rowHeader(rr);
      int typ = headType(heaRow);
      int gap = (rr == 0) ? 0 : Vgap;

      if (typ == HEADER_ORIGINAL) {
        // maximum-minimum of the row
        VdimPref[rr] = minHeightOfRow(rr, true);
        VdimMin[rr] = minHeightOfRow(rr, false);
        log.dbg(2, "precalculateAll", "Adaption... VdimPref[rr] = " + VdimPref[rr]);
      } else if (typ == HEADER_EXPAND) {
        rowsReparto.add(new int[] {rr}); // compute later
        log.dbg(2, "precalculateAll", "Expand... VdimPref[rr] = " + VdimPref[rr]);
      } else {
        // indicated size
        VdimPref[rr] = VdimMin[rr] = stdlib.atoi(heaRow);
        log.dbg(2, "precalculateAll", "Explicit... VdimPref[rr] = " + VdimPref[rr]);
      }

      Vpos[rr] = fijoV + gap;
      fijoV += VdimPref[rr];
      fijoV += gap;
    }
    fijoV += Vmargin;
    log.dbg(2, "precalculateAll", "fijoV = " + fijoV + " Vmargin = " + Vmargin + " Vgap = " + Vgap);

    // DEBUG ....
    if (log.isDebugging(2)) {
      String vertical = "Vertical array (posY/prefHeight/minHeight)";
      for (int rr = 0; rr < Vpos.length; rr++)
        vertical += "  " + rr + ") " + Vpos[rr] + "/" + VdimPref[rr] + "/" + VdimMin[rr];

      log.dbg(2, "precalculateAll", vertical);
    }

    // compute Hdim (Note: it might be precalculated if needed)
    fijoH = Hmargin;
    for (int cc = 0; cc < nColumns(); cc++) {
      String heaCol = columnHeader(cc);
      int typ = headType(heaCol);
      int gap = (cc == 0) ? 0 : Hgap;

      if (typ == HEADER_ORIGINAL) {
        // maximum-minimum of the column
        HdimPref[cc] = minWidthOfColumn(cc, true);
        HdimMin[cc] = minWidthOfColumn(cc, false);
      } else if (typ == HEADER_EXPAND) columnsReparto.add(new int[] {cc}); // compute later
      else HdimPref[cc] = HdimMin[cc] = stdlib.atoi(heaCol); // indicated size

      Hpos[cc] = fijoH + gap;
      fijoH += HdimPref[cc];
      fijoH += gap;
    }
    fijoH += Hmargin;
    log.dbg(2, "precalculateAll", "fijoH = " + fijoH);

    // DEBUG ....
    if (log.isDebugging(2)) {
      String horizontal = "Horizontal array (posX/prefWidth/minWidth)";
      for (int cc = 0; cc < Hpos.length; cc++)
        horizontal += "  " + cc + ") " + Hpos[cc] + "/" + HdimPref[cc] + "/" + HdimMin[cc];

      log.dbg(2, "precalculateAll", horizontal);
    }

    // finding all components in the layout array
    for (int cc = 0; cc < nColumns(); cc++) {
      for (int rr = 0; rr < nRows(); rr++) {
        String name = widgetAt(rr, cc);

        LayoutParams wid = theComponent(name);
        if (wid == null) continue;

        // set position x,y
        wid.posCol0 = cc;
        wid.posRow0 = rr;

        // set position x2,y2
        int ava = cc;
        while (ava + 1 < nColumns() && widgetAt(rr, ava + 1).equals(EXPAND_HORIZONTAL)) ava++;
        wid.posCol1 = ava;

        ava = rr;
        while (ava + 1 < nRows() && widgetAt(ava + 1, cc).equals(EXPAND_VERTICAL)) ava++;
        wid.posRow1 = ava;

        wid.isLaidOut = true;

        // DEBUG ....
        if (log.isDebugging(2)) {
          log.dbg(
              2,
              "precalculateAll",
              wid.name
                  + " leftTop ("
                  + wid.posCol0
                  + ", "
                  + wid.posRow0
                  + ") rightBottom ("
                  + wid.posCol1
                  + ", "
                  + wid.posRow1
                  + ")");
        }
      }
    }

    isPrecalculated = true;
  }