import com.yuji.ef.dao.NodeDao;
import com.yuji.ef.dao.NodeDaoImpl;
import com.yuji.ef.dao.RootNode;
+import com.yuji.ef.exception.EfError;
+import com.yuji.ef.exception.EfException;
+import com.yuji.ef.pref.EditPrefUtil;
import com.yuji.ef.utility.BaseActivity;
import com.yuji.ef.utility.BitmapCacheFactory;
import com.yuji.ef.utility.EvernoteIntentUtil;
Normal, AddNode, DeleteNode, RenameNode
};
+ private EditPrefUtil pref = new EditPrefUtil(this);
+
private LinearLayout msgLayout;
private LinearLayout msgButtonLayout;
private Button msgOkButton;
private LinearLayout buttonLayout;
private Button leftButton;
private Button rightButton;
- // private Button addButton;
- // private Button deleteButton;
private ScreenStatus status;
private NodeComparator nodeComparator = new NodeComparator();
private boolean isInit = true;
private boolean isInCycle = false;
private boolean isResult = false;
+ private LockHandler lockHandler = null;
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
- if (action.compareTo(Constant.ACTION_UPDATE) == 0) {
- LockDao lockDao = (LockDao) LockDao.getInstance();
- lock = lockDao.lock(EverFolderActivity.this,
- Constant.LOCK_UPDATE_NOTE);
- if (lock) {
- updateList();
+ if (action.equals(Constant.ACTION_MESSAGE)) {
+ String msg = intent
+ .getStringExtra(Constant.ACTION_MESSAGE_MESSAGE);
+ EfException.msg(EverFolderActivity.this, msg);
+ } else if (action.equals(Constant.ACTION_UPDATE)) {
+ if (isInCycle && !lock) {
+ LockDao lockDao = (LockDao) LockDao.getInstance();
+ lock = lockDao.lock(EverFolderActivity.this,
+ Constant.LOCK_UPDATE_NOTE);
+ if (lock) {
+ updateList();
+ // ほんとは、setStatus()に入れたい
+ layout.setVisibility(View.VISIBLE);
+ }
+ setStatus();
}
- setStatus();
}
}
};
try {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Constant.ACTION_UPDATE);
+ intentFilter.addAction(Constant.ACTION_MESSAGE);
registerReceiver(receiver, intentFilter);
scrollView = (IconScrollView) findViewById(R.id.scrollView);
buttonLayout = (LinearLayout) findViewById(R.id.mainButtonLayout);
leftButton = (Button) findViewById(R.id.leftButton);
rightButton = (Button) findViewById(R.id.rightButton);
- // addButton = (Button) findViewById(R.id.addButton);
- // deleteButton = (Button) findViewById(R.id.deleteButton);
msgLayout = (LinearLayout) findViewById(R.id.mainMsgLayout);
confirmMsg = (TextView) findViewById(R.id.mainConfirmMsg);
rightButtonOnClick();
}
});
- // addButton.setOnClickListener(new OnClickListener() {
- // @Override
- // public void onClick(View v) {
- // addButtonOnClick();
- // }
- // });
- // deleteButton.setOnClickListener(new OnClickListener() {
- // @Override
- // public void onClick(View v) {
- // deleteButtonOnClick();
- // }
- // });
msgEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
leftButton.setTextSize(fSize);
rightButton.setTextSize(fSize);
} catch (Exception e) {
- // TODO
- e.printStackTrace();
+ EfException.msg(R.string.ErrorSystem, e);
}
}
boolean ret = super.onCreateOptionsMenu(menu);
int index = 0;
- menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "カット");
- menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "ペースト");
- menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "追加");
- menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "削除");
- menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "リネーム");
- menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE, "設定");
+ menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE,
+ getString(R.string.MenuCut));
+ menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE,
+ getString(R.string.MenuPaste));
+ menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE,
+ getString(R.string.MenuAdd));
+ menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE,
+ getString(R.string.MenuDelete));
+ menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE,
+ getString(R.string.MenuRename));
+ menu.add(Menu.NONE, Menu.FIRST + index++, Menu.NONE,
+ getString(R.string.MenuSetting));
return ret;
}
try {
b = dao.lock(this, "key");
b = dao.lock(this, "key");
- dao.unlock(new Object(), "key");
- b = dao.lock(this, "key");
+ b = dao.lock(new Object(), "key");
dao.unlock(this, "key");
+ b = dao.lock(new Object(), "key");
b = dao.lock(this, "key");
b = dao.lock(this, "key");
b = dao.lock(this, "key");
+ dao.unlock(new Object(), "key");
} catch (Exception e) {
e.printStackTrace();
NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
top = dao.searchRoot();
if (top == null) {
- // TODO
+ // データ0件(データ未更新)
+ return;
}
- layout.removeAllViews();
updateList(top);
- layout.refresh();
}
private void updateList(Node parent) {
viewY = 10;
- // List<Node> list = parent.getChildren();
- // for (Node node : list){
- // updateList(node, x);
- // }
+ scrollView.setVisibility(View.GONE);
+ layout.removeAllViews();
updateList(parent, 0);
layout.setMinimumHeight(viewY);
+ scrollView.setVisibility(View.VISIBLE);
+ layout.refresh();
scrollView.invalidate();
-
- // layout.invalidate();
-
- // this.runOnUiThread(new Runnable() {
- // @Override
- // public void run() {
- // // ビューを再描画し,UI上で画像変更を反映
- // scrollView.invalidate();
- // }
- // });
}
private void updateList(Node node, int depth) {
for (Long id : idList) {
Node n = dao.searchById(id);
if (n == null) {
- // TODO
+ // ERROR
continue;
}
if (n instanceof DirNode) {
params.y = y;
v.setLayoutParams(params);
- // LabelIconView siv = v.getStatusImageView();
- // if (siv != null) {
- // layout.addView(siv, false);
- // }
-
layout.addView(v);
v.layout(x, y, x + v.getWidth(), y + v.getHeight());
}
@Override
public void sendLockResult(boolean b) {
+ lock = b;
NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
- if (isResult){
- if (dao.isEmpty()) {
- finish();
- return;
- }
+ pref.put(Constant.PREF_UPDATE_DATA, Constant.OFF);
+ pref.update();
+
+ if (isResult) {
+ if (dao.isEmpty()) {
+ finish();
+ return;
+ }
}
isResult = false;
-
-
+
if (dao.isEmpty()) {
if (isInit) {
Intent intent = new Intent(this,
}
}
- LockDao lockDao = (LockDao) LockDao.getInstance();
- lock = lockDao.lock(this, Constant.LOCK_UPDATE_NOTE);
-
if (isInCycle) {
if (isInit) {
status = ScreenStatus.Normal;
setStatus();
isInit = false;
} else {
+ if (lock) {
+ layout.setVisibility(View.VISIBLE);
+ updateList();
+ }
setStatus();
}
} else {
- // TODO
- // lock解除
+ LockDao lockDao = (LockDao) LockDao.getInstance();
+ lockDao.unlock(EverFolderActivity.this, Constant.LOCK_UPDATE_NOTE);
+ lock = false;
}
}
@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;
}
super.onResume();
isInCycle = true;
- LockHandler handler = new LockHandler();
- handler.lock(this, Constant.LOCK_UPDATE_NOTE);
- lock = false;
+ // #29573
+ // 「強制的のロックを削除するためのフラグ」をOFFに
+ // →起動時の初回のみ削除を試みるため
+ boolean isUnlock = pref.getInt(Constant.PREF_DELETE_LOCK)== Constant.ON;
+ if (isUnlock){
+ pref.put(Constant.PREF_DELETE_LOCK, Constant.OFF);
+ pref.update();
+ }
- if (isInit){
+ lockHandler = new LockHandler();
+ lockHandler.lock(this, Constant.LOCK_UPDATE_NOTE, true, isUnlock);
+ lock = false;
+
+ if (isInit) {
+ layout.setVisibility(View.INVISIBLE);
+ setStatus();
+ } else {
+ // #29589
+ //// #29421
+ //updateList();
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
lockDao.unlock(this, Constant.LOCK_UPDATE_NOTE);
lock = false;
+ if (lockHandler != null){
+ lockHandler.cancel();
+ lockHandler = null;
+ }
+
super.onPause();
isInCycle = false;
}
}
}
- // private void addButtonOnClick() {
- // setStatus(ScreenStatus.AddNode);
- // }
- //
- // private void deleteButtonOnClick() {
- // FolderUtil util = FolderUtil.getInstance();
- // LabelIconView target = layout.getSelectedTarget();
- // long id = target.getNodeId();
- // NodeDao dao = (NodeDao) NodeDao.getInstance();
- // Node node = dao.searchById(id);
- // if (node != null) {
- // util.deleteNode(node);
- // // TODO 三角マークも消さないといけないのでは
- // layout.removeView(target);
- // updateList();
- // setStatus();
- // }
- // }
-
private void msgOkButtonOnClick(View v) {
FolderUtil util = FolderUtil.getInstance();
LabelIconView target = layout.getSelectedTarget();
NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
if (srcId < 0) {
- // TODO
+ throw new EfException(EfError.NOT_FOUND);
}
if (dstId < 0) {
- // TODO
+ throw new EfException(EfError.NOT_FOUND);
}
Node src = dao.searchById(srcId);
Node sp = dao.searchById(src.getParent());
if (sp == null) {
- // TODO
+ throw new EfException(EfError.NOT_FOUND);
}
Node dp = null;
- if (src.getParent() == dst.getParent()) {
+ if (src.getParent() == dst.getParent() || dst.getParent() < 0) {
dp = sp;
} else {
dp = dao.searchById(dst.getParent());
}
if (dp == null) {
- // TODO
+ throw new EfException(EfError.NOT_FOUND);
}
- // TODO DBへのアクセス
- // sp.remove(src.getId());
SQLiteDatabase db = DatabaseHelper.getInstance()
.getSQLiteDatabase();
db.beginTransaction();
try {
dao.removeChildrenIdNT(sp, src.getId());
if (dst instanceof DirNode) {
- // dst.add(src.getId());
dao.updateParentNT(src, dst.getId());
dao.addChildrenIdNT(dst, src.getId());
} else if (dst instanceof FileNode) {
- // dp.add(src.getId());
dao.updateParentNT(src, dp.getId());
dao.addChildrenIdNT(dp, src.getId());
}
} finally {
db.endTransaction();
}
+ } catch (EfException e) {
+ EfException.msg(R.string.ErrorSystem, e);
} finally {
updateList();
}
}
Node node = dao.searchById(dstId);
if (node == null) {
- // TODO エラー
+ // ERROR
return false;
}
if (!(node instanceof DirNode)) {
}
public void execute(long id) {
- NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
+ try {
+ NodeDao dao = (NodeDao) NodeCacheDao.getInstance();
- Node node = dao.searchById(id);
- if (node == null) {
- // TODO
- }
- node.toggleStatus();
- Status status = node.getStatus();
+ Node node = dao.searchById(id);
+ if (node == null) {
+ throw new EfException(EfError.NOT_FOUND);
+ }
+ node.toggleStatus();
+ Status status = node.getStatus();
- dao.updateStatus(node, status);
+ dao.updateStatus(node, status);
- // removeAllNodeView();
- updateList();
+ updateList();
+ } catch (EfException e) {
+ EfException.msg(R.string.ErrorSystem, e);
+ }
}
public void executeView(long id) {
}
if (!lock) {
- msgLayout.setVisibility(View.VISIBLE);
- confirmMsg.setText(getString(R.string.mainUpdateMsg));
+ int update = pref.getInt(Constant.PREF_UPDATE_DATA);
+
+ if (update == Constant.ON) {
+ msgLayout.setVisibility(View.VISIBLE);
+ confirmMsg.setText(getString(R.string.mainUpdateMsg));
+ } else {
+ msgLayout.setVisibility(View.GONE);
+ }
msgEditText.setVisibility(View.GONE);
msgButtonLayout.setVisibility(View.GONE);
+
+ leftButton.setEnabled(false);
+ rightButton.setEnabled(false);
+
status = ScreenStatus.Normal;
return;
}
if (status == ScreenStatus.Normal) {
msgLayout.setVisibility(View.GONE);
- // mainMsgEditText.setText("");
boolean leftButtonFlag = true;
boolean rightButtonFlag = true;
- // boolean addButtonFlag = true;
- // boolean deleteButtonFlag = true;
if (indent <= 0) {
leftButtonFlag = false;
}
- // LabelIconView target = layout.getSelectedTarget();
- // NodeDao dao = (NodeDao) NodeDao.getInstance();
- // long id = -1;
- // Node node = null;
- // if (target != null) {
- // id = target.getNodeId();
- // node = dao.searchById(id);
- // }
- // if (target == null || node == null || !(node instanceof
- // DirNode))
- // {
- // addButtonFlag = false;
- // }
- // if (target == null || (node != null && node instanceof
- // RootNode))
- // {
- // deleteButtonFlag = false;
- // }
layout.setElabledTouchEvent(true);
leftButton.setEnabled(leftButtonFlag);
rightButton.setEnabled(rightButtonFlag);
- // addButton.setEnabled(addButtonFlag);
- // deleteButton.setEnabled(deleteButtonFlag);
} else if (status == ScreenStatus.AddNode) {
msgLayout.setVisibility(View.VISIBLE);
msgEditText.setVisibility(View.VISIBLE);
leftButton.setEnabled(false);
rightButton.setEnabled(false);
}
- } catch (Throwable e) {
- // TODO
- e.printStackTrace();
+ } catch (Exception e) {
+ EfException.msg(R.string.ErrorSystem, e);
}
}