Exemplo n.º 1
0
  public static void saveThumbnail(String path) {
    byte[] is;
    for (String image : UshahidiService.mNewIncidentsThumbnails) {

      if (!TextUtils.isEmpty(image)) {
        File thumbnailFilename = new File(image);
        // Log.i("Save Images", "Image :" + UshahidiPref.savePath +
        // thumbnailFilename.getName());
        File f = new File(path, thumbnailFilename.getName());
        if (!f.exists()) {
          try {
            is = UshahidiHttpClient.fetchImage(UshahidiPref.domain + "/media/uploads/" + image);
            if (is != null) {
              writeImage(is, thumbnailFilename.getName(), path);
            }
          } catch (MalformedURLException e) {

            e.printStackTrace();
          } catch (IOException e) {

            e.printStackTrace();
          }
        }
      }
    }

    // clear images
    UshahidiService.mNewIncidentsThumbnails.clear();
  }
Exemplo n.º 2
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // The preferences returned if the request code is what we had given
    // earlier in startSubActivity
    switch (requestCode) {
      case REQUEST_CODE_CAMERA:
        setRequestedOrientation(
            ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); // pull it out of landscape mode
        break;

      case REQUEST_CODE_IMAGE:
        if (resultCode != RESULT_OK) {
          return;
        }
        Uri uri = data.getData();
        Bitmap b = null;
        try {
          b = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
        } catch (FileNotFoundException e) {
          break;
        } catch (IOException e) {
          break;
        }
        ByteArrayOutputStream byteArrayos = new ByteArrayOutputStream();
        try {
          b.compress(CompressFormat.JPEG, 75, byteArrayos);
          byteArrayos.flush();
        } catch (OutOfMemoryError e) {
          break;
        } catch (IOException e) {
          break;
        }
        filename = "android_pic_upload" + randomString() + ".jpg";
        ImageManager.writeImage(byteArrayos.toByteArray(), filename);
        UshahidiService.fileName = filename;
        selectedPhoto.setText(UshahidiService.fileName);
        break;

      case VIEW_MAP:
        if (resultCode != RESULT_OK) {
          return;
        }

        bundle = null;
        extras = data.getExtras();
        if (extras != null) bundle = extras.getBundle("locations");

        if (bundle != null && !bundle.isEmpty()) {
          incidentLocation.setText(bundle.getString("location"));

          AddIncident.latitude = bundle.getDouble("latitude");
          AddIncident.longitude = bundle.getDouble("longitude");
        }
        break;
    }
  }
Exemplo n.º 3
0
  public static void saveImageFromURL(String url, String fileName, String path) {
    byte[] is;

    if (!TextUtils.isEmpty(url)) {
      File imageFilename = new File(fileName);
      File f = new File(path, imageFilename.getName());
      if (!f.exists()) {
        try {
          is = UshahidiHttpClient.fetchImage(url);
          if (is != null) {
            writeImage(is, imageFilename.getName(), path);
          }
        } catch (MalformedURLException e) {

          e.printStackTrace();
        } catch (IOException e) {

          e.printStackTrace();
        }
      }
    }
  }