Ejemplo n.º 1
0
  private void setList() {

    TextView tv1 = (TextView) findViewById(R.id.INVENTARIOS_PROYECTO_ID);

    tv1.setText(proyecto);

    TableLayout tl = (TableLayout) findViewById(R.id.LISTA_INVENTARIO_ID);

    listMenu = (LinearLayout) findViewById(R.id.LISTA_INVENTARIO_ID);

    List<String> inventarios = controller.getInventarioIds();

    listMenu.removeAllViews();

    if (inventarios != null) {

      int i = 1;
      for (String inventarioId : inventarios) {

        TableRow tr = new TableRow(this);
        LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        tr.setLayoutParams(lp);

        Inventario inventario = controller.getInventario(inventarioId);

        HashMap<String, String> data = inventario.getData();

        TextView tv = new TextView(this);

        String dProyecto = data.get(Inventario.PROYECTO);
        String display = data.get(Inventario.NOMBRE);

        if (dProyecto == null || !dProyecto.equals(proyecto) || display == null) {

          continue;
        }

        String lastSaved = data.get(Inventario.LAST_SAVED);
        String lastSync = data.get(Inventario.LAST_SYNC);

        tv.setText(display);
        tv.setTypeface(null, Typeface.BOLD);
        tv.setPadding(10, 0, 0, 0);
        tv.setLayoutParams(lp);
        tv.setTextSize(20);
        tv.setLayoutParams(new LayoutParams(300, LayoutParams.WRAP_CONTENT));

        ImageView imgView = new ImageView(this);
        imgView.setPadding(10, 0, 0, 0);
        imgView.setLayoutParams(lp);

        int color = R.drawable.red_light;

        if (lastSaved != null && lastSync != null && lastSaved.equals(lastSync)) {

          color = R.drawable.green_light;
        }

        imgView.setImageDrawable(getResources().getDrawable(color));

        if (i % 2 == 0) {

          tr.setBackgroundColor(0xffcccccc);

        } else {

          tr.setBackgroundColor(0xff888888);
        }

        ImageView imgViewSync = new ImageView(this);
        imgViewSync.setImageDrawable(getResources().getDrawable(R.drawable.sync));
        imgViewSync.setPadding(20, 0, 0, 0);
        imgViewSync.setLayoutParams(lp);
        imgViewSync.setOnClickListener(new syncClickHandler(inventarioId, display));

        ImageView imgViewRemove = new ImageView(this);
        imgViewRemove.setImageDrawable(getResources().getDrawable(R.drawable.remove));
        imgViewRemove.setPadding(20, 0, 0, 0);
        imgViewRemove.setLayoutParams(lp);
        imgViewRemove.setOnClickListener(new removeClickHandler(inventarioId, display));

        ImageView imgViewEdit = new ImageView(this);
        imgViewEdit.setImageDrawable(getResources().getDrawable(R.drawable.writing));
        imgViewEdit.setPadding(20, 0, 0, 0);
        imgViewEdit.setLayoutParams(lp);
        imgViewEdit.setOnClickListener(new InventarioClickHandler(inventario.getId()));

        tr.addView(imgView);
        tr.addView(tv);
        tr.addView(imgViewSync);
        tr.addView(imgViewRemove);
        tr.addView(imgViewEdit);

        tl.addView(
            tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        i++;
      }
    }
  }