private void saveData() { reg.addValue("SELECT" + depto.getId(), depto.getSelectedItem().toString()); reg.addValue("SELECT" + province.getId(), province.getSelectedItem().toString()); reg.addValue("SELECT" + district.getId(), district.getSelectedItem().toString()); reg.addValue("SELECT" + station.getId(), station.getSelectedItem().toString()); for (Modulo m : modulos) { for (cl.tdc.felipe.tdc.objects.Relevar.Item i : m.getItems()) { View v = i.getVista(); View c = i.getDescription(); if (i.getCheckBoxes() != null) { for (int x = 0; x < i.getCheckBoxes().size(); x++) { CheckBox check = i.getCheckBoxes().get(x); reg.addValue("CHECK" + check.getId(), check.isChecked()); if (x == 0) reg.addValue("COMMENTCHECK" + check.getId(), ((EditText) c).getText().toString()); } } if (v instanceof Spinner) { reg.addValue("SELECT" + v.getId(), ((Spinner) v).getSelectedItem().toString()); reg.addValue("COMMENTSELECT" + v.getId(), ((EditText) c).getText().toString()); } if (v instanceof EditText) { reg.addValue("TEXT" + v.getId(), ((EditText) v).getText().toString()); if (c != null) reg.addValue("COMMENTTEXT" + v.getId(), ((EditText) c).getText().toString()); } } } for (FormImage img : imagenes) { if (img.getImage() != null) { String id1 = "FOTOBITMAP" + img.getIdSystem() + img.getIdSubSystem(); String id2 = "FOTONAME" + img.getIdSystem() + img.getIdSubSystem(); String id3 = "FOTOCOMMENT" + img.getIdSystem() + img.getIdSubSystem(); reg.addValue(id1, Funciones.encodeTobase64(img.getImage())); reg.addValue(id2, img.getName()); reg.addValue(id3, img.getComment()); } } }
private View getView(int mId, cl.tdc.felipe.tdc.objects.Relevar.Item item) { String type = item.getType(); List<String> values = item.getValues(); LinearLayout contenido = new LinearLayout(this); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); contenido.setLayoutParams(params); params.setMargins(0, 6, 0, 0); contenido.setOrientation(LinearLayout.VERTICAL); contenido.setGravity(Gravity.CENTER_HORIZONTAL); String comment = ""; if (type.equals("SELECT")) { Spinner s = new Spinner(this); s.setBackgroundResource(R.drawable.spinner_bg); s.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, values); s.setAdapter(adapter); String id = mId + item.getId() + item.getName() + values.toString(); s.setId(Funciones.str2int(id)); String Selected = reg.getString("SELECT" + s.getId()); s.setSelection(adapter.getPosition(Selected)); contenido.addView(s); item.setVista(s); comment = reg.getString("COMMENTSELECT" + s.getId()); } else if (type.equals("CHECK")) { LinearLayout checkboxLayout = new LinearLayout(this); checkboxLayout.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); checkboxLayout.setOrientation(LinearLayout.VERTICAL); ArrayList<CheckBox> checkBoxes = new ArrayList<>(); int count = 0; while (count < values.size()) { LinearLayout dump = new LinearLayout(this); dump.setOrientation(LinearLayout.HORIZONTAL); dump.setGravity(Gravity.CENTER_HORIZONTAL); dump.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int p = 0; p < 3; p++) { if (count < values.size()) { String state = values.get(count); CheckBox cb = new CheckBox(this); String id = mId + item.getId() + item.getName() + values.get(count); cb.setId(Funciones.str2int(id)); cb.setChecked(reg.getBoolean("CHECK" + cb.getId())); cb.setText(state); checkBoxes.add(cb); dump.addView(cb); if (count == 0) comment = reg.getString("COMMENTCHECK" + cb.getId()); count++; vistas.add(cb); } } checkboxLayout.addView(dump); } makeOnlyOneCheckable(checkBoxes); item.setCheckBoxes(checkBoxes); contenido.addView(checkboxLayout); } else if (type.equals("NUM")) { EditText e = new EditText(this); e.setBackgroundResource(R.drawable.fondo_edittext); e.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); String id = mId + item.getId() + item.getName(); e.setId(Funciones.str2int(id)); e.setText(reg.getString("TEXT" + e.getId())); e.setLayoutParams(new LinearLayout.LayoutParams(100, ViewGroup.LayoutParams.WRAP_CONTENT)); e.setGravity(Gravity.CENTER_HORIZONTAL); vistas.add(e); item.setVista(e); contenido.addView(e); comment = reg.getString("COMMENTTEXT" + e.getId()); } else if (type.equals("VARCHAR")) { EditText e = new EditText(this); e.setBackgroundResource(R.drawable.fondo_edittext); e.setInputType(InputType.TYPE_CLASS_TEXT); e.setLines(2); e.setGravity(Gravity.LEFT | Gravity.TOP); String id = mId + item.getId() + item.getName(); e.setId(Funciones.str2int(id)); e.setText(reg.getString("TEXT" + e.getId())); vistas.add(e); item.setVista(e); contenido.addView(e); comment = reg.getString("COMMENTTEXT" + e.getId()); } if (!item.getName().equals("COMENTARIOS")) { EditText comentario = new EditText(this); comentario.setLayoutParams(params); comentario.setBackgroundResource(R.drawable.fondo_edittext); comentario.setLines(3); comentario.setText(comment); comentario.setHint("Observaciones"); item.setDescription(comentario); contenido.addView(comentario); } return contenido; }
private boolean fechasOK() { for (final Dia d : mDias) { String fecha = d.getFecha().getText().toString(); if (fecha.length() > 0) { if (!Funciones.validateDate(fecha)) { AlertDialog.Builder b1 = new AlertDialog.Builder(mContext); b1.setIcon(android.R.drawable.ic_dialog_alert); b1.setMessage("Formato de fecha Incorrecto.\nDebe ser AAAA-MM-DD"); b1.setTitle("Dia " + d.getDayNumber()); b1.setNeutralButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (d.getlContenido().getVisibility() == View.GONE) { d.getlContenido().setVisibility(View.VISIBLE); } d.getFecha().requestFocus(); dialogInterface.dismiss(); } }); b1.show(); return false; } else { try { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date hoy = new Date(); Date fecha_envia = formatter.parse(fecha); Log.d("FECHAS", hoy + " " + fecha_envia); if (formatter.format(fecha_envia).compareTo(formatter.format(hoy)) < 0) { AlertDialog.Builder b1 = new AlertDialog.Builder(mContext); b1.setIcon(android.R.drawable.ic_dialog_alert); b1.setMessage("No puede ingresar una fecha anterior al día de hoy."); b1.setTitle("Dia " + d.getDayNumber()); b1.setNeutralButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (d.getlContenido().getVisibility() == View.GONE) { d.getlContenido().setVisibility(View.VISIBLE); } d.getFecha().requestFocus(); dialogInterface.dismiss(); } }); b1.show(); return false; } } catch (Exception e) { e.printStackTrace(); Toast.makeText( mContext, "Ocurrió un error al comprobar la fecha, por favor reintente", Toast.LENGTH_LONG) .show(); return false; } } } } return true; }