コード例 #1
0
  /** Notes sharing */
  public void shareNote(Note note) {

    String titleText = note.getTitle();

    String contentText = titleText + System.getProperty("line.separator") + note.getContent();

    Intent shareIntent = new Intent();
    // Prepare sharing intent with only text
    if (note.getAttachmentsList().size() == 0) {
      shareIntent.setAction(Intent.ACTION_SEND);
      shareIntent.setType("text/plain");
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
      shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);

      // Intent with single image attachment
    } else if (note.getAttachmentsList().size() == 1) {
      shareIntent.setAction(Intent.ACTION_SEND);
      shareIntent.setType(note.getAttachmentsList().get(0).getMime_type());
      shareIntent.putExtra(Intent.EXTRA_STREAM, note.getAttachmentsList().get(0).getUri());
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
      shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);

      // Intent with multiple images
    } else if (note.getAttachmentsList().size() > 1) {
      shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
      ArrayList<Uri> uris = new ArrayList<>();
      // A check to decide the mime type of attachments to share is done here
      HashMap<String, Boolean> mimeTypes = new HashMap<>();
      for (Attachment attachment : note.getAttachmentsList()) {
        uris.add(attachment.getUri());
        mimeTypes.put(attachment.getMime_type(), true);
      }
      // If many mime types are present a general type is assigned to intent
      if (mimeTypes.size() > 1) {
        shareIntent.setType("*/*");
      } else {
        shareIntent.setType((String) mimeTypes.keySet().toArray()[0]);
      }

      shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
      shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);
    }

    startActivity(
        Intent.createChooser(
            shareIntent, getResources().getString(R.string.share_message_chooser)));
  }
コード例 #2
0
ファイル: DbHelper.java プロジェクト: jinguoliang/Omni-Notes
 /** Counts words in a note */
 public int getWords(Note note) {
   int count = 0;
   String[] fields = {note.getTitle(), note.getContent()};
   for (String field : fields) {
     boolean word = false;
     int endOfLine = field.length() - 1;
     for (int i = 0; i < field.length(); i++) {
       // if the char is a letter, word = true.
       if (Character.isLetter(field.charAt(i)) && i != endOfLine) {
         word = true;
         // if char isn't a letter and there have been letters before,
         // counter goes up.
       } else if (!Character.isLetter(field.charAt(i)) && word) {
         count++;
         word = false;
         // last word of String; if it doesn't end with a non letter, it
         // wouldn't count without this.
       } else if (Character.isLetter(field.charAt(i)) && i == endOfLine) {
         count++;
       }
     }
   }
   return count;
 }
コード例 #3
0
ファイル: DbHelper.java プロジェクト: jinguoliang/Omni-Notes
 /** Counts chars in a note */
 public int getChars(Note note) {
   int count = 0;
   count += note.getTitle().length();
   count += note.getContent().length();
   return count;
 }
コード例 #4
0
ファイル: DbHelper.java プロジェクト: jinguoliang/Omni-Notes
  // Inserting or updating single note
  public Note updateNote(Note note, boolean updateLastModification) {
    SQLiteDatabase db = getDatabase(true);

    String content;
    if (note.isLocked()) {
      content = Security.encrypt(note.getContent(), prefs.getString(Constants.PREF_PASSWORD, ""));
    } else {
      content = note.getContent();
    }

    // To ensure note and attachments insertions are atomical and boost performances transaction are
    // used
    db.beginTransaction();

    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, note.getTitle());
    values.put(KEY_CONTENT, content);
    values.put(
        KEY_CREATION,
        note.getCreation() != null ? note.getCreation() : Calendar.getInstance().getTimeInMillis());
    values.put(
        KEY_LAST_MODIFICATION,
        updateLastModification
            ? Calendar.getInstance().getTimeInMillis()
            : (note.getLastModification() != null
                ? note.getLastModification()
                : Calendar.getInstance().getTimeInMillis()));
    values.put(KEY_ARCHIVED, note.isArchived());
    values.put(KEY_TRASHED, note.isTrashed());
    values.put(KEY_REMINDER, note.getAlarm());
    values.put(KEY_REMINDER_FIRED, note.isReminderFired());
    values.put(KEY_RECURRENCE_RULE, note.getRecurrenceRule());
    values.put(KEY_LATITUDE, note.getLatitude());
    values.put(KEY_LONGITUDE, note.getLongitude());
    values.put(KEY_ADDRESS, note.getAddress());
    values.put(KEY_CATEGORY, note.getCategory() != null ? note.getCategory().getId() : null);
    boolean locked = note.isLocked() != null ? note.isLocked() : false;
    values.put(KEY_LOCKED, locked);
    boolean checklist = note.isChecklist() != null ? note.isChecklist() : false;
    values.put(KEY_CHECKLIST, checklist);

    db.insertWithOnConflict(TABLE_NOTES, KEY_ID, values, SQLiteDatabase.CONFLICT_REPLACE);
    Log.d(Constants.TAG, "Updated note titled '" + note.getTitle() + "'");

    // Updating attachments
    List<Attachment> deletedAttachments = note.getAttachmentsListOld();
    for (Attachment attachment : note.getAttachmentsList()) {
      updateAttachment(
          note.get_id() != null ? note.get_id() : values.getAsLong(KEY_CREATION), attachment, db);
      deletedAttachments.remove(attachment);
    }
    // Remove from database deleted attachments
    for (Attachment attachmentDeleted : deletedAttachments) {
      db.delete(
          TABLE_ATTACHMENTS,
          KEY_ATTACHMENT_ID + " = ?",
          new String[] {String.valueOf(attachmentDeleted.getId())});
    }

    db.setTransactionSuccessful();
    db.endTransaction();

    // Fill the note with correct data before returning it
    note.setCreation(
        note.getCreation() != null ? note.getCreation() : values.getAsLong(KEY_CREATION));
    note.setLastModification(values.getAsLong(KEY_LAST_MODIFICATION));

    return note;
  }