Android Open Source - notes Notes Utils






From Project

Back to project page notes.

License

The source code is released under:

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> Everyone is permitted to copy and distribute verbatim or...

If you think the Android project notes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.iliakplv.notes.notes;
/* w w w  .  j  a  va2 s .  c  om*/
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.iliakplv.notes.NotesApplication;
import com.iliakplv.notes.R;
import com.iliakplv.notes.analytics.Event;
import com.iliakplv.notes.analytics.EventTracker;
import com.iliakplv.notes.utils.StringUtils;

import java.io.Serializable;

public final class NotesUtils {

  private NotesUtils() {
    throw new AssertionError("Instance creation not allowed!");
  }

  public static final Serializable DEFAULT_ID = "";

  public static enum NoteSortOrder {
    Title,
    CreateDateAscending,
    CreateDateDescending,
    ChangeDate
  }

  public static final NoteSortOrder DEFAULT_SORT_ORDER = NoteSortOrder.Title;


  private static final String[] COLORS_NAMES =
      NotesApplication.getContext().getResources().getStringArray(R.array.label_colors_names);


  public static String getTitleForNoteInDialog(AbstractNote note) {
    if (isNoteBlank(note)) {
      return NotesApplication.getContext().getString(R.string.empty_note_placeholder);
    } else if (!isNoteTitleBlank(note)) {
      return note.getTitle().trim();
    } else {
      return note.getBody().trim();
    }
  }

  public static String getTitleForNoteInList(AbstractNote note) {
    if (isNoteBlank(note)) {
      return NotesApplication.getContext().getString(R.string.empty_note_placeholder);
    } else {
      return note.getTitle().trim();
    }
  }

  public static boolean isNoteTitleBlank(AbstractNote note) {
    return StringUtils.isBlank(note.getTitle());
  }

  public static boolean isNoteBodyBlank(AbstractNote note) {
    return StringUtils.isBlank(note.getBody());
  }

  public static boolean isNoteBlank(AbstractNote note) {
    return isNoteTitleBlank(note) && isNoteBodyBlank(note);
  }


  public static String getTitleForLabel(Label label) {
    if (!StringUtils.isBlank(label.getName())) {
      return label.getName().trim();
    } else {
      return "(" + COLORS_NAMES[label.getColor()] + ")";
    }
  }

  public static Serializable getValidNoteId(Serializable id) {
    return id != null ? id : DEFAULT_ID;
  }


  public static void shareNote(Context context, AbstractNote note, boolean showToastIfEmpty) {
    shareNote(context, note.getTitle(), note.getBody(), showToastIfEmpty);
  }

  public static void shareNote(Context context, String subject, String text, boolean showToastIfEmpty) {
    final boolean empty = StringUtils.isNullOrEmpty(subject) && StringUtils.isNullOrEmpty(text);
    if (!empty) {
      final Intent intent = new Intent(Intent.ACTION_SEND);
      intent.setType("text/plain");
      intent.putExtra(Intent.EXTRA_SUBJECT, subject);
      intent.putExtra(Intent.EXTRA_TEXT, text);
      context.startActivity(Intent.createChooser(intent, context.getString(R.string.action_bar_share_title)));
      EventTracker.track(Event.NoteShareDialogShow);
    } else if (showToastIfEmpty) {
      Toast.makeText(context, R.string.empty_note_not_shared, Toast.LENGTH_SHORT).show();
    }
  }
}




Java Source Code List

com.iliakplv.notes.NotesApplication.java
com.iliakplv.notes.analytics.EventTracker.java
com.iliakplv.notes.analytics.Event.java
com.iliakplv.notes.gui.main.MainActivityTest.java
com.iliakplv.notes.gui.main.MainActivity.java
com.iliakplv.notes.gui.main.NavigationDrawerFragment.java
com.iliakplv.notes.gui.main.NoteDetailsFragment.java
com.iliakplv.notes.gui.main.NotesListFragment.java
com.iliakplv.notes.gui.main.dialogs.AboutDialog.java
com.iliakplv.notes.gui.main.dialogs.AbstractItemDialog.java
com.iliakplv.notes.gui.main.dialogs.DropboxAccountLinkingDialog.java
com.iliakplv.notes.gui.main.dialogs.LabelEditDialog.java
com.iliakplv.notes.gui.main.dialogs.NoteLabelsDialog.java
com.iliakplv.notes.gui.main.dialogs.SimpleItemDialog.java
com.iliakplv.notes.gui.main.dialogs.VoiceSearchInstallDialog.java
com.iliakplv.notes.gui.settings.SettingsActivity.java
com.iliakplv.notes.notes.AbstractNote.java
com.iliakplv.notes.notes.LabelComparator.java
com.iliakplv.notes.notes.Label.java
com.iliakplv.notes.notes.NoteComparator.java
com.iliakplv.notes.notes.NotesUtils.java
com.iliakplv.notes.notes.TextNote.java
com.iliakplv.notes.notes.db.NotesDatabaseAdapter.java
com.iliakplv.notes.notes.db.NotesDatabaseOpenHelper.java
com.iliakplv.notes.notes.db.NotesDatabaseStorage.java
com.iliakplv.notes.notes.dropbox.DropboxHelper.java
com.iliakplv.notes.notes.dropbox.NotesDropboxStorage.java
com.iliakplv.notes.notes.storage.NotesStorageListener.java
com.iliakplv.notes.notes.storage.NotesStorage.java
com.iliakplv.notes.notes.storage.StorageDataTransfer.java
com.iliakplv.notes.notes.storage.StorageWrapper.java
com.iliakplv.notes.notes.storage.Storage.java
com.iliakplv.notes.storage.StorageTest.java
com.iliakplv.notes.utils.AppLog.java
com.iliakplv.notes.utils.ConnectivityUtils.java
com.iliakplv.notes.utils.StringUtils.java
com.iliakplv.notes.utils.Utils.java