3 import java.util.Calendar;
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.Menu;
11 import android.view.MenuItem;
12 import android.view.View;
13 import android.view.View.OnClickListener;
14 import android.widget.Button;
15 import android.widget.CompoundButton;
16 import android.widget.CompoundButton.OnCheckedChangeListener;
17 import android.widget.EditText;
18 import android.widget.TextView;
19 import android.widget.ToggleButton;
21 import com.yuji.em.common.CommonUtil;
22 import com.yuji.em.common.Constant;
23 import com.yuji.em.data.Note;
24 import com.yuji.em.data.NoteDao;
25 import com.yuji.em.task.UpdateNoteTask;
26 import com.yuji.em.utility.AsyncTaskCommand;
27 import com.yuji.em.utility.EditPrefUtil;
28 import com.yuji.em.utility.EvernoteUtil;
30 public class EverMemoActivity extends Activity {
31 private EditPrefUtil pref = new EditPrefUtil(this);
32 private EvernoteUtil util = EvernoteUtil.getInstance();
33 private TextView titleText = null;
34 private Button sendButton = null;
35 private EditText editText = null;
36 private ToggleButton[] toggleButton = new ToggleButton[Constant.TOGGLE_SIZE];
37 private int selectedIndex = -1;
38 private boolean checkFlag = false;
39 private List<Note> noteList;
40 private boolean isEmpty = true;
43 public void onCreate(Bundle savedInstanceState) {
44 super.onCreate(savedInstanceState);
45 setContentView(R.layout.main);
47 titleText = (TextView) this.findViewById(R.id.mainTitle);
48 sendButton = (Button) this.findViewById(R.id.mainSendButton);
49 editText = (EditText) this.findViewById(R.id.mainEditText);
50 toggleButton[0] = (ToggleButton) this
51 .findViewById(R.id.mainToggleButton1);
52 toggleButton[1] = (ToggleButton) this
53 .findViewById(R.id.mainToggleButton2);
54 toggleButton[2] = (ToggleButton) this
55 .findViewById(R.id.mainToggleButton3);
56 toggleButton[3] = (ToggleButton) this
57 .findViewById(R.id.mainToggleButton4);
58 toggleButton[4] = (ToggleButton) this
59 .findViewById(R.id.mainToggleButton5);
61 sendButton.setOnClickListener(new OnClickListener() {
62 public void onClick(View v) {
67 for (int i = 0; i < Constant.TOGGLE_SIZE; i++) {
69 .setOnCheckedChangeListener(new OnCheckedChangeListener() {
70 public void onCheckedChanged(CompoundButton buttonView,
72 toggleButtonOnCheckedChanged(buttonView, isChecked);
77 String username = CommonUtil.getUsername(this);
78 String password = CommonUtil.getPassword(this);
79 util.setConfig(username, password);
86 protected void onActivityResult(int requestCode, int resultCode, Intent data){
92 // protected void onResume() {
95 // InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
96 // imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
97 // editText.setFocusable(true);
99 // catch (Exception e){
101 // e.printStackTrace();
105 private void toggleButtonOnCheckedChanged(CompoundButton buttonView,
112 buttonView.setChecked(true);
117 int index = getToggleButtonIndex(buttonView);
118 for (int i = 0; i < Constant.TOGGLE_SIZE; i++) {
120 toggleButton[i].setChecked(false);
123 String text = noteList.get(index).getTitle();
124 titleText.setText(text);
126 selectedIndex = index;
127 pref.put(Constant.PREF_NOTE_INDEX, selectedIndex);
133 private int getToggleButtonIndex(CompoundButton button) {
135 for (i = 0; i < Constant.TOGGLE_SIZE; i++) {
136 if (toggleButton[i] == button) {
144 public boolean onCreateOptionsMenu(Menu menu) {
145 boolean ret = super.onCreateOptionsMenu(menu);
146 menu.add(Menu.NONE, Menu.FIRST, Menu.NONE, R.string.mainMenuSetting);
147 // menu.add(Menu.NONE, Menu.FIRST + 1, Menu.NONE,
148 // R.string.mainMenuSetting);
153 public boolean onOptionsItemSelected(MenuItem item) {
156 switch (item.getItemId()) {
158 intent = new Intent(this, (Class<?>) SettingActivity.class);
159 startActivityForResult(intent, 0);
161 // case Menu.FIRST + 1:
162 // intent = new Intent(this, (Class<?>) UserPasswordActivity.class);
163 // startActivity(intent);
168 } catch (Exception e) {
172 return super.onOptionsItemSelected(item);
175 private void updateList(){
176 NoteDao dao = NoteDao.getInstance();
177 noteList = dao.search(this);
179 isEmpty = dao.isEmpty(noteList);
182 private void sendButtonOnClick() {
183 // NoteList noteList = util.getNoteList();
184 // List<Note> list = noteList.getNotes();
185 // Note note = list.get(0);
187 String guid = noteList.get(selectedIndex).getGuid();
189 // http://y-anz-m.blogspot.com/2011/06/android.html
190 // http://www.taosoftware.co.jp/blog/2009/03/android_20.html
191 // String title = "<hr /><h3>%DATE%</h3><hr />";
192 String title = pref.get(Constant.PREF_HEADER,
193 "<hr /><h3>%DATE%</h3><hr />");
194 // TODO header
\89æ
\96Ê
\82Ì
\8f\89\8aú
\92l
\82à
\8dl
\97¶
\82·
\82é
\82±
\82Æ
197 Calendar cal = Calendar.getInstance();
198 long l = cal.getTimeInMillis();
199 String dateStr = DateUtils
200 .formatDateTime(this, l, DateUtils.FORMAT_SHOW_YEAR
201 | DateUtils.FORMAT_SHOW_DATE);
202 String timeStr = DateUtils
203 .formatDateTime(this, l, DateUtils.FORMAT_SHOW_TIME);
205 title = CommonUtil.replaceString(title, "%DATE%", dateStr);
206 title = CommonUtil.replaceString(title, "%TIME%", timeStr);
209 String text = editText.getText().toString();
210 text = CommonUtil.escapeHtml(text);
213 String nl = System.getProperty("line.separator");
214 List<String> lines = CommonUtil.split(text, nl);
215 StringBuffer sb = new StringBuffer();
216 for (String line : lines){
218 if (line.equals("")){
219 line = "<br clear=\'none\'/>";
224 text = sb.toString();
227 //util.updateNoteContext(guid, title, text);
228 UpdateNoteTask task = new UpdateNoteTask(guid, title, text);
229 AsyncTaskCommand command = new AsyncTaskCommand(this, task);
230 command.setDialog(false);
233 editText.setText("");
236 private void setStatus() {
241 //
\96¢
\91I
\91ð
\8e\9e\82Ì
\83`
\83F
\83b
\83N
\82Ì
\83N
\83\8a\83A
243 selectedIndex = pref.getInt(Constant.PREF_NOTE_INDEX, -1);
244 titleText.setText("");
245 if (selectedIndex >= 0){
246 note = noteList.get(selectedIndex);
247 b = !CommonUtil.isNull(note.getGuid());
249 toggleButton[selectedIndex].setChecked(true);
250 titleText.setText(note.getTitle());
254 toggleButton[selectedIndex].setChecked(false);
257 pref.put(Constant.PREF_NOTE_INDEX, -1);
261 for (int i = 0; i < toggleButton.length; i++){
262 note = noteList.get(i);
263 b = !CommonUtil.isNull(note.getGuid());
264 toggleButton[i].setEnabled(b);
265 if (selectedIndex < 0 && b){
267 toggleButton[i].setChecked(true);
268 titleText.setText(note.getTitle());
269 pref.put(Constant.PREF_NOTE_INDEX, selectedIndex);
274 sendButton.setEnabled(!isEmpty);
275 editText.setEnabled(!isEmpty);