OSDN Git Service

debian
[everfolder/source.git] / source / workspace / EverFolder / src / com / yuji / ef / EverFolderActivity.java
index 2375da6..7c539fe 100644 (file)
@@ -43,9 +43,11 @@ import com.yuji.ef.utility.BaseActivity;
 import com.yuji.ef.utility.BitmapCacheFactory;
 import com.yuji.ef.utility.EvernoteIntentUtil;
 import com.yuji.ef.utility.FolderUtil;
+import com.yuji.ef.utility.LockHandler;
+import com.yuji.ef.utility.LockListener;
 import com.yuji.ef.utility.ScaleUtil;
 
-public class EverFolderActivity extends BaseActivity {
+public class EverFolderActivity extends BaseActivity implements LockListener {
        private enum ScreenStatus {
                Normal, AddNode, DeleteNode, RenameNode
        };
@@ -75,7 +77,9 @@ public class EverFolderActivity extends BaseActivity {
        private int viewY;
        private boolean lock = false;
        private boolean isInit = true;
-
+       private boolean isInCycle = false;
+       private boolean isResult = false;
+       
        private BroadcastReceiver receiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
@@ -219,10 +223,10 @@ public class EverFolderActivity extends BaseActivity {
                boolean ret = super.onMenuOpened(featureId, menu);
 
                // #29304
-               if (menu == null){
+               if (menu == null) {
                        return false;
                }
-               
+
                MenuItem item;
 
                boolean cutButtonFlag = false;
@@ -454,20 +458,20 @@ public class EverFolderActivity extends BaseActivity {
                // }
                updateList(parent, 0);
                layout.setMinimumHeight(viewY);
-               
+
                scrollView.invalidate();
-               
-//             layout.invalidate();
 
-//             this.runOnUiThread(new Runnable() {
-//                     @Override
-//                     public void run() {
-//                             // ビューを再描画し,UI上で画像変更を反映
-//                             scrollView.invalidate();
-//                     }
-//             });
+               // layout.invalidate();
+
+               // this.runOnUiThread(new Runnable() {
+               // @Override
+               // public void run() {
+               // // ビューを再描画し,UI上で画像変更を反映
+               // scrollView.invalidate();
+               // }
+               // });
        }
-       
+
        private void updateList(Node node, int depth) {
                int N = (int) (bmpWidth * 0.6);
                int M = (int) (bmpWidth * 1.2);
@@ -509,13 +513,13 @@ public class EverFolderActivity extends BaseActivity {
                NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
                for (Long id : idList) {
                        Node n = dao.searchById(id);
-                       if (n == null){
+                       if (n == null) {
                                // TODO
                                continue;
                        }
-                       if (n instanceof DirNode){
-                               DirNode d = (DirNode)n;
-                               if (isNoteBook(d) && !d.isSelected()){
+                       if (n instanceof DirNode) {
+                               DirNode d = (DirNode) n;
+                               if (isNoteBook(d) && !d.isSelected()) {
                                        continue;
                                }
                        }
@@ -555,26 +559,18 @@ public class EverFolderActivity extends BaseActivity {
        }
 
        @Override
-       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-               // updateList();
-               // setStatus();
+       public void sendLockResult(boolean b) {
                NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
-               if (dao.isEmpty()) {
-                       finish();
-               }
-               isInit = true;
-       }
 
-       @Override
-       protected void onStart() {
-               super.onStart();
-       }
-
-       @Override
-       protected void onResume() {
-               super.onResume();
-
-               NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
+               if (isResult){
+                        if (dao.isEmpty()) {
+                                finish();
+                                return;
+                        }                      
+               }
+               isResult = false;
+               
+               
                if (dao.isEmpty()) {
                        if (isInit) {
                                Intent intent = new Intent(this,
@@ -591,19 +587,87 @@ public class EverFolderActivity extends BaseActivity {
                LockDao lockDao = (LockDao) LockDao.getInstance();
                lock = lockDao.lock(this, Constant.LOCK_UPDATE_NOTE);
 
-               if (isInit) {
-                       status = ScreenStatus.Normal;
+               if (isInCycle) {
+                       if (isInit) {
+                               status = ScreenStatus.Normal;
 
-                       if (lock) {
-                               updateList();
+                               if (lock) {
+                                       layout.setVisibility(View.VISIBLE);
+                                       updateList();
+                               } else {
+                                       layout.removeAllViews();
+                               }
+                               setStatus();
+                               isInit = false;
                        } else {
-                               layout.removeAllViews();
+                               setStatus();
                        }
-                       setStatus();
-                       isInit = false;
                } else {
+                       // TODO
+                       // lock解除
+               }
+       }
+
+       @Override
+       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+               // TODO sendLockResult()、「lock解除」のため、とりあえずコメント
+               // NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
+               // if (dao.isEmpty()) {
+               // finish();
+               // }
+               isResult = true;
+               isInit = true;
+       }
+
+       @Override
+       protected void onStart() {
+               super.onStart();
+       }
+
+       @Override
+       protected void onResume() {
+               super.onResume();
+               isInCycle = true;
+
+               LockHandler handler = new LockHandler();
+               handler.lock(this, Constant.LOCK_UPDATE_NOTE);
+               lock = false;
+               
+               if (isInit){
+                       layout.setVisibility(View.INVISIBLE);
                        setStatus();
                }
+
+               // NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
+               // if (dao.isEmpty()) {
+               // if (isInit) {
+               // Intent intent = new Intent(this,
+               // (Class<?>) SettingActivity.class);
+               // startActivityForResult(intent, 0);
+               //
+               // isInit = false;
+               // } else {
+               // finish();
+               // isInit = true;
+               // }
+               // }
+               //
+               // LockDao lockDao = (LockDao) LockDao.getInstance();
+               // lock = lockDao.lock(this, Constant.LOCK_UPDATE_NOTE);
+               //
+               // if (isInit) {
+               // status = ScreenStatus.Normal;
+               //
+               // if (lock) {
+               // updateList();
+               // } else {
+               // layout.removeAllViews();
+               // }
+               // setStatus();
+               // isInit = false;
+               // } else {
+               // setStatus();
+               // }
        }
 
        @Override
@@ -614,6 +678,7 @@ public class EverFolderActivity extends BaseActivity {
                lock = false;
 
                super.onPause();
+               isInCycle = false;
        }
 
        private void leftButtonOnClick() {
@@ -694,9 +759,9 @@ public class EverFolderActivity extends BaseActivity {
                        }
                        layout.setCutTarget(null, false);
                }
-               
+
                closeIME(v);
-               
+
                layout.clearTarget();
                updateList();
                setStatus(ScreenStatus.Normal);
@@ -704,15 +769,15 @@ public class EverFolderActivity extends BaseActivity {
 
        private void msgCancelOnClick(View v) {
                closeIME(v);
-               
+
                setStatus(ScreenStatus.Normal);
        }
 
-       private void closeIME(View v){
-               InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
-               imm.hideSoftInputFromWindow(v.getWindowToken(),0);
+       private void closeIME(View v) {
+               InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+               imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
-       
+
        public void execute(long srcId, long dstId) {
                try {
                        removeAllNodeView();
@@ -933,4 +998,5 @@ public class EverFolderActivity extends BaseActivity {
                        e.printStackTrace();
                }
        }
+
 }
\ No newline at end of file