3 import android.content.Context;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.view.View;
7 import android.view.View.OnClickListener;
8 import android.widget.AdapterView;
9 import android.widget.AdapterView.OnItemSelectedListener;
10 import android.widget.ArrayAdapter;
11 import android.widget.Button;
12 import android.widget.LinearLayout;
13 import android.widget.Spinner;
14 import android.widget.TextView;
15 import android.widget.Toast;
17 import com.yuji.ec.common.CommonUtil;
18 import com.yuji.ec.common.Constant;
19 import com.yuji.ec.db.NoteDao;
20 import com.yuji.ec.task.NoteUpdateTask;
21 import com.yuji.ec.utility.AsyncTaskCommand;
22 import com.yuji.ec.utility.BaseActivity;
23 import com.yuji.ec.utility.EditPrefUtil;
24 import com.yuji.ec.utility.EvernoteUtil;
26 public class NoteUpdatorActivity extends BaseActivity {
27 private EditPrefUtil pref = new EditPrefUtil(this);
29 private TextView updatorMessage = null;
30 private LinearLayout noteLayout = null;
31 private Spinner noteTypeSpinner = null;
32 private LinearLayout noteTypeLayout = null;
33 private TextView noteTypeView = null;
34 private Button noteTypeButton = null;
35 private Button updateButton = null;
36 private Button closeButton = null;
39 private boolean isEmpty = true;
42 public void onCreate(Bundle savedInstanceState) {
43 super.onCreate(savedInstanceState);
44 setContentView(R.layout.note_updator);
46 updatorMessage = (TextView) this.findViewById(R.id.updatorMessage);
47 noteLayout = (LinearLayout) this.findViewById(R.id.updatorLayout);
48 noteTypeSpinner = (Spinner) this.findViewById(R.id.updatorNoteSpinner);
49 noteTypeLayout = (LinearLayout) this
50 .findViewById(R.id.updatorNoteLayout);
51 noteTypeView = (TextView) this.findViewById(R.id.updatorNoteText);
52 noteTypeButton = (Button) this.findViewById(R.id.updatorNoteButton);
54 updateButton = (Button) this.findViewById(R.id.updatorUpdateButton);
55 closeButton = (Button) this.findViewById(R.id.updatorCloseButton);
57 noteTypeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
58 public void onItemSelected(AdapterView<?> parent, View view,
59 int position, long id) {
60 noteTypeSpinnerItemSelected(parent, view, position, id);
63 public void onNothingSelected(AdapterView<?> view) {
67 noteTypeButton.setOnClickListener(new OnClickListener() {
68 public void onClick(View view) {
69 noteTypeButtonOnClick();
72 updateButton.setOnClickListener(new OnClickListener() {
73 public void onClick(View view) {
74 updateButtonOnClick();
77 closeButton.setOnClickListener(new OnClickListener() {
78 public void onClick(View view) {
83 String msg = getString(R.string.updatorMessage);
84 msg = CommonUtil.replaceString(msg, "\\\\n", "\n");
85 updatorMessage.setText(msg);
87 ArrayAdapter<CharSequence> noteTypeAdapter = ArrayAdapter
88 .createFromResource(this, R.array.note_item_array,
89 android.R.layout.simple_spinner_item);
91 .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
92 noteTypeSpinner.setAdapter(noteTypeAdapter);
96 public void onStart() {
99 int noteItemType = pref.getInt(Constant.PREF_NOTE_ITEM_TYPE_TMP,
100 Constant.NOTE_ITEM_TYPE_ALL);
101 noteTypeSpinner.setSelection(noteItemType);
103 guid = pref.get(Constant.PREF_NOTE_ITEM_GUID_TMP);
105 String title = pref.get(Constant.PREF_NOTE_ITEM_TEXT);
106 noteTypeView.setText(title);
110 public void onPause() {
111 int noteItemType = noteTypeSpinner.getSelectedItemPosition();
112 pref.put(Constant.PREF_NOTE_ITEM_TYPE_TMP, noteItemType);
120 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
121 if (resultCode == RESULT_OK) {
122 Bundle ex = data.getExtras();
123 String guid = ex.getString(Constant.EXTRA_GUID);
124 String title = ex.getString(Constant.EXTRA_TITLE);
125 int noteItemType = noteTypeSpinner.getSelectedItemPosition();
128 pref.put(Constant.PREF_NOTE_ITEM_GUID_TMP, guid);
129 pref.put(Constant.PREF_NOTE_ITEM_TEXT, title);
130 pref.put(Constant.PREF_NOTE_ITEM_GUID_TYPE_TMP, noteItemType);
133 noteTypeView.setText(title);
139 private void noteTypeSpinnerItemSelected(AdapterView<?> parent, View view,
140 int position, long id) {
144 private void noteTypeButtonOnClick() {
145 Intent intent = new Intent(this, (Class<?>) NoteTypeListActivity.class);
146 startActivityForResult(intent, 0);
149 private void updateButtonOnClick() {
150 int noteItemType = noteTypeSpinner.getSelectedItemPosition();
152 NoteUpdateTask task = new NoteUpdateTask(this, noteItemType, guid);
153 AsyncTaskCommand command = new AsyncTaskCommand(this, task);
154 command.setTitle(getString(R.string.updatorNoteDialogTitle));
155 command.setButtonTitle(getString(R.string.cancelButton));
156 command.setCancelable(false);
160 private void closeButtonOnClick() {
164 public void done(EvernoteUtil.Error errorCode) {
165 if (errorCode != null && !errorCode.equals(EvernoteUtil.Error.NONE)) {
166 EvernoteUtil util = EvernoteUtil.getInstance();
167 Toast.makeText(this, util.getErrorMessage(this, errorCode),
168 Toast.LENGTH_LONG).show();
170 closeButtonOnClick();
174 int noteItemType = noteTypeSpinner.getSelectedItemPosition();
175 pref.put(Constant.PREF_NOTE_ITEM_TYPE, noteItemType);
176 pref.copy(Constant.PREF_NOTE_ITEM_GUID_TMP,
177 Constant.PREF_NOTE_ITEM_GUID);
178 if (noteItemType == Constant.NOTE_ITEM_TYPE_ALL){
179 pref.remove(Constant.PREF_NOTE_ITEM_GUID);
180 pref.remove(Constant.PREF_NOTE_ITEM_TEXT);
184 closeButtonOnClick();
187 private void setStatus() {
189 *
\81\9b\91Î
\8fÛ type guid guidType(guid
\82Ì
\90Ý
\92è
\83^
\83C
\83~
\83\93\83O
\82Å
\90Ý
\92è
\81A
\8f\89\8aú
\92lnull)
191 *
\81\9b\8dX
\90V
\83{
\83^
\83\93\82Ì
\8a\88\90«
\83\8b\81[
\83\8b(
\8a\88\90«
\82Ì
\8fð
\8c\8f) type1=type2 guid1<>guid2 guidType=type2
193 * type1<>type2 guidType=type2
195 int srcNoteItemType = pref.getInt(Constant.PREF_NOTE_ITEM_TYPE,
196 Constant.NOTE_ITEM_TYPE_ALL);
197 String srcGuid = pref.get(Constant.PREF_NOTE_ITEM_GUID);
199 int noteItemType = noteTypeSpinner.getSelectedItemPosition();
200 int guidType = pref.getInt(Constant.PREF_NOTE_ITEM_GUID_TYPE_TMP, -1);
202 boolean enabled = false;
203 if (noteItemType == Constant.NOTE_ITEM_TYPE_ALL) {
205 // } else if (srcNoteItemType == noteItemType) {
206 // if (!CommonUtil.isNull(guid) && !guid.equals(srcGuid)) {
207 // if (guidType >= 0 && guidType == noteItemType) {
212 // if (guidType >= 0 && guidType == noteItemType) {
217 else if (guidType >= 0 && guidType == noteItemType) {
221 updateButton.setEnabled(enabled);
223 .setVisibility((noteItemType == Constant.NOTE_ITEM_TYPE_ALL) ? View.GONE
226 NoteDao dao = (NoteDao) NoteDao.getInstance();
227 isEmpty = dao.isEmpty();
229 noteLayout.setVisibility(View.VISIBLE);
231 noteLayout.setVisibility(View.GONE);
235 public static void init(Context context) {
236 EditPrefUtil pref = new EditPrefUtil(context);
238 pref.copy(Constant.PREF_NOTE_ITEM_TYPE,
239 Constant.PREF_NOTE_ITEM_TYPE_TMP);
240 pref.copy(Constant.PREF_NOTE_ITEM_GUID,
241 Constant.PREF_NOTE_ITEM_GUID_TMP);
242 pref.copy(Constant.PREF_NOTE_ITEM_TYPE,
243 Constant.PREF_NOTE_ITEM_GUID_TYPE_TMP);