示例#1
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 0) {
      if (resultCode == -1) {
        if (data != null) {
          if (data.hasExtra("data")) {
            imgTmp.setImage(
                Bitmap.createScaledBitmap(
                    (Bitmap) data.getParcelableExtra("data"), 640, 480, true));
          }
        } else {
          imgTmp.setImage(
              Bitmap.createScaledBitmap(BitmapFactory.decodeFile(name), 640, 480, true));
        }

        final EditText desc = new EditText(this);
        desc.setLines(1);
        desc.setMaxLines(1);

        desc.setBackgroundResource(R.drawable.fondo_edittext);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(desc);

        builder.setIcon(R.drawable.ic_camera);
        builder.setTitle("¿Qué fotografió?");
        builder.setPositiveButton("Guardar", null);
        builder.setNegativeButton(
            "Cancelar",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                imgTmp = null;
                dialogInterface.dismiss();
              }
            });
        builder.setCancelable(false);

        final AlertDialog alert = builder.create();
        alert.setCanceledOnTouchOutside(false);
        alert.setCancelable(false);
        alert.show();
        alert
            .getButton(DialogInterface.BUTTON_POSITIVE)
            .setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                    if (desc.getText().toString().length() == 0) {
                      Toast.makeText(
                              getApplicationContext(),
                              "Ingrese una descripción de lo fotografiado",
                              Toast.LENGTH_LONG)
                          .show();
                      return;
                    }
                    imgTmp.setComment(desc.getText().toString());
                    imgTmp.newNameRelevo(imgTmp.getIdSystem(), imgTmp.getComment());
                    imagenes.add(imgTmp);
                    imgTmp = null;
                    alert.dismiss();
                  }
                });
      }
    }

    if (requestCode == idRelevo) {
      if (resultCode == Activity.RESULT_OK) {
        reg.clearPreferences();
        ((Activity) context).finish();
      }
    }
  }
示例#2
0
  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());
      }
    }
  }
示例#3
0
    @Override
    protected String doInBackground(String... params) {
      String response = "";

      for (FormImage img : imagenes) {
        try {
          String fileName = img.getName();

          publishProgress(fileName);
          Log.i("ENVIANDO", fileName);
          Log.i("ENVIANDO", "comentario: " + img.getComment());
          Log.i("ENVIANDO", "system: " + img.getIdSystem());
          Log.i("ENVIANDO", "subsystem: " + img.getIdSubSystem());
          HttpURLConnection conn;
          DataOutputStream dos;
          String lineEnd = "\r\n";
          String twoHyphens = "--";
          String boundary = "*****";
          int bytesRead, bytesAvailable, bufferSize;

          File done =
              new File(Environment.getExternalStorageDirectory().getAbsolutePath(), fileName);
          done.createNewFile();

          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          img.getImage().compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
          byte[] bitmapdata = bos.toByteArray();

          FileOutputStream fos = new FileOutputStream(done);
          fos.write(bitmapdata);
          fos.flush();
          fos.close();

          if (!done.isFile()) Log.e("DownloadManager", "no existe");
          else {
            FileInputStream fileInputStream = new FileInputStream(done);
            URL url = new URL(dummy.URL_R_SEND_CHECK_IMGS);

            conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("ENCTYPE", "multipart/form-data");
            conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
            conn.setRequestProperty("uploaded_file", fileName);

            dos = new DataOutputStream(conn.getOutputStream());

            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes(
                "Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
                    + fileName
                    + "\""
                    + lineEnd);
            dos.writeBytes(lineEnd);

            bytesAvailable = fileInputStream.available();

            bufferSize = Math.min(bytesAvailable, 1 * 1024 * 1024);
            byte[] buf = new byte[bufferSize];

            bytesRead = fileInputStream.read(buf, 0, bufferSize);

            while (bytesRead > 0) {

              dos.write(buf, 0, bufferSize);
              bytesAvailable = fileInputStream.available();
              bufferSize = Math.min(bytesAvailable, 1 * 1024 * 1024);
              bytesRead = fileInputStream.read(buf, 0, bufferSize);
            }

            dos.writeBytes(lineEnd);
            dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
            int serverResponseCode = conn.getResponseCode();
            String serverResponseMessage = conn.getResponseMessage();

            Log.i(
                "UploadManager",
                "HTTP response is: " + serverResponseMessage + ": " + serverResponseCode);

            fileInputStream.close();
            dos.flush();
            dos.close();

            InputStream responseStream = new BufferedInputStream(conn.getInputStream());

            BufferedReader responseStreamReader =
                new BufferedReader(new InputStreamReader(responseStream));
            String line = "";
            StringBuilder stringBuilder = new StringBuilder();
            while ((line = responseStreamReader.readLine()) != null) {
              stringBuilder.append(line).append("\n");
            }
            responseStreamReader.close();

            response = stringBuilder.toString();

            if (response.contains("<MESSAGE>OK</MESSAGE>")) {
              Log.d("ENVIANDO", "OK");
              img.setSend(true);
            } else {
              Log.d("ENVIANDO", "NOK");
            }
          }

        } catch (Exception e) {
          Log.d("TAG", "Error: " + e.getMessage());
          response = "ERROR";
        }
      }
      return response;
    }