public Note makeNote(
      EvernoteNoteStoreClient noteStore,
      String noteTitle,
      String noteBody,
      Bitmap... imageResources) {

    // Create a Note instance with title and body
    // Send Note object to user's account
    Note note = new Note();
    note.setTitle(noteTitle);

    // Build body of note
    StringBuilder body = new StringBuilder(EvernoteUtil.NOTE_PREFIX).append(noteBody);

    if (imageResources != null && imageResources.length > 0) {
      // Create Resource objects from image resources and add them to note body
      body.append("<br /><br />");
      List<Resource> resources = new ArrayList<>(imageResources.length);
      note.setResources(resources);
      for (Bitmap image : imageResources) {
        Resource r = makeResource(image);
        if (r == null) continue;
        resources.add(r);
        body.append("Attachment with hash ")
            .append(Arrays.toString(r.getData().getBodyHash()))
            .append(": <br /><en-media type=\"")
            .append(r.getMime())
            .append("\" hash=\"")
            .append(Arrays.toString(r.getData().getBodyHash()))
            .append("\" /><br />");
      }
      body.append(EvernoteUtil.NOTE_SUFFIX);

      note.setContent(body.toString());

      // Attempt to create note in Evernote account
      try {
        note = noteStore.createNote(note);
      } catch (Exception e) {
        // Something was wrong with the note data
        // See EDAMErrorCode enumeration for error code explanation
        // http://dev.evernote.com/documentation/reference/Errors.html#Enum_EDAMErrorCode
        Toast.makeText(this, R.string.save_note_error, Toast.LENGTH_LONG).show();
        note = null;
      }
    }

    // Return created note object
    return note;
  }
Пример #2
0
 @Override
 public String convert(Resource resource, List<Attribute> attributes) {
   String type = getAttributeValue(attributes, "type");
   if (type != null && type.startsWith("image/")) {
     String src = upload(resource.getData().getBody());
     attributes.add(new Attribute("src", src));
     return "img";
   }
   return null;
 }
 private Resource makeResource(Bitmap image) {
   Resource imageResource = new Resource();
   Data resourceData = new Data();
   imageResource.setData(resourceData);
   try {
     ByteArrayOutputStream stream = new ByteArrayOutputStream();
     // Write bitmap to file using PNG and 85% quality
     image.compress(Bitmap.CompressFormat.PNG, 85, stream);
     byte[] byteArray = stream.toByteArray();
     stream.close();
     resourceData.setBody(byteArray);
     resourceData.setSize(byteArray.length);
     resourceData.setBodyHash(Arrays.copyOfRange(md5(byteArray), 0, Constants.EDAM_HASH_LEN));
     imageResource.setMime(Constants.EDAM_MIME_TYPE_PNG);
     imageResource.setHeight((short) image.getHeight());
     imageResource.setWidth((short) image.getWidth());
     image.recycle();
   } catch (IOException ioe) {
     Log.e(
         FingerPaintView.class.getName(), "makeResource [IOException]: " + ioe.getMessage(), ioe);
     imageResource = null;
   }
   return imageResource;
 }
Пример #4
0
  // Convert the binary data to a resource
  private Resource createResource(byte[] fileData, String address) {
    logger.log(logger.EXTREME, "Inside create resource");
    // These two lines are added to handle odd characters in the name like #.  Without it
    // toLocalFile() chokes and returns the wrong name.
    MessageDigest md;
    try {
      logger.log(logger.EXTREME, "Generating MD5");
      md = MessageDigest.getInstance("MD5");
      md.update(fileData);
      byte[] hash = md.digest();

      Resource r = new Resource();
      r.setGuid(QUuid.createUuid().toString().replace("}", "").replace("{", ""));
      r.setNoteGuid(noteGuid);
      r.setMime("image/" + address.substring(address.lastIndexOf(".") + 1));
      r.setActive(true);
      r.setUpdateSequenceNum(0);
      r.setWidth((short) 0);
      r.setHeight((short) 0);
      r.setDuration((short) 0);

      Data d = new Data();
      d.setBody(fileData);
      d.setBodyIsSet(true);
      d.setBodyHash(hash);
      d.setBodyHashIsSet(true);
      r.setData(d);
      d.setSize(fileData.length);

      int fileNamePos = address.lastIndexOf(File.separator);
      if (fileNamePos == -1) fileNamePos = address.lastIndexOf("/");
      String fileName = address.substring(fileNamePos + 1);
      ResourceAttributes a = new ResourceAttributes();
      a.setAltitude(0);
      a.setAltitudeIsSet(false);
      a.setLongitude(0);
      a.setLongitudeIsSet(false);
      a.setLatitude(0);
      a.setLatitudeIsSet(false);
      a.setCameraMake("");
      a.setCameraMakeIsSet(false);
      a.setCameraModel("");
      a.setCameraModelIsSet(false);
      a.setAttachment(false);
      a.setAttachmentIsSet(true);
      a.setClientWillIndex(false);
      a.setClientWillIndexIsSet(true);
      a.setRecoType("");
      a.setRecoTypeIsSet(false);
      a.setSourceURL(fileName);
      a.setSourceURLIsSet(true);
      a.setTimestamp(0);
      a.setTimestampIsSet(false);
      a.setFileName(fileName);
      a.setFileNameIsSet(true);
      r.setAttributes(a);

      // conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);
      logger.log(logger.EXTREME, "Resource created");

      // Now write it out so someone else can look at it

      return r;
    } catch (NoSuchAlgorithmException e1) {
      e1.printStackTrace();
    }
    return null;
  }