<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="lib" path="libs/evernote-api-1.21.jar"/>
+ <classpathentry kind="lib" path="libs/evernote-client-android.jar"/>
+ <classpathentry kind="lib" path="libs/libthrift.jar"/>
+ <classpathentry kind="lib" path="libs/scribe-1.3.0.jar"/>
+ <classpathentry kind="lib" path="libs/slf4j-android-1.5.8.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
+++ /dev/null
-/** Automatically generated file. DO NOT MODIFY */
-package com.yuji.ef;
-
-public final class BuildConfig {
- public final static boolean DEBUG = true;
-}
\ No newline at end of file
import android.content.Intent;
import android.content.res.Resources;
+import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.view.WindowManager;
import android.widget.Button;
+import com.yuji.ef.dao.DatabaseHelper;
import com.yuji.ef.dao.DirNode;
import com.yuji.ef.dao.FileNode;
+import com.yuji.ef.dao.IDao;
import com.yuji.ef.dao.Node;
import com.yuji.ef.dao.Node.Status;
import com.yuji.ef.dao.NodeDao;
try {
switch (item.getItemId()) {
case Menu.FIRST:
+ dummy();
break;
case Menu.FIRST + 1:
intent = new Intent(this, (Class<?>) SettingActivity.class);
return super.onOptionsItemSelected(item);
}
+ private void dummy(){
+ try {
+ FolderUtil util = FolderUtil.getInstance();
+
+ DatabaseHelper helper = DatabaseHelper.getInstance();
+ SQLiteDatabase db = helper.getWritableDatabase();
+
+ db.beginTransaction();
+ try {
+ util.updateNotebook(db);
+
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ updateList();
+ setStatus();
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
private void updateList() {
NodeDao dao = (NodeDao) NodeDao.getInstance();
top = dao.searchRoot();
--- /dev/null
+package com.yuji.ef.dao;
+
+public class Book {
+ private long id;
+ private long nid;
+ private String guid;
+ private String name;
+
+ public Book(long id, String guid, long nid, String name){
+ this.id = id;
+ this.guid = guid;
+ this.nid = nid;
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getGuid() {
+ return guid;
+ }
+
+ public long getNId() {
+ return nid;
+ }
+}
--- /dev/null
+package com.yuji.ef.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteStatement;
+
+import com.yuji.ef.common.CommonUtil;
+import com.yuji.ef.utility.Debug;
+import com.yuji.ef.utility.FolderUtil;
+
+public class BookDao implements IDao<Book> {
+ private static IDao<Book> instance = null;
+ private SQLiteStatement insertStmt = null;
+ private SQLiteStatement updateStmt = null;
+ private SQLiteStatement deleteIdStmt = null;
+
+ public static IDao<Book> getInstance() {
+ if (instance == null) {
+ instance = new BookDao();
+ }
+ return instance;
+ }
+
+ private BookDao() {
+
+ }
+
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL("CREATE TABLE BOOK (" + android.provider.BaseColumns._ID
+ + " INTEGER PRIMARY KEY AUTOINCREMENT," + "TYPE INTEGER,"
+ + "GUID TEXT," + "NID INTEGER," + "NAME TEXT" + ");");
+
+ // TODO
+ // CREATE INDEX インデックス名 ON テーブル名(カラム名1, カラム名2, ...);
+ }
+
+ public void init(SQLiteDatabase db) {
+ insertStmt = db.compileStatement("INSERT INTO BOOK (" + "GUID,"
+ + "NID," + "NAME" + ") VALUES (" + "?,?,?" + ");");
+ updateStmt = db.compileStatement("UPDATE BOOK SET NAME = ? WHERE "
+ + android.provider.BaseColumns._ID + " = ?");
+ deleteIdStmt = db.compileStatement("DELETE FROM BOOK WHERE "
+ + android.provider.BaseColumns._ID + " = ?");
+ }
+
+ public void start(SQLiteDatabase db) {
+
+ }
+
+ // TODO 共通
+ public SQLiteDatabase getSQLiteDatabase() {
+ DatabaseHelper helper = DatabaseHelper.getInstance();
+ SQLiteDatabase db = helper.getWritableDatabase();
+ return db;
+ }
+
+ public List<Book> search() {
+ return search(null, null, null);
+ }
+
+ public List<Book> search(SQLiteDatabase db) {
+ return search(db, null, null, null);
+ }
+
+ public Book searchById(long id) {
+ String selection = android.provider.BaseColumns._ID + " = ?";
+ String[] selectionArgs = { String.valueOf(id) };
+ String orderBy = null;
+ List<Book> list = search(selection, selectionArgs, orderBy);
+ if (list.size() <= 0) {
+ return null;
+ }
+ return list.get(0);
+ }
+
+ public Book searchByGuid(SQLiteDatabase db, String guid) {
+ String selection = "GUID" + " = ?";
+ String[] selectionArgs = { guid };
+ String orderBy = null;
+ List<Book> list = search(db, selection, selectionArgs, orderBy);
+ if (list.size() <= 0) {
+ return null;
+ }
+ return list.get(0);
+ }
+
+ private List<Book> search(String selection, String[] selectionArgs,
+ String orderBy) {
+ return search(getSQLiteDatabase(), selection, selectionArgs, orderBy);
+ }
+
+ private List<Book> search(SQLiteDatabase db, String selection, String[] selectionArgs,
+ String orderBy) {
+ List<Book> list = new ArrayList<Book>();
+ Cursor cursor = null;
+ try {
+ cursor = db.query("BOOK", new String[] {
+ android.provider.BaseColumns._ID, "GUID", "NID", "NAME" },
+ selection, selectionArgs, null, null, orderBy);
+ cursor.moveToFirst();
+ int size = cursor.getCount();
+ for (int i = 0; i < size; i++) {
+ Book book = new Book(cursor.getLong(0), cursor.getString(1),
+ cursor.getLong(2), cursor.getString(3));
+ list.add(book);
+ cursor.moveToNext();
+ }
+ } catch (SQLException e) {
+ Debug.d(this, null, e);
+ list = null;
+ } catch (Exception e) {
+ Debug.d(this, null, e);
+ list = null;
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ cursor = null;
+ }
+ }
+ return list;
+ }
+
+ public boolean isEmpty() {
+ List<Book> list = search();
+ return list == null || list.size() <= 0;
+ }
+
+ public long add(Book book) {
+ return add(getSQLiteDatabase(), book);
+ }
+
+ private long add(SQLiteDatabase db, Book book) {
+ long id = -1;
+ db.beginTransaction();
+ try {
+ id = addNT(book);
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ return id;
+ }
+
+ public long addNT(Book book) {
+ long id = -1;
+ int i = 1;
+ SQLiteStatement stmt = insertStmt;
+ stmt.bindString(i++, book.getGuid());
+ stmt.bindLong(i++, book.getNId());
+ stmt.bindString(i++, book.getName());
+ id = stmt.executeInsert();
+ return id;
+ }
+
+ public long delete(long id){
+ return delete(getSQLiteDatabase(), id);
+ }
+
+ public long updateName(Book book, String name) {
+ return updateName(getSQLiteDatabase(), book, name);
+ }
+
+ public long updateName(SQLiteDatabase db, Book book, String name) {
+ long id = -1;
+
+ db.beginTransaction();
+ try {
+ id = updateNameNT(book, name);
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ return id;
+ }
+
+ public long updateNameNT(Book book, String name) {
+ long id = -1;
+ int i = 1;
+
+ SQLiteStatement stmt = updateStmt;
+ stmt.bindString(i++, name);
+ stmt.bindLong(i++, book.getId());
+ id = stmt.executeInsert();
+ return id;
+ }
+
+
+ public long delete(SQLiteDatabase db, long did){
+ long id = -1;
+
+ db.beginTransaction();
+ try {
+ id = deleteNT(did);
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ return id;
+ }
+
+ public long deleteNT(long did) {
+ long id = -1; // TODO
+ int i = 1;
+
+ SQLiteStatement stmt = deleteIdStmt;
+ stmt.bindLong(i++, did);
+ stmt.execute();
+ return id;
+ }
+}
\ No newline at end of file
}
daoList = new ArrayList<IDao<?>>();
daoList.add(NodeDao.getInstance());
+ daoList.add(BookDao.getInstance());
DatabaseHelper helper = new DatabaseHelper(context);
SQLiteDatabase db = helper.getWritableDatabase();
import android.database.sqlite.SQLiteStatement;
import com.yuji.ef.common.CommonUtil;
-import com.yuji.ef.dao.Node.Status;
import com.yuji.ef.utility.Debug;
import com.yuji.ef.utility.FolderUtil;
private SQLiteStatement insertStmt = null;
private SQLiteStatement updateChildrenStmt = null;
private SQLiteStatement updateStatusStmt = null;
+ private SQLiteStatement updateNameStmt = null;
private SQLiteStatement deleteStmt = null;
private SQLiteStatement deleteIdStmt = null;
public void init(SQLiteDatabase db) {
insertStmt = db.compileStatement("INSERT INTO Node (" + "TYPE,"
- + "GUID," + "PARENT," + "NAME," + "CHILDREN," + "STATUS" + ") VALUES ("
- + "?,?,?,?,?,?" + ");");
- updateChildrenStmt = db.compileStatement("UPDATE Node SET CHILDREN = ? WHERE "
- + android.provider.BaseColumns._ID + " = ?");
- updateStatusStmt = db.compileStatement("UPDATE Node SET STATUS = ? WHERE "
- + android.provider.BaseColumns._ID + " = ?");
+ + "GUID," + "PARENT," + "NAME," + "CHILDREN," + "STATUS"
+ + ") VALUES (" + "?,?,?,?,?,?" + ");");
+ updateChildrenStmt = db
+ .compileStatement("UPDATE Node SET CHILDREN = ? WHERE "
+ + android.provider.BaseColumns._ID + " = ?");
+ updateStatusStmt = db
+ .compileStatement("UPDATE Node SET STATUS = ? WHERE "
+ + android.provider.BaseColumns._ID + " = ?");
+ updateNameStmt = db
+ .compileStatement("UPDATE Node SET NAME = ? WHERE "
+ + android.provider.BaseColumns._ID + " = ?");
deleteStmt = db.compileStatement("DELETE FROM Node");
- deleteIdStmt = db.compileStatement("DELETE FROM Node WHERE " + android.provider.BaseColumns._ID + " = ?");
+ deleteIdStmt = db.compileStatement("DELETE FROM Node WHERE "
+ + android.provider.BaseColumns._ID + " = ?");
}
public void start(SQLiteDatabase db) {
FolderUtil util = FolderUtil.getInstance();
util.init(db);
}
-
+
public void start2(SQLiteDatabase db) {
// top = new DirNode(null, null);
// top.setStatus(Node.Status.OPEN);
id = addNT(node);
node.setId(id);
addChildrenIdNT(top, node.getId());
- //top.add(node.getId());
+ // top.add(node.getId());
// SUB
n = new FileNode("ファイルaaa", null);
n.setParent(node.getId());
id = addNT(n);
addChildrenIdNT(node, id);
- //node.add(n.getId());
+ // node.add(n.getId());
n = new FileNode("ファイルbb", null);
n.setParent(node.getId());
id = addNT(n);
addChildrenIdNT(node, id);
- //node.add(n.getId());
+ // node.add(n.getId());
n = new FileNode("ファイルc", null);
n.setParent(node.getId());
id = addNT(n);
addChildrenIdNT(node, id);
- //node.add(n.getId());
+ // node.add(n.getId());
// NODE
node = new DirNode("ディレクトリAAA", null);
node.setParent(top.getId());
id = addNT(node);
addChildrenIdNT(top, id);
- //top.add(node.getId());
+ // top.add(node.getId());
// SUB
n = new DirNode("ディレクトリ", null);
n.setParent(node.getId());
id = addNT(n);
addChildrenIdNT(node, id);
- //node.add(n.getId());
+ // node.add(n.getId());
n = new FileNode("yyyファイル", null);
n.setParent(node.getId());
id = addNT(n);
addChildrenIdNT(node, id);
- //node.add(n.getId());
+ // node.add(n.getId());
// NODE
node = new FileNode("ファイルあいうえお", null);
node.setParent(top.getId());
id = addNT(node);
addChildrenIdNT(top, id);
- //top.add(node.getId());
+ // top.add(node.getId());
}
- public SQLiteDatabase getSQLiteDatabase(){
+ public SQLiteDatabase getSQLiteDatabase() {
DatabaseHelper helper = DatabaseHelper.getInstance();
SQLiteDatabase db = helper.getWritableDatabase();
- return db;
+ return db;
}
-
+
public List<Node> search() {
- return search(null, null, null);
+ return search(getSQLiteDatabase(), null, null, null);
}
public Node searchRoot() {
+ return searchRoot(getSQLiteDatabase());
+ }
+
+ public Node searchRoot(SQLiteDatabase db) {
String selection = "TYPE = ?";
String[] selectionArgs = { "0" };
String orderBy = null;
- List<Node> list = search(selection, selectionArgs, orderBy);
+ List<Node> list = search(db, selection, selectionArgs, orderBy);
if (list.size() <= 0) {
return null;
}
}
public Node searchById(long id) {
+ return searchById(getSQLiteDatabase(), id);
+ }
+
+ public Node searchById(SQLiteDatabase db, long id) {
String selection = android.provider.BaseColumns._ID + " = ?";
String[] selectionArgs = { String.valueOf(id) };
String orderBy = null;
- List<Node> list = search(selection, selectionArgs, orderBy);
+ List<Node> list = search(db, selection, selectionArgs, orderBy);
if (list.size() <= 0) {
return null;
}
return list.get(0);
}
- private List<Node> search(String selection, String[] selectionArgs,
+ private List<Node> search(SQLiteDatabase db, String selection, String[] selectionArgs,
String orderBy) {
List<Node> list = new ArrayList<Node>();
Cursor cursor = null;
try {
- DatabaseHelper helper = DatabaseHelper.getInstance();
- SQLiteDatabase db = helper.getReadableDatabase();
-
NodeFactory factory = NodeFactory.getInstance();
cursor = db.query("Node", new String[] {
android.provider.BaseColumns._ID, "TYPE", "GUID", "PARENT",
- "NAME", "CHILDREN", "STATUS" }, selection, selectionArgs, null, null,
- orderBy);
+ "NAME", "CHILDREN", "STATUS" }, selection, selectionArgs,
+ null, null, orderBy);
cursor.moveToFirst();
int size = cursor.getCount();
for (int i = 0; i < size; i++) {
// cursor.getLong(4));
Node node = factory.create(cursor.getLong(0), cursor.getInt(1),
cursor.getString(2), cursor.getLong(3),
- cursor.getString(4), cursor.getString(5), cursor.getInt(6));
+ cursor.getString(4), cursor.getString(5),
+ cursor.getInt(6));
list.add(node);
cursor.moveToNext();
}
List<Node> list = search();
return list == null || list.size() <= 0;
}
-
+
public long add(Node node) {
DatabaseHelper helper = DatabaseHelper.getInstance();
SQLiteDatabase db = helper.getWritableDatabase();
// node.add(id);
return updateChildrenNT(node, Node.concatChildren(l));
}
-
- public long updateStatus(Node node, Node.Status status){
- DatabaseHelper helper = DatabaseHelper.getInstance();
- SQLiteDatabase db = helper.getWritableDatabase();
- return updateStatus(db, node, status);
+
+ public long updateStatus(Node node, Node.Status status) {
+ return updateStatus(getSQLiteDatabase(), node, status);
}
-
- public long updateStatus(SQLiteDatabase db, Node node, Node.Status status){
+
+ public long updateStatus(SQLiteDatabase db, Node node, Node.Status status) {
long id = -1;
-
+
db.beginTransaction();
try {
id = updateStatusNT(node, status);
}
return id;
}
-
+
public long updateStatusNT(Node node, Node.Status status) {
long id = -1;
int i = 1;
int code = Node.getStatusCode(status);
-
+
SQLiteStatement stmt = updateStatusStmt;
stmt.bindLong(i++, code);
stmt.bindLong(i++, node.getId());
return id;
}
+ public long updateName(Node node, String name) {
+ return updateName(getSQLiteDatabase(), node, name);
+ }
+
+ public long updateName(SQLiteDatabase db, Node node, String name) {
+ long id = -1;
+
+ db.beginTransaction();
+ try {
+ id = updateNameNT(node, name);
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ return id;
+ }
+
+ public long updateNameNT(Node node, String name) {
+ long id = -1;
+ int i = 1;
+
+ SQLiteStatement stmt = updateNameStmt;
+ stmt.bindString(i++, name);
+ stmt.bindLong(i++, node.getId());
+ id = stmt.executeInsert();
+ return id;
+ }
+
public long updateChildren(Node node, String children) {
DatabaseHelper helper = DatabaseHelper.getInstance();
SQLiteDatabase db = helper.getWritableDatabase();
return id;
}
- public long delete(long id){
+ public long delete(long id) {
DatabaseHelper helper = DatabaseHelper.getInstance();
SQLiteDatabase db = helper.getWritableDatabase();
- return delete(db, id);
+ return delete(db, id);
}
-
- public long delete(SQLiteDatabase db, long did){
+
+ public long delete(SQLiteDatabase db, long did) {
long id = -1;
-
+
db.beginTransaction();
try {
id = deleteNT(did);
}
return id;
}
-
+
public long deleteNT(long did) {
long id = -1; // TODO
int i = 1;
-
+
SQLiteStatement stmt = deleteIdStmt;
stmt.bindLong(i++, did);
stmt.execute();
return id;
}
- public long delete(){
+ public long delete() {
DatabaseHelper helper = DatabaseHelper.getInstance();
SQLiteDatabase db = helper.getWritableDatabase();
- return delete(db);
+ return delete(db);
}
-
- public long delete(SQLiteDatabase db){
+
+ public long delete(SQLiteDatabase db) {
long id = -1;
-
+
db.beginTransaction();
try {
deleteNT();
}
return id;
}
-
+
public void deleteNT() {
SQLiteStatement stmt = deleteStmt;
stmt.execute();
import com.evernote.edam.notestore.NoteList;
import com.evernote.edam.type.Note;
import com.evernote.edam.type.Notebook;
-import com.evernote.edam.type.Tag;
+import com.yuji.ef.dao.Book;
+import com.yuji.ef.dao.BookDao;
import com.yuji.ef.dao.DatabaseHelper;
import com.yuji.ef.dao.DirNode;
import com.yuji.ef.dao.FileNode;
public class FolderUtil {
private EvernoteUtil util = EvernoteUtil.getInstance();
- private NodeDao dao = (NodeDao) NodeDao.getInstance();
+ private NodeDao nodeDao = (NodeDao) NodeDao.getInstance();
+ private BookDao bookDao = (BookDao) BookDao.getInstance();
public static FolderUtil getInstance() {
if (instance == null) {
}
public void init(SQLiteDatabase db) {
- List<Notebook> noteBookList = util.getNoteBookList();
- List<Tag> tagList = util.getTagList();
+ // List<Notebook> noteBookList = util.getNoteBookList();
+ // List<Tag> tagList = util.getTagList();
- dao.delete(db);
+ // nodeDao.delete(db);
// ROOT
Node node;
long id;
String guid;
- HashMap<String, Node> map = new HashMap<String, Node>();
-
Node top = new RootNode("", null);
- id = dao.addNT(top);
+ id = nodeDao.addNT(top);
top.setId(id);
- for (Notebook noteBook : noteBookList) {
- String name = noteBook.getName();
+ updateNotebook(db);
- // NODE
- node = new DirNode(name, null);
- addDirNodeNT(top, node);
-
- DirNode dirNode = (DirNode) node;
+ List<Book> noteBookList = bookDao.search(db);
+ HashMap<String, Node> map = new HashMap<String, Node>();
+ for (Book noteBook : noteBookList) {
guid = noteBook.getGuid();
- dirNode.setNotebookGuid(guid);
-
+ DirNode dirNode = (DirNode) nodeDao.searchById(db,
+ noteBook.getNId());
+ if (dirNode == null){
+ // TODO
+ }
map.put(guid, dirNode);
-
- // SUB
- // for (Tag tag : tagList) {
- // name = tag.getName();
- //
- // n = new DirNode(name, null);
- // n.setParent(node.getId());
- // id = dao.addNT(n);
- // dao.addChildrenIdNT(node, id);
- // }
}
List<NoteList> noteListList = util.getNoteList();
}
}
+ public void updateNotebook(SQLiteDatabase db) {
+ List<Notebook> noteBookList = util.getNoteBookList();
+
+ long id;
+ Node top = nodeDao.searchRoot(db);
+
+ for (Notebook notebook : noteBookList) {
+ String guid = notebook.getGuid();
+ String name = notebook.getName();
+
+ Book oldBook = bookDao.searchByGuid(db, guid);
+ if (oldBook == null) {
+ DirNode dirNode = new DirNode(name, null);
+ guid = notebook.getGuid();
+ dirNode.setNotebookGuid(guid);
+
+ id = addDirNodeNT(top, dirNode);
+
+ Book book = new Book(-1, guid, id, name);
+ bookDao.addNT(book);
+ } else {
+ String oldName = oldBook.getName();
+ if (!name.equals(oldName)) {
+ bookDao.updateNameNT(oldBook, name);
+
+ // TODO #29015
+ Node node = nodeDao.searchById(db, oldBook.getNId());
+ nodeDao.updateNameNT(node, name);
+ }
+ }
+ }
+ }
+
public long addFileNode(Node parent, Node node) {
DatabaseHelper helper = DatabaseHelper.getInstance();
SQLiteDatabase db = helper.getWritableDatabase();
private long addFileNodeNT(Node parent, Node node) {
long id;
node.setParent(parent.getId());
- id = dao.addNT(node);
- dao.addChildrenIdNT(parent, id);
+ id = nodeDao.addNT(node);
+ nodeDao.addChildrenIdNT(parent, id);
return id;
}
private long addDirNodeNT(Node parent, Node node) {
long id;
node.setParent(parent.getId());
- id = dao.addNT(node);
+ id = nodeDao.addNT(node);
node.setId(id);
- dao.addChildrenIdNT(parent, node.getId());
+ nodeDao.addChildrenIdNT(parent, node.getId());
return id;
}
private long deleteNodeNT(Node node) {
long id;
-
- if (node instanceof DirNode){
- DirNode dirNode = (DirNode)node;
+
+ if (node instanceof DirNode) {
+ DirNode dirNode = (DirNode) node;
List<Long> list = dirNode.getChildren();
- for (Long l : list){
+ for (Long l : list) {
id = l.longValue();
- Node n = dao.searchById(id);
- if (n != null){
+ Node n = nodeDao.searchById(id);
+ if (n != null) {
deleteNodeNT(n);
}
}
}
-
+
id = node.getParent();
- if (id >= 0){
- Node p = dao.searchById(id);
- if (p != null){
- dao.remoteChildrenIdNT(p, node.getId());
+ if (id >= 0) {
+ Node p = nodeDao.searchById(id);
+ if (p != null) {
+ nodeDao.remoteChildrenIdNT(p, node.getId());
}
}
- dao.deleteNT(node.getId());
-
-
-
+ nodeDao.deleteNT(node.getId());
+
return 0;
}
}