// List<Note> list = noteList.getNotes();
// Note note = list.get(0);
- String guid = noteList.get(selectedIndex).getGuid();
+ Note note = noteList.get(selectedIndex);
+ String guid = note.getGuid();
// http://y-anz-m.blogspot.com/2011/06/android.html
// http://www.taosoftware.co.jp/blog/2009/03/android_20.html
// \8dX\90V
// util.updateNoteContext(guid, title, text);
- UpdateNoteTask task = new UpdateNoteTask(this, guid, title, text);
+ UpdateNoteTask task = new UpdateNoteTask(this, guid,
+ note.getTitle(), title, text);
AsyncTaskCommand command = new AsyncTaskCommand(this, task);
command.setDialog(false);
command.execute("");
Status status = command.getStatus();
-
+
editText.setText("");
} catch (RuntimeException e) {
Debug.d(this, null, e); // TODO
import android.content.Context;
import android.widget.Toast;
+import com.evernote.edam.error.EDAMNotFoundException;
import com.evernote.edam.type.Note;
import com.yuji.em.utility.AsyncTaskIF;
import com.yuji.em.utility.Debug;
import com.yuji.em.utility.EvernoteUtil;
public class UpdateNoteTask implements AsyncTaskIF {
+ public static final int ERROR_NONE = 0;
+ public static final int ERROR_NOT_FOUND = 1;
+ public static final int ERROR_SYSTEM = 9;
+
private static int RETRY_COUNT = 3;
private Context context = null;
private String guid;
+ private String noteName;
private String title;
private String text;
private EvernoteUtil util = EvernoteUtil.getInstance();
private int status = -1;
- public UpdateNoteTask(Context context, String guid, String title, String text) {
+ public UpdateNoteTask(Context context, String guid, String noteName, String title,
+ String text) {
this.context = context;
this.guid = guid;
+ this.noteName = noteName;
this.title = title;
this.text = text;
}
@Override
public void doExecute() {
- int i = 0;
- synchronized (context) {
- for (i = 0; i < RETRY_COUNT; i++) {
- Note note = util.updateNoteContext(guid, title, text);
- if (note != null) {
- break;
- }
- Debug.d(this, "retry updateNoteContext()"); // TODO
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- ;
+ try {
+ int i = 0;
+ synchronized (context) {
+ for (i = 0; i < RETRY_COUNT; i++) {
+ Note note = util.updateNoteContext(guid, title, text);
+ if (note != null) {
+ break;
+ }
+ Debug.d(this, "retry updateNoteContext()"); // TODO
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ ;
+ }
}
}
- }
- if (i < RETRY_COUNT) {
- status = 0;
- }
- else {
- status = 1;
- Toast.makeText(context, "\8f\91\82«\8d\9e\82Ý\82É\8e¸\94s\82µ\82Ü\82µ\82½" + text, Toast.LENGTH_LONG); // TODO
- Debug.d(this, "doExecute"); // TODO
+ if (i < RETRY_COUNT) {
+ status = ERROR_NONE;
+ } else {
+ status = ERROR_SYSTEM;
+ Toast.makeText(context, "\8f\91\82«\8d\9e\82Ý\82É\8e¸\94s\82µ\82Ü\82µ\82½" + text, Toast.LENGTH_LONG); // TODO
+ Debug.d(this, "doExecute"); // TODO
+ }
+ } catch (EDAMNotFoundException e) {
+ status = ERROR_NOT_FOUND;
}
}
@Override
public void done(boolean isCancel) {
- // TODO Auto-generated method stub
+ switch (status) {
+ case ERROR_NOT_FOUND:
+ Toast.makeText(context, "\83m\81[\83g\82ª\82 \82è\82Ü\82¹\82ñ " + noteName, Toast.LENGTH_LONG)
+ .show(); // TODO
+ break;
+ }
}
@Override
- public int getStatus(){
+ public int getStatus() {
return status;
}
}
}
- public Note getNote(String guid) {
+ public Note getNote(String guid) throws EDAMNotFoundException {
boolean withContent = true;
boolean withResourcesData = false;
boolean withResourcesRecognition = false;
Note note = null;
try {
String token = getAuthenticationToken();
- note = noteStore.getNote(token, guid,
- withContent, withResourcesData, withResourcesRecognition,
+ note = noteStore.getNote(token, guid, withContent,
+ withResourcesData, withResourcesRecognition,
withResourcesAlternateData);
} catch (EDAMUserException e) {
Debug.d(this, null, e);
Debug.d(this, null, e);
} catch (EDAMNotFoundException e) {
Debug.d(this, null, e);
+ throw e;
} catch (TException e) {
Debug.d(this, null, e);
}
NoteList noteList = null;
try {
String token = getAuthenticationToken();
- noteList = noteStore.findNotes(token, filter, 0,
- 100);
+ noteList = noteStore.findNotes(token, filter, 0, 100);
} catch (EDAMUserException e) {
Debug.d(this, null, e);
} catch (EDAMSystemException e) {
return noteList;
}
- public Note updateNoteContext(String guid, String title, String text) {
+ public Note updateNoteContext(String guid, String title, String text)
+ throws EDAMNotFoundException {
Note note = getNote(guid);
- if (note == null){
+ if (note == null) {
return null;
}
String content = note.getContent();
AuthenticationResult authResult = userStore.authenticate(
username, password, consumerKey, consumerSecret);
authenticationToken = authResult.getAuthenticationToken();
-
+
String noteStoreUrlBase = "https://sandbox.evernote.com/edam/note/";
User user = authResult.getUser();
String noteStoreUrl = noteStoreUrlBase + user.getShardId();
THttpClient noteStoreTrans = new THttpClient(noteStoreUrl);
- TBinaryProtocol noteStoreProt = new TBinaryProtocol(noteStoreTrans);
+ TBinaryProtocol noteStoreProt = new TBinaryProtocol(
+ noteStoreTrans);
noteStore = new NoteStore.Client(noteStoreProt);
- }
+ }
} catch (TTransportException e) {
// TODO
authenticationToken = null;