Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add authenticate.

  • Loading branch information...
commit e5575c056a939df5202267566dc105aa74070385 1 parent 4282ce9
@napthats authored
Showing with 45 additions and 0 deletions.
  1. +45 −0 src/main/java/com/napthats/android/evernote/EvernoteActivity.java
View
45 src/main/java/com/napthats/android/evernote/EvernoteActivity.java
@@ -4,6 +4,8 @@
import android.app.Activity;
import android.os.Environment;
+import android.content.Context;
+import android.content.Intent;
import com.evernote.client.oauth.android.EvernoteSession;
@@ -46,4 +48,47 @@ private void _initEvernote(String c_key, String c_secret, String evernote_host,
session = EvernoteSession.init((android.content.Context)this, c_key, c_secret, evernote_host, temp_file);
}
+
+ /**
+ * Authenticate Evernote and set callback after authentication.
+ *
+ * @param succeeded Callback after succeeding authentication.
+ * @param failed Callback after failing authentication.
+ */
+ protected final void authenticate(CallBack succeeded, CallBack failed)
+ throws NotInitializedException {
+ checkInitialized();
+ succeededCallbackAfterAuthentication = succeeded;
+ failedCallbackAfterAuthentication = failed;
+ session.authenticate(this);
+ }
+
+ private CallBack succeededCallbackAfterAuthentication = null;
+ private CallBack failedCallbackAfterAuthentication = null;
+
+ protected interface CallBack {
+ public void call();
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (session == null) {return;}
+ if (requestCode == EvernoteSession.REQUEST_CODE_OAUTH) {
+ if (resultCode == Activity.RESULT_OK) {
+ succeededCallbackAfterAuthentication.call();
+ }
+ else
+ {
+ failedCallbackAfterAuthentication.call();
+ }
+ }
+ }
+
+
+ private void checkInitialized() throws NotInitializedException {
+ if (session == null) {throw new NotInitializedException();}
+ }
+
+ public class NotInitializedException extends Exception {}
}

0 comments on commit e5575c0

Please sign in to comment.
Something went wrong with that request. Please try again.