OSDN Git Service

T29683
authorYuji Konishi <yuji.k64613@gmail.com>
Sat, 29 Sep 2012 05:24:37 +0000 (14:24 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Sat, 29 Sep 2012 05:24:37 +0000 (14:24 +0900)
workspace/EverClip/res/values-ja/strings.xml
workspace/EverClip/res/values/strings.xml
workspace/EverClip/src/com/yuji/ec/EverClipActivity.java
workspace/EverClip/src/com/yuji/ec/Initialize.java
workspace/EverClip/src/com/yuji/ec/NoteUpdatorActivity.java
workspace/EverClip/src/com/yuji/ec/OAuthActivity.java
workspace/EverClip/src/com/yuji/ec/SettingActivity.java
workspace/EverClip/src/com/yuji/ec/service/NoteUpdatorService.java
workspace/EverClip/src/com/yuji/ec/utility/EvernoteUtil.java

index 5faafc6..7c2466f 100644 (file)
@@ -12,7 +12,7 @@
 
     <string name="mainMenuSetting">設定</string>
     
-       <string name="mainTitle">EverMemo</string>
+       <string name="mainTitle">ClipEver</string>
        <string name="mainConfirmTitle">フィルター</string>
 
     <string name="settingConfirmTitle">確認</string>
index 165a5d3..4da885e 100644 (file)
@@ -12,7 +12,7 @@
 
     <string name="mainMenuSetting">Settings</string>
     
-       <string name="mainTitle">EverMemo</string>
+       <string name="mainTitle">ClipEver</string>
        <string name="mainConfirmTitle">Filter</string>
 
     <string name="settingConfirmTitle">Confirm</string>
index 0529e35..aa26bb8 100644 (file)
@@ -29,6 +29,7 @@ import com.yuji.ec.db.NoteDao;
 import com.yuji.ec.db.NoteListItem;
 import com.yuji.ec.utility.BaseActivity;
 import com.yuji.ec.utility.EditPrefUtil;
+import com.yuji.ec.utility.EvernoteUtil;
 import com.yuji.ec.utility.NoteComparator;
 
 public class EverClipActivity extends BaseActivity {
@@ -96,6 +97,7 @@ public class EverClipActivity extends BaseActivity {
 
                updateList();
 
+               EverClipActivity.init(true);            
                setStatus();
        }
 
@@ -107,8 +109,8 @@ public class EverClipActivity extends BaseActivity {
        }
 
        @Override
-       protected void onStart() {
-               super.onStart();
+       protected void onResume() {
+               super.onResume();
 
                isVisible = true;
                if (isEmpty) {
@@ -123,6 +125,23 @@ public class EverClipActivity extends BaseActivity {
                                isInit = true;
                        }
                }
+               else {
+                       EvernoteUtil util = EvernoteUtil.getInstance();
+                       if (isInit) {
+                               if (!util.isLoggedIn()){
+                                       Intent intent = new Intent(this,
+                                                       (Class<?>) SettingActivity.class);
+                                       startActivityForResult(intent, 0);
+
+                                       isInit = false;
+                               }                               
+                       }
+                       else {
+                               if (!util.isLoggedIn()){
+                                       finish();                               
+                               }
+                       }
+               }
        }
 
        @Override
index c84015d..69319d4 100644 (file)
@@ -20,20 +20,25 @@ public class Initialize {
                        return;
                }
                
-               DatabaseHelper.init(context);
-               NoteUpdatorService.init(context);
-               
                EditPrefUtil pref = new EditPrefUtil(context);
                pref.getLong(Constant.PREF_LOGIN_DATE, 0L);
+               pref.getInt(Constant.PREF_AUTO_UPDATE, 0);
+               pref.getLong(Constant.PREF_UPDATE_TIME, 0L);
                pref.update();
                
+               DatabaseHelper.init(context);
+               NoteUpdatorService.init(context);
+               EverClipActivity.init(true);
+               
                try {
-               OAuthUtil authUtil = OAuthUtil.getInstance();
-               EvernoteSession session = authUtil.setupSession(context);
-               EvernoteUtil.getInstance().setSession(session);
+                       OAuthUtil authUtil = OAuthUtil.getInstance();
+                       EvernoteSession session = authUtil.setupSession(context);
+                       EvernoteUtil.getInstance().setSession(session);
                }
                catch (Throwable t){
+                       // TODO
                        t.printStackTrace();
+                       return;
                }
                isInit = false;
        }
index 6d1bb1e..8274e09 100644 (file)
@@ -93,8 +93,8 @@ public class NoteUpdatorActivity extends BaseActivity {
        }
 
        @Override
-       public void onStart() {
-               super.onStart();
+       public void onResume() {
+               super.onResume();
 
                int noteItemType = pref.getInt(Constant.PREF_NOTE_ITEM_TYPE_TMP,
                                Constant.NOTE_ITEM_TYPE_ALL);
index bcc5452..8000568 100644 (file)
@@ -127,10 +127,13 @@ public class OAuthActivity extends BaseActivity {
                if (isInit) {
                        isInit = false;
                } else {
+                       EvernoteUtil.getInstance().setSession(util.getSession());
                        if (isCompleteAuth) {
-                               EvernoteUtil.getInstance().setSession(util.getSession());
                                util.setLoginTime(this);
                        }
+                       else {
+                               util.logout(this);                              
+                       }
                        finish();
                }
        }
index a87e970..04f2656 100644 (file)
@@ -166,8 +166,8 @@ public class SettingActivity extends BaseActivity {
        }
 
        @Override
-       public void onStart() {
-               super.onStart();
+       public void onResume() {
+               super.onResume();
 
                int noteOrder = pref.getInt(Constant.PREF_NOTE_ORDER,
                                Constant.NOTE_ORDER_CREATE);
index 54db105..bb3d18f 100644 (file)
@@ -11,13 +11,16 @@ import android.os.Binder;
 import android.os.IBinder;
 import android.widget.Toast;
 
+import com.evernote.client.oauth.android.EvernoteSession;
 import com.yuji.ec.Initialize;
 import com.yuji.ec.common.Constant;
 import com.yuji.ec.utility.DateUtil;
 import com.yuji.ec.utility.Debug;
 import com.yuji.ec.utility.EditPrefUtil;
+import com.yuji.ec.utility.EvernoteUtil;
 import com.yuji.ec.utility.NetworkUtil;
 import com.yuji.ec.utility.NoteUpdator;
+import com.yuji.ec.utility.OAuthUtil;
 
 public class NoteUpdatorService extends Service {
        private static final boolean DEBUG = false;
@@ -77,6 +80,13 @@ public class NoteUpdatorService extends Service {
                        Initialize.initialize(NoteUpdatorService.this);
                        Initialize.initialize(NoteUpdatorService.this, "");
                        
+                       OAuthUtil authUtil = OAuthUtil.getInstance();
+                       EvernoteSession session = authUtil.setupSession(NoteUpdatorService.this);
+                       EvernoteUtil.getInstance().setSession(session);
+                       if (!EvernoteUtil.getInstance().isLoggedIn()){
+                               return;
+                       }
+                       
                        int noteItemType = pref.getInt(Constant.PREF_NOTE_ITEM_TYPE,
                                        Constant.NOTE_ITEM_TYPE_ALL);
                        String guid = pref.get(Constant.PREF_NOTE_ITEM_GUID);
index 2cdc9a7..74993b0 100644 (file)
@@ -25,8 +25,9 @@ import com.yuji.ec.db.INoteItem;
 
 public class EvernoteUtil {
        private static final int N = 50;
-       //private String username;
-       //private String password;
+
+       // private String username;
+       // private String password;
 
        public enum Error {
                NONE, CONNECT, INVALID_AUTH, NOT_FOUND, OTHER
@@ -52,12 +53,12 @@ public class EvernoteUtil {
        private NoteStore.Client noteStore = null;
        private EvernoteSession session = null;
 
-       //public void setConfig(String username, String password) {
-       //      this.username = username;
-       //      this.password = password;
-       //      authenticationToken = null;
-       //      noteStore = null;
-       //}
+       // public void setConfig(String username, String password) {
+       // this.username = username;
+       // this.password = password;
+       // authenticationToken = null;
+       // noteStore = null;
+       // }
 
        private void init() {
 
@@ -96,15 +97,15 @@ public class EvernoteUtil {
                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);
@@ -115,7 +116,7 @@ public class EvernoteUtil {
                filter.setNotebookGuid(notebookGuid);
                return getNoteList(filter);
        }
-       
+
        public List<NoteList> getNoteListByTag(String tagGuid) {
                NoteFilter filter = getDefaultFilter();
                List<String> tagGuids = new ArrayList<String>();
@@ -123,7 +124,7 @@ public class EvernoteUtil {
                filter.setTagGuids(tagGuids);
                return getNoteList(filter);
        }
-       
+
        public List<NoteList> getNoteList(NoteFilter filter) {
                errorCode = Error.OTHER;
 
@@ -134,20 +135,21 @@ public class EvernoteUtil {
                                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);
@@ -285,64 +287,68 @@ public class EvernoteUtil {
        }
 
        private String getAuthenticationToken() {
-//             try {
-//                     if (authenticationToken == null) {
-//                             // String userStoreUrl =
-//                             // "https://sandbox.evernote.com/edam/user";
-//                             String userStoreUrl = "https://www.evernote.com/edam/user";
-//                             THttpClient userStoreTrans = new THttpClient(userStoreUrl);
-//                             TBinaryProtocol userStoreProt = new TBinaryProtocol(
-//                                             userStoreTrans);
-//                             UserStore.Client userStore = new UserStore.Client(userStoreProt);
-//
-//                             // #27612
-//                             // http://www.antun.net/tips/api/evernote.html
-//                             // expiredTime=time.time()+(authResult.expiration/1000.0-authResult.currentTime/1000.0)
-//                             // # expiredTime<time.time() なら認証し直して、authenticationToken
-//                             // を取得し直すべし
-//
-//                             String consumerKey = "yuji_k64613";
-//                             String consumerSecret = "d5528b4fdb3a7fee";
-//                             AuthenticationResult authResult = userStore.authenticate(
-//                                             username, password, consumerKey, consumerSecret);
-//                             authenticationToken = authResult.getAuthenticationToken();
-//
-//                             // String noteStoreUrlBase =
-//                             // "https://sandbox.evernote.com/edam/note/";
-//                             String noteStoreUrlBase = "https://www.evernote.com/edam/note/";
-//                             User user = authResult.getUser();
-//                             String noteStoreUrl = noteStoreUrlBase + user.getShardId();
-//                             THttpClient noteStoreTrans = new THttpClient(noteStoreUrl);
-//                             TBinaryProtocol noteStoreProt = new TBinaryProtocol(
-//                                             noteStoreTrans);
-//                             noteStore = new NoteStore.Client(noteStoreProt);
-//                     }
-//             } catch (TTransportException e) {
-//                     authenticationToken = null;
-//                     noteStore = null;
-//                     Debug.d(this, null, e);
-//
-//                     errorCode = Error.CONNECT;
-//             } catch (EDAMUserException e) {
-//                     Debug.d(this, null, e);
-//
-//                     EDAMErrorCode code = e.getErrorCode();
-//                     if (code.equals(EDAMErrorCode.INVALID_AUTH)) {
-//                             errorCode = Error.INVALID_AUTH;
-//                     }
-//             } catch (EDAMSystemException e) {
-//                     Debug.d(this, null, e);
-//             } catch (TException e) {
-//                     Debug.d(this, null, e);
-//
-//                     if (e.getCause() instanceof ConnectException) {
-//                             errorCode = Error.CONNECT;
-//                     }
-//             }
-//
-//             return authenticationToken;
+               // try {
+               // if (authenticationToken == null) {
+               // // String userStoreUrl =
+               // // "https://sandbox.evernote.com/edam/user";
+               // String userStoreUrl = "https://www.evernote.com/edam/user";
+               // THttpClient userStoreTrans = new THttpClient(userStoreUrl);
+               // TBinaryProtocol userStoreProt = new TBinaryProtocol(
+               // userStoreTrans);
+               // UserStore.Client userStore = new UserStore.Client(userStoreProt);
+               //
+               // // #27612
+               // // http://www.antun.net/tips/api/evernote.html
+               // //
+               // expiredTime=time.time()+(authResult.expiration/1000.0-authResult.currentTime/1000.0)
+               // // # expiredTime<time.time() なら認証し直して、authenticationToken
+               // // を取得し直すべし
+               //
+               // String consumerKey = "yuji_k64613";
+               // String consumerSecret = "d5528b4fdb3a7fee";
+               // AuthenticationResult authResult = userStore.authenticate(
+               // username, password, consumerKey, consumerSecret);
+               // authenticationToken = authResult.getAuthenticationToken();
+               //
+               // // String noteStoreUrlBase =
+               // // "https://sandbox.evernote.com/edam/note/";
+               // String noteStoreUrlBase = "https://www.evernote.com/edam/note/";
+               // User user = authResult.getUser();
+               // String noteStoreUrl = noteStoreUrlBase + user.getShardId();
+               // THttpClient noteStoreTrans = new THttpClient(noteStoreUrl);
+               // TBinaryProtocol noteStoreProt = new TBinaryProtocol(
+               // noteStoreTrans);
+               // noteStore = new NoteStore.Client(noteStoreProt);
+               // }
+               // } catch (TTransportException e) {
+               // authenticationToken = null;
+               // noteStore = null;
+               // Debug.d(this, null, e);
+               //
+               // errorCode = Error.CONNECT;
+               // } catch (EDAMUserException e) {
+               // Debug.d(this, null, e);
+               //
+               // EDAMErrorCode code = e.getErrorCode();
+               // if (code.equals(EDAMErrorCode.INVALID_AUTH)) {
+               // errorCode = Error.INVALID_AUTH;
+               // }
+               // } catch (EDAMSystemException e) {
+               // Debug.d(this, null, e);
+               // } catch (TException e) {
+               // Debug.d(this, null, e);
+               //
+               // if (e.getCause() instanceof ConnectException) {
+               // errorCode = Error.CONNECT;
+               // }
+               // }
+               //
+               // return authenticationToken;
                if (authenticationToken == null) {
                        authenticationToken = session.getAuthToken();
+                       if (authenticationToken == null) {
+                               return null;
+                       }
                        try {
                                noteStore = session.createNoteStore();
                        } catch (TTransportException e) {
@@ -378,18 +384,19 @@ public class EvernoteUtil {
                return note;
        }
 
-       public List<com.yuji.ec.db.Note> getNoteContentList(List<NoteList> noteListList) {
+       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){
+               for (NoteList noteList : noteListList) {
                        List<com.yuji.ec.db.Note> l = getNoteContentList(noteList);
-                       if (l == null){
+                       if (l == null) {
                                return null;
                        }
                        list.addAll(l);
                }
                return list;
        }
-       
+
        public List<com.yuji.ec.db.Note> getNoteContentList(NoteList noteList) {
                errorCode = Error.OTHER;
 
@@ -404,7 +411,7 @@ public class EvernoteUtil {
                                String guid = n.getGuid();
                                Note nc = getNote(guid);
                                String content = nc.getContent();
-                               if (!parser.parse(content)){
+                               if (!parser.parse(content)) {
                                        return null;
                                }
                                String text = parser.getText();
@@ -446,7 +453,7 @@ public class EvernoteUtil {
        }
 
        public boolean isLoggedIn() {
-               if (session == null){
+               if (session == null) {
                        return false;
                }
                return session.isLoggedIn();