コード例 #1
0
  private void addTableRow(TableLayout table, String parameter, String value) {

    TableRow row = new TableRow(table.getContext());

    TableRow.LayoutParams trParams = new TableRow.LayoutParams();
    trParams.setMargins(2, 2, 2, 1);
    row.setLayoutParams(trParams);
    row.setBackgroundColor(Color.rgb(0x00, 0x00, 0x00));

    TextView text1 = new TextView(row.getContext());
    text1.setTextSize(18);
    text1.setText(parameter);
    text1.setBackgroundColor(Color.rgb(0x18, 0x18, 0x18));
    text1.setLayoutParams(trParams);
    text1.setPadding(5, 0, 0, 0);
    row.addView(text1);

    TextView text2 = new TextView(row.getContext());
    text2.setTextSize(18);
    text2.setText(value);
    text2.setBackgroundColor(Color.rgb(0x18, 0x18, 0x18));
    text2.setLayoutParams(trParams);
    text2.setPadding(5, 0, 0, 0);
    row.addView(text2);

    table.addView(row);
  }
コード例 #2
0
  // suppress this error message to be able to use spaces in higher api levels
  @SuppressLint("NewApi")
  public void refresh() {

    if (mAdapter == null) {
      mAdapter = new StackAdapter(mContext, mStacks, mSwipeable);
      if (mListView != null) {
        mListView.setAdapter(mAdapter);
      } else if (mTableLayout != null) {
        TableRow tr = null;
        for (int i = 0; i < mAdapter.getCount(); i += mColumnNumber) {
          // add a new table row with the current context
          tr = new TableRow(mTableLayout.getContext());
          tr.setOrientation(TableRow.HORIZONTAL);
          tr.setLayoutParams(
              new TableRow.LayoutParams(
                  TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
          // add as many cards as the number of columns indicates per row
          for (int j = 0; j < mColumnNumber; j++) {
            if (i + j < mAdapter.getCount()) {
              View card = mAdapter.getView(i + j, null, tr);
              if (card.getLayoutParams() != null) {
                card.setLayoutParams(
                    new TableRow.LayoutParams(
                        card.getLayoutParams().width, card.getLayoutParams().height, 1f));
              } else {
                card.setLayoutParams(
                    new TableRow.LayoutParams(
                        TableRow.LayoutParams.MATCH_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT,
                        1f));
              }
              tr.addView(card);
            }
          }
          mTableLayout.addView(tr);
        }
        if (tr != null) {
          // fill the empty space with spacers
          for (int j = mAdapter.getCount() % mColumnNumber; j > 0; j--) {
            View space = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
              space = new Space(tr.getContext());
            } else {
              space = new View(tr.getContext());
            }
            space.setLayoutParams(
                new TableRow.LayoutParams(
                    TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
            tr.addView(space);
          }
        }
      }
    } else {
      mAdapter.setSwipeable(mSwipeable); // in case swipeable changed;
      mAdapter.setItems(mStacks);
    }
  }
コード例 #3
0
  public TableRow createRow(
      View image, String appName, String date, Double value, String reason, Context activity) {
    TableRow row = new TableRow(activity);
    row.setGravity(Gravity.CENTER);

    image.setPadding((int) (ratio * 10), 0, (int) (ratio * 15), 0);
    ((LinearLayout) image).setGravity(Gravity.LEFT);

    LinearLayout img = new LinearLayout(row.getContext());
    img.setLayoutParams(
        new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    img.setOrientation(LinearLayout.HORIZONTAL);
    img.setGravity(Gravity.CENTER);
    img.addView(image);

    row.addView(
        img, new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, (int) (ratio * 70)));

    LinearLayout main = new LinearLayout(row.getContext());
    main.setLayoutParams(
        new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    main.setOrientation(LinearLayout.VERTICAL);

    TextView appname = new TextView(activity);
    appname.setText(appName);
    appname.setPadding(0, 0, 0, 0);
    appname.setTextColor(Color.parseColor("#545859"));
    appname.setMaxLines(1);
    appname.setTextSize(16);
    appname.setLayoutParams(
        new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView movdate = new TextView(activity);
    // PARSE DATE AND SET TEXTVIEW
    try {
      SimpleDateFormat curFormater = new SimpleDateFormat("d-MMM-y HH:mm:ss", Locale.ENGLISH);
      curFormater.setTimeZone(TimeZone.getTimeZone("GMT"));
      Date endDate = curFormater.parse(date);
      curFormater.setTimeZone(TimeZone.getDefault());

      movdate.setText(
          DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
              .format(endDate));
      movdate.setPadding(0, 0, 0, 0);
      movdate.setTextColor(Color.parseColor("#787A77"));
      movdate.setTextSize(12);
    } catch (Exception e) {
      e.printStackTrace();
    }
    movdate.setLayoutParams(
        new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView movreason = new TextView(activity);
    Field field;
    try {
      field = (R.string.class.getField(reason));
      movreason.setText(activity.getString(field.getInt(R.string.class)));
    } catch (SecurityException e) {
    } catch (NoSuchFieldException e) {
    } catch (IllegalArgumentException e) {
    } catch (IllegalAccessException e) {
    }

    movreason.setPadding(0, 0, 0, 0);
    movreason.setTextColor(Color.parseColor("#545859"));
    movreason.setMaxLines(2);
    movreason.setTextSize(12);
    movreason.setLayoutParams(
        new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

    main.addView(appname);
    main.addView(movdate);
    main.addView(movreason);

    row.addView(
        main,
        new TableRow.LayoutParams(
            TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));

    LinearLayout position = new LinearLayout(row.getContext());
    position.setGravity(Gravity.CENTER);

    TextView movvalue = new TextView(activity);
    String textvalue;
    if (value > 0) textvalue = "+" + value; // String.format("%02d", (int)value);
    else textvalue = value.toString(); // String.format("%02d", (int)value);
    movvalue.setText(textvalue);
    movvalue.setPadding(0, 0, 0, 0);
    movvalue.setTextColor(Color.GRAY);
    movvalue.setTextSize(30);
    position.addView(movvalue);

    TableRow.LayoutParams params =
        new TableRow.LayoutParams(
            TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
    params.setMargins(0, 0, 10, 0);
    row.addView(position, params);

    return row;
  }