/** Creates a blank space to fill the row. */
 private ImageView createBlankSpace() {
   ImageView view = new ImageView(getContext());
   TableRow.LayoutParams params = new TableRow.LayoutParams(mSwatchLength, mSwatchLength);
   params.setMargins(mMarginSize, mMarginSize, mMarginSize, mMarginSize);
   view.setLayoutParams(params);
   return view;
 }
  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();
  }
 public static void setMargins(View view, int margin) {
   TableRow.LayoutParams params =
       new TableRow.LayoutParams(
           TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, Gravity.RIGHT);
   params.setMargins(margin, margin, margin, margin);
   view.setLayoutParams(params);
 }
  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);
  }
 /** Creates a color swatch. */
 private ColorPickerSwatch createColorSwatch(int color, int selectedColor) {
   ColorPickerSwatch view =
       new ColorPickerSwatch(
           getContext(), color, color == selectedColor, mOnColorSelectedListener);
   TableRow.LayoutParams params = new TableRow.LayoutParams(mSwatchLength, mSwatchLength);
   params.setMargins(mMarginSize, mMarginSize, mMarginSize, mMarginSize);
   view.setLayoutParams(params);
   return view;
 }
  private void BuildTable(int rows, int cols) {

    try {

      // outer for loop
      for (int i = 1; i <= rows; i++) {

        TableRow row = new TableRow(getActivity());
        row.setBackgroundResource(R.drawable.layout_border5);

        /* row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                                TableRow.LayoutParams.WRAP_CONTENT));
        */
        TableRow.LayoutParams params =
            new TableRow.LayoutParams(
                TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
        params.setMargins(2, 2, 0, 0);
        row.setLayoutParams(params);

        // inner for loop
        for (int j = 1; j <= cols; j++) {

          TextView tv = new TextView(getActivity());
          tv.setLayoutParams(
              new TableRow.LayoutParams(
                  TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
          // tv.setBackgroundResource(R.drawable.cell_shape);
          if (j == 1) {
            tv.setPadding(40, 5, 10, 10);
          } else {
            tv.setPadding(80, 10, 10, 14);
          }

          try {
            tv.setText("   " + monthlyOrders.get(i - 1));
          } catch (Exception e) {
            e.printStackTrace();
          }
          if (j == 2) {
            tv.setText("   " + orders_inprogress.get(i - 1));
          }
          if (j == 3) {
            tv.setText("   " + orders_completed.get(i - 1));
          }
          row.addView(tv);
        }

        table_layout.addView(row);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #7
0
  private void buildTable() {

    db = helper.getReadableDatabase();
    Cursor c = helper.readEntry(db);

    int rows = c.getCount();
    int columns = c.getColumnCount();

    c.moveToFirst();

    for (int i = 0; i < rows; i++) {
      TableRow row = new TableRow(this);
      row.setLayoutParams(
          new TableRow.LayoutParams(
              TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));

      //            for (int j = 0; j < columns; j++) {
      //                content = content + " at " + c.getString(j);
      //            }

      String content = c.getString(0) + " at " + c.getString(1);

      TextView tv = new TextView(this);
      TableRow.LayoutParams tableRowParams =
          new TableRow.LayoutParams(
              TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);

      int topMargin = 3;
      int bottomMargin = 3;

      tableRowParams.setMargins(0, topMargin, 0, bottomMargin);

      tv.setLayoutParams(tableRowParams);

      tv.setBackgroundResource(R.drawable.cell_shape);
      tv.setGravity(Gravity.CENTER);
      tv.setTextSize(18);
      tv.setTextColor(Color.WHITE);
      tv.setText(content);

      row.addView(tv);

      c.moveToNext();
      table_layout.addView(row);
    }
    helper.close();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ScrollView sv = new ScrollView(getActivity());
    TableLayout tl = new TableLayout(getActivity());
    sv.addView(tl);

    if (displayReportController == null) {
      return sv;
    }
    AdsenseReportsGenerateResponse response = displayReportController.getReportResponse();

    TableLayout.LayoutParams tableRowParams =
        new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    tableRowParams.setMargins(10, 10, 10, 10);

    TableRow.LayoutParams tvParams =
        new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    tvParams.setMargins(10, 10, 10, 10);

    List<Headers> headers = response.getHeaders();
    TableRow tr = new TableRow(getActivity());
    tl.addView(tr);

    for (Headers header : headers) {
      TextView tv = new TextView(getActivity());
      tv.setText(header.getName());
      tr.setLayoutParams(tableRowParams);
      tr.addView(tv);
    }
    if (response.getRows() != null && !response.getRows().isEmpty()) {
      for (List<String> row : response.getRows()) {
        TableRow trow = new TableRow(getActivity());
        tl.addView(trow);
        for (String cell : row) {
          TextView tv = new TextView(getActivity());
          tv.setText(cell);
          trow.addView(tv);
          tv.setLayoutParams(tvParams);
          tv.setPadding(15, 5, 15, 5);
          tv.setBackgroundColor(Color.WHITE);
        }
      }
    }
    return sv;
  }
Beispiel #9
0
 private TableRow buildAmenityTableRow(Context ctx, Amenity amenity) {
   TextView textView = new TextView(ctx);
   String amName = amenity.name();
   int id = getResources().getIdentifier(ctx.getPackageName() + ":string/" + amName, null, null);
   String value = ctx.getString(id);
   textView.setText(value);
   textView.setGravity(Gravity.RIGHT);
   CheckBox checkBox = new CheckBox(ctx);
   checkBox.setChecked(false);
   checkBox.setOnCheckedChangeListener(new AmenityOnCheckChangeListener(this.amenities, amenity));
   TableRow tableRow = new TableRow(ctx);
   TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();
   layoutParams.setMargins(0, 0, 10, 0);
   tableRow.addView(textView, layoutParams);
   tableRow.addView(checkBox);
   return tableRow;
 }
 @SuppressLint("NewApi")
 public void addPhotoElement(Uri imgUri) {
   LinearLayout item = new LinearLayout(this);
   item.setBackgroundColor(Color.BLACK);
   item.setBackgroundResource(R.drawable.shape);
   TableRow.LayoutParams item_params =
       new TableRow.LayoutParams(
           ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
   //		item_params.gravity =Gravity.RIGHT;
   item_params.setMargins(5, 8, 5, 8);
   item.setLayoutParams(item_params);
   item.setPadding(-20, 40, -20, 40);
   //        item.setPadding(-30, 20, -30, 20);
   ImageView iv = new ImageView(this);
   TableRow.LayoutParams iv_params = new TableRow.LayoutParams(500, 500);
   iv.setLayoutParams(iv_params);
   iv.setImageURI(imgUri);
   item.addView(iv);
   body.addView(item);
   addTimeStamp();
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final OfflineTabActivity activity = (OfflineTabActivity) getActivity();
    menu = activity.getMenu();
    View rootView = inflater.inflate(R.layout.menu_layout, container, false);

    ScrollView scroll = new ScrollView(getActivity().getApplicationContext());
    TableLayout menulist = new TableLayout(getActivity().getApplicationContext());
    TableRow.LayoutParams param = new TableRow.LayoutParams();
    param.setMargins(0, 0, 15, 0);
    final String sid = "4";
    int id = 0;
    for (Beverage beverage : menu) {
      if (beverage.getType().equals("soft")) {
        id++;

        TableRow row = new TableRow(getActivity().getApplicationContext());

        TextView tekst = new TextView(getActivity().getApplicationContext());
        tekst.setText(beverage.getName());
        tekst.setLayoutParams(param);
        tekst.setId(Integer.parseInt(sid + id));
        row.addView(tekst);

        TextView amount = new TextView(getActivity().getApplicationContext());
        amount.setText("€ " + beverage.getPrice());
        amount.setLayoutParams(param);
        row.addView(amount);

        menulist.addView(row);
      }
    }
    scroll.setPadding(20, 5, 0, 5);
    scroll.addView(menulist);
    return scroll;
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.detalle_estacionamiento, null);
    TextView titulo = (TextView) view.findViewById(R.id.nombreEstacionamiento);
    desc = (TextView) view.findViewById(R.id.descripcionEstacionamiento);
    mComentarioView = (EditText) view.findViewById(R.id.comentario);
    horarios = (TableLayout) view.findViewById(R.id.horarios);
    comentarios = (Button) view.findViewById(R.id.comentarios);
    title = getArguments().getString("title");
    if (getArguments().getString("descripcion") != null) {
      descripcion = getArguments().getString("descripcion");
    }

    RatingBar puntaje = (RatingBar) view.findViewById(R.id.ratingBar);
    puntaje.setOnRatingBarChangeListener(
        new RatingBar.OnRatingBarChangeListener() {
          @Override
          public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            if (fromUser) {
              checkFacebookSession();
              puntajeActual = rating;
              mComentarioView.setVisibility(View.VISIBLE);
              desc.setVisibility(View.GONE);
              horarios.setVisibility(View.GONE);
              comentarios.setVisibility(View.GONE);
            }
          }
        });
    puntajeActual = getArguments().getDouble("puntaje");
    puntaje.setRating((float) puntajeActual);
    titulo.setText(title);
    desc.setText(descripcion);

    comentarios.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent verComentarios = new Intent(getContext(), VerComentariosActivity.class);
            verComentarios.putExtra(
                VerComentariosActivity.ARG_ID_ESTACIONAMIENTO, getArguments().getString("title"));
            startActivity(verComentarios);
          }
        });

    for (Estacionamiento est : RecorridoHolder.getInstance().getEstacionamientos()) {
      if (est.getNombre().equals(title)) {
        for (Tarifa tarifa : est.getTarifas()) {

          TableRow newRow = new TableRow(getContext());
          TextView vehiculo = new TextView(getContext());
          TextView tarifaHora = new TextView(getContext());
          TextView tarifaDia = new TextView(getContext());

          TableRow.LayoutParams llp =
              new TableRow.LayoutParams(
                  TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
          llp.setMargins(12, 0, 0, 0); // llp.setMargins(left, top, right, bottom);

          vehiculo.setPadding(3, 3, 3, 3);
          vehiculo.setLayoutParams(llp);
          tarifaHora.setPadding(3, 3, 3, 3);
          tarifaHora.setLayoutParams(llp);
          tarifaDia.setPadding(3, 3, 3, 3);
          tarifaDia.setLayoutParams(llp);

          vehiculo.setText(tarifa.getDescripcion());
          tarifaHora.setText("$" + tarifa.getPrecioHora());
          tarifaDia.setText("$" + tarifa.getPrecioDia());

          newRow.addView(vehiculo, 0);
          newRow.addView(tarifaHora, 1);
          newRow.addView(tarifaDia, 2);

          horarios.addView(newRow);
        }
        break;
      }
    }

    builder
        .setView(view)
        // Add action buttons
        .setPositiveButton(
            R.string.accept,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {
                if (mComentarioView.getVisibility() == View.VISIBLE)
                  EstacionamientosServices.calificar(
                      title,
                      puntajeActual,
                      mComentarioView.getText().toString(),
                      User.getCurrentUser().getName());
              }
            });

    return builder.create();
  }
  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;
  }
Beispiel #14
0
  private void createDataTable() {
    sqlite.openConnection();
    ArrayList<Grafica> candidatos = sqlite.getCandidatos();
    sqlite.closeConnection();

    //
    TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams();
    tableRowParams.setMargins(5, 3, 5, 3);
    tableRowParams.weight = 1;
    // encabezado
    TableRow rowHead = new TableRow(this);
    rowHead.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    // col 1
    TextView col1 = new TextView(this);
    col1.setBackgroundResource(R.drawable.tv_bg);
    col1.setGravity(Gravity.CENTER);
    col1.setTypeface(null, Typeface.BOLD);
    col1.setTextSize(12);
    col1.setPadding(6, 10, 6, 10);
    col1.setText("TEMA");
    // col 2
    TextView col2 = new TextView(this);
    col2.setBackgroundResource(R.drawable.tv_bg);
    col2.setGravity(Gravity.CENTER);
    col2.setTypeface(null, Typeface.BOLD);
    col2.setTextSize(12);
    col2.setPadding(6, 10, 6, 10);
    col2.setText("LECCIÓN");
    // col 3
    TextView col3 = new TextView(this);
    col3.setBackgroundResource(R.drawable.tv_bg);
    col3.setGravity(Gravity.CENTER);
    col3.setTypeface(null, Typeface.BOLD);
    col3.setTextSize(12);
    col3.setPadding(6, 10, 6, 10);
    col3.setText("CALF");
    // añade columnas
    rowHead.addView(col1, tableRowParams);
    rowHead.addView(col2, tableRowParams);
    rowHead.addView(col3, tableRowParams);
    // añade fila
    table_layout.addView(rowHead);
    for (Grafica c : candidatos) {
      TableRow row = new TableRow(this);
      row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

      // col 1
      TextView tv1 = new TextView(this);
      tv1.setBackgroundResource(R.drawable.tv_bg);
      tv1.setGravity(Gravity.CENTER);
      tv1.setTypeface(null, Typeface.BOLD);
      tv1.setTextSize(12);
      tv1.setPadding(6, 10, 6, 10);
      tv1.setText(c.getSigla());
      // col 2
      TextView tv2 = new TextView(this);
      tv2.setBackgroundResource(R.drawable.tv_bg);
      tv2.setGravity(Gravity.CENTER);
      tv2.setTextSize(12);
      tv2.setPadding(6, 10, 6, 10);
      tv2.setText(c.getNombre());
      // col 3
      TextView tv3 = new TextView(this);
      tv3.setBackgroundResource(R.drawable.tv_bg);
      tv3.setGravity(Gravity.CENTER);
      tv3.setTextSize(12);
      tv3.setPadding(6, 10, 6, 10);
      tv3.setText(String.valueOf(c.getVotos()));
      // añade columnas
      row.addView(tv1, tableRowParams);
      row.addView(tv2, tableRowParams);
      row.addView(tv3, tableRowParams);
      // añade fila
      table_layout.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;
  }
  @SuppressLint("NewApi")
  public void addTextElement(final String val) {
    // todo check for URL
    if (Tools.checkURL(val)) {
      LinearLayout item = new LinearLayout(this);
      item.setBackgroundColor(Color.BLACK);
      item.setLayoutParams(Tools.setMargins());
      item.setBackgroundResource(R.drawable.shape);
      item.setOrientation(LinearLayout.VERTICAL);
      TableRow.LayoutParams item_params =
          new TableRow.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      item_params.setMargins(5, 8, 5, 8);
      item.setLayoutParams(item_params);
      TextView tv = new TextView(this);
      tv.setTextColor(Color.parseColor("#00FFFF"));
      tv.setText(val);

      if (Tools.checkURLType(val)) {
        //          webview ------
        w = new WebView(this);
        WebSettings webSettings = w.getSettings();
        webSettings.setJavaScriptEnabled(true);
        w.setVerticalScrollBarEnabled(false);
        w.setHorizontalScrollBarEnabled(false);
        w.setWebViewClient(
            new WebViewClient() {
              public void onPageFinished(WebView view, String url) {
                Picture picture = view.capturePicture();
                Bitmap b =
                    Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
                Canvas c = new Canvas(b);
                picture.draw(c);
                FileOutputStream fos = null;
                try {
                  fos =
                      new FileOutputStream(
                          Tools.getContextWrapperDir(Notes_Activity.this) + "/temp.jpg");
                  if (fos != null) {
                    b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
                    fos.close();
                  }
                } catch (Exception e) {
                }
              }
            });
        w.setOnTouchListener(
            new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                return (event.getAction() == MotionEvent.ACTION_MOVE);
              }
            });

        w.loadUrl(Tools.checkURLTypeWebView(val));
        item.addView(w, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 600));
      }
      // clickable
      item.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              String url = val;
              Intent i = new Intent(Intent.ACTION_VIEW);
              i.setData(Uri.parse(url));
              startActivity(i);
            }
          });
      // webicew -------------

      item.addView(tv);
      body.addView(item);
      scrollDown();
      addTimeStamp();
    } else {
      LinearLayout item = new LinearLayout(this);
      item.setBackgroundColor(Color.BLACK);
      item.setLayoutParams(Tools.setMargins());
      item.setBackgroundResource(R.drawable.shape);
      TableRow.LayoutParams item_params =
          new TableRow.LayoutParams(
              ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      //		item_params.gravity =Gravity.LEFT;
      item_params.setMargins(5, 8, 5, 8);
      item.setLayoutParams(item_params);

      TextView tv = new TextView(this);
      tv.setTextColor(Color.WHITE);
      tv.setText(val);
      item.addView(tv);
      body.addView(item);
      scrollDown();
      addTimeStamp();
    }
  }
  /**
   * 创建BallTable
   *
   * @param LinearLayout aParentView 上一级Layout
   * @param int aLayoutId 当前BallTable的LayoutId
   * @param int aFieldWidth BallTable区域的宽度(如屏幕宽度)
   * @param int aBallNum 小球个数
   * @param int aBallViewWidth 小球视图的宽度(图片宽度)
   * @param int[] aResId 小球图片Id
   * @param int aIdStart 小球Id起始数值
   * @param int aBallViewText 0:小球从0开始显示,1:小球从1开始显示 ,3小球从3开始显示(福彩3D和值组6从3开始)
   * @return BallTable
   */
  private BallTable makeBallTable(
      LinearLayout aParentView,
      int aLayoutId,
      int aFieldWidth,
      int aBallNum,
      int[] aResId,
      int aIdStart,
      int aBallViewText) {
    BallTable iBallTable = new BallTable(aParentView, aLayoutId, aIdStart);

    int iBallNum = aBallNum;

    int iFieldWidth = aFieldWidth;
    int scrollBarWidth = 6;
    // 定义没行小球的个数为7
    int viewNumPerLine = 7;
    int iBallViewWidth = (iFieldWidth - scrollBarWidth) / viewNumPerLine - 2;

    int lineNum = iBallNum / viewNumPerLine;
    int lastLineViewNum = iBallNum % viewNumPerLine;
    int margin = (iFieldWidth - scrollBarWidth - (iBallViewWidth + 2) * viewNumPerLine) / 2;
    int iBallViewNo = 0;
    for (int row = 0; row < lineNum; row++) {
      TableRow tableRow = new TableRow(aParentView.getContext());
      for (int col = 0; col < viewNumPerLine; col++) {
        String iStrTemp = "";
        if (aBallViewText == 0) {
          iStrTemp = "" + (iBallViewNo); // 小球从0开始
        } else if (aBallViewText == 1) {
          iStrTemp = "" + (iBallViewNo + 1); // 小球从1开始
        } else if (aBallViewText == 3) {
          iStrTemp = "" + (iBallViewNo + 3); // 小球从3开始
        }
        OneBallView tempBallView = new OneBallView(aParentView.getContext());
        tempBallView.setId(aIdStart + iBallViewNo);
        tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId);
        tempBallView.setOnClickListener(this);

        iBallTable.addBallView(tempBallView);

        TableRow.LayoutParams lp = new TableRow.LayoutParams();
        if (col == 0) {
          lp.setMargins(margin + 1, 1, 1, 1);
        } else if (col == viewNumPerLine - 1) {
          lp.setMargins(1, 1, margin + scrollBarWidth + 1, 1);
        } else lp.setMargins(1, 1, 1, 1);
        tableRow.addView(tempBallView, lp);
        iBallViewNo++;
      }
      // 新建的TableRow添加到TableLayout
      iBallTable.tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC));
    }
    if (lastLineViewNum > 0) {
      TableRow tableRow = new TableRow(this);
      for (int col = 0; col < lastLineViewNum; col++) {

        String iStrTemp = "";
        if (aBallViewText == 0) {
          iStrTemp = "" + (iBallViewNo); // 小球从0开始
        } else if (aBallViewText == 1) {
          iStrTemp = "" + (iBallViewNo + 1); // 小球从1开始
        } else if (aBallViewText == 3) {
          iStrTemp = "" + (iBallViewNo + 3); // 小球从3开始
        }
        OneBallView tempBallView = new OneBallView(aParentView.getContext());
        tempBallView.setId(aIdStart + iBallViewNo);
        tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId);
        tempBallView.setOnClickListener(this);
        iBallTable.addBallView(tempBallView);
        TableRow.LayoutParams lp = new TableRow.LayoutParams();
        if (col == 0) {
          lp.setMargins(margin + 1, 1, 1, 1);
        } else lp.setMargins(1, 1, 1, 1);
        tableRow.addView(tempBallView, lp);
        iBallViewNo++;
      }
      // 新建的TableRow添加到TableLayout
      iBallTable.tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC));
    }
    return iBallTable;
  }
Beispiel #18
0
  protected void resizeContent(final int screenWidth, final int screenHeight) {
    if (null == game)
      throw new IllegalStateException(this + " must be initialized with onCreate()");
    final float imageRatio = game.isImageSelected() ? game.getImageAspectRatio() : 1f;
    final int boardSize = getBoardSize();
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    // border width 1 dp rounded up to nearest whole pixels
    final int borderWidth = (int) Math.ceil(metrics.density);
    // calculate spacing allotment
    final int spacing = borderWidth * 2 * boardSize;
    if (screenWidth < spacing + boardSize || screenHeight < spacing + boardSize)
      throw new UnsupportedOperationException(
          "Screen size ("
              + screenWidth
              + " x "
              + screenHeight
              + ") too small for a board of "
              + boardSize
              + " rows");
    final float adjustedScreenRatio = (float) (screenWidth - spacing) / (screenHeight - spacing);

    int width, height;
    if (adjustedScreenRatio > imageRatio) {
      // scale to screen height
      height = screenHeight;
      // fix width = imageRatio * height
      width = (int) (imageRatio * height);
      if (width < spacing + boardSize)
        throw new UnsupportedOperationException(
            "Need a wider image to make a board: scaled to "
                + width
                + " pixels, need "
                + (spacing + boardSize));
    } else {
      // scale to screen width
      width = screenWidth;
      // fix height = width / imageRatio
      height = (int) (width / imageRatio);
      if (height < spacing + boardSize)
        throw new UnsupportedOperationException(
            "Need a taller image to make a board: scaled to "
                + height
                + " pixels, need "
                + (spacing + boardSize));
    }

    // make the dimensions divisible by row/column count
    height -= height % boardSize;
    width -= width % boardSize;
    RelativeLayout.LayoutParams boardLayoutParams = new RelativeLayout.LayoutParams(width, height);
    boardLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    numericBoardView.setLayoutParams(boardLayoutParams);
    imageBoardView.setLayoutParams(boardLayoutParams);

    // load and resize the image
    width = width / boardSize - 2 * borderWidth;
    height = height / boardSize - 2 * borderWidth;
    game.setTileSize(width, height);
    if (game.isImageSelected())
      try {
        game.loadImage(this);
      } catch (ImageProcessingException failure) {
        game.resetSelectedImage();
        Log.e(getClass().getName(), failure.getMessage(), failure);
        hideBoard();
        alert(R.string.image_load_error);
        return;
      }

    // size and fill cell views
    TableRow.LayoutParams cellParams = new TableRow.LayoutParams(width, height);
    cellParams.setMargins(borderWidth, borderWidth, borderWidth, borderWidth);
    float fontSize = width * 4f / 3;
    if (fontSize > height) fontSize = height;
    fontSize *= .5f;
    final Board board = getBoardModel();
    for (int i = 0; i < boardSize; i++) {
      for (int j = 0; j < boardSize; j++) {
        TextView numericCell = numericCells[i][j];
        numericCell.setLayoutParams(cellParams);
        numericCell.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
        ImageView imageCell = imageCells[i][j];
        imageCell.setLayoutParams(cellParams);
        Tile tile = board.getTileAt(i, j);
        assignTile(numericCell, tile);
        assignTile(imageCell, tile);
      }
    }
    countDownCell.setLayoutParams(cellParams);
    countDownCell.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
  }
Beispiel #19
0
    @Override
    protected void onPostExecute(List<Action> actions) {
      if (actions == null) {
        statusLabel.setText("Unable to get actions");
        return;
      }

      // all is ok, replace start pane
      LinearLayout contentPane = (LinearLayout) findViewById(R.id.contentPane);
      contentPane.removeView(startPane);

      LinearLayout buttonsLayout = new LinearLayout(getApplicationContext());
      buttonsLayout.setGravity(Gravity.CENTER);

      TableLayout buttonsTable = new TableLayout(getApplicationContext());
      TableRow currentTableRow = new TableRow(getApplicationContext());

      TableRow.LayoutParams buttonMarginParams =
          new TableRow.LayoutParams(
              TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
      int marginPx =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());
      buttonMarginParams.setMargins(marginPx, marginPx, marginPx, marginPx);

      for (final Action action : actions) {
        ImageButton actionButton = new ImageButton(getApplicationContext());
        int drawableId = getResources().getIdentifier(action.icon, "drawable", getPackageName());
        actionButton.setImageDrawable(getResources().getDrawable(drawableId));
        actionButton.setContentDescription(action.description);
        actionButton.setLayoutParams(buttonMarginParams);
        actionButton.setBackgroundResource(R.drawable.button);
        actionButton.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                new PerformActionAsyncTask().execute(action.name);
              }
            });

        currentTableRow.addView(actionButton);
        if (currentTableRow.getChildCount() == 3) {
          buttonsTable.addView(currentTableRow);
          currentTableRow = new TableRow(getApplicationContext());
        }
      }

      if (currentTableRow.getChildCount() > 0) {
        buttonsTable.addView(currentTableRow);
      }

      buttonsLayout.addView(buttonsTable);

      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
      contentPane.addView(buttonsLayout, params);

      runStatusUpdateTimer();
    }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sp = getSharedPreferences("prefs", MODE_PRIVATE);
    ScrollView sv = new ScrollView(this);
    sv.setFillViewport(true);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setBackgroundColor(Color.parseColor("#000000"));
    sv.addView(ll);

    setContentView(sv);

    Button name, status;
    name = new Button(this);
    status = new Button(this);
    name.setText(sp.getString("name", "null"));
    name.setBackgroundColor(Color.parseColor("#43FFFD"));
    name.setTextColor(Color.parseColor("#ff0000"));
    name.setGravity(View.TEXT_ALIGNMENT_GRAVITY);

    status.setText("Current Percent Stats");
    status.setBackgroundColor(Color.parseColor("#43FFFD"));
    status.setTextColor(Color.parseColor("#ff0000"));
    status.setGravity(View.TEXT_ALIGNMENT_GRAVITY);
    LinearLayout.LayoutParams p =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    p.setMargins(10, 10, 10, 10);
    ll.addView(name, p);
    ll.addView(status, p);

    TableRow.LayoutParams lp =
        new TableRow.LayoutParams(
            TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
    lp.setMargins(20, 20, 20, 20);

    TableLayout tl = new TableLayout(this);
    tl.setStretchAllColumns(true);
    tl.setShrinkAllColumns(true);
    // tl.setBackgroundColor(Color.parseColor("#ffff00"));
    ll.addView(tl);
    int i, n, num, den;
    double ans;
    n = Integer.parseInt(sp.getString("noofsubj", "1"));
    TableRow tr[] = new TableRow[n];

    for (i = 0; i < n; i++) {
      tr[i] = new TableRow(this);
      TextView sntv = new TextView(this);

      TextView per = new TextView(this);
      sntv.setText(sp.getString("subject" + (i + 1), "null"));

      num = sp.getInt("p" + (i + 1), 0);
      den = sp.getInt("t" + (i + 1), 0);
      if (den == 0) ans = 0.0;
      else ans = num * 100.0 / den;

      ans = (Math.rint(ans * 100)) / 100;

      per.setText(ans + "%");
      // sntv.setLayoutParams(lp);
      // per.setLayoutParams(lp);
      sntv.setBackgroundColor(Color.parseColor("#ffff00"));
      per.setBackgroundColor(Color.parseColor("#ffff00"));
      sntv.setTextSize(20);
      per.setTextSize(20);
      tr[i].addView(sntv, lp);
      tr[i].addView(per, lp);

      tl.addView(tr[i]);
    }
    Button btnFin = new Button(this);
    btnFin.setText("FINISH");
    // btnFin.setText(sp.getString("initialized","null").equals("true")+"-"+"ABCabc");
    btnFin.setTextColor(Color.parseColor("#000000"));
    btnFin.setBackgroundColor(Color.parseColor("#00ff00"));
    tl.addView(btnFin);
    btnFin.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            action();
          }
        });
  }
Beispiel #21
0
  @Override
  public BallTable makeBallTable(
      TableLayout tableLayout,
      int aFieldWidth,
      int aBallNum,
      int[] aResId,
      int aIdStart,
      int aBallViewText,
      Context context,
      OnClickListener onclick) {
    TableLayout tabble = tableLayout;
    BallTable iBallTable = new BallTable(aIdStart, context);
    int iBallNum = aBallNum;

    int viewNumPerLine = 8; // 定义没行小球的个数为7
    int iFieldWidth = aFieldWidth;
    int scrollBarWidth = 6;
    int iBallViewWidth = (iFieldWidth - scrollBarWidth) / viewNumPerLine - 2;
    int lineNum = iBallNum / viewNumPerLine;
    int lastLineViewNum = iBallNum % viewNumPerLine;
    int margin = (iFieldWidth - scrollBarWidth - (iBallViewWidth + 2) * viewNumPerLine) / 2;
    int iBallViewNo = 0;
    for (int row = 0; row < lineNum; row++) {
      TableRow tableRow = new TableRow(context);
      for (int col = 0; col < viewNumPerLine; col++) {
        String iStrTemp = "";
        switch (col) {
          case 0:
            iStrTemp = "大";
            break;
          case 1:
            iStrTemp = "小";
            break;
          case 2:
            iStrTemp = "单";
            break;
          case 3:
            iStrTemp = "双";
            break;
        }
        OneBallView tempBallView = new OneBallView(context);
        tempBallView.setId(aIdStart + iBallViewNo);
        tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId);
        tempBallView.setOnClickListener(onclick);
        iBallTable.addBallView(tempBallView);

        TableRow.LayoutParams lp = new TableRow.LayoutParams();
        if (col == 0) {
          lp.setMargins(margin, 1, 1, 1);
        } else if (col == viewNumPerLine - 1) {
          lp.setMargins(1, 1, margin + scrollBarWidth + 1, 1);
        } else lp.setMargins(1, 1, 1, 1);
        tableRow.addView(tempBallView, lp);
        iBallViewNo++;
      }
      tabble.addView(tableRow, new TableLayout.LayoutParams(PublicConst.FP, PublicConst.WC));
    }
    if (lastLineViewNum > 0) {
      TableRow tableRow = new TableRow(context);
      for (int col = 0; col < lastLineViewNum; col++) {
        String iStrTemp = "";
        switch (col) {
          case 0:
            iStrTemp = "大";
            break;
          case 1:
            iStrTemp = "小";
            break;
          case 2:
            iStrTemp = "单";
            break;
          case 3:
            iStrTemp = "双";
            break;
        }
        OneBallView tempBallView = new OneBallView(context);
        tempBallView.setId(aIdStart + iBallViewNo);
        tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId);
        tempBallView.setOnClickListener(onclick);
        iBallTable.addBallView(tempBallView);
        TableRow.LayoutParams lp = new TableRow.LayoutParams();
        if (col == 0) {
          lp.setMargins(margin, 1, 1, 1);
        } else lp.setMargins(1, 1, 1, 1);
        tableRow.addView(tempBallView, lp);
        iBallViewNo++;
      }
      // 新建的TableRow添加到TableLayout
      tabble.addView(tableRow, new TableLayout.LayoutParams(PublicConst.FP, PublicConst.WC));
    }
    return iBallTable;
  }
Beispiel #22
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final TabActivity activity = (TabActivity) getActivity();
    menu = activity.getMenu();
    View rootView = inflater.inflate(R.layout.menu_layout, container, false);

    ScrollView scroll = new ScrollView(getActivity().getApplicationContext());
    TableLayout menulist = new TableLayout(getActivity().getApplicationContext());
    TableRow.LayoutParams param = new TableRow.LayoutParams();
    param.setMargins(0, 0, 15, 0);
    final String sid = "1";
    int id = 0;
    for (Beverage beverage : menu) {
      if (beverage.getType().equals("bier")) {
        id++;

        TableRow row = new TableRow(getActivity().getApplicationContext());

        TextView tekst = new TextView(getActivity().getApplicationContext());
        tekst.setText(beverage.getName());
        tekst.setLayoutParams(param);
        tekst.setId(Integer.parseInt(sid + id));
        row.addView(tekst);

        Button plus = new Button(getActivity().getApplicationContext());
        plus.setText("plus");
        plus.setLayoutParams(param);
        plus.setId(id);
        plus.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                int id = v.getId();
                TextView name = (TextView) getView().findViewById(Integer.parseInt(sid + id));
                String naam = name.getText().toString();
                String currentsaldo = activity.plus(naam);
                TextView total = (TextView) getView().findViewById(Integer.parseInt(sid + id + id));
                total.setText("€ " + currentsaldo);
                activity.setTotal();
                total.invalidate();
              }
            });
        row.addView(plus);

        Button min = new Button(getActivity().getApplicationContext());
        min.setText("min");
        min.setLayoutParams(param);
        min.setId(id);
        min.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                int id = v.getId();
                TextView name = (TextView) getView().findViewById(Integer.parseInt(sid + id));
                String naam = name.getText().toString();
                String currentsaldo = activity.min(naam);
                TextView total = (TextView) getView().findViewById(Integer.parseInt(sid + id + id));
                total.setText("€ " + currentsaldo);
                activity.setTotal();
                total.invalidate();
              }
            });
        row.addView(min);

        TextView amount = new TextView(getActivity().getApplicationContext());
        amount.setText("€" + beverage.getPrice());
        amount.setLayoutParams(param);
        row.addView(amount);

        TextView total = new TextView(getActivity().getApplicationContext());
        total.setLayoutParams(param);
        total.setText("€ 0.00");
        total.setId(Integer.parseInt(sid + id + id));
        row.addView(total);

        menulist.addView(row);
      }
    }
    scroll.setPadding(20, 5, 0, 5);
    scroll.addView(menulist);
    return scroll;
  }