Browse files

Add createNoteStore returning NoteStoreProxy (tentative).

  • Loading branch information...
1 parent 16081f1 commit 60fbe4a9282c4d693b3b94558d1a20bb1b7d9b84 @napthats committed Dec 26, 2012
Showing with 77 additions and 0 deletions.
  1. +5 −0 pom.xml
  2. +72 −0 src/main/java/com/napthats/android/evernote/EvernoteActivity.java
View
5 pom.xml
@@ -29,6 +29,11 @@
<systemPath>${basedir}/lib/android-sdk-1.0.1.jar</systemPath>
</dependency>
<dependency>
+ <groupId>com.evernote</groupId>
+ <artifactId>evernote-api</artifactId>
+ <version>1.23</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
View
72 src/main/java/com/napthats/android/evernote/EvernoteActivity.java
@@ -1,13 +1,27 @@
package com.napthats.android.evernote;
import java.io.File;
+import java.util.List;
+
+import java.lang.reflect.Proxy;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
import android.app.Activity;
import android.os.Environment;
import android.content.Context;
import android.content.Intent;
+//
+import android.util.Log;
+//
import com.evernote.client.oauth.android.EvernoteSession;
+import com.evernote.edam.type.Note;
+import com.evernote.edam.type.Tag;
+import com.evernote.edam.notestore.NoteStore;
+import com.evernote.edam.notestore.NoteList;
+import com.evernote.edam.notestore.NoteFilter;
public class EvernoteActivity extends Activity
@@ -17,6 +31,64 @@
private EvernoteSession session = null;
+ //tentative
+ protected final NoteStoreProxy createNoteStore() {
+ checkInitialized();
+ return (NoteStoreProxy) Proxy.newProxyInstance(
+ NoteStoreProxy.class.getClassLoader(),
+ new Class[] {NoteStoreProxy.class},
+ new InvocationHandler() {
+ private NoteStore.Client note_store = null;
+ {
+ try {
+ note_store = session.createNoteStore();
+ }
+ catch (Exception e) {
+ //TODO: Deal with exceptions.
+ }
+ }
+ public Object invoke(Object proxy, Method proxy_method, Object[] args)
+ throws Throwable {
+ //TODO: Deal with exceptions.
+ //TODO: Deal with few methods without an auth token.
+ try {
+ Object[] authkey_added_args = new Object[args.length + 1];
+ authkey_added_args[0] = session.getAuthToken();
+ System.arraycopy(args, 0, authkey_added_args, 1, args.length);
+ Class[] authkey_added_argsclass = new Class[args.length + 1];
+ authkey_added_argsclass[0] = String.class;
+ System.arraycopy(proxy_method.getParameterTypes(), 0, authkey_added_argsclass, 1, args.length);
+ Method method = note_store.getClass().getMethod(proxy_method.getName(), authkey_added_argsclass);
+ return method.invoke(note_store, authkey_added_args);
+ }
+ catch (Throwable e) {
+ throw e.getCause();
+ }
+ }
+ }
+ );
+ }
+
+
+ public interface NoteStoreProxy {
+ public List<Tag> listTags();
+ public Note updateNote(Note note);
+ public Tag createTag(Tag tag);
+ public Note getNote(String guid, boolean b1, boolean b2, boolean b3, boolean b4);
+ public NoteList findNotes(NoteFilter filter, int i1, int i2);
+ public Note createNote(Note note);
+ }
+
+
+ /**
+ * isLoggedIn.
+ */
+ protected final boolean isLoggedIn() {
+ checkInitialized();
+ return session.isLoggedIn();
+ }
+
+
/**
* Initialize settings of Evernote.
* This method have to be called before all other methods.

0 comments on commit 60fbe4a

Please sign in to comment.