3 import java.util.ArrayList;
6 import android.app.Activity;
7 import android.content.Intent;
8 import android.os.Bundle;
9 import android.text.format.DateUtils;
10 import android.view.View;
11 import android.view.View.OnClickListener;
12 import android.widget.AdapterView;
13 import android.widget.AdapterView.OnItemClickListener;
14 import android.widget.Button;
15 import android.widget.ListView;
16 import android.widget.TextView;
18 import com.evernote.edam.notestore.NoteList;
19 import com.yuji.em.common.Constant;
20 import com.yuji.em.data.Note;
21 import com.yuji.em.data.NoteDao;
22 import com.yuji.em.task.NoteListTask;
23 import com.yuji.em.utility.AsyncTaskCommand;
25 public class NoteListActivity extends Activity {
26 private ListView listView = null;
27 private Button closeButton = null;
28 private int index = -1;
31 public void onCreate(Bundle savedInstanceState) {
32 super.onCreate(savedInstanceState);
33 setContentView(R.layout.note_list);
36 listView = (ListView) this.findViewById(R.id.noteListView);
37 closeButton = (Button) this.findViewById(R.id.noteListCloseButton);
39 listView.setOnItemClickListener(new OnItemClickListener() {
40 public void onItemClick(AdapterView<?> parent, View view,
41 int position, long id) {
42 listViewOnItemClickListener(parent, view, position, id);
46 closeButton.setOnClickListener(new OnClickListener(){
47 public void onClick(View v) {
51 Bundle extras = getIntent().getExtras();
52 index = extras.getInt(Constant.EXTRA_INDEX);
54 NoteListTask task = new NoteListTask(this);
55 AsyncTaskCommand command = new AsyncTaskCommand(this, task);
57 } catch (Exception e) {
63 private void closeButtonOnClick(){
64 Intent intent = new Intent();
65 setResult(RESULT_CANCELED, intent);
69 private void listViewOnItemClickListener(AdapterView<?> parent, View view,
70 int position, long id) {
71 ListView listView = (ListView) parent;
72 NoteListItem item = (NoteListItem) listView.getItemAtPosition(position);
74 Note note = item.getNote();
79 NoteDao dao = NoteDao.getInstance();
80 dao.update(this, note, index);
82 Intent intent = new Intent();
83 setResult(RESULT_OK, intent);
87 // private void createList() {
88 // NoteList noteList = util.getNoteList();
89 // List<NoteListItem> list = new ArrayList<NoteListItem>();
91 // List<Note> notes = noteList.getNotes();
92 // String oldTitle = "";
94 // for (Note note : notes) {
95 // // long l = note.getUpdated();
96 // long l = note.getCreated();
97 // String title = DateUtils
98 // .formatDateTime(this, l, DateUtils.FORMAT_SHOW_YEAR
99 // | DateUtils.FORMAT_SHOW_DATE/*
101 // * FORMAT_SHOW_TIME
103 // if (!title.equals(oldTitle)) {
104 // item = new NoteListItem(title, null);
109 // item = new NoteListItem(null, note);
113 // NoteListViewArrayAdapter adapter = new NoteListViewArrayAdapter(this,
114 // R.layout.simple_list_item_1, list);
115 // listView.setAdapter(adapter);
118 public void done(NoteList noteList) {
119 if (noteList == null){
123 List<NoteListItem> list = new ArrayList<NoteListItem>();
126 List<com.evernote.edam.type.Note> notes = noteList.getNotes();
127 String oldTitle = "";
129 for (com.evernote.edam.type.Note note : notes) {
130 long l = note.getUpdated();
131 //long l = note.getCreated(); // TODO
\83\
\81[
\83g
\8f\87\82Í
\81A
\8dX
\90V
\93ú?
132 String title = DateUtils
133 .formatDateTime(this, l, DateUtils.FORMAT_SHOW_YEAR
134 | DateUtils.FORMAT_SHOW_DATE);
135 if (!title.equals(oldTitle)) {
136 item = new NoteListItem(title, null);
141 Note n = new Note(note.getGuid(), note.getTitle());
142 item = new NoteListItem(null, n);
146 NoteListViewArrayAdapter adapter = new NoteListViewArrayAdapter(this,
147 R.layout.simple_list_item_1, list);
148 listView.setAdapter(adapter);