import java.util.Calendar;
import java.util.List;
-import android.app.Activity;
import android.content.Intent;
+import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import com.yuji.em.data.NoteDao;
import com.yuji.em.task.UpdateNoteTask;
import com.yuji.em.utility.AsyncTaskCommand;
+import com.yuji.em.utility.BaseActivity;
+import com.yuji.em.utility.Debug;
import com.yuji.em.utility.EditPrefUtil;
import com.yuji.em.utility.EvernoteUtil;
-public class EverMemoActivity extends Activity {
+public class EverMemoActivity extends BaseActivity {
private EditPrefUtil pref = new EditPrefUtil(this);
private EvernoteUtil util = EvernoteUtil.getInstance();
private TextView titleText = null;
AsyncTaskCommand command = new AsyncTaskCommand(this, task);
command.setDialog(false);
command.execute("");
-
+ Status status = command.getStatus();
+
editText.setText("");
+ } catch (RuntimeException e) {
+ Debug.d(this, null, e); // TODO
+ throw e;
} catch (Exception e) {
e.printStackTrace();
}
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
-import android.widget.TextView;
import com.evernote.edam.notestore.NoteList;
import com.yuji.em.common.Constant;
NoteDao dao = NoteDao.getInstance();
int n = dao.search(this, note);
if (n >= 0){
- // TODO #27613
-
+ // #27613
Intent intent = new Intent();
setResult(RESULT_CANCELED, intent);
finish();
+ return;
}
dao.update(this, note, index);
import com.evernote.edam.type.Note;
import com.yuji.em.utility.AsyncTaskIF;
+import com.yuji.em.utility.Debug;
import com.yuji.em.utility.EvernoteUtil;
public class UpdateNoteTask implements AsyncTaskIF {
+ private static int RETRY_COUNT = 3;
private EvernoteUtil util = EvernoteUtil.getInstance();
private String guid;
private String title;
// catch (Exception e){
// e.printStackTrace();
// }
- Note note = util.updateNoteContext(guid, title, text);
+ int i = 0;
+ for (i = 0; i < RETRY_COUNT; i++){
+ Note note = util.updateNoteContext(guid, title, text);
+ if (note != null){
+ break;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ ;
+ }
+ }
+ if (i >= RETRY_COUNT){
+ Debug.d(this, "doExecute"); // TODO
+ }
}
@Override
private ProgressDialog dialog;\r
private boolean isCancel = false;\r
private boolean isDialog = true;\r
- \r
+\r
@SuppressWarnings({ "rawtypes", "unchecked" })\r
- public AsyncTaskCommand(Activity activity, AsyncTaskIF command){\r
+ public AsyncTaskCommand(Activity activity, AsyncTaskIF command) {\r
this.activityRef = new WeakReference(activity);\r
this.command = command;\r
}\r
\r
@Override\r
- protected void onPreExecute(){\r
+ protected void onPreExecute() {\r
Debug.d(this, "onPreExecute start");\r
- \r
+\r
Activity activity = activityRef.get();\r
- if (activity == null){\r
+ if (activity == null) {\r
return;\r
}\r
- if (isDialog){\r
+ if (isDialog) {\r
dialog = new ProgressDialog(activity);\r
dialog.setIndeterminate(true);\r
dialog.setCancelable(false);\r
// TODO\r
- // dialog.setTitle(activity.getString(R.string.calculating));\r
- // dialog.setButton(activity.getString(R.string.cancel), new DialogInterface.OnClickListener() {\r
+ // dialog.setTitle(activity.getString(R.string.calculating));\r
+ // dialog.setButton(activity.getString(R.string.cancel), new\r
+ // DialogInterface.OnClickListener() {\r
dialog.setTitle("\8cv\8eZ\92\86\81\97\81\97\81\97");\r
dialog.setButton("\83L\83\83\83\93\83Z\83\8b\81\97\81\97\81\97", new DialogInterface.OnClickListener() {\r
@Override\r
}\r
Debug.d(this, "onPreExecute end");\r
}\r
- \r
+\r
@Override\r
protected String doInBackground(String... arg0) {\r
- Debug.d(this, "doInBackground start");\r
- command.doExecute();\r
- Debug.d(this, "doInBackground end");\r
- \r
+ try {\r
+ Debug.d(this, "doInBackground start");\r
+ command.doExecute();\r
+ Debug.d(this, "doInBackground end");\r
+ } catch (RuntimeException e) {\r
+ Debug.d(this, null, e);\r
+ throw e;\r
+ }\r
return null;\r
}\r
- \r
+\r
@Override\r
- protected void onCancelled(){\r
+ protected void onCancelled() {\r
Debug.d(this, "onCancelled start");\r
- \r
+\r
isCancel = true;\r
- \r
- if (command != null){\r
+\r
+ if (command != null) {\r
command.cancel();\r
- } \r
+ }\r
onPostExecute(null);\r
Debug.d(this, "onCancelled end");\r
}\r
\r
@Override\r
- protected void onPostExecute(String result){\r
+ protected void onPostExecute(String result) {\r
Debug.d(this, "onPostExecute start");\r
\r
try {\r
- if (command != null){\r
+ if (command != null) {\r
command.done(isCancel);\r
- command = null; \r
+ command = null;\r
}\r
- if (dialog != null){\r
+ if (dialog != null) {\r
dialog.dismiss();\r
dialog = null;\r
}\r
activityRef = null;\r
- }\r
- catch (RuntimeException e){\r
+ } catch (RuntimeException e) {\r
Debug.d(this, null, e);\r
throw e;\r
}\r
Debug.d(this, "onPostExecute end");\r
}\r
- \r
- public void stop(){\r
+\r
+ public void stop() {\r
Debug.d(this, "stop start");\r
- \r
- if (command != null){\r
+\r
+ if (command != null) {\r
isCancel = true;\r
command.cancel();\r
}\r
// onPostExecute()\82Ìdialog.dismiss();\82Å\83G\83\89\81[\82Æ\82È\82é\82½\82ß\r
// \96{\8e¿\93I\82È\89ð\8c\88\8dô\82Å\82Í\82È\82¢\r
-// dialog = null;\r
- if (dialog != null){\r
+ // dialog = null;\r
+ if (dialog != null) {\r
dialog.dismiss();\r
dialog = null;\r
}\r
\r
Debug.d(this, "stop end");\r
}\r
- \r
- public void setDialog(boolean b){\r
+\r
+ public void setDialog(boolean b) {\r
isDialog = b;\r
}\r
}\r
--- /dev/null
+package com.yuji.em.utility;\r
+\r
+import android.app.Activity;\r
+import android.app.AlertDialog;\r
+import android.content.DialogInterface;\r
+import android.content.Intent;\r
+import android.os.Bundle;\r
+import android.view.KeyEvent;\r
+import android.view.Window;\r
+import android.view.WindowManager;\r
+\r
+public class BaseActivity extends Activity {\r
+ @Override\r
+ public void onCreate(Bundle savedInstanceState) {\r
+ super.onCreate(savedInstanceState);\r
+ Debug.d(this, Debug.ON_CREATE);\r
+// \r
+// Context context = getApplicationContext();\r
+// try {\r
+// Thread.setDefaultUncaughtExceptionHandler(new TrainDelayedUncaughtExceptionHandler(\r
+// context));\r
+// DatabaseHelper.init(context);\r
+// Initialize.initialize(context);\r
+// } catch (TdException e) {\r
+// terminate(e);\r
+// }\r
+ }\r
+ \r
+ @Override\r
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r
+ super.onActivityResult(requestCode, resultCode, data);\r
+ }\r
+ \r
+ @Override\r
+ protected void onRestart() {\r
+ super.onRestart();\r
+ Debug.d(this, Debug.ON_RESTART);\r
+ }\r
+\r
+ @Override\r
+ protected void onResume() {\r
+ super.onResume();\r
+ Debug.d(this, Debug.ON_RESUME);\r
+ }\r
+\r
+ @Override\r
+ protected void onStart() {\r
+ super.onStart();\r
+ Debug.d(this, Debug.ON_START);\r
+ }\r
+\r
+ @Override\r
+ protected void onPause() {\r
+ super.onPause();\r
+ Debug.d(this, Debug.ON_PAUSE);\r
+ }\r
+\r
+ @Override\r
+ protected void onStop() {\r
+ super.onStop();\r
+ Debug.d(this, Debug.ON_STOP);\r
+ }\r
+\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
+\r
+ @Override\r
+ public boolean dispatchKeyEvent(KeyEvent event) {\r
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {\r
+ switch (event.getKeyCode()) {\r
+ case KeyEvent.KEYCODE_SEARCH:\r
+ return true;\r
+ }\r
+ }\r
+ return super.dispatchKeyEvent(event);\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
+ 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
+ }\r
+\r
+ protected void showDialog(String title, String msg) {\r
+ showDialog(title, msg, false);\r
+ }\r
+\r
+ protected void showDialog(Object target, Throwable t) {\r
+ if (t != null){\r
+ Debug.d(target, null, t);\r
+ }\r
+ // TODO\r
+// showDialog(getString(R.string.system_error_title_msg),\r
+// getString(R.string.system_error_msg));\r
+ }\r
+\r
+ public void terminate(Throwable t){\r
+ if (t != null){\r
+ Debug.d(this, null, t);\r
+ }\r
+ moveTaskToBack(true);\r
+ }\r
+}\r
withContent, withResourcesData, withResourcesRecognition,
withResourcesAlternateData);
} catch (EDAMUserException e) {
+ Debug.d(this, null, e);
} catch (EDAMSystemException e) {
+ Debug.d(this, null, e);
} catch (EDAMNotFoundException e) {
+ Debug.d(this, null, e);
} catch (TException e) {
+ Debug.d(this, null, e);
}
return note;
}
noteList = noteStore.findNotes(token, filter, 0,
100);
} catch (EDAMUserException e) {
+ Debug.d(this, null, e);
} catch (EDAMSystemException e) {
+ Debug.d(this, null, e);
} catch (EDAMNotFoundException e) {
+ Debug.d(this, null, e);
} catch (TException e) {
+ Debug.d(this, null, e);
}
return noteList;
}
public Note updateNoteContext(String guid, String title, String text) {
Note note = getNote(guid);
+ if (note == null){
+ return null;
+ }
String content = note.getContent();
// TODO
String token = getAuthenticationToken();
n = noteStore.updateNote(token, note);
} catch (EDAMUserException e) {
- e.printStackTrace();
+ Debug.d(this, null, e);
} catch (EDAMSystemException e) {
- e.printStackTrace();
+ Debug.d(this, null, e);
} catch (EDAMNotFoundException e) {
e.printStackTrace();
} catch (TException e) {
- e.printStackTrace();
+ Debug.d(this, null, e);
}
return n;
}
// TODO
authenticationToken = null;
noteStore = null; // clear()?
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Debug.d(this, null, e);
} catch (EDAMUserException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Debug.d(this, null, e);
} catch (EDAMSystemException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Debug.d(this, null, e);
} catch (TException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Debug.d(this, null, e);
}
return authenticationToken;