-<?xml version="1.0" encoding="UTF-8"?>\r
-<classpath>\r
- <classpathentry kind="src" path="src"/>\r
- <classpathentry kind="src" path="gen"/>\r
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>\r
- <classpathentry kind="lib" path="lib/evernote-api-1.20.jar"/>\r
- <classpathentry kind="lib" path="lib/libthrift.jar"/>\r
- <classpathentry kind="lib" path="lib/log4j-1.2.14.jar"/>\r
- <classpathentry kind="output" path="bin"/>\r
-</classpath>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="lib" path="libs/evernote-api-1.22.jar"/>
+ <classpathentry kind="lib" path="libs/evernote-client-android.jar"/>
+ <classpathentry kind="lib" path="libs/libthrift.jar"/>
+ <classpathentry kind="lib" path="libs/scribe-1.3.1.jar"/>
+ <classpathentry kind="lib" path="libs/slf4j-android-1.5.8.jar"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.yuji.em"
- android:versionCode="2"
- android:versionName="1.0.1">
+ package="com.yuji.em"
+ android:versionCode="2"
+ android:versionName="1.0.1" >
+
<uses-sdk android:minSdkVersion="7" />
- <application android:icon="@drawable/icon" android:label="@string/app_name"
- android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
- >
- <activity android:name=".EverMemoActivity"
- android:label="@string/app_name"
- android:windowSoftInputMode="stateVisible|adjustResize"
- android:launchMode="singleTop"
- >
+ <application
+ android:icon="@drawable/icon"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
+ <activity
+ android:name=".EverMemoActivity"
+ android:label="@string/app_name"
+ android:launchMode="singleTop"
+ android:windowSoftInputMode="stateVisible|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
+
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
- <activity android:name=".SelectNoteListActivity"></activity>
- <activity android:name=".NoteListActivity"></activity>
- <activity android:name=".SettingActivity"></activity>
- <activity android:name=".HeaderActivity"></activity>
- <activity android:name=".UserPasswordActivity"></activity>
-
- </application>
+ <activity android:name=".SelectNoteListActivity" >
+ </activity>
+ <activity android:name=".NoteListActivity" >
+ </activity>
+ <activity android:name=".SettingActivity" >
+ </activity>
+ <activity android:name=".HeaderActivity" >
+ </activity>
+ <activity android:name=".OAuthActivity" >
+ </activity>
+ <activity
+ android:name="com.evernote.client.oauth.android.EvernoteOAuthActivity"
+ android:configChanges="orientation|keyboard"
+ android:launchMode="singleTask" >
+ <intent-filter>
+
+ <!-- Change this to be en- followed by your consumer key -->
+ <data android:scheme="en-yuji-k64613" />
+
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.BROWSABLE" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+ </application>
+
<uses-permission android:name="android.permission.INTERNET" />
+
</manifest>
\ No newline at end of file
+++ /dev/null
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=android-7
--- /dev/null
+/** Automatically generated file. DO NOT MODIFY */
+package com.yuji.em;
+
+public final class BuildConfig {
+ public final static boolean DEBUG = true;
+}
\ No newline at end of file
public static final int header=0x7f030000;
public static final int main=0x7f030001;
public static final int note_list=0x7f030002;
- public static final int select_note_list=0x7f030003;
- public static final int setting=0x7f030004;
- public static final int simple_list_item_1=0x7f030005;
- public static final int simple_list_item_2=0x7f030006;
- public static final int small_list_item_1=0x7f030007;
- public static final int user_password=0x7f030008;
+ public static final int oauth=0x7f030003;
+ public static final int select_note_list=0x7f030004;
+ public static final int setting=0x7f030005;
+ public static final int simple_list_item_1=0x7f030006;
+ public static final int simple_list_item_2=0x7f030007;
+ public static final int small_list_item_1=0x7f030008;
+ public static final int user_password=0x7f030009;
}
public static final class string {
+ public static final int ErrorLogin=0x7f050027;
public static final int app_name=0x7f050000;
public static final int cancelButton=0x7f050006;
public static final int closeButton=0x7f050007;
public static final int headerExplainText3=0x7f05001c;
public static final int headerExplainText4=0x7f05001d;
public static final int mainMenuSetting=0x7f050008;
- public static final int mainTitle=0x7f050027;
+ public static final int mainTitle=0x7f050028;
public static final int noButton=0x7f050003;
public static final int noteListGetting=0x7f050018;
public static final int selectListConfirmDeleteMsg=0x7f05000b;
public static final int selectListConfirmNoteMsg=0x7f05000c;
public static final int selectListConfirmTitle=0x7f05000a;
public static final int selectListTitle=0x7f050009;
- public static final int selectTitle=0x7f050028;
+ public static final int selectTitle=0x7f050029;
public static final int sendButton=0x7f050001;
public static final int settingConfirmNoteMsg=0x7f050011;
public static final int settingConfirmTitle=0x7f05000f;
--- /dev/null
+ Copyright (c) 2004-2008 QOS.ch
+ All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-7
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+ </LinearLayout>
+
+</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="app_name">EverMemo</string>
+ <string name="app_name">MemoEver</string>
<string name="sendButton">送信</string>
<string name="yesButton">はい</string>
<string name="dialogErrorTitle">エラー</string>
<string name="dialogSystemError">システムエラーが発生しました</string>
+
+ <string name="ErrorLogin">ログインに失敗しました</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="app_name">EverMemo</string>
+ <string name="app_name">MemoEver</string>
<string name="sendButton">Send</string>
<string name="yesButton">Yes</string>
<string name="dialogErrorTitle">Error</string>
<string name="dialogSystemError">System error has occurred.</string>
+
+ <string name="ErrorLogin">Failed to login</string>
</resources>
import android.content.Context;
-import com.yuji.em.common.CommonUtil;
+import com.evernote.client.oauth.android.EvernoteSession;
+import com.yuji.em.common.Constant;
+import com.yuji.em.utility.EditPrefUtil;
import com.yuji.em.utility.EvernoteUtil;
-import com.yuji.em.utility.PasswordUtil;
+import com.yuji.em.utility.OAuthUtil;
public class Initialize {
private static boolean isInit = true; // falseになっていた。なぞ。
if (!isInit) {
return;
}
- isInit = false;
+ //EvernoteUtil util = EvernoteUtil.getInstance();
+ //String username = PasswordUtil.getUsername(context);
+ //String password = PasswordUtil.getPassword(context);
+ //if (!CommonUtil.isNull(username) && !CommonUtil.isNull(password)) {
+ // util.setConfig(username, password);
+ //}
+
+ EditPrefUtil pref = new EditPrefUtil(context);
+ pref.getLong(Constant.PREF_LOGIN_DATE, 0L);
+ pref.update();
- EvernoteUtil util = EvernoteUtil.getInstance();
- String username = PasswordUtil.getUsername(context);
- String password = PasswordUtil.getPassword(context);
- if (!CommonUtil.isNull(username) && !CommonUtil.isNull(password)) {
- util.setConfig(username, password);
+ try {
+ OAuthUtil authUtil = OAuthUtil.getInstance();
+ EvernoteSession session = authUtil.setupSession(context);
+ EvernoteUtil.getInstance().setSession(session);
+ }
+ catch (Throwable t){
+ // TODO
+ t.printStackTrace();
+ return;
}
+
+ isInit = false;
}
public static void setInitialize() {
--- /dev/null
+package com.yuji.em;
+
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Toast;
+
+import com.evernote.client.oauth.android.EvernoteSession;
+import com.yuji.em.utility.BaseActivity;
+import com.yuji.em.utility.EvernoteUtil;
+import com.yuji.em.utility.OAuthUtil;
+
+/**
+ * This simple Android app demonstrates how to integrate with the Evernote Cloud
+ * API (aka EDAM) to create a note.
+ *
+ * In this sample, the user authorizes access to their account using OAuth and
+ * chooses an image from the device's image gallery. The image is then saved
+ * directly to Evernote using the Cloud API.
+ */
+public class OAuthActivity extends BaseActivity {
+
+ /***************************************************************************
+ * You MUST change the following values to run this sample application. *
+ ***************************************************************************/
+
+ // Your Evernote API key. See http://dev.evernote.com/documentation/cloud/
+ // Please obfuscate your code to help keep these values secret.
+ // private static final String CONSUMER_KEY = "yuji-k64613";
+ // private static final String CONSUMER_SECRET = "98b2cbf35f747d2d";
+
+ /***************************************************************************
+ * Change these values as needed to use this code in your own application. *
+ ***************************************************************************/
+
+ // Name of this application, for logging
+ // private static final String TAG = "HelloEDAM";
+
+ // A directory on disk where your application stores temporary data
+ // private static final String APP_DATA_PATH =
+ // "/Android/data/com.evernote.android.sample/temp/";
+ // private static final String APP_DATA_PATH =
+ // "/Android/data/com.yuji.ef/temp/";
+
+ // Change to "www.evernote.com" to use the Evernote production service
+ // instead of the sandbox
+ // private static final String EVERNOTE_HOST = "sandbox.evernote.com";
+ // private static final String EVERNOTE_HOST = "www.evernote.com";
+
+ // private static final String APP_NAME = "FolderErver";
+ // private static final String APP_VERSION = "1.0.0";
+
+ /***************************************************************************
+ * The following values are simply part of the demo application. *
+ ***************************************************************************/
+
+ // Activity result request codes
+ // private static final int SELECT_IMAGE = 1;
+
+ // The ENML preamble to every Evernote note.
+ // Note content goes between <en-note> and </en-note>
+ // private static final String NOTE_PREFIX =
+ // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ // "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" +
+ // "<en-note>";
+
+ // The ENML postamble to every Evernote note
+ // private static final String NOTE_SUFFIX = "</en-note>";
+
+ // Used to interact with the Evernote web service
+ // private EvernoteSession session;
+
+ // UI elements that we update
+ // private Button btnAuth;
+ // private Button btnSave;
+ // private Button btnSelect;
+ // private TextView msgArea;
+
+ // The path to and MIME type of the currently selected image from the
+ // gallery
+ // private String filePath;
+ // private String mimeType;
+ // private String fileName;
+
+ // ADD
+ private OAuthUtil util = OAuthUtil.getInstance();
+ private boolean isInit = true;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // setContentView(R.layout.main);
+ setContentView(R.layout.oauth);
+
+ // DELETE
+ // msgArea = (TextView)findViewById(R.id.message);
+ // btnAuth = (Button) findViewById(R.id.auth_button);
+ // btnSelect = (Button) findViewById(R.id.select_button);
+ // btnSave = (Button) findViewById(R.id.save_button);
+
+ setupSession();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ // Complete the Evernote authentication process if necessary
+ // EDIT
+ // if (!session.completeAuthentication(getPreferencesForAuthData())) {
+ // // We only want to do this when we're resuming after
+ // authentication...
+ // Toast.makeText(this, "Evernote login failed",
+ // Toast.LENGTH_LONG).show();
+ // }
+ boolean isCompleteAuth = util.isCompleteAuth(this);
+ if (!isInit && !isCompleteAuth) {
+ // We only want to do this when we're resuming after
+ // authentication...
+ Toast.makeText(this, getString(R.string.ErrorLogin),
+ Toast.LENGTH_LONG).show();
+ }
+
+ updateUi();
+
+ // ADD
+ if (isInit) {
+ isInit = false;
+ } else {
+ if (isCompleteAuth) {
+ EvernoteUtil.getInstance().setSession(util.getSession());
+ util.setLoginTime(this);
+ }
+ finish();
+ }
+ }
+
+ /**
+ * Evernote authentication data will be stored to this SharedPreferences if
+ * we are resuming as a result of a successful OAuth authorization. You may
+ * wish to pass a different SharedPreferences so that Evernote settings are
+ * stored along with other settings persisted by your application.
+ */
+ // private SharedPreferences getPreferencesForAuthData() {
+ // return getPreferences(MODE_PRIVATE);
+ // }
+
+ /**
+ * Setup the EvernoteSession used to access the Evernote API.
+ */
+ private void setupSession() {
+ // EDIT
+ // ApplicationInfo info =
+ // new ApplicationInfo(CONSUMER_KEY, CONSUMER_SECRET, EVERNOTE_HOST,
+ // APP_NAME, APP_VERSION);
+ //
+ // // Retrieve persisted authentication information
+ // session = new EvernoteSession(info, getPreferencesForAuthData(),
+ // getTempDir());
+ util.setupSession(this);
+ updateUi();
+
+ // ADD
+ startAuth(null);
+ }
+
+ /**
+ * Update the UI based on Evernote authentication state.
+ */
+ private void updateUi() {
+ // DELETE
+ // if (session.isLoggedIn()) {
+ // btnAuth.setText(R.string.label_log_out);
+ // btnSave.setEnabled(true);
+ // btnSelect.setEnabled(true);
+ // } else {
+ // btnAuth.setText(R.string.label_log_in);
+ // btnSave.setEnabled(false);
+ // btnSelect.setEnabled(false);
+ // }
+ }
+
+ /**
+ * Called when the user taps the "Log in to Evernote" button. Initiates the
+ * Evernote OAuth process, or logs out if the user is already logged in.
+ */
+ public void startAuth(View view) {
+ // ADD
+ EvernoteSession session = util.getSession();
+
+ // EDIT
+ // if (session.isLoggedIn()) {
+ // session.logOut(util.getPreferencesForAuthData(this));
+ // } else {
+ // session.authenticate(this);
+ // }
+ if (session.isLoggedIn()) {
+ session.logOut(util.getPreferencesForAuthData(this));
+ }
+ session.authenticate(this);
+
+ updateUi();
+ }
+
+ /**
+ * Get a temporary directory that can be used by this application to store
+ * potentially large files sent to and retrieved from the Evernote API.
+ */
+ // private File getTempDir() {
+ // return new File(Environment.getExternalStorageDirectory(),
+ // APP_DATA_PATH);
+ // }
+}
\ No newline at end of file
import android.widget.LinearLayout;
import android.widget.TextView;
-import com.yuji.em.common.CommonUtil;
import com.yuji.em.data.NoteDao;
import com.yuji.em.utility.BaseActivity;
-import com.yuji.em.utility.PasswordUtil;
+import com.yuji.em.utility.EvernoteUtil;
public class SettingActivity extends BaseActivity {
private LinearLayout messageLayout = null;
}
private void userButtonOnClick() {
- Intent intent = new Intent(this, (Class<?>) UserPasswordActivity.class);
+ //Intent intent = new Intent(this, (Class<?>) UserPasswordActivity.class);
+ //startActivityForResult(intent, 0);
+ Intent intent = new Intent(this, (Class<?>) OAuthActivity.class);
startActivityForResult(intent, 0);
}
}
private void setStatus() {
- String passwd = PasswordUtil.getPassword(this);
+ //String passwd = PasswordUtil.getPassword(this);
- if (CommonUtil.isNull(passwd)) {
+ EvernoteUtil util = EvernoteUtil.getInstance();
+ //if (CommonUtil.isNull(passwd)) {
+ if (!util.isLoggedIn()){
messageLayout.setVisibility(View.VISIBLE);
messageView.setText(getString(R.string.settingConfirmUserMsg));
noteButton.setEnabled(false);
PasswordUtil.setUserAndPassword(this, username, password);
EvernoteUtil util = EvernoteUtil.getInstance();
- util.setConfig(username, password);
+ //util.setConfig(username, password);
finish();
}
public static final int TOGGLE_SIZE = 5;
public static final String DEFAULT_HEADER_TEXT = "<hr /><h3>{DATE} {TIME}</h3><hr />";
+ public static final String PREF_LOGIN_DATE = "LOGIN_DATE";
}
import java.util.Set;
import android.content.Context;
+import android.content.SharedPreferences;
public class EditPrefUtil implements PrefUtil {
private static final String DELM = "\t";
pref = new PrefUtilImpl(context);
}
+ @Override
+ public SharedPreferences getSharedPreferences() {
+ return pref.getSharedPreferences();
+ }
+
+ @Override
public void put(String key, String value) {
hash.put(key, value);
}
+ @Override
public void put(String key, int value) {
hash.put(key, String.valueOf(value));
}
+ @Override
+ public void put(String key, long value) {
+ hash.put(key, String.valueOf(value));
+ }
+
+ @Override
public String get(String key) {
String value = hash.get(key);
if (value != null){
return value;
}
+ @Override
public int getInt(String key) {
return Integer.parseInt(get(key));
}
+ @Override
+ public long getLong(String key) {
+ return Long.parseLong(get(key));
+ }
+
+ @Override
public String get(String key, String initValue) {
String value = get(key);
if (value != null){
return initValue;
}
+ @Override
public int getInt(String key, int initValue) {
return Integer.valueOf(get(key, String.valueOf(initValue)));
}
+ @Override
+ public long getLong(String key, long initValue) {
+ return Long.valueOf(get(key, String.valueOf(initValue)));
+ }
+
public void update(){
Set<Entry<String, String>> set = hash.entrySet();
for (Iterator<Entry<String, String>> it = set.iterator(); it.hasNext(); ){
hash.clear();
}
+ @Override
+ public void copy(String srcKey, String dstKey){
+ String value = get(srcKey);
+ put(dstKey, value);
+ }
+
+ @Override
public void remove(String key) {
hash.put(key, null);
}
put(prefKey, prefValue);
}
}
-
}
import java.util.List;
import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.transport.THttpClient;
import org.apache.thrift.transport.TTransportException;
import android.content.Context;
-import com.evernote.edam.error.EDAMErrorCode;
+import com.evernote.client.oauth.android.EvernoteSession;
import com.evernote.edam.error.EDAMNotFoundException;
import com.evernote.edam.error.EDAMSystemException;
import com.evernote.edam.error.EDAMUserException;
import com.evernote.edam.notestore.NoteStore;
import com.evernote.edam.type.Note;
import com.evernote.edam.type.NoteSortOrder;
-import com.evernote.edam.type.User;
-import com.evernote.edam.userstore.AuthenticationResult;
-import com.evernote.edam.userstore.UserStore;
import com.yuji.em.R;
public class EvernoteUtil {
private static final int N = 50;
- private String username;
- private String password;
+ private EvernoteSession session = null;
+
+ // private String username;
+ // private String password;
public enum Error {
- NONE,
- CONNECT,
- INVALID_AUTH,
- NOT_FOUND,
- OTHER
+ NONE, CONNECT, INVALID_AUTH, NOT_FOUND, OTHER
};
+
private Error errorCode;
-
+
public static EvernoteUtil getInstance() {
if (instance == null) {
instance = new EvernoteUtil();
private String authenticationToken = null;
private NoteStore.Client noteStore = 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() {
errorCode = Error.OTHER;
try {
String token = getAuthenticationToken();
- if (token == null){
+ if (token == null) {
return null;
}
note = noteStore.getNote(token, guid, withContent,
throw e;
} catch (TException e) {
Debug.d(this, null, e);
-
- if (e.getCause() instanceof ConnectException){
- errorCode = Error.CONNECT;
+
+ if (e.getCause() instanceof ConnectException) {
+ errorCode = Error.CONNECT;
}
}
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 list;
}
- public Note updateNoteContext(String guid, String title, String text){
+ public Note updateNoteContext(String guid, String title, String text) {
errorCode = Error.OTHER;
Note note = null;
Note n = null;
try {
String token = getAuthenticationToken();
- if (token == null){
+ if (token == null) {
return null;
}
n = noteStore.updateNote(token, note);
} catch (TException e) {
Debug.d(this, null, e);
- if (e.getCause() instanceof ConnectException){
- errorCode = Error.CONNECT;
+ if (e.getCause() instanceof ConnectException) {
+ errorCode = Error.CONNECT;
}
}
return n;
}
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;
+ if (authenticationToken == null) {
+ authenticationToken = session.getAuthToken();
+ try {
+ noteStore = session.createNoteStore();
+ } catch (TTransportException e) {
+ authenticationToken = null;
}
}
-
return authenticationToken;
}
-
- public Error getErrorCode(){
+
+ public Error getErrorCode() {
return errorCode;
}
-
- public String getErrorMessage(Context context, Error code){
- if (code.equals(Error.NONE)){
+
+ public String getErrorMessage(Context context, Error code) {
+ if (code.equals(Error.NONE)) {
return "";
}
- if (code.equals(Error.CONNECT)){
+ if (code.equals(Error.CONNECT)) {
return context.getString(R.string.toastConnect);
}
- if (code.equals(Error.INVALID_AUTH)){
+ if (code.equals(Error.INVALID_AUTH)) {
return context.getString(R.string.toastInvalidAuth);
}
- if (code.equals(Error.NOT_FOUND)){
+ if (code.equals(Error.NOT_FOUND)) {
return context.getString(R.string.toastNoteDoesNotExist);
}
return context.getString(R.string.toastEvernoteSystem);
}
+
+ public void setSession(EvernoteSession session) {
+ this.session = session;
+ }
+
+ public boolean isLoggedIn() {
+ if (session == null) {
+ return false;
+ }
+ return session.isLoggedIn();
+ }
}
--- /dev/null
+package com.yuji.em.utility;
+
+import java.io.File;
+import java.util.Calendar;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Environment;
+
+import com.evernote.client.conn.ApplicationInfo;
+import com.evernote.client.oauth.android.EvernoteSession;
+import com.yuji.em.common.Constant;
+
+public class OAuthUtil {
+ private static final String CONSUMER_KEY = "yuji-k64613";
+ private static final String CONSUMER_SECRET = "98b2cbf35f747d2d";
+ private static final String APP_DATA_PATH = "/Android/data/com.yuji.em/temp/";
+ private static final String EVERNOTE_HOST = "www.evernote.com";
+
+ private static final String APP_NAME = "MemoErver";
+ private static final String APP_VERSION = "1.0.0";
+
+ private static OAuthUtil instance = null;
+ private EvernoteSession session;
+
+ public static OAuthUtil getInstance() {
+ if (instance == null) {
+ instance = new OAuthUtil();
+ }
+ return instance;
+ }
+
+ private OAuthUtil() {
+
+ }
+
+ public EvernoteSession setupSession(Context context) {
+ ApplicationInfo info = new ApplicationInfo(CONSUMER_KEY,
+ CONSUMER_SECRET, EVERNOTE_HOST, APP_NAME, APP_VERSION);
+
+ // Retrieve persisted authentication information
+ session = new EvernoteSession(info,
+ getPreferencesForAuthData(context), getTempDir());
+
+ // セッションの期限切れをチェック
+ EditPrefUtil pref = new EditPrefUtil(context);
+ Calendar cal = Calendar.getInstance();
+ long now = cal.getTimeInMillis();
+ long loginTime = pref.getLong(Constant.PREF_LOGIN_DATE);
+ long diff = (now - loginTime) / 1000;
+
+ //if (loginTime > 0 && diff > 60){ // 1分
+ if (loginTime > 0 && diff > (365 - 1) * 24 * 60 * 60){ // 余裕を持って1日前に削除
+ logout(context);
+ pref.put(Constant.PREF_LOGIN_DATE, 0L);
+ pref.update();
+
+ session = new EvernoteSession(info,
+ getPreferencesForAuthData(context), getTempDir());
+ }
+
+ return session;
+ }
+
+ public boolean isCompleteAuth(Context context) {
+ if (session == null) {
+ return false;
+ }
+ return session
+ .completeAuthentication(getPreferencesForAuthData(context));
+ }
+
+ public SharedPreferences getPreferencesForAuthData(Context context) {
+ PrefUtil pref = new PrefUtilImpl(context);
+ return pref.getSharedPreferences();
+ }
+
+ private File getTempDir() {
+ return new File(Environment.getExternalStorageDirectory(),
+ APP_DATA_PATH);
+ }
+
+ public EvernoteSession getSession() {
+ return session;
+ }
+
+ public void logout(Context context){
+ session.logOut(getPreferencesForAuthData(context));
+
+ EditPrefUtil pref = new EditPrefUtil(context);
+ pref.put(Constant.PREF_LOGIN_DATE, 0L);
+ pref.update();
+ }
+
+ public void setLoginTime(Context context) {
+ Calendar cal = Calendar.getInstance();
+ long t = cal.getTimeInMillis();
+ EditPrefUtil pref = new EditPrefUtil(context);
+ pref.put(Constant.PREF_LOGIN_DATE, t);
+ pref.update();
+ }
+}
package com.yuji.em.utility;
+import android.content.SharedPreferences;
+
public interface PrefUtil {
+ SharedPreferences getSharedPreferences();
void put(String key, String value);
void put(String key, int value);
+ void put(String key, long value);
String get(String key);
int getInt(String key);
+ long getLong(String key);
String get(String key, String initValue);
int getInt(String key, int initValue);
+ long getLong(String key, long initValue);
+ void copy(String srcKey, String dstKey);
void remove(String key);
}
import android.content.pm.PackageManager.NameNotFoundException;
public class PrefUtilImpl implements PrefUtil {
- private static final String EVER_MEMO_ACTIVITY = "EverMemoActivity";
+ private static final String EVER_CLIP_ACTIVITY = "EverMemoActivity";
private static final String PACKAGE_COM_YUJI_EM = "com.yuji.em";
private Context context;
this.context = context;
}
+ @Override
+ public SharedPreferences getSharedPreferences(){
+ SharedPreferences pref = null;
+ try {
+ Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EM,
+ Context.CONTEXT_RESTRICTED);
+ pref = ctxt.getSharedPreferences(EVER_CLIP_ACTIVITY,
+ Context.MODE_PRIVATE);
+ } catch (NameNotFoundException e) {
+ Debug.d(this, null, e);
+ }
+ return pref;
+ }
+
+ @Override
public void put(String key, String value) {
synchronized (this) {
- SharedPreferences pref = null;
- try {
- Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EM,
- Context.CONTEXT_RESTRICTED);
- pref = ctxt.getSharedPreferences(EVER_MEMO_ACTIVITY,
- Context.MODE_PRIVATE);
- } catch (NameNotFoundException e) {
- Debug.d(this, null, e);
+ SharedPreferences pref = getSharedPreferences();
+ if (pref == null){
return;
}
}
}
+ @Override
public void put(String key, int value) {
put(key, String.valueOf(value));
}
+ @Override
+ public void put(String key, long value) {
+ put(key, String.valueOf(value));
+ }
+
+ @Override
public String get(String key) {
String val;
synchronized (this) {
- SharedPreferences pref = null;
- try {
- Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EM,
- Context.CONTEXT_RESTRICTED);
- pref = ctxt.getSharedPreferences(EVER_MEMO_ACTIVITY,
- Context.MODE_WORLD_READABLE);
- } catch (NameNotFoundException e) {
- Debug.d(this, null, e);
+ SharedPreferences pref = getSharedPreferences();
+ if (pref == null){
return null;
}
+
val = pref.getString(key, null);
}
return val;
}
+ @Override
public int getInt(String key) {
return Integer.parseInt(get(key));
}
+ @Override
+ public long getLong(String key) {
+ return Long.parseLong(get(key));
+ }
+
+ @Override
public String get(String key, String initValue) {
String value = get(key);
if (value != null) {
return initValue;
}
+ @Override
public int getInt(String key, int initValue) {
return Integer.valueOf(get(key, String.valueOf(initValue)));
}
+ @Override
+ public long getLong(String key, long initValue) {
+ return Long.valueOf(get(key, String.valueOf(initValue)));
+ }
+
+ @Override
+ public void copy(String srcKey, String dstKey){
+ String value = get(srcKey);
+ put(dstKey, value);
+ }
+
+ @Override
public void remove(String key) {
put(key, null);
}