3 import java.util.ArrayList;
6 import android.content.Intent;
7 import android.os.Bundle;
8 import android.text.format.DateUtils;
9 import android.view.View;
10 import android.view.View.OnClickListener;
11 import android.widget.AdapterView;
12 import android.widget.AdapterView.OnItemClickListener;
13 import android.widget.Button;
14 import android.widget.ListView;
16 import com.evernote.edam.notestore.NoteList;
17 import com.yuji.em.common.Constant;
18 import com.yuji.em.data.Note;
19 import com.yuji.em.data.NoteDao;
20 import com.yuji.em.task.NoteListTask;
21 import com.yuji.em.utility.AsyncTaskCommand;
22 import com.yuji.em.utility.BaseActivity;
24 public class NoteListActivity extends BaseActivity {
25 private static List<NoteListItem> noteList = null;
27 private ListView listView = null;
28 private Button closeButton = null;
29 private int index = -1;
32 public void onCreate(Bundle savedInstanceState) {
33 super.onCreate(savedInstanceState);
34 setContentView(R.layout.note_list);
37 listView = (ListView) this.findViewById(R.id.noteListView);
38 closeButton = (Button) this.findViewById(R.id.noteListCloseButton);
40 listView.setOnItemClickListener(new OnItemClickListener() {
41 public void onItemClick(AdapterView<?> parent, View view,
42 int position, long id) {
43 listViewOnItemClickListener(parent, view, position, id);
47 closeButton.setOnClickListener(new OnClickListener() {
48 public void onClick(View v) {
53 Bundle extras = getIntent().getExtras();
54 index = extras.getInt(Constant.EXTRA_INDEX);
56 if (noteList != null) {
57 setNoteList(noteList);
59 NoteListTask task = new NoteListTask(this);
60 AsyncTaskCommand command = new AsyncTaskCommand(this, task);
61 command.setTitle(getString(R.string.noteListGetting));
62 command.setButtonTitle(getString(R.string.cancelButton));
65 } catch (Exception e) {
71 private void closeButtonOnClick() {
72 Intent intent = new Intent();
73 setResult(RESULT_CANCELED, intent);
77 private void listViewOnItemClickListener(AdapterView<?> parent, View view,
78 int position, long id) {
79 ListView listView = (ListView) parent;
80 NoteListItem item = (NoteListItem) listView.getItemAtPosition(position);
82 Note note = item.getNote();
87 NoteDao dao = NoteDao.getInstance();
88 int n = dao.search(this, note);
91 Intent intent = new Intent();
92 setResult(RESULT_CANCELED, intent);
96 dao.update(this, note, index);
98 Intent intent = new Intent();
99 setResult(RESULT_OK, intent);
103 public void done(NoteList nList) {
105 //
\83L
\83\83\83\93\83Z
\83\8b\83{
\83^
\83\93\89\9f\89º
\8e\9e
106 closeButtonOnClick();
110 List<NoteListItem> list = getNoteList(nList);
112 closeButtonOnClick();
119 private void setNoteList(List<NoteListItem> list) {
120 NoteListViewArrayAdapter adapter = new NoteListViewArrayAdapter(this,
121 R.layout.simple_list_item_1, list);
122 listView.setAdapter(adapter);
125 private List<NoteListItem> getNoteList(NoteList nList) {
126 List<NoteListItem> list = new ArrayList<NoteListItem>();
129 List<com.evernote.edam.type.Note> notes = nList.getNotes();
134 String oldTitle = "";
136 for (com.evernote.edam.type.Note note : notes) {
137 long l = note.getUpdated();
138 // long l = note.getCreated(); // TODO
\83\
\81[
\83g
\8f\87\82Í
\81A
\8dX
\90V
\93ú?
139 String title = DateUtils.formatDateTime(this, l,
140 DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE);
141 if (!title.equals(oldTitle)) {
142 item = new NoteListItem(title, null);
147 Note n = new Note(note.getGuid(), note.getTitle());
148 item = new NoteListItem(null, n);
154 public static void init(){