public static final int cancelButton=0x7f050006;
public static final int closeButton=0x7f050007;
public static final int deleteButton=0x7f050005;
- public static final int dialogErrorTitle=0x7f050021;
- public static final int dialogSystemError=0x7f050022;
+ public static final int dialogErrorTitle=0x7f050025;
+ public static final int dialogSystemError=0x7f050026;
public static final int headerEditTitle=0x7f050019;
public static final int headerExplainText1=0x7f05001a;
public static final int headerExplainText2=0x7f05001b;
public static final int headerExplainText3=0x7f05001c;
public static final int headerExplainText4=0x7f05001d;
public static final int mainMenuSetting=0x7f050008;
- public static final int mainTitle=0x7f050023;
+ public static final int mainTitle=0x7f050027;
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=0x7f050024;
+ public static final int selectTitle=0x7f050028;
public static final int sendButton=0x7f050001;
public static final int settingConfirmNoteMsg=0x7f050011;
public static final int settingConfirmTitle=0x7f05000f;
public static final int settingNoteTitle=0x7f050013;
public static final int settingUserButton=0x7f050015;
public static final int settingUserTitle=0x7f050012;
- public static final int toastFailedToGetList=0x7f050020;
+ public static final int toastConnect=0x7f05001f;
+ public static final int toastEvernoteSystem=0x7f050023;
+ public static final int toastFailedToGetList=0x7f050021;
public static final int toastFailedToWrite=0x7f05001e;
- public static final int toastNoteDoesNotExist=0x7f05001f;
+ public static final int toastInvalidAuth=0x7f050022;
+ public static final int toastNoteDoesNotExist=0x7f050020;
+ public static final int toastSystem=0x7f050024;
public static final int updateButton=0x7f050004;
public static final int userPasswordTitle=0x7f05000e;
public static final int userUserTitle=0x7f05000d;
<string name="headerExplainText4">・例) <hr /><h3>{DATE} {TIME}</h3><hr /></string>
<string name="toastFailedToWrite">書き込みに失敗しました</string>
+ <string name="toastConnect">Evernoteとの接続に失敗しました</string>
<string name="toastNoteDoesNotExist">ノートがありません</string>
<string name="toastFailedToGetList">リストの取得に失敗しました</string>
+ <string name="toastInvalidAuth">認証に失敗しました</string>
+ <string name="toastEvernoteSystem">Evernoteとの連係に失敗しました</string>
+ <string name="toastSystem">システムエラーが発生しました</string>
<string name="dialogErrorTitle">エラー</string>
<string name="dialogSystemError">システムエラーが発生しました</string>
<string name="headerExplainText4">・Example: <hr /><h3>{DATE} {TIME}</h3><hr /></string>
<string name="toastFailedToWrite">Failed to write.</string>
+ <string name="toastConnect">Failed to connect Evernote.</string>
<string name="toastNoteDoesNotExist">Note does not exist.</string>
<string name="toastFailedToGetList">Failed to get list.</string>
+ <string name="toastInvalidAuth">Invalid Auth.</string>
+ <string name="toastEvernoteSystem">Failed to cooperate with Evernote.</string>
+ <string name="toastSystem">System error has occurred.</string>
<string name="dialogErrorTitle">Error</string>
<string name="dialogSystemError">System error has occurred.</string>
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
+import android.widget.Toast;
import com.evernote.edam.notestore.NoteList;
import com.yuji.em.common.Constant;
import com.yuji.em.task.NoteListTask;
import com.yuji.em.utility.AsyncTaskCommand;
import com.yuji.em.utility.BaseActivity;
+import com.yuji.em.utility.EvernoteUtil;
+import com.yuji.em.utility.EvernoteUtil.Error;
public class NoteListActivity extends BaseActivity {
private static List<NoteListItem> noteList = null;
finish();
}
- public void done(NoteList nList) {
+ public void done(NoteList nList, Error errorCode) {
+ if (errorCode != null && !errorCode.equals(Error.NONE)) {
+ EvernoteUtil util = EvernoteUtil.getInstance();
+ Toast.makeText(this, util.getErrorMessage(this, errorCode),
+ Toast.LENGTH_LONG).show();
+ }
+
if (nList == null) {
// \83L\83\83\83\93\83Z\83\8b\83{\83^\83\93\89\9f\89º\8e\9e
closeButtonOnClick();
}
return list;
}
-
- public static void init(){
+
+ public static void init() {
noteList = null;
}
}
private EvernoteUtil util = EvernoteUtil.getInstance();
private NoteList noteList;
private WeakReference<NoteListActivity> activityRef;
-
+ private EvernoteUtil.Error errorCode = null;
+
public NoteListTask(NoteListActivity activity) {
activityRef = new WeakReference<NoteListActivity>(activity);
}
@Override
public void doExecute() {
- noteList = util.getNoteList();
+ try {
+ noteList = util.getNoteList();
+ }
+ finally {
+ errorCode = util.getErrorCode();
+ }
}
@Override
public void done(boolean isCancel) {
NoteListActivity activity = activityRef.get();
if (activity != null) {
- activity.done((!isCancel ? noteList : null));
+ activity.done((!isCancel ? noteList : null), errorCode);
activityRef = null;
}
}
public NoteList getNoteList() {
return noteList;
}
+
+ public EvernoteUtil.Error getErrorCode(){
+ return errorCode;
+ }
}
import com.yuji.em.utility.AsyncTaskIF;
import com.yuji.em.utility.Debug;
import com.yuji.em.utility.EvernoteUtil;
+import com.yuji.em.utility.EvernoteUtil.Error;
public class UpdateNoteTask implements AsyncTaskIF {
- public static final int ERROR_NONE = 0;
- public static final int ERROR_NOT_FOUND = 1;
- public static final int ERROR_SYSTEM = 9;
-
private Context context = null;
private String guid;
private String noteName;
private String text;
private EvernoteUtil util = EvernoteUtil.getInstance();
- private int status = -1;
-
+ private EvernoteUtil.Error errorCode = null;
+
public UpdateNoteTask(Context context, String guid, String noteName,
String title, String text) {
this.context = context;
@Override
public void doExecute() {
- try {
- synchronized (context) {
- Note note = util.updateNoteContext(guid, title, text);
- if (note != null) {
- NoteDao dao = NoteDao.getInstance();
- com.yuji.em.data.Note n = new com.yuji.em.data.Note(
- note.getGuid(), note.getTitle());
- dao.update(context, n);
- status = ERROR_NONE;
- } else {
- Toast.makeText(context,
- context.getString(R.string.toastFailedToWrite)
- + ":" + text, Toast.LENGTH_LONG);
- Debug.d(this, "doExecute");
- status = ERROR_SYSTEM;
- }
+ synchronized (context) {
+ Note note = util.updateNoteContext(guid, title, text);
+ if (note != null) {
+ NoteDao dao = NoteDao.getInstance();
+ com.yuji.em.data.Note n = new com.yuji.em.data.Note(
+ note.getGuid(), note.getTitle());
+ dao.update(context, n);
+ } else {
+ errorCode = util.getErrorCode();
}
- } catch (EDAMNotFoundException e) {
- status = ERROR_NOT_FOUND;
}
}
@Override
public void done(boolean isCancel) {
- switch (status) {
- case ERROR_NOT_FOUND:
- Toast.makeText(
- context,
- context.getString(R.string.toastNoteDoesNotExist) + ":"
- + noteName, Toast.LENGTH_LONG).show();
- break;
+ if (errorCode != null && !errorCode.equals(Error.NONE)){
+ Toast.makeText(context, util.getErrorMessage(context, errorCode),
+ Toast.LENGTH_LONG).show();
}
-
}
@Override
public int getStatus() {
- return status;
+ if (errorCode != null && !errorCode.equals(Error.NONE)){
+ return -1;
+ }
+ return 0;
}
}
import android.view.KeyEvent;\r
import android.view.Window;\r
import android.view.WindowManager;\r
+import android.widget.Toast;\r
\r
import com.yuji.em.Initialize;\r
import com.yuji.em.R;\r
\r
public class BaseActivity extends Activity {\r
@Override\r
- public void onCreate(Bundle savedInstanceState) {\r
- super.onCreate(savedInstanceState);\r
+ public void onCreate(Bundle savedInstanceState) {\r
+ super.onCreate(savedInstanceState);\r
Debug.d(this, Debug.ON_CREATE);\r
\r
Context context = getApplicationContext();\r
- //Thread.setDefaultUncaughtExceptionHandler(new TrainDelayedUncaughtExceptionHandler(\r
- // context));\r
- //DatabaseHelper.init(context);\r
+ // Thread.setDefaultUncaughtExceptionHandler(new\r
+ // TrainDelayedUncaughtExceptionHandler(\r
+ // context));\r
+ // DatabaseHelper.init(context);\r
Initialize.initialize(context);\r
- }\r
- \r
- @Override\r
+ }\r
+\r
+ @Override\r
protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r
- super.onActivityResult(requestCode, resultCode, data);\r
+ super.onActivityResult(requestCode, resultCode, data);\r
}\r
- \r
- @Override\r
+\r
+ @Override\r
protected void onRestart() {\r
super.onRestart();\r
Debug.d(this, Debug.ON_RESTART);\r
Debug.d(this, Debug.ON_STOP);\r
}\r
\r
- @Override\r
+ @Override\r
protected void onDestroy() {\r
super.onDestroy();\r
Debug.d(this, Debug.ON_DESTROY);\r
}\r
\r
-// @Override\r
-// public boolean onCreateOptionsMenu(Menu menu) {\r
-// boolean ret = super.onCreateOptionsMenu(menu);\r
-// menu.add(0, Menu.FIRST, Menu.NONE, R.string.help);\r
-// return ret;\r
-// }\r
-// \r
-// @Override\r
-// public boolean onOptionsItemSelected(MenuItem item) {\r
-// try {\r
-// Intent intent = new Intent(this, (Class<?>)Help.class);\r
-// startActivity(intent);\r
-// }\r
-// catch (Exception e){\r
-// terminate(e);\r
-// }\r
-// return super.onOptionsItemSelected(item);\r
-// }\r
+ // @Override\r
+ // public boolean onCreateOptionsMenu(Menu menu) {\r
+ // boolean ret = super.onCreateOptionsMenu(menu);\r
+ // menu.add(0, Menu.FIRST, Menu.NONE, R.string.help);\r
+ // return ret;\r
+ // }\r
+ //\r
+ // @Override\r
+ // public boolean onOptionsItemSelected(MenuItem item) {\r
+ // try {\r
+ // Intent intent = new Intent(this, (Class<?>)Help.class);\r
+ // startActivity(intent);\r
+ // }\r
+ // catch (Exception e){\r
+ // terminate(e);\r
+ // }\r
+ // return super.onOptionsItemSelected(item);\r
+ // }\r
\r
@Override\r
public boolean dispatchKeyEvent(KeyEvent event) {\r
}\r
return super.dispatchKeyEvent(event);\r
}\r
- \r
+\r
protected void setFullscreen() {\r
- requestWindowFeature(Window.FEATURE_NO_TITLE);\r
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,\r
- WindowManager.LayoutParams.FLAG_FULLSCREEN);\r
- }\r
- \r
+ requestWindowFeature(Window.FEATURE_NO_TITLE);\r
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,\r
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);\r
+ }\r
+\r
protected void showDialog(String title, String msg, final boolean isFinish) {\r
- new AlertDialog.Builder(this).setTitle(title).setMessage(msg)\r
- .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {\r
- public void onClick(DialogInterface dialog, int whichButton) {\r
- if (isFinish){\r
- finish();\r
- }\r
- }\r
- }).show();\r
+ new AlertDialog.Builder(this)\r
+ .setTitle(title)\r
+ .setMessage(msg)\r
+ .setNeutralButton(android.R.string.ok,\r
+ new DialogInterface.OnClickListener() {\r
+ public void onClick(DialogInterface dialog,\r
+ int whichButton) {\r
+ if (isFinish) {\r
+ finish();\r
+ }\r
+ }\r
+ }).show();\r
}\r
\r
protected void showDialog(String title, String msg) {\r
}\r
\r
protected void showDialog(Object target, Throwable t) {\r
- if (t != null){\r
- Debug.d(target, null, t);\r
- }\r
+ if (t != null) {\r
+ Debug.d(target, null, t);\r
+ }\r
showDialog(getString(R.string.dialogErrorTitle),\r
getString(R.string.dialogSystemError));\r
}\r
\r
- public void terminate(Throwable t){\r
- if (t != null){\r
- Debug.d(this, null, t);\r
- }\r
- moveTaskToBack(true);\r
- }\r
+ public void terminate(Throwable t) {\r
+ if (t != null) {\r
+ Debug.d(this, null, t);\r
+\r
+ Toast.makeText(\r
+ this,\r
+ getString(R.string.toastSystem) + ":"\r
+ + t.getLocalizedMessage(), Toast.LENGTH_LONG);\r
+ }\r
+ moveTaskToBack(true);\r
+ }\r
}\r
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.edam.error.EDAMNotFoundException;
import com.evernote.edam.error.EDAMSystemException;
import com.evernote.edam.error.EDAMUserException;
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 String username;
private String password;
-
+ public enum Error {
+ NONE,
+ CONNECT,
+ INVALID_AUTH,
+ NOT_FOUND,
+ OTHER
+ };
+ private Error errorCode;
+
public static EvernoteUtil getInstance() {
if (instance == null) {
instance = new EvernoteUtil();
private static EvernoteUtil instance = null;
private EvernoteUtil() {
-
+ errorCode = Error.NONE;
}
private String authenticationToken = null;
boolean withResourcesRecognition = false;
boolean withResourcesAlternateData = false;
Note note = null;
+ errorCode = Error.OTHER;
try {
String token = getAuthenticationToken();
+ if (token == null){
+ return null;
+ }
note = noteStore.getNote(token, guid, withContent,
withResourcesData, withResourcesRecognition,
withResourcesAlternateData);
+ errorCode = Error.NONE;
} catch (EDAMUserException e) {
Debug.d(this, null, e);
} catch (EDAMSystemException e) {
}
public NoteList getNoteList() {
+ errorCode = Error.OTHER;
+
// \8c\9f\8dõ\8fð\8c\8f\82Æ\82µ\82Ä\81A\8c\9f\8dõ\8cê\82È\82µ\81A\8dX\90V\93ú\8f\87\83\\81[\83g\82ð\8ew\92è
NoteFilter filter = new NoteFilter();
filter.setOrder(NoteSortOrder.UPDATED.getValue());
NoteList noteList = null;
try {
String token = getAuthenticationToken();
+ if (token == null){
+ return null;
+ }
noteList = noteStore.findNotes(token, filter, 0, 100);
+ errorCode = Error.NONE;
} catch (EDAMUserException e) {
Debug.d(this, null, e);
} catch (EDAMSystemException e) {
return noteList;
}
- public Note updateNoteContext(String guid, String title, String text)
- throws EDAMNotFoundException {
- Note note = getNote(guid);
+ public Note updateNoteContext(String guid, String title, String text){
+ errorCode = Error.OTHER;
+
+ Note note = null;
+ try {
+ note = getNote(guid);
+ } catch (EDAMNotFoundException e) {
+ errorCode = Error.NOT_FOUND;
+ }
if (note == null) {
return null;
}
note.setContent(content);
Note n = updateNote(note);
+
+ errorCode = Error.NONE;
return n;
}
public Note updateNote(Note note) {
+ errorCode = Error.OTHER;
Note n = null;
try {
String token = getAuthenticationToken();
+ if (token == null){
+ return null;
+ }
n = noteStore.updateNote(token, note);
+ errorCode = Error.NONE;
} catch (EDAMUserException e) {
Debug.d(this, null, e);
} catch (EDAMSystemException e) {
noteStore = new NoteStore.Client(noteStoreProt);
}
} catch (TTransportException e) {
- // TODO
authenticationToken = null;
- noteStore = null; // clear()?
+ 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) {
return authenticationToken;
}
+
+ public Error getErrorCode(){
+ return errorCode;
+ }
+
+ public String getErrorMessage(Context context, Error code){
+ if (code.equals(Error.NONE)){
+ return "";
+ }
+ if (code.equals(Error.CONNECT)){
+ return context.getString(R.string.toastConnect);
+ }
+ if (code.equals(Error.INVALID_AUTH)){
+ return context.getString(R.string.toastInvalidAuth);
+ }
+ return context.getString(R.string.toastEvernoteSystem);
+ }
}