Esempio n. 1
0
  private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Intent intent = getIntent();

    final DatabaseHandler dbHandler = new DatabaseHandler(getApplicationContext());
    int id = intent.getIntExtra("id", 0);

    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
      // Create the File where the photo should go
      // File photoFile = null;
      try {
        photoFile = PhotoHelper.createImageFileForDocument(id, getApplicationContext());

      } catch (IOException ex) {
        // Error occurred wh7ile creating the File

      }

      // Continue only if the File was successfully created
      if (photoFile != null) {
        takePictureIntent.putExtra("output", Uri.fromFile(photoFile));

        // final document_obj doc_obj = new document_obj();
        doc_obj.set_doc_name(photoFile.getPath());
        doc_obj.set_doc_path(photoFile.getPath());
        // bitmap =BitmapFactory.decodeFile(photoFile.getPath());
        // doc_obj.set_bmp(PhotoHelper.getBitmapAsByteArray(bitmap));
        doc_obj.set_id(id);

        startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
      }
    }
  }
Esempio n. 2
0
  public void getDocumentsList(int id) {

    DatabaseHandler dbHandler = new DatabaseHandler(getApplicationContext());

    ArrayList<Item> nameWithImage = new ArrayList<Item>();
    Item displayDocument = new Item();
    Patient patient = dbHandler.getPatient(id);
    setTitle(patient.get_name() + "'s Documents");
    Bitmap bmpImage = null;
    document_obj doc_obj = new document_obj();
    List<document_obj> documentList = dbHandler.getDocuments(id);
    for (int i = 0; i < documentList.size(); i++) {

      if ((documentList.get(i).get_doc_name() != null)
          || (documentList.get(i).get_doc_name() != null)) {
        displayDocument.setTitle(documentList.get(i).get_doc_name());
        displayDocument.setDiagnosis(documentList.get(i).get_doc_path());

        if (documentList.get(i).get_bmp() == null) {
          doc_obj = documentList.get(i);
          doc_obj = PhotoHelper.addMissingBmp(doc_obj);
          dbHandler.updateDocument(doc_obj, "0");
        }
        bmpImage =
            BitmapFactory.decodeByteArray(
                documentList.get(i).get_bmp(), 0, documentList.get(i).get_bmp().length);

        displayDocument.setBmp(bmpImage);
        displayDocument.setPatient_id(documentList.get(i).get_id());

        nameWithImage.add(displayDocument);
        displayDocument = new Item();
      }
    }
    displayDocuments(nameWithImage);
  }
Esempio n. 3
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Calendar c = Calendar.getInstance();
    final DatabaseHandler dbHandler = new DatabaseHandler(getApplicationContext());
    Resources resources = getResources();
    Patient patient = dbHandler.getPatient(pid);
    SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
    String formattedDate = df.format(c.getTime());
    if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {

      Bitmap bitmap;
      bitmap = BitmapFactory.decodeFile(doc_obj.get_doc_path());
      ByteArrayOutputStream ostream = new ByteArrayOutputStream();

      // save image into gallery
      bitmap.compress(Bitmap.CompressFormat.JPEG, 20, ostream);

      try {
        FileOutputStream fout = new FileOutputStream(photoFile);
        fout.write(ostream.toByteArray());
        fout.close();
      } catch (Exception e) {
        e.printStackTrace();
      }

      // doc_obj.set_bmp(PhotoHelper.getBitmapAsByteArray(Bitmap.createScaledBitmap(bitmap,120,120,false)));
      doc_obj = PhotoHelper.addMissingBmp(doc_obj);
      if (doc_obj.get_bmp() != null) {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());

        String imageFileName = "IMG_" + timeStamp;
        doc_obj.set_doc_name(imageFileName);
        doc_obj.set_date(formattedDate);

        patient.set_last_seen_date(formattedDate);
        dbHandler.updatePatient(patient);
        dbHandler.addDocument(doc_obj);
      }
      utility.recreateActivityCompat(documents.this);

      // utility.recreateActivityCompat(this);

    } else if ((requestCode == PICKFILE_RESULT_CODE)
        && ((data != null) && (data.getData() != null))) {
      Uri uri = data.getData();
      File file = null;
      String file_name = "";
      String file_path = "";
      ; // "/mnt/sdcard/FileName.mp3"
      try {
        file = new File(uri.getPath());
        String a = file.getAbsolutePath();

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

      if (uri.getScheme().compareTo("content") == 0) {
        Cursor cursor = getContentResolver().query(uri, null, null, null, null);
        if (cursor.moveToFirst()) {
          int column_index =
              cursor.getColumnIndexOrThrow(
                  MediaStore.Images.Media
                      .DATA); // Instead of "MediaStore.Images.Media.DATA" can be used "_data"
          Uri filePathUri = Uri.parse(cursor.getString(column_index));
          file_name = filePathUri.getLastPathSegment();
          file_path = filePathUri.getPath();
        }
      } else {
        Uri filePathUri = Uri.fromFile(file);
        file_name = filePathUri.getLastPathSegment();
        file_path = filePathUri.getPath();
      }
      if (file_name.contains(".doc")) {
        doc_obj.set_bmp(
            PhotoHelper.getBitmapAsByteArray(
                BitmapFactory.decodeResource(resources, R.drawable.ic_doc)));
      } else if (file_name.contains(".pdf")) {
        doc_obj.set_bmp(
            PhotoHelper.getBitmapAsByteArray(
                BitmapFactory.decodeResource(resources, R.drawable.ic_pdf)));
      } else if (file_name.contains(".txt")) {
        doc_obj.set_bmp(
            PhotoHelper.getBitmapAsByteArray(
                BitmapFactory.decodeResource(resources, R.drawable.ic_txt)));
      } else if ((file_name.contains(".jpg")) || (file_name.contains(".png"))) {
        doc_obj.set_bmp(PhotoHelper.getBitmapAsByteArray(BitmapFactory.decodeFile(file_path)));
      }

      doc_obj.set_doc_name(file_name);
      doc_obj.set_doc_path(file_path);
      doc_obj.set_id(pid);
      doc_obj.set_date(formattedDate);
      dbHandler.updatePatient(patient);
      dbHandler.addDocument(doc_obj);
      Toast.makeText(
              this, "File Name & PATH are:" + file_name + "\n" + file_path, Toast.LENGTH_LONG)
          .show();

      // }
    }

    utility.recreateActivityCompat(documents.this);
  }