OSDN Git Service

A29272
[everfolder/source.git] / source / workspace / EverFolder / src / com / yuji / ef / EverFolderActivity.java
1 package com.yuji.ef;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7 import android.content.BroadcastReceiver;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.content.IntentFilter;
11 import android.content.res.Resources;
12 import android.database.sqlite.SQLiteDatabase;
13 import android.graphics.Bitmap;
14 import android.graphics.BitmapFactory;
15 import android.graphics.PixelFormat;
16 import android.os.Bundle;
17 import android.text.Editable;
18 import android.text.TextWatcher;
19 import android.view.Gravity;
20 import android.view.Menu;
21 import android.view.MenuItem;
22 import android.view.View;
23 import android.view.View.OnClickListener;
24 import android.view.WindowManager;
25 import android.widget.Button;
26 import android.widget.EditText;
27 import android.widget.LinearLayout;
28 import android.widget.TextView;
29
30 import com.yuji.ef.common.CommonUtil;
31 import com.yuji.ef.common.Constant;
32 import com.yuji.ef.dao.DatabaseHelper;
33 import com.yuji.ef.dao.DirNode;
34 import com.yuji.ef.dao.FileNode;
35 import com.yuji.ef.dao.LockDao;
36 import com.yuji.ef.dao.Node;
37 import com.yuji.ef.dao.Node.Status;
38 import com.yuji.ef.dao.NodeCacheDao;
39 import com.yuji.ef.dao.NodeComparator;
40 import com.yuji.ef.dao.NodeDao;
41 import com.yuji.ef.dao.NodeDaoImpl;
42 import com.yuji.ef.dao.RootNode;
43 import com.yuji.ef.utility.BaseActivity;
44 import com.yuji.ef.utility.BitmapCacheFactory;
45 import com.yuji.ef.utility.EvernoteIntentUtil;
46 import com.yuji.ef.utility.FolderUtil;
47 import com.yuji.ef.utility.ScaleUtil;
48
49 public class EverFolderActivity extends BaseActivity {
50         private enum ScreenStatus {
51                 Normal, AddNode, DeleteNode, RenameNode
52         };
53
54         private LinearLayout msgLayout;
55         private LinearLayout msgButtonLayout;
56         private Button msgOkButton;
57         private Button msgCancelButton;
58         private EditText msgEditText;
59
60         private IconFrameLayout layout;
61         private TextView confirmMsg;
62         private IconScrollView scrollView;
63         private LinearLayout buttonLayout;
64         private Button leftButton;
65         private Button rightButton;
66         // private Button addButton;
67         // private Button deleteButton;
68
69         private ScreenStatus status;
70         private NodeComparator nodeComparator = new NodeComparator();
71         private BitmapCacheFactory bitmapFactory = BitmapCacheFactory.getInstance();
72         private Node top = null;
73         private int indent = 0;
74         private int bmpPaddingLeft;
75         private int bmpWidth;
76         private int viewY;
77         private boolean lock = false;
78         private boolean isInit = true;
79
80         private BroadcastReceiver receiver = new BroadcastReceiver() {
81                 @Override
82                 public void onReceive(Context context, Intent intent) {
83                         String action = intent.getAction();
84
85                         if (action.compareTo(Constant.ACTION_UPDATE) == 0) {
86                                 LockDao lockDao = (LockDao) LockDao.getInstance();
87                                 lock = lockDao.lock(EverFolderActivity.this,
88                                                 Constant.LOCK_UPDATE_NOTE);
89                                 if (lock) {
90                                         updateList();
91                                 }
92                                 setStatus();
93                         }
94                 }
95         };
96
97         @Override
98         public void onCreate(Bundle savedInstanceState) {
99                 super.onCreate(savedInstanceState);
100                 setContentView(R.layout.main);
101
102                 try {
103                         IntentFilter intentFilter = new IntentFilter();
104                         intentFilter.addAction(Constant.ACTION_UPDATE);
105                         registerReceiver(receiver, intentFilter);
106
107                         scrollView = (IconScrollView) findViewById(R.id.scrollView);
108                         layout = (IconFrameLayout) findViewById(R.id.frameLayout);
109                         layout.setActivity(this);
110                         layout.setScrollView(scrollView);
111
112                         buttonLayout = (LinearLayout) findViewById(R.id.mainButtonLayout);
113                         leftButton = (Button) findViewById(R.id.leftButton);
114                         rightButton = (Button) findViewById(R.id.rightButton);
115                         // addButton = (Button) findViewById(R.id.addButton);
116                         // deleteButton = (Button) findViewById(R.id.deleteButton);
117
118                         msgLayout = (LinearLayout) findViewById(R.id.mainMsgLayout);
119                         confirmMsg = (TextView) findViewById(R.id.mainConfirmMsg);
120                         msgEditText = (EditText) findViewById(R.id.mainMsgEditText);
121                         msgButtonLayout = (LinearLayout) findViewById(R.id.mainMsgButtonLayout);
122                         msgOkButton = (Button) findViewById(R.id.mainMsgOkButton);
123                         msgCancelButton = (Button) findViewById(R.id.mainMsgCancelButton);
124
125                         leftButton.setOnClickListener(new OnClickListener() {
126                                 @Override
127                                 public void onClick(View v) {
128                                         leftButtonOnClick();
129                                 }
130                         });
131                         rightButton.setOnClickListener(new OnClickListener() {
132                                 @Override
133                                 public void onClick(View v) {
134                                         rightButtonOnClick();
135                                 }
136                         });
137                         // addButton.setOnClickListener(new OnClickListener() {
138                         // @Override
139                         // public void onClick(View v) {
140                         // addButtonOnClick();
141                         // }
142                         // });
143                         // deleteButton.setOnClickListener(new OnClickListener() {
144                         // @Override
145                         // public void onClick(View v) {
146                         // deleteButtonOnClick();
147                         // }
148                         // });
149
150                         msgEditText.addTextChangedListener(new TextWatcher() {
151                                 public void afterTextChanged(Editable s) {
152                                         String text = s.toString();
153                                         msgOkButton.setEnabled(text.length() > 0);
154                                 }
155
156                                 public void beforeTextChanged(CharSequence s, int start,
157                                                 int count, int after) {
158
159                                 }
160
161                                 public void onTextChanged(CharSequence s, int start,
162                                                 int before, int count) {
163
164                                 }
165                         });
166
167                         msgOkButton.setOnClickListener(new OnClickListener() {
168                                 @Override
169                                 public void onClick(View v) {
170                                         msgOkButtonOnClick();
171                                 }
172                         });
173                         msgCancelButton.setOnClickListener(new OnClickListener() {
174                                 @Override
175                                 public void onClick(View v) {
176                                         msgCancelOnClick();
177                                 }
178                         });
179
180                         ScaleUtil scaleUtil = ScaleUtil.getInstance();
181                         scaleUtil.init(this);
182
183                         bitmapFactory.init(this);
184                         Node node = new DirNode(null, null);
185                         Bitmap bmp = null;
186                         bmp = bitmapFactory.get(node.getStatusIconId());
187                         bmpPaddingLeft = bmp.getWidth();
188                         bmp = bitmapFactory.get(node.getIconId());
189                         bmpWidth = bmp.getWidth();
190
191                         float fSize = 48 * (1 / 2.0f);
192                         leftButton.setTextSize(fSize);
193                         rightButton.setTextSize(fSize);
194                 } catch (Exception e) {
195                         // TODO
196                         e.printStackTrace();
197                 }
198         }
199
200         @Override
201         public boolean onCreateOptionsMenu(Menu menu) {
202                 boolean ret = super.onCreateOptionsMenu(menu);
203                 int index = 0;
204
205                 menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "カット");
206                 menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "ペースト");
207                 menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "追加");
208                 menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "削除");
209                 menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "リネーム");
210                 menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "設定");
211                 return ret;
212         }
213
214         @Override
215         public boolean onMenuOpened(int featureId, Menu menu) {
216                 boolean ret = super.onMenuOpened(featureId, menu);
217
218                 MenuItem item;
219
220                 boolean cutButtonFlag = false;
221                 boolean pastButtonFlag = false;
222                 boolean addButtonFlag = false;
223                 boolean deleteButtonFlag = false;
224                 boolean renameButtonFlag = false;
225                 boolean confButtonFlag = true;
226
227                 if (status == ScreenStatus.Normal) {
228                         LabelIconView target = layout.getSelectedTarget();
229                         NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
230                         long id = -1;
231                         Node node = null;
232                         if (target != null) {
233                                 id = target.getNodeId();
234                                 node = dao.searchById(id);
235                         }
236
237                         if (isDirNode(target, node, false) || isFileNode(node)) {
238                                 cutButtonFlag = true;
239                         }
240                         if (isDirNode(target, node, true) && isCut()) {
241                                 pastButtonFlag = true;
242                         }
243                         if (isDirNode(target, node, true)) {
244                                 addButtonFlag = true;
245                         }
246                         if (isDirNode(target, node, false) && !isNoteBook(node)
247                                         && CommonUtil.isNull(node.getChildrenString())) {
248                                 deleteButtonFlag = true;
249                         }
250                         if (isDirNode(target, node, false) && !isNoteBook(node)) {
251                                 renameButtonFlag = true;
252                         }
253                 }
254
255                 int index = 0;
256                 item = menu.getItem(index++);
257                 item.setVisible(cutButtonFlag);
258                 item = menu.getItem(index++);
259                 item.setVisible(pastButtonFlag);
260                 item = menu.getItem(index++);
261                 item.setVisible(addButtonFlag);
262                 item = menu.getItem(index++);
263                 item.setVisible(deleteButtonFlag);
264                 item = menu.getItem(index++);
265                 item.setVisible(renameButtonFlag);
266                 item = menu.getItem(index++);
267                 item.setVisible(confButtonFlag);
268
269                 return ret;
270         }
271
272         private boolean isFileNode(Node node) {
273                 if (node == null || !(node instanceof FileNode)) {
274                         return false;
275                 }
276                 return true;
277         }
278
279         private boolean isDirNode(LabelIconView target, Node node,
280                         boolean containRoot) {
281                 if (target == null) {
282                         return false;
283                 }
284                 if (node == null) {
285                         return false;
286                 }
287                 if (!containRoot && (node instanceof RootNode)) {
288                         return false;
289                 }
290                 if (!(node instanceof DirNode)) {
291                         return false;
292                 }
293                 return true;
294         }
295
296         private boolean isNoteBook(Node node) {
297                 if (node == null) {
298                         return false;
299                 }
300                 if (CommonUtil.isNull(node.getGuid())) {
301                         return false;
302                 }
303                 return true;
304         }
305
306         private boolean isCut() {
307                 LabelIconView srcTarget = layout.getCutTarget();
308                 if (srcTarget == null) {
309                         return false;
310                 }
311                 return true;
312         }
313
314         @Override
315         public boolean onOptionsItemSelected(MenuItem item) {
316                 Intent intent;
317                 try {
318                         switch (item.getItemId()) {
319                         case Menu.FIRST + 0:
320                                 selectMenuCut();
321                                 break;
322                         case Menu.FIRST + 1:
323                                 selectMenuPast();
324                                 break;
325                         case Menu.FIRST + 2:
326                                 selectMenuAdd();
327                                 break;
328                         case Menu.FIRST + 3:
329                                 selectMenuDelete();
330                                 break;
331                         case Menu.FIRST + 4:
332                                 selectMenuRename();
333                                 break;
334                         case Menu.FIRST + 5:
335                                 // dummy();
336                                 // dummy2();
337                                 intent = new Intent(this, (Class<?>) SettingActivity.class);
338                                 startActivityForResult(intent, 0);
339                                 break;
340                         default:
341                                 break;
342                         }
343                 } catch (Exception e) {
344                         terminate(e);
345                 }
346                 return super.onOptionsItemSelected(item);
347         }
348
349         private void dummy() {
350                 NodeDaoImpl dao = (NodeDaoImpl) NodeCacheDao.getInstance();
351                 List<Node> list = dao.search();
352                 for (Node node : list) {
353                         System.out.println(node.toString());
354                 }
355         }
356
357         private void dummy2() {
358                 LockDao dao = (LockDao) LockDao.getInstance();
359                 boolean b;
360
361                 try {
362                         b = dao.lock(this, "key");
363                         b = dao.lock(this, "key");
364                         dao.unlock(new Object(), "key");
365                         b = dao.lock(this, "key");
366                         dao.unlock(this, "key");
367                         b = dao.lock(this, "key");
368                         b = dao.lock(this, "key");
369                         b = dao.lock(this, "key");
370
371                 } catch (Exception e) {
372                         e.printStackTrace();
373                 }
374
375         }
376
377         private void selectMenuAdd() {
378                 setStatus(ScreenStatus.AddNode);
379         }
380
381         private void selectMenuDelete() {
382                 setStatus(ScreenStatus.DeleteNode);
383         }
384
385         private void selectMenuRename() {
386                 LabelIconView target = layout.getSelectedTarget();
387                 if (target == null) {
388                         return;
389                 }
390
391                 long id = target.getNodeId();
392                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
393                 Node node = dao.searchById(id);
394                 if (node != null) {
395                         String text = node.getName();
396                         msgEditText.setText(text);
397                         setStatus(ScreenStatus.RenameNode);
398                 }
399         }
400
401         private void selectMenuCut() {
402                 LabelIconView target = layout.getSelectedTarget();
403                 if (target == null) {
404                         return;
405                 }
406
407                 layout.setCutTarget(target);
408                 layout.refresh();
409         }
410
411         private void selectMenuPast() {
412                 LabelIconView srcTarget = layout.getCutTarget();
413                 if (srcTarget == null) {
414                         return;
415                 }
416
417                 LabelIconView dstTarget = layout.getSelectedTarget();
418                 if (dstTarget == null) {
419                         return;
420                 }
421
422                 layout.setCutTarget(null);
423
424                 long srcId = srcTarget.getNodeId();
425                 long dstId = dstTarget.getNodeId();
426                 execute(srcId, dstId);
427         }
428
429         private void updateList() {
430                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
431                 top = dao.searchRoot();
432                 if (top == null) {
433                         // TODO
434                 }
435                 layout.removeAllViews();
436                 updateList(top);
437                 layout.refresh();
438         }
439
440         private void updateList(Node parent) {
441                 viewY = 10;
442
443                 // List<Node> list = parent.getChildren();
444                 // for (Node node : list){
445                 // updateList(node, x);
446                 // }
447                 updateList(parent, 0);
448                 layout.setMinimumHeight(viewY);
449                 layout.invalidate();
450         }
451
452         private void updateList(Node node, int depth) {
453                 int N = (int) (bmpWidth * 0.6);
454                 int M = (int) (bmpWidth * 1.2);
455                 int x = N * (depth - indent);
456
457                 if (depth - indent >= 0
458                                 && !(depth - indent == 0 && node instanceof FileNode)) {
459                         LabelIconView view = new LabelIconView(this);
460                         node.setView(view);
461
462                         Bitmap bmp1 = null;
463                         int id = node.getStatusIconId();
464                         if (id >= 0) {
465                                 // DirNode
466                                 bmp1 = bitmapFactory.get(node.getStatusIconId());
467                         } else {
468                                 // FileNode
469                                 x += bmpPaddingLeft;
470                         }
471                         Bitmap bmp2 = bitmapFactory.get(node.getIconId());
472                         createIconImageView(view, bmp1, bmp2, node.getName(), x, viewY);
473                         // LabelIconView s = view.getStatusImageView();
474                         // if (s != null) {
475                         // s.setNodeId(node.getId());
476                         // }
477                         view.setNodeId(node.getId());
478                 }
479                 viewY += M;
480
481                 if (node.getStatus() != Node.Status.OPEN) {
482                         return;
483                 }
484                 List<Long> idList = node.getChildren();
485                 if (idList == null) {
486                         return;
487                 }
488
489                 List<Node> list = new ArrayList<Node>();
490                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
491                 for (Long id : idList) {
492                         Node n = dao.searchById(id);
493                         list.add(n);
494                 }
495                 Collections.sort(list, nodeComparator);
496                 for (Node n : list) {
497                         updateList(n, depth + 1);
498                 }
499         }
500
501         private void createIconImageView(LabelIconView v, Bitmap bmp1, Bitmap bmp2,
502                         String text, int x, int y) {
503                 v.init(x, y, bmp1, bmp2, text);
504
505                 android.view.WindowManager.LayoutParams params = new WindowManager.LayoutParams();
506                 params.gravity = Gravity.TOP | Gravity.LEFT;
507                 params.height = WindowManager.LayoutParams.WRAP_CONTENT;
508                 params.width = WindowManager.LayoutParams.WRAP_CONTENT;
509                 params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
510                                 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
511                                 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
512                                 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
513                 params.format = PixelFormat.TRANSLUCENT;
514                 params.windowAnimations = 0;
515                 params.x = x;
516                 params.y = y;
517                 v.setLayoutParams(params);
518
519                 // LabelIconView siv = v.getStatusImageView();
520                 // if (siv != null) {
521                 // layout.addView(siv, false);
522                 // }
523
524                 layout.addView(v);
525                 v.layout(x, y, x + v.getWidth(), y + v.getHeight());
526         }
527
528         @Override
529         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
530                 // updateList();
531                 // setStatus();
532                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
533                 if (dao.isEmpty()) {
534                         finish();
535                 }
536                 isInit = true;
537         }
538
539         @Override
540         protected void onStart() {
541                 super.onStart();
542         }
543
544         @Override
545         protected void onResume() {
546                 super.onResume();
547
548                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
549                 if (dao.isEmpty()) {
550                         if (isInit) {
551                                 Intent intent = new Intent(this,
552                                                 (Class<?>) SettingActivity.class);
553                                 startActivityForResult(intent, 0);
554
555                                 isInit = false;
556                         } else {
557                                 finish();
558                                 isInit = true;
559                         }
560                 }
561                 
562                 LockDao lockDao = (LockDao) LockDao.getInstance();
563                 lock = lockDao.lock(this, Constant.LOCK_UPDATE_NOTE);
564
565                 if (isInit) {
566                         status = ScreenStatus.Normal;
567
568                         if (lock) {
569                                 updateList();
570                         } else {
571                                 layout.removeAllViews();
572                         }
573                         setStatus();
574                         isInit = false;
575                 } else {
576                         setStatus();
577                 }
578         }
579
580         @Override
581         protected void onPause() {
582                 // ロック未取得でも解除する(ゴミ掃除)
583                 LockDao lockDao = (LockDao) LockDao.getInstance();
584                 lockDao.unlock(this, Constant.LOCK_UPDATE_NOTE);
585                 lock = false;
586
587                 super.onPause();
588         }
589
590         private void leftButtonOnClick() {
591                 moveButtonOnClick(-1);
592                 setStatus();
593         }
594
595         private void rightButtonOnClick() {
596                 moveButtonOnClick(1);
597                 setStatus();
598         }
599
600         private void moveButtonOnClick(int dx) {
601                 int mx = 0;
602
603                 if (dx < 0) {
604                         if (indent > 0) {
605                                 mx = -1;
606                         }
607                 } else {
608                         mx = 1;
609                 }
610                 if (mx != 0) {
611                         indent += mx;
612                         removeAllNodeView();
613                         updateList();
614                 }
615         }
616
617         // private void addButtonOnClick() {
618         // setStatus(ScreenStatus.AddNode);
619         // }
620         //
621         // private void deleteButtonOnClick() {
622         // FolderUtil util = FolderUtil.getInstance();
623         // LabelIconView target = layout.getSelectedTarget();
624         // long id = target.getNodeId();
625         // NodeDao dao = (NodeDao) NodeDao.getInstance();
626         // Node node = dao.searchById(id);
627         // if (node != null) {
628         // util.deleteNode(node);
629         // // TODO 三角マークも消さないといけないのでは
630         // layout.removeView(target);
631         // updateList();
632         // setStatus();
633         // }
634         // }
635
636         private void msgOkButtonOnClick() {
637                 FolderUtil util = FolderUtil.getInstance();
638                 LabelIconView target = layout.getSelectedTarget();
639                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
640
641                 if (status == ScreenStatus.AddNode) {
642                         long id = target.getNodeId();
643                         Node parent = dao.searchById(id);
644                         if (parent != null) {
645                                 String text = msgEditText.getText().toString();
646                                 DirNode node = new DirNode(text, null);
647                                 util.addDirNode(parent, node);
648                         }
649                         layout.setCutTarget(null, false);
650                 }
651                 else if (status == ScreenStatus.DeleteNode) {
652                         long id = target.getNodeId();
653                         Node node = dao.searchById(id);
654                         if (node != null) {
655                                 util.deleteNode(node);
656                                 layout.removeView(target);
657                         }
658                         layout.setCutTarget(null, false);
659                 } else if (status == ScreenStatus.RenameNode) {
660                         long id = target.getNodeId();
661                         Node node = dao.searchById(id);
662                         if (node != null) {
663                                 String text = msgEditText.getText().toString();
664
665                                 dao.updateName(node, text);
666                         }
667                         layout.setCutTarget(null, false);
668                 }
669                 layout.clearTarget();
670                 updateList();
671                 setStatus(ScreenStatus.Normal);
672         }
673
674         private void msgCancelOnClick() {
675                 setStatus(ScreenStatus.Normal);
676         }
677
678         public void execute(long srcId, long dstId) {
679                 try {
680                         removeAllNodeView();
681
682                         NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
683
684                         if (srcId < 0) {
685                                 // TODO
686                         }
687                         if (dstId < 0) {
688                                 // TODO
689                         }
690
691                         Node src = dao.searchById(srcId);
692                         Node dst = null;
693                         if (srcId == dstId) {
694                                 dst = src;
695                         } else {
696                                 dst = dao.searchById(dstId);
697                         }
698
699                         if (dstId == src.getParent()) {
700                                 // 同じ場所に移動
701                                 return;
702                         }
703                         if (!isFileNode(src) && !isMovable(srcId, dstId)) {
704                                 // 再帰的な移動
705                                 return;
706                         }
707
708                         Node sp = dao.searchById(src.getParent());
709                         if (sp == null) {
710                                 // TODO
711                         }
712                         Node dp = null;
713                         if (src.getParent() == dst.getParent()) {
714                                 dp = sp;
715                         } else {
716                                 dp = dao.searchById(dst.getParent());
717                         }
718                         if (dp == null) {
719                                 // TODO
720                         }
721
722                         // TODO DBへのアクセス
723                         // sp.remove(src.getId());
724                         SQLiteDatabase db = DatabaseHelper.getInstance()
725                                         .getSQLiteDatabase();
726                         db.beginTransaction();
727                         try {
728                                 dao.removeChildrenIdNT(sp, src.getId());
729                                 if (dst instanceof DirNode) {
730                                         // dst.add(src.getId());
731                                         dao.updateParentNT(src, dst.getId());
732                                         dao.addChildrenIdNT(dst, src.getId());
733                                 } else if (dst instanceof FileNode) {
734                                         // dp.add(src.getId());
735                                         dao.updateParentNT(src, dp.getId());
736                                         dao.addChildrenIdNT(dp, src.getId());
737                                 }
738
739                                 db.setTransactionSuccessful();
740                         } finally {
741                                 db.endTransaction();
742                         }
743                 } finally {
744                         updateList();
745                 }
746         }
747
748         private boolean isMovable(long srcId, long dstId) {
749                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
750
751                 while (dstId >= 0) {
752                         if (srcId == dstId) {
753                                 return false;
754                         }
755                         Node node = dao.searchById(dstId);
756                         if (node == null) {
757                                 // TODO エラー
758                                 return false;
759                         }
760                         if (!(node instanceof DirNode)) {
761                                 return true;
762                         }
763                         dstId = node.getParent();
764                 }
765                 return true;
766         }
767
768         public void execute(long id) {
769                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
770
771                 Node node = dao.searchById(id);
772                 if (node == null) {
773                         // TODO
774                 }
775                 node.toggleStatus();
776                 Status status = node.getStatus();
777
778                 dao.updateStatus(node, status);
779
780                 // removeAllNodeView();
781                 updateList();
782         }
783
784         public void executeView(long id) {
785                 NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
786
787                 Node node = dao.searchById(id);
788                 if (!isFileNode(node)) {
789                         return;
790                 }
791                 String guid = node.getGuid();
792
793                 EvernoteIntentUtil util = EvernoteIntentUtil.getInstance();
794                 util.viewNote(this, guid);
795         }
796
797         public void targetSelectedChanged(boolean status) {
798                 setStatus();
799         }
800
801         public void removeAllNodeView() {
802                 layout.removeAllViews();
803         }
804
805         private void setStatus() {
806                 setStatus(status);
807         }
808
809         private void setStatus(ScreenStatus status) {
810                 try {
811                         if (this.status != status) {
812                                 this.status = status;
813                         }
814
815                         if (!lock) {
816                                 msgLayout.setVisibility(View.VISIBLE);
817                                 confirmMsg.setText(getString(R.string.mainUpdateMsg));
818                                 msgEditText.setVisibility(View.GONE);
819                                 msgButtonLayout.setVisibility(View.GONE);
820                                 status = ScreenStatus.Normal;
821                                 return;
822                         }
823
824                         if (status == ScreenStatus.Normal) {
825                                 msgLayout.setVisibility(View.GONE);
826                                 // mainMsgEditText.setText("");
827
828                                 boolean leftButtonFlag = true;
829                                 boolean rightButtonFlag = true;
830                                 // boolean addButtonFlag = true;
831                                 // boolean deleteButtonFlag = true;
832
833                                 if (indent <= 0) {
834                                         leftButtonFlag = false;
835                                 }
836
837                                 // LabelIconView target = layout.getSelectedTarget();
838                                 // NodeDao dao = (NodeDao) NodeDao.getInstance();
839                                 // long id = -1;
840                                 // Node node = null;
841                                 // if (target != null) {
842                                 // id = target.getNodeId();
843                                 // node = dao.searchById(id);
844                                 // }
845                                 // if (target == null || node == null || !(node instanceof
846                                 // DirNode))
847                                 // {
848                                 // addButtonFlag = false;
849                                 // }
850                                 // if (target == null || (node != null && node instanceof
851                                 // RootNode))
852                                 // {
853                                 // deleteButtonFlag = false;
854                                 // }
855                                 layout.setElabledTouchEvent(true);
856
857                                 leftButton.setEnabled(leftButtonFlag);
858                                 rightButton.setEnabled(rightButtonFlag);
859                                 // addButton.setEnabled(addButtonFlag);
860                                 // deleteButton.setEnabled(deleteButtonFlag);
861                         } else if (status == ScreenStatus.AddNode) {
862                                 msgLayout.setVisibility(View.VISIBLE);
863                                 msgEditText.setVisibility(View.VISIBLE);
864                                 msgButtonLayout.setVisibility(View.VISIBLE);
865                                 confirmMsg.setText(getString(R.string.mainAddMsg));
866                                 msgEditText.setText("");
867
868                                 layout.setElabledTouchEvent(false);
869
870                                 leftButton.setEnabled(false);
871                                 rightButton.setEnabled(false);
872                         } else if (status == ScreenStatus.DeleteNode) {
873                                 msgLayout.setVisibility(View.VISIBLE);
874                                 msgEditText.setVisibility(View.GONE);
875                                 msgButtonLayout.setVisibility(View.VISIBLE);
876                                 confirmMsg.setText(getString(R.string.mainDeleteMsg));
877
878                                 layout.setElabledTouchEvent(false);
879
880                                 leftButton.setEnabled(false);
881                                 rightButton.setEnabled(false);
882                         } else if (status == ScreenStatus.RenameNode) {
883                                 msgLayout.setVisibility(View.VISIBLE);
884                                 msgEditText.setVisibility(View.VISIBLE);
885                                 msgButtonLayout.setVisibility(View.VISIBLE);
886                                 confirmMsg.setText(getString(R.string.mainRenameMsg));
887
888                                 layout.setElabledTouchEvent(false);
889
890                                 leftButton.setEnabled(false);
891                                 rightButton.setEnabled(false);
892                         }
893                 } catch (Throwable e) {
894                         // TODO
895                         e.printStackTrace();
896                 }
897         }
898 }