OSDN Git Service

T27592
authorYuji Konishi <yuji.k64613@gmail.com>
Tue, 20 Mar 2012 08:02:14 +0000 (17:02 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Tue, 20 Mar 2012 08:02:14 +0000 (17:02 +0900)
workspace/EverMemo/src/com/yuji/em/EverMemoActivity.java
workspace/EverMemo/src/com/yuji/em/task/UpdateNoteTask.java
workspace/EverMemo/src/com/yuji/em/utility/EvernoteUtil.java

index efdcd14..9f8a585 100644 (file)
@@ -210,7 +210,8 @@ public class EverMemoActivity extends BaseActivity {
                        // 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
@@ -250,12 +251,13 @@ public class EverMemoActivity extends BaseActivity {
 
                        // \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
index d1dc623..c61cc0c 100644 (file)
@@ -3,53 +3,64 @@ package com.yuji.em.task;
 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;
                }
        }
 
@@ -61,12 +72,17 @@ public class UpdateNoteTask implements AsyncTaskIF {
 
        @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;
        }
 }
index 4dbb717..f91296a 100644 (file)
@@ -49,7 +49,7 @@ public class EvernoteUtil {
 
        }
 
-       public Note getNote(String guid) {
+       public Note getNote(String guid) throws EDAMNotFoundException {
                boolean withContent = true;
                boolean withResourcesData = false;
                boolean withResourcesRecognition = false;
@@ -57,8 +57,8 @@ public class EvernoteUtil {
                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);
@@ -66,6 +66,7 @@ public class EvernoteUtil {
                        Debug.d(this, null, e);
                } catch (EDAMNotFoundException e) {
                        Debug.d(this, null, e);
+                       throw e;
                } catch (TException e) {
                        Debug.d(this, null, e);
                }
@@ -81,8 +82,7 @@ public class EvernoteUtil {
                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) {
@@ -95,9 +95,10 @@ public class EvernoteUtil {
                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();
@@ -163,14 +164,15 @@ public class EvernoteUtil {
                                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;