return note;
}
- private NoteFilter getDefaultFilter(){
+ private NoteFilter getDefaultFilter() {
// 検索条件として、検索語なし、更新日順ソートを指定
NoteFilter filter = new NoteFilter();
filter.setOrder(NoteSortOrder.UPDATED.getValue());
- filter.setAscending(false);
+ filter.setAscending(false);
return filter;
}
-
+
public List<NoteList> getNoteList() {
NoteFilter filter = getDefaultFilter();
return getNoteList(filter);
filter.setNotebookGuid(notebookGuid);
return getNoteList(filter);
}
-
+
public List<NoteList> getNoteListByTag(String tagGuid) {
NoteFilter filter = getDefaultFilter();
List<String> tagGuids = new ArrayList<String>();
filter.setTagGuids(tagGuids);
return getNoteList(filter);
}
-
+
public List<NoteList> getNoteList(NoteFilter filter) {
errorCode = Error.OTHER;
return null;
}
int index = 0;
- while (true){
- NoteList noteList = noteStore.findNotes(token, filter, index, N);
+ while (true) {
+ NoteList noteList = noteStore
+ .findNotes(token, filter, index, N);
int size = noteList.getNotesSize();
-
- if (size <= 0){
+
+ if (size <= 0) {
break;
}
list.add(noteList);
- if (size < N){
+ if (size < N) {
break;
}
index += size;
}
-
+
errorCode = Error.NONE;
} catch (EDAMUserException e) {
Debug.d(this, null, e);
return n;
}
- public boolean isLoggedIn(){
+ public boolean isLoggedIn() {
return session != null;
}
-
+
private String getAuthenticationToken() {
if (authenticationToken == null) {
- authenticationToken = session.getAuthToken();
+ authenticationToken = session.getAuthToken();
try {
noteStore = session.createNoteStore();
} catch (TTransportException e) {
}
return authenticationToken;
}
-
+
private String getAuthenticationTokenBak() {
try {
if (authenticationToken == null) {
this.session = session;
}
+ public void createNotes(String guid, String title, int size){
+ Note note;
+ String token = getAuthenticationToken();
+ if (token == null) {
+ return;
+ }
+ Notebook notebook;
+ try {
+ notebook = noteStore.getNotebook(token, guid);
+ for (int i = 0; i < size; i++){
+ note = createNote(notebook, title + i);
+ if (note == null){
+ return;
+ }
+ }
+ } catch (EDAMUserException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (EDAMSystemException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (EDAMNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (TException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
-// public String getErrorMessage(Context context, Error code) {
-// if (code.equals(Error.NONE)) {
-// return "";
-// }
-// if (code.equals(Error.CONNECT)) {
-// return context.getString(R.string.toastConnect);
-// }
-// if (code.equals(Error.INVALID_AUTH)) {
-// return context.getString(R.string.toastInvalidAuth);
-// }
-// if (code.equals(Error.NOT_FOUND)) {
-// return context.getString(R.string.toastNoteDoesNotExist);
-// }
-// return context.getString(R.string.toastEvernoteSystem);
-// }
-//
-// public static com.yuji.ec.db.Note toNote(Note n, String text) {
-// com.yuji.ec.db.Note note = new com.yuji.ec.db.Note(n.getGuid(), text,
-// n.getCreated(), n.getUpdated());
-// return note;
-// }
-//
-// public List<com.yuji.ec.db.Note> getNoteContentList(List<NoteList> noteListList) {
-// List<com.yuji.ec.db.Note> list = new ArrayList<com.yuji.ec.db.Note>();
-// for (NoteList noteList : noteListList){
-// List<com.yuji.ec.db.Note> l = getNoteContentList(noteList);
-// if (l == null){
-// return null;
-// }
-// list.addAll(l);
-// }
-// return list;
-// }
-//
-// public List<com.yuji.ec.db.Note> getNoteContentList(NoteList noteList) {
-// errorCode = Error.OTHER;
-//
-// List<com.yuji.ec.db.Note> list = new ArrayList<com.yuji.ec.db.Note>();
-// HtmlParser parser = new HtmlParser();
-//
-// try {
-// List<Note> notes = noteList.getNotes();
-// int s = noteList.getNotesSize();
-// System.out.println("" + s);
-// for (Note n : notes) {
-// String guid = n.getGuid();
-// Note nc = getNote(guid);
-// String content = nc.getContent();
-// if (!parser.parse(content)){
-// return null;
-// }
-// String text = parser.getText();
-// com.yuji.ec.db.Note note = toNote(nc, text);
-// list.add(note);
-// }
-// notes = noteList.getNotes();
-// s = noteList.getNotesSize();
-// errorCode = Error.NONE;
-// } catch (EDAMNotFoundException e) {
-// errorCode = Error.NOT_FOUND;
-// return null;
-// }
-// return list;
-// }
-//
-// public List<INoteItem> toNoteItemFromNoteBook(List<Notebook> noteList) {
-// List<INoteItem> list = new ArrayList<INoteItem>();
-// for (Notebook notebook : noteList) {
-// com.yuji.ec.db.Note item = new com.yuji.ec.db.Note(
-// notebook.getGuid(), notebook.getName(), -1, -1);
-// list.add(item);
-// }
-// return list;
-// }
-//
-// public List<INoteItem> toNoteItemFromTag(List<Tag> tagList) {
-// List<INoteItem> list = new ArrayList<INoteItem>();
-// for (Tag tag : tagList) {
-// com.yuji.ec.db.Note item = new com.yuji.ec.db.Note(tag.getGuid(),
-// tag.getName(), -1, -1);
-// list.add(item);
-// }
-// return list;
-// }
+ public Note createNote(Notebook notebook, String title){
+ String authToken = getAuthenticationToken();
+ if (authToken == null){
+ return null;
+ }
+ Note note = new Note();
+ note.setTitle(title);
+ String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml.dtd\">"
+ + "<en-note>Hello Evernote.</en-note>";
+ note.setContent(content);
+ note.setNotebookGuid(notebook.getGuid());
+ Note newNote = null;
+ try {
+ newNote = noteStore.createNote(authToken, note);
+ } catch (EDAMUserException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (EDAMSystemException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (EDAMNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (TException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return newNote;
+ }
+ // public String getErrorMessage(Context context, Error code) {
+ // if (code.equals(Error.NONE)) {
+ // return "";
+ // }
+ // if (code.equals(Error.CONNECT)) {
+ // return context.getString(R.string.toastConnect);
+ // }
+ // if (code.equals(Error.INVALID_AUTH)) {
+ // return context.getString(R.string.toastInvalidAuth);
+ // }
+ // if (code.equals(Error.NOT_FOUND)) {
+ // return context.getString(R.string.toastNoteDoesNotExist);
+ // }
+ // return context.getString(R.string.toastEvernoteSystem);
+ // }
+ //
+ // public static com.yuji.ec.db.Note toNote(Note n, String text) {
+ // com.yuji.ec.db.Note note = new com.yuji.ec.db.Note(n.getGuid(), text,
+ // n.getCreated(), n.getUpdated());
+ // return note;
+ // }
+ //
+ // public List<com.yuji.ec.db.Note> getNoteContentList(List<NoteList>
+ // noteListList) {
+ // List<com.yuji.ec.db.Note> list = new ArrayList<com.yuji.ec.db.Note>();
+ // for (NoteList noteList : noteListList){
+ // List<com.yuji.ec.db.Note> l = getNoteContentList(noteList);
+ // if (l == null){
+ // return null;
+ // }
+ // list.addAll(l);
+ // }
+ // return list;
+ // }
+ //
+ // public List<com.yuji.ec.db.Note> getNoteContentList(NoteList noteList) {
+ // errorCode = Error.OTHER;
+ //
+ // List<com.yuji.ec.db.Note> list = new ArrayList<com.yuji.ec.db.Note>();
+ // HtmlParser parser = new HtmlParser();
+ //
+ // try {
+ // List<Note> notes = noteList.getNotes();
+ // int s = noteList.getNotesSize();
+ // System.out.println("" + s);
+ // for (Note n : notes) {
+ // String guid = n.getGuid();
+ // Note nc = getNote(guid);
+ // String content = nc.getContent();
+ // if (!parser.parse(content)){
+ // return null;
+ // }
+ // String text = parser.getText();
+ // com.yuji.ec.db.Note note = toNote(nc, text);
+ // list.add(note);
+ // }
+ // notes = noteList.getNotes();
+ // s = noteList.getNotesSize();
+ // errorCode = Error.NONE;
+ // } catch (EDAMNotFoundException e) {
+ // errorCode = Error.NOT_FOUND;
+ // return null;
+ // }
+ // return list;
+ // }
+ //
+ // public List<INoteItem> toNoteItemFromNoteBook(List<Notebook> noteList) {
+ // List<INoteItem> list = new ArrayList<INoteItem>();
+ // for (Notebook notebook : noteList) {
+ // com.yuji.ec.db.Note item = new com.yuji.ec.db.Note(
+ // notebook.getGuid(), notebook.getName(), -1, -1);
+ // list.add(item);
+ // }
+ // return list;
+ // }
+ //
+ // public List<INoteItem> toNoteItemFromTag(List<Tag> tagList) {
+ // List<INoteItem> list = new ArrayList<INoteItem>();
+ // for (Tag tag : tagList) {
+ // com.yuji.ec.db.Note item = new com.yuji.ec.db.Note(tag.getGuid(),
+ // tag.getName(), -1, -1);
+ // list.add(item);
+ // }
+ // return list;
+ // }
}
\ No newline at end of file