OSDN Git Service

OAuth
authorYuji Konishi <yuji.k64613@gmail.com>
Tue, 18 Sep 2012 12:56:41 +0000 (21:56 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Tue, 18 Sep 2012 12:56:41 +0000 (21:56 +0900)
28 files changed:
.gitignore
workspace/EverClip/.classpath
workspace/EverClip/.settings/org.eclipse.jdt.core.prefs
workspace/EverClip/AndroidManifest.xml
workspace/EverClip/default.properties [deleted file]
workspace/EverClip/gen/com/yuji/ec/BuildConfig.java [new file with mode: 0644]
workspace/EverClip/gen/com/yuji/ec/R.java
workspace/EverClip/lib/evernote-api-1.20.jar [deleted file]
workspace/EverClip/libs/evernote-api-1.22.jar [new file with mode: 0644]
workspace/EverClip/libs/evernote-client-android.jar [new file with mode: 0644]
workspace/EverClip/libs/libthrift.jar [moved from workspace/EverClip/lib/libthrift.jar with 84% similarity]
workspace/EverClip/libs/log4j-1.2.14.jar [moved from workspace/EverClip/lib/log4j-1.2.14.jar with 100% similarity]
workspace/EverClip/libs/scribe-1.3.1.jar [new file with mode: 0644]
workspace/EverClip/libs/slf4j-android-1.5.8.jar [new file with mode: 0644]
workspace/EverClip/libs/slf4j.license [new file with mode: 0644]
workspace/EverClip/libs/tagsoup-1.2.1.jar [moved from workspace/EverClip/lib/tagsoup-1.2.1.jar with 100% similarity]
workspace/EverClip/project.properties [new file with mode: 0644]
workspace/EverClip/res/layout/oauth.xml [new file with mode: 0644]
workspace/EverClip/res/values-ja/strings.xml
workspace/EverClip/res/values/strings.xml
workspace/EverClip/src/com/yuji/ec/Initialize.java
workspace/EverClip/src/com/yuji/ec/OAuthActivity.java [new file with mode: 0644]
workspace/EverClip/src/com/yuji/ec/SettingActivity.java
workspace/EverClip/src/com/yuji/ec/utility/EditPrefUtil.java
workspace/EverClip/src/com/yuji/ec/utility/EvernoteUtil.java
workspace/EverClip/src/com/yuji/ec/utility/OAuthUtil.java [new file with mode: 0644]
workspace/EverClip/src/com/yuji/ec/utility/PrefUtil.java
workspace/EverClip/src/com/yuji/ec/utility/PrefUtilImpl.java

index 9c35e3b..3c98652 100644 (file)
@@ -1,4 +1,4 @@
-workspace/.metadata\r
-*.class\r
-workspace/EverClip/bin\r
-.DS_Store\r
+workspace/.metadata
+*.class
+workspace/EverClip/bin
+.DS_Store
index dd7c936..cd50317 100644 (file)
@@ -1,11 +1,15 @@
-<?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="lib" path="lib/tagsoup-1.2.1.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/log4j-1.2.14.jar"/>
+       <classpathentry kind="lib" path="libs/scribe-1.3.1.jar"/>
+       <classpathentry kind="lib" path="libs/slf4j-android-1.5.8.jar"/>
+       <classpathentry kind="lib" path="libs/tagsoup-1.2.1.jar"/>
+       <classpathentry kind="output" path="bin/classes"/>
+</classpath>
index 42318a6..8000cd6 100644 (file)
@@ -1,5 +1,11 @@
-#Thu Apr 05 15:34:06 JST 2012\r
-eclipse.preferences.version=1\r
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5\r
-org.eclipse.jdt.core.compiler.compliance=1.5\r
-org.eclipse.jdt.core.compiler.source=1.5\r
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
index e55ca94..ee474e4 100644 (file)
@@ -1,30 +1,64 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-       package="com.yuji.ec" android:versionCode="1" android:versionName="1.0.0">
-       <uses-sdk android:minSdkVersion="7" />
+    package="com.yuji.ec"
+    android:versionCode="1"
+    android:versionName="1.0.0" >
+
+    <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=".SettingActivity"
+            android:label="@string/app_name"
+            android:launchMode="singleTop" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity
+            android:name=".EverClipActivity"
+            android:label="@string/app_name"
+            android:launchMode="singleTop" >
+            <intent-filter>
+                <action android:name="com.adamrocker.android.simeji.ACTION_INTERCEPT" />
+
+                <category android:name="com.adamrocker.android.simeji.REPLACE" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+        <activity android:name=".UserPasswordActivity" >
+        </activity>
+        <activity android:name=".NoteTypeListActivity" >
+        </activity>
+        <activity android:name=".NoteUpdatorActivity" >
+        </activity>
+        <activity
+            android:name=".OAuthActivity"
+            android:launchMode="singleTop" >
+        </activity>
+        <activity
+          android:name="com.evernote.client.oauth.android.EvernoteOAuthActivity"
+          android:launchMode="singleTask"
+          android:configChanges="orientation|keyboard">
+          <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>
+        <service
+            android:name=".service.NoteUpdatorService"
+            android:enabled="true" />
+    </application>
+
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 
-       <application android:icon="@drawable/icon" android:label="@string/app_name"
-               android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
-               <activity android:name=".SettingActivity" android:label="@string/app_name"
-                       android:launchMode="singleTop">
-                       <intent-filter>
-                               <action android:name="android.intent.action.MAIN" />
-                               <category android:name="android.intent.category.LAUNCHER" />
-                       </intent-filter>
-               </activity>
-               <activity android:name=".EverClipActivity" android:label="@string/app_name"
-                       android:launchMode="singleTop">
-                       <intent-filter>
-                               <action android:name="com.adamrocker.android.simeji.ACTION_INTERCEPT" />
-                               <category android:name="com.adamrocker.android.simeji.REPLACE" />
-                               <category android:name="android.intent.category.DEFAULT" />
-                       </intent-filter>
-               </activity>
-               <activity android:name=".UserPasswordActivity"></activity>
-               <activity android:name=".NoteTypeListActivity"></activity>
-               <activity android:name=".NoteUpdatorActivity"></activity>
-               <service android:enabled="true" android:name=".service.NoteUpdatorService" />
-       </application>
-       <uses-permission android:name="android.permission.INTERNET" />
-       <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 </manifest>
\ No newline at end of file
diff --git a/workspace/EverClip/default.properties b/workspace/EverClip/default.properties
deleted file mode 100644 (file)
index 46769a7..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-# 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
diff --git a/workspace/EverClip/gen/com/yuji/ec/BuildConfig.java b/workspace/EverClip/gen/com/yuji/ec/BuildConfig.java
new file mode 100644 (file)
index 0000000..b55492e
--- /dev/null
@@ -0,0 +1,6 @@
+/** Automatically generated file. DO NOT MODIFY */
+package com.yuji.ec;
+
+public final class BuildConfig {
+    public final static boolean DEBUG = true;
+}
\ No newline at end of file
index 81dd084..94b70fa 100644 (file)
@@ -70,12 +70,14 @@ public final class R {
         public static final int main=0x7f030000;
         public static final int note_type_list=0x7f030001;
         public static final int note_updator=0x7f030002;
-        public static final int setting=0x7f030003;
-        public static final int simple_list_item_1=0x7f030004;
-        public static final int small_list_item_1=0x7f030005;
-        public static final int user_password=0x7f030006;
+        public static final int oauth=0x7f030003;
+        public static final int setting=0x7f030004;
+        public static final int simple_list_item_1=0x7f030005;
+        public static final int small_list_item_1=0x7f030006;
+        public static final int user_password=0x7f030007;
     }
     public static final class string {
+        public static final int ErrorLogin=0x7f05002d;
         public static final int app_name=0x7f050000;
         public static final int cancelButton=0x7f050006;
         public static final int closeButton=0x7f050007;
@@ -86,10 +88,10 @@ public final class R {
         public static final int mainMenuSetting=0x7f050008;
         public static final int mainTitle=0x7f050009;
         public static final int noButton=0x7f050003;
-        public static final int noteTypeConfirmTitle=0x7f05002e;
+        public static final int noteTypeConfirmTitle=0x7f05002f;
         public static final int noteTypeDialogTitle=0x7f050020;
         public static final int noteTypeTitle=0x7f05001f;
-        public static final int selectTitle=0x7f05002d;
+        public static final int selectTitle=0x7f05002e;
         public static final int sendButton=0x7f050001;
         public static final int settingConfirmNoteMsg=0x7f05000d;
         public static final int settingConfirmTitle=0x7f05000b;
@@ -101,7 +103,7 @@ public final class R {
         public static final int settingSortTitle=0x7f050012;
         public static final int settingTimeButton=0x7f050019;
         public static final int settingTimeCheck=0x7f050018;
-        public static final int settingTimeText=0x7f050030;
+        public static final int settingTimeText=0x7f050031;
         public static final int settingTimeTitle=0x7f050017;
         public static final int settingUpdateButton=0x7f050016;
         public static final int settingUpdateTitle=0x7f050015;
@@ -120,7 +122,7 @@ public final class R {
         public static final int updatorMessage=0x7f05001b;
         public static final int updatorNoteButton=0x7f05001d;
         public static final int updatorNoteDialogTitle=0x7f05001e;
-        public static final int updatorNoteText=0x7f05002f;
+        public static final int updatorNoteText=0x7f050030;
         public static final int updatorNoteTitle=0x7f05001c;
         public static final int userPasswordTitle=0x7f050022;
         public static final int userUserTitle=0x7f050021;
diff --git a/workspace/EverClip/lib/evernote-api-1.20.jar b/workspace/EverClip/lib/evernote-api-1.20.jar
deleted file mode 100644 (file)
index c5b6da7..0000000
Binary files a/workspace/EverClip/lib/evernote-api-1.20.jar and /dev/null differ
diff --git a/workspace/EverClip/libs/evernote-api-1.22.jar b/workspace/EverClip/libs/evernote-api-1.22.jar
new file mode 100644 (file)
index 0000000..57f1fe7
Binary files /dev/null and b/workspace/EverClip/libs/evernote-api-1.22.jar differ
diff --git a/workspace/EverClip/libs/evernote-client-android.jar b/workspace/EverClip/libs/evernote-client-android.jar
new file mode 100644 (file)
index 0000000..01fbdf3
Binary files /dev/null and b/workspace/EverClip/libs/evernote-client-android.jar differ
similarity index 84%
rename from workspace/EverClip/lib/libthrift.jar
rename to workspace/EverClip/libs/libthrift.jar
index 47c3cd3..fff381f 100644 (file)
Binary files a/workspace/EverClip/lib/libthrift.jar and b/workspace/EverClip/libs/libthrift.jar differ
diff --git a/workspace/EverClip/libs/scribe-1.3.1.jar b/workspace/EverClip/libs/scribe-1.3.1.jar
new file mode 100644 (file)
index 0000000..4abc551
Binary files /dev/null and b/workspace/EverClip/libs/scribe-1.3.1.jar differ
diff --git a/workspace/EverClip/libs/slf4j-android-1.5.8.jar b/workspace/EverClip/libs/slf4j-android-1.5.8.jar
new file mode 100644 (file)
index 0000000..e0128bc
Binary files /dev/null and b/workspace/EverClip/libs/slf4j-android-1.5.8.jar differ
diff --git a/workspace/EverClip/libs/slf4j.license b/workspace/EverClip/libs/slf4j.license
new file mode 100644 (file)
index 0000000..8ef6d25
--- /dev/null
@@ -0,0 +1,21 @@
+ 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.
diff --git a/workspace/EverClip/project.properties b/workspace/EverClip/project.properties
new file mode 100644 (file)
index 0000000..22d0dca
--- /dev/null
@@ -0,0 +1,14 @@
+# 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
diff --git a/workspace/EverClip/res/layout/oauth.xml b/workspace/EverClip/res/layout/oauth.xml
new file mode 100644 (file)
index 0000000..9e3d912
--- /dev/null
@@ -0,0 +1,12 @@
+<?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
index 02ff2cd..5faafc6 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-    <string name="app_name">EverClip</string>
+    <string name="app_name">ClipEver</string>
 
     <string name="sendButton">送信</string>
     <string name="yesButton">はい</string>
@@ -55,7 +55,9 @@
 
     <string name="dialogErrorTitle">エラー</string>
     <string name="dialogSystemError">システムエラーが発生しました</string>
-    
+     
+    <string name="ErrorLogin">ログインに失敗しました</string>
+        
        <string-array name="note_item_array">
            <item>全てのノート</item>
            <item>ノートブック</item>
index 6d487c8..165a5d3 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-    <string name="app_name">EverClip</string>
+    <string name="app_name">ClipEver</string>
 
     <string name="sendButton">Send</string>
     <string name="yesButton">Yes</string>
@@ -55,7 +55,9 @@
 
     <string name="dialogErrorTitle">Error</string>
     <string name="dialogSystemError">System error has occurred.</string>
-    
+    <string name="ErrorLogin">Failed to login</string>
+        
        <string-array name="note_item_array">
            <item>All notes</item>
            <item>Notebook</item>
index dcddbb3..9950638 100644 (file)
@@ -2,10 +2,12 @@ package com.yuji.ec;
 
 import android.content.Context;
 
+import com.evernote.client.oauth.android.EvernoteSession;
 import com.yuji.ec.common.CommonUtil;
 import com.yuji.ec.db.DatabaseHelper;
 import com.yuji.ec.service.NoteUpdatorService;
 import com.yuji.ec.utility.EvernoteUtil;
+import com.yuji.ec.utility.OAuthUtil;
 import com.yuji.ec.utility.PasswordUtil;
 
 public class Initialize {
@@ -21,6 +23,14 @@ public class Initialize {
                DatabaseHelper.init(context);
                NoteUpdatorService.init(context);
                
+               try {
+               OAuthUtil authUtil = OAuthUtil.getInstance();
+               EvernoteSession session = authUtil.setupSession(context);
+               EvernoteUtil.getInstance().setSession(session);
+               }
+               catch (Throwable t){
+                       t.printStackTrace();
+               }
                isInit = false;
        }
 
@@ -32,12 +42,12 @@ public class Initialize {
                        return;
                }
                
-               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);
-               }
+//             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);
+//             }
                
                isInit2 = false;        
        }
diff --git a/workspace/EverClip/src/com/yuji/ec/OAuthActivity.java b/workspace/EverClip/src/com/yuji/ec/OAuthActivity.java
new file mode 100644 (file)
index 0000000..8626721
--- /dev/null
@@ -0,0 +1,207 @@
+package com.yuji.ec;
+
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Toast;
+
+import com.evernote.client.oauth.android.EvernoteSession;
+import com.yuji.ec.utility.BaseActivity;
+import com.yuji.ec.utility.EvernoteUtil;
+import com.yuji.ec.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());
+               }
+               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
index 022d2a7..4076529 100644 (file)
@@ -37,6 +37,7 @@ import com.yuji.ec.utility.BaseActivity;
 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.PasswordUtil;
 
 public class SettingActivity extends BaseActivity {
@@ -289,7 +290,9 @@ public class SettingActivity extends BaseActivity {
        }
 
        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);
        }
 
@@ -363,8 +366,10 @@ public class SettingActivity extends BaseActivity {
                timeLayout.setVisibility(timeCheckBox.isChecked() ? View.VISIBLE
                                : View.GONE);
 
-               String passwd = PasswordUtil.getPassword(this);
-               if (CommonUtil.isNull(passwd)) {
+               //String passwd = PasswordUtil.getPassword(this);
+               //if (CommonUtil.isNull(passwd)) {
+               EvernoteUtil util = EvernoteUtil.getInstance();
+               if (!util.isLoggedIn()){
                        messageLayout.setVisibility(View.VISIBLE);
                        messageView.setText(getString(R.string.settingConfirmUserMsg));
                        noteButton.setEnabled(false);
index 1ad3974..6ae1ced 100644 (file)
@@ -7,6 +7,7 @@ import java.util.Map.Entry;
 import java.util.Set;
 
 import android.content.Context;
+import android.content.SharedPreferences;
 
 public class EditPrefUtil implements PrefUtil {
        private static final String DELM = "\t";
@@ -17,18 +18,27 @@ public class EditPrefUtil implements PrefUtil {
                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){
@@ -39,14 +49,17 @@ public class EditPrefUtil implements PrefUtil {
                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){
@@ -56,13 +69,16 @@ public class EditPrefUtil implements PrefUtil {
                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(); ){
@@ -74,11 +90,13 @@ public class EditPrefUtil implements PrefUtil {
                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);
        }
index d57966c..0029fdd 100644 (file)
@@ -11,6 +11,7 @@ import org.apache.thrift.transport.TTransportException;
 
 import android.content.Context;
 
+import com.evernote.client.oauth.android.EvernoteSession;
 import com.evernote.edam.error.EDAMErrorCode;
 import com.evernote.edam.error.EDAMNotFoundException;
 import com.evernote.edam.error.EDAMSystemException;
@@ -55,6 +56,7 @@ public class EvernoteUtil {
 
        private String authenticationToken = null;
        private NoteStore.Client noteStore = null;
+       private EvernoteSession session = null;
 
        public void setConfig(String username, String password) {
                this.username = username;
@@ -289,61 +291,70 @@ 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;
+//             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();
+                       try {
+                               noteStore = session.createNoteStore();
+                       } catch (TTransportException e) {
+                               authenticationToken = null;
                        }
                }
-
                return authenticationToken;
        }
 
@@ -436,4 +447,14 @@ public class EvernoteUtil {
                return list;
        }
 
+       public void setSession(EvernoteSession session) {
+               this.session = session;
+       }
+
+       public boolean isLoggedIn() {
+               if (session == null){
+                       return false;
+               }
+               return session.isLoggedIn();
+       }
 }
diff --git a/workspace/EverClip/src/com/yuji/ec/utility/OAuthUtil.java b/workspace/EverClip/src/com/yuji/ec/utility/OAuthUtil.java
new file mode 100644 (file)
index 0000000..41f57e6
--- /dev/null
@@ -0,0 +1,67 @@
+package com.yuji.ec.utility;
+
+import java.io.File;
+
+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;
+
+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.ec/temp/";
+       private static final String EVERNOTE_HOST = "www.evernote.com";
+
+       private static final String APP_NAME = "ClipErver";
+       private static final String APP_VERSION = "1.1.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());
+               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;
+       }
+
+}
index a57ccd7..3a8f1ab 100644 (file)
@@ -1,6 +1,9 @@
 package com.yuji.ec.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);
index 31018ad..f47e306 100644 (file)
@@ -14,16 +14,25 @@ public class PrefUtilImpl implements PrefUtil {
                this.context = context;
        }
 
+       @Override
+       public SharedPreferences getSharedPreferences(){
+               SharedPreferences pref = null;
+               try {
+                       Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EC,
+                                       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_EC,
-                                               Context.CONTEXT_RESTRICTED);
-                               pref = ctxt.getSharedPreferences(EVER_CLIP_ACTIVITY,
-                                               Context.MODE_PRIVATE);
-                       } catch (NameNotFoundException e) {
-                               Debug.d(this, null, e);
+                       SharedPreferences pref = getSharedPreferences();
+                       if (pref == null){
                                return;
                        }
 
@@ -33,42 +42,43 @@ public class PrefUtilImpl implements PrefUtil {
                }
        }
 
+       @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_EC,
-                                               Context.CONTEXT_RESTRICTED);
-                               pref = ctxt.getSharedPreferences(EVER_CLIP_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) {
@@ -78,19 +88,23 @@ public class PrefUtilImpl implements PrefUtil {
                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);
        }