public void addFlagElement() {
    LinearLayout item = new LinearLayout(this);
    item.setBackgroundColor(Color.BLACK);
    item.setLayoutParams(Tools.setMargins());
    item.setBackgroundResource(R.drawable.shape);
    item.setWeightSum(10f);

    ImageView iv = new ImageView(this);
    iv.setBackgroundResource(R.drawable.flag);
    TableRow.LayoutParams ivparams = new TableRow.LayoutParams(75, 75);
    ivparams.setMargins(25, 25, 55, 25);
    iv.setLayoutParams(ivparams);

    TextView tv = new TextView(this);
    TableRow.LayoutParams tvparams =
        new TableRow.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    tvparams.gravity = Gravity.CENTER;
    tv.setLayoutParams(tvparams);
    tv.setText("Flag is set here!!!");
    tv.setTextColor(Color.WHITE);

    item.addView(iv);
    item.addView(tv);
    body.addView(item);
    addTimeStamp();
  }
  private void addTableRow(
      TableLayout layout, int rank, String name, int score, boolean textStyleBold) {
    TableRow row = new TableRow(HighscoreActivity.this);

    TextView textViewNumber = new TextView(HighscoreActivity.this);
    textViewNumber.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30);
    textViewNumber.setText(rank + ".");
    TableRow.LayoutParams layoutParamsLeft =
        new TableRow.LayoutParams(
            TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
    layoutParamsLeft.gravity = Gravity.START;
    textViewNumber.setLayoutParams(layoutParamsLeft);
    row.addView(textViewNumber);

    TextView textViewPlayer = new TextView(HighscoreActivity.this);
    textViewPlayer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30);
    if (name.length() > 14) {
      name = name.substring(0, 11) + "...";
    }
    textViewPlayer.setText(name);
    TableRow.LayoutParams layoutParamsCenter =
        new TableRow.LayoutParams(
            TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
    layoutParamsCenter.gravity = Gravity.CENTER;
    textViewPlayer.setLayoutParams(layoutParamsCenter);
    row.addView(textViewPlayer);

    TextView textViewScore = new TextView(HighscoreActivity.this);
    textViewScore.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30);
    textViewScore.setText(String.valueOf(score));
    TableRow.LayoutParams layoutParamsRight =
        new TableRow.LayoutParams(
            TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
    layoutParamsRight.gravity = Gravity.END;
    textViewScore.setLayoutParams(layoutParamsRight);
    row.addView(textViewScore);

    if (textStyleBold) {
      textViewNumber.setTypeface(null, Typeface.BOLD_ITALIC);
      textViewPlayer.setTypeface(null, Typeface.BOLD_ITALIC);
      textViewScore.setTypeface(null, Typeface.BOLD_ITALIC);
    }

    layout.addView(row);
  }
 public void addTimeStamp() {
   TextView tv = new TextView(this);
   TableRow.LayoutParams tvparams_time =
       new TableRow.LayoutParams(
           ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
   tvparams_time.gravity = Gravity.RIGHT;
   tv.setText(Tools.getTimeStamp());
   tv.setTextColor(Color.GRAY);
   tv.setTextSize(10f);
   tv.setLayoutParams(tvparams_time);
   tv.setPadding(0, 0, 5, 0);
   body.addView(tv);
 }
  private void updateTable() {
    tbLayout.removeAllViews();
    for (SensorMeasure measure : this.mainListSensorMeasures) {
      if ((calendarFilter != null)
          && (measure.getTimestamp().getTimeInMillis() < calendarFilter.getTimeInMillis()))
        continue; // Si la medida es anterior al filtro, nos la saltamos
      TableRow row = new TableRow(this);
      TextView tvDate = new TextView(this);
      TableRow.LayoutParams params = new TableRow.LayoutParams();
      params.column = 1;
      params.gravity = Gravity.LEFT;
      tvDate.setLayoutParams(params);

      tvDate.setText(DateFormat.getDateTimeInstance().format(measure.getTimestamp().getTime()));
      TextView tvValue = new TextView(this);
      tvValue.setGravity(Gravity.RIGHT + Gravity.FILL_HORIZONTAL);
      tvValue.setText(measure.getValue());
      row.addView(tvDate);
      row.addView(tvValue);
      tbLayout.addView(row);
    }
  }
  /**
   * Creates the actual minesweeper board as well as all Boxes. Sets up certain boxes as mines.
   *
   * @param frame2 tablerow to hold board
   * @param x number of rows
   * @param y number of columns
   * @param mines number of mines
   * @param context context of activity
   */
  public void createBoard(ViewGroup frame2, int x, int y, int mines, MainActivity context) {
    TableLayout frame = (TableLayout) frame2;
    this.context = context;
    this.context.minesRemaining.setText(Integer.toString(mines));
    this.x = x;
    this.y = y;
    this.mines = mines;
    this.boxesFilled = 0;
    this.isGoing = false;
    this.isPaused = false;
    int minesCreated = 0;
    this.board = new Box[x][y];

    for (int i = 0; i < this.x; ++i) {
      TableRow row = new TableRow(context);
      int height =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP,
                  (float) 48.0,
                  context.getResources().getDisplayMetrics());
      TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, height);
      params.gravity = Gravity.CENTER;
      params.setMargins(0, 0, 0, 0);
      row.setLayoutParams(params);
      row.setOrientation(0);
      int padding =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP,
                  (float) -2,
                  context.getResources().getDisplayMetrics());
      row.setPadding(padding, padding, padding, padding);

      for (int j = 0; j < this.y; ++j) {
        this.board[i][j] = new Box(this, context);
        final int localI = i;
        final int localJ = j;
        final MainActivity newcontext = context;
        this.board[i][j].setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                final int result;
                if (newcontext.flagMode == 1) {
                  result = flagIt(localI, localJ);
                } else {
                  result = hitIt(localI, localJ);
                }
                getResult(result);
              }
            });
        row.addView(this.board[i][j]);
      }
      frame.addView(row);
    }

    // use a while loop for more randomness
    while (minesCreated < this.mines) {
      Random r = new Random();
      int i = r.nextInt(this.x);
      int j = r.nextInt(this.y);
      double rando =
          (((this.mines - minesCreated) / ((this.x * this.y) - ((i * this.y) + j) * 1.0)) * 10);
      int surroundingMines = this.getSurrounding(i, j);
      int temp = r.nextInt(10 - (surroundingMines / 2));
      if (rando >= temp && this.board[i][j].isMine() == 0) {
        this.board[i][j].makeMine();
        this.addSurrounding(i, j);
        minesCreated++;
      }
    }
    /*for (int i = 0; i < this.x; ++i) {
    	for (int j = 0; j < this.y; ++j) {
    		Random r = new Random();
    		double rando =  (((this.mines-minesCreated) / ((this.x*this.y)-((i * this.y) + j)*1.0)) * 10);
    		int surroundingMines = this.getSurrounding(i, j);
    		int temp = r.nextInt(10-surroundingMines);
    		if (rando >= temp && minesCreated < this.mines) {
    			this.board[i][j].makeMine();
    			this.addSurrounding(i, j);
    			minesCreated++;
    		}
    	}
    }*/

    // zoom in and out code
    final Minesweeper ms2 = this;
    ImageView zoomOutButton = (ImageView) context.findViewById(R.id.zoomout);
    zoomOutButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            ms2.resizeMe(1);
          }
        });

    ImageView zoomInButton = (ImageView) context.findViewById(R.id.zoomin);
    zoomInButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            ms2.resizeMe(0);
          }
        });

    context.flagButton.setImageDrawable(context.getResources().getDrawable(R.drawable.mine));
    context.flagMode = 0;
  }
  private TableLayout getTable(Trigger trigger) {
    WindowManager mWinMgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    int displayWidth = mWinMgr.getDefaultDisplay().getWidth();

    TextView description = new TextView(ctx);
    description.setText(trigger.getDescription());
    description.setTextColor(Color.BLACK);
    description.setTextSize(16);

    TextView hostName = new TextView(ctx);
    hostName.setText(trigger.getHost());
    hostName.setTextColor(Color.BLACK);
    hostName.setTextSize(14);

    TextView age = new TextView(ctx);
    age.setText(trigger.getAgeTime());
    age.setTextColor(Color.DKGRAY);
    age.setTextSize(12);
    age.setPadding(0, 10, 0, 0);

    // ##############################################################################3
    TableLayout table = new TableLayout(ctx);
    // ##############################################################################3

    TableRow row1 = new TableRow(ctx);

    if (!showage()) {
      TableRow.LayoutParams hostNameparam =
          new TableRow.LayoutParams(displayWidth / 2, LayoutParams.WRAP_CONTENT);
      hostNameparam.gravity = Gravity.LEFT;

      row1.addView(hostName, hostNameparam);
      TableRow.LayoutParams ageparam =
          new TableRow.LayoutParams(displayWidth / 3, LayoutParams.WRAP_CONTENT);
      ageparam.gravity = Gravity.RIGHT;
      row1.addView(age, ageparam);
    } else {
      TableRow.LayoutParams hostNameparam =
          new TableRow.LayoutParams(displayWidth - 40, LayoutParams.WRAP_CONTENT);
      hostNameparam.gravity = Gravity.LEFT;

      row1.addView(hostName, hostNameparam);
    }

    table.addView(row1, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    // ##############################################################################3

    TableRow row2 = new TableRow(ctx);

    LinearLayout descripionLayout = new LinearLayout(ctx);

    TableRow.LayoutParams params = new TableRow.LayoutParams();
    params.span = 2;
    descripionLayout.addView(description);
    descripionLayout.setLayoutParams(params);
    row2.addView(descripionLayout);

    table.addView(row2);

    return table;
  }