/** * */ package net.tasksnow.model.sqlite; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import net.tasksnow.model.cards.Label; import net.tasksnow.model.cards.Project; import net.tasksnow.model.cards.Task; import net.tasksnow.view.task.ActionMapper; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; /** * @author D056974 * */ public class DatabaseHandler extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; // Database Name private static final String DATABASE_NAME = "tasksnow"; //tasks table name private static final String TABLE_TASKS = "tasks"; // tasks table column names private static final String KEY_ID = "id"; private static final String NAME = "name"; private static final String END = "enddate"; private static final String IMPORTANCE = "importance"; private static final String PROJECT_ID = "project_id"; private static final String DESCR = "descr"; private static final String ACTION = "action"; private static final String NOTIFICATION = "notification"; private static final String STATUS = "done"; //projects table name private static final String TABLE_PROJECTS = "projects"; //projects table column names private static final String PRO_ID = "id"; private static final String PRO_NAME = "name"; private static final String PRO_END = "enddate"; private static final String PRO_DESCR = "descr"; private static final String PRO_DONE = "done"; private static final String NO_TASKS = "no_tasks"; private static final String NO_DONE_TASKS = "done_tasks"; //label table name private static final String TABLE_LABELS = "labels"; //label table column names private static final String L_NAME = "name"; //label tasks mapping table private static final String TABLE_MAP = "tasks_label"; //columns private static final String TASK_ID = "task_id"; private static final String LABEL_ID = "label_id"; public DatabaseHandler(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } /* Fertig * @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase) */ @Override public void onCreate(SQLiteDatabase db) { String CREATE_TASKS_TABLE = "CREATE TABLE " + TABLE_TASKS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + NAME + " TEXT," + END + " TEXT, " + IMPORTANCE + " INT," + DESCR + " TEXT," + ACTION + " INTEGER," + NOTIFICATION + " INTEGER," + STATUS + " INTEGER," + PROJECT_ID + " INT, FOREIGN KEY(" + PROJECT_ID + ") REFERENCES " + TABLE_PROJECTS + " (" + PRO_ID + "))"; db.execSQL(CREATE_TASKS_TABLE); String CREATE_PROJECTS_TABLE = "CREATE TABLE " + TABLE_PROJECTS + "(" + PRO_ID + " INTEGER PRIMARY KEY," + PRO_NAME + " TEXT," + PRO_END + " TEXT, " + PRO_DESCR + " TEXT," + PRO_DONE + " INTEGER," + NO_TASKS + " INTEGER," + NO_DONE_TASKS + " INTEGER)"; db.execSQL(CREATE_PROJECTS_TABLE); String CREATE_LABELS_TABLE = "CREATE TABLE " + TABLE_LABELS + "(" + L_NAME + " TEXT PRIMARY KEY)"; db.execSQL(CREATE_LABELS_TABLE); String CREATE_MAPPING_TABLE = "CREATE TABLE " + TABLE_MAP + "( " + TASK_ID + " INT, " + LABEL_ID + " TEXT, FOREIGN KEY(" + TASK_ID + ") REFERENCES " + TABLE_TASKS + " (" + KEY_ID + "), FOREIGN KEY(" + LABEL_ID + ") REFERENCES " + TABLE_LABELS + " (" + L_NAME + "))"; db.execSQL(CREATE_MAPPING_TABLE); } /* Fertig * @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int) */ @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_TASKS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_PROJECTS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_LABELS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_MAP); onCreate(db); } public void addTestTags() { SQLiteDatabase db = this.getWritableDatabase(); db.execSQL("DELETE FROM " + TABLE_LABELS); this.addLabel(new Label("city")); this.addLabel(new Label("home")); this.addLabel(new Label("family")); this.addLabel(new Label("work")); this.addLabel(new Label("vacation")); this.addLabel(new Label("values")); this.addLabel(new Label("other stuff")); } public void testProjectsTasks() { SQLiteDatabase db = this.getWritableDatabase(); db.execSQL("DELETE FROM " + TABLE_TASKS); db.execSQL("DELETE FROM " + TABLE_PROJECTS); db.execSQL("DELETE FROM " + TABLE_MAP); ArrayList<Label> label = new ArrayList<Label>(); this.addProject(new Project(-1, "Switch to TaskNow", new GregorianCalendar(2013, 3, 20).getTime(), "Switch to TaskNow", false, 10, 3)); label.add(new Label("other stuff")); this.addTask(new Task(-1, "Get known with TaskNow", label, "lern how to interact with all these touch gestures", new GregorianCalendar(2013, 4, 01).getTime(), 1, 2, false, 0, ActionMapper.ACTION_NOACTION, "Switch to TaskNow")); this.addTask(new Task(-1, "Transfer all Tasks into TaskNow", label, "", new GregorianCalendar(2013, 4, 02).getTime(), 1, 2, false, 0, ActionMapper.ACTION_NOACTION, "Switch to TaskNow")); this.addTask(new Task(-1, "Delete all other task-apps", label, "no longer needed when using TaskNow", new GregorianCalendar(2013, 4, 03).getTime(), 1, 2, false, 0, ActionMapper.ACTION_NOACTION, "Switch to TaskNow")); this.addTask(new Task(-1, "Give the app a 5 star rating", label, "...because it is awesome! Rate in Boogle Pay Store", new GregorianCalendar(2013, 4, 03).getTime(), 1, 2, false, 0, ActionMapper.ACTION_URL, "Switch to TaskNow")); label.clear(); this.addProject(new Project(-1, "Shopping", new GregorianCalendar(2013, 4, 20).getTime(), "prepare for movie-night", false, 5, 2)); label.add(new Label("city")); label.add(new Label("home")); label.add(new Label("family")); this.addTask(new Task(-1, "Buy some new DVDs", label, "The Hobbit, Skyfall, ...", new GregorianCalendar(2013, 4, 20).getTime(), 2, 2, false, 0, ActionMapper.ACTION_LOCATION, "Shopping")); this.addTask(new Task(-1, "Call Peter", label, "talk about new TV", new GregorianCalendar(2013, 4, 20).getTime(), 2, 2, false, 0, ActionMapper.ACTION_CALL, "Shopping")); this.addTask(new Task(-1, "Get food", label, "delicious meal in the evening", new GregorianCalendar(2013, 4, 20).getTime(), 2, 2, false, 0, ActionMapper.ACTION_LOCATION, "Shopping")); label.clear(); this.addProject(new Project(-1, "Global journey", new GregorianCalendar(2013, 7, 5).getTime(), "organize next world tour", false, 30, 20)); label.add(new Label("vacation")); label.add(new Label("home")); this.addTask(new Task(-1, "Plan", label, "find cheap hotels and flights", new GregorianCalendar(2013, 5, 21).getTime(), 3, 2, false, 0, ActionMapper.ACTION_URL, "Global journey")); label.remove(new Label("home")); label.add(new Label("work")); this.addTask(new Task(-1, "Preperation @ Work", label, "do all the stuff at work...", new GregorianCalendar(2013, 7, 2).getTime(), 3, 2, false, 0, ActionMapper.ACTION_TIMER, "Global journey")); label.remove(new Label("work")); label.add(new Label("city")); this.addTask(new Task(-1, "Buy equipment", label, "new tent and ...", new GregorianCalendar(2013, 6, 10).getTime(), 3, 2, false, 0, ActionMapper.ACTION_LOCATION, "Global journey")); label.remove(new Label("city")); label.clear(); this.addProject(new Project(-1, "Recruiting", new GregorianCalendar(2013, 5, 27).getTime(), "need more stuff", false, 10, 1)); label.add(new Label("work")); this.addTask(new Task(-1, "search", label, "", new GregorianCalendar(2013, 4, 30).getTime(), 4, 2, false, 0, ActionMapper.ACTION_NOACTION, "Recruiting")); this.addTask(new Task(-1, "invite", label, "", new GregorianCalendar(2013, 5, 15).getTime(), 4, 2, false, 0, ActionMapper.ACTION_MESSAGE, "Recruiting")); this.addTask(new Task(-1, "decide", label, "", new GregorianCalendar(2013, 5, 26).getTime(), 4, 2, false, 0, ActionMapper.ACTION_NOACTION, "Recruiting")); label.clear(); this.addProject(new Project(-1, "Jean's birthday-party", new GregorianCalendar(2013, 5, 27).getTime(), "all things about my son's party", false, 0, 0)); label.add(new Label("family")); label.add(new Label("city")); this.addTask(new Task(-1, "Buy present", label, "Boogle Plexus 15", new GregorianCalendar(2013, 4, 9).getTime(), 5, 2, false, 0, ActionMapper.ACTION_URL, "Jean's birthday-party")); this.addTask(new Task(-1, "Find a new babysitter", label, "for prepearing the party", new GregorianCalendar(2013, 5, 10).getTime(), 5, 2, false, 0, ActionMapper.ACTION_NOACTION, "Jean's birthday-party")); this.addTask(new Task(-1, "Invite the whole family", label, "", new GregorianCalendar(2013, 5, 15).getTime(), 5, 2, false, 0, ActionMapper.ACTION_MESSAGE, "Jean's birthday-party")); this.addTask(new Task(-1, "Invite Dimitri", label, "", new GregorianCalendar(2013, 5, 15).getTime(), 5, 2, false, 0, ActionMapper.ACTION_CALL, "Jean's birthday-party")); this.addTask(new Task(-1, "Party", label, "The big day", new GregorianCalendar(2013, 5, 25).getTime(), 5, 2, false, 0, ActionMapper.ACTION_NOACTION, "Jean's birthday-party")); } /** * Fertig * * @param task * A task object, every attribute should be filled ;) */ public void addTask(Task task) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(NAME, task.getName()); values.put(END, this.DateToString(task.getDate())); values.put(IMPORTANCE, task.getImportance()); values.put(DESCR, task.getDescription()); values.put(NOTIFICATION, task.getNotification()); values.put(STATUS, task.getStatus()); values.put(PROJECT_ID, task.getProjectID()); values.put(ACTION, task.getAction()); db.insert(TABLE_TASKS, null, values); //get the id of the inserted task String query = "SELECT " + KEY_ID + " from " + TABLE_TASKS + " order by " + KEY_ID + " DESC limit 1"; Cursor c = db.rawQuery(query, null); int lastId = 0; if (c != null && c.moveToFirst()) { lastId = (int) c.getLong(0); //The 0 is the column index, we only have 1 column, so the index is 0 } //insert the mappers to assign labels to tasks ArrayList<Label> tagList = task.getLabels(); for (Label tag : tagList) { addTaskLabelMapper(lastId, tag.getValue()); } } /** * Updates an task * * @param task */ public void updateTask(Task task) { String query = "UPDATE " + TABLE_TASKS; query = query + " SET " + NAME + "='" + task.getName() + "'"; query = query + ", " + END + "='" + this.DateToString(task.getDate()) + "'"; query = query + ", " + IMPORTANCE + "=" + task.getImportance(); query = query + ", " + DESCR + "='" + task.getDescription() + "'"; query = query + ", " + ACTION + "=" + task.getAction(); query = query + ", " + NOTIFICATION + "=" + boolean_to_int(task.getNotification()); query = query + ", " + STATUS + "=" + task.getStatus(); query = query + ", " + PROJECT_ID + "=" + task.getProjectID(); query = query + " WHERE " + KEY_ID + "=" + task.getId(); SQLiteDatabase db = this.getWritableDatabase(); db.execSQL(query); //deletes old labels of the task and inserts the new ones (which can of course be the same like the old ones) ArrayList<Label> tagList = task.getLabels(); db.delete(TABLE_MAP, TASK_ID + " ='" + task.getId() + "'", null); for (Label tag : tagList) { addTaskLabelMapper(task.getId(), tag.getValue()); } } /** * Fertig * * @param id * of a task * @return the task object */ public Task getTask(int id) { String selectQuery = "SELECT * FROM " + TABLE_TASKS + " WHERE " + KEY_ID + " = " + id; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(selectQuery, null); Task task = new Task(); if (c != null) { c.moveToFirst(); ArrayList<Label> tags = this.getLabelsForTask(c.getInt(0)); task = new Task(c.getInt(0), c.getString(1), tags, c.getString(4), this.StringToDate(c.getString(2)), c.getInt(8), c.getInt(3), this.int_to_boolean(c.getInt(6)), c.getInt(7), c.getInt(5), this.getProjectName(c.getInt(8))); } return task; } /** * Get all tasks of the user * * @return ArrayList of Tasks */ public ArrayList<Task> getAllTasks() { String selectQuery = "SELECT * FROM " + TABLE_TASKS; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(selectQuery, null); ArrayList<Task> tasks = new ArrayList(); if (c.moveToFirst()) { do { ArrayList<Label> tags = this.getLabelsForTask(c.getInt(0)); tasks.add(new Task(c.getInt(0), c.getString(1), tags, c.getString(4), this.StringToDate(c.getString(2)), c.getInt(8), c .getInt(3), this.int_to_boolean(c.getInt(6)), c.getInt(7), c.getInt(5), this.getProjectName(c.getInt(8)))); } while (c.moveToNext()); } return tasks; } /** * Set the status of a task to complete * * @param id * of the Task */ public void completeTask(int id) { String query = "UPDATE " + TABLE_TASKS + " SET " + STATUS + "=1"; SQLiteDatabase db = this.getWritableDatabase(); db.execSQL(query); } /** * Set the status of a task to complete * * @param task * Object */ public void completeTask(Task task) { this.completeTask(task.getId()); } /** * Dismiss a task * * @param id * of the Task */ public void dismissTask(int id) { String query = "UPDATE " + TABLE_TASKS + " SET " + STATUS + "=-1"; SQLiteDatabase db = this.getWritableDatabase(); db.execSQL(query); } /** * Dismiss a task * * @param task * Object */ public void dismissTask(Task task) { this.dismissTask(task.getId()); } public Label getLabel(String labelname) { return new Label(labelname); } /** * Get all Tags of the user. * * @return ArrayList of Tags */ public ArrayList<Label> getAllLabels() { String selectQuery = "SELECT * FROM " + TABLE_LABELS; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(selectQuery, null); ArrayList<Label> result = new ArrayList(); if (c != null) { if (c.moveToFirst()) { do { result.add(new Label(c.getString(0))); } while (c.moveToNext()); } } return result; } /** * Gets all tags for one task. * * @param id * of a task * @return An ArrayList of all tags for this task */ public ArrayList<Label> getLabelsForTask(int id) { String selectQuery = "SELECT * FROM " + TABLE_MAP + " WHERE " + TASK_ID + "=" + id; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(selectQuery, null); ArrayList<Label> tags = new ArrayList<Label>(); if (c.moveToFirst()) { do { selectQuery = "SELECT " + L_NAME + " FROM " + TABLE_LABELS + " WHERE " + L_NAME + " = '" + c.getString(1) + "'"; Cursor c2 = db.rawQuery(selectQuery, null); if (c2 != null) { c2.moveToFirst(); tags.add(new Label(c2.getString(0))); } } while (c.moveToNext()); } return tags; } /** * Adds a tag into the database * * @param tag */ public void addLabel(Label tag) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(L_NAME, tag.getValue()); db.insert(TABLE_LABELS, null, values); } /** * Adds a project into the database * * @param project * The project you want to add */ public void addProject(Project project) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(PRO_NAME, project.getName()); values.put(PRO_END, this.DateToString(project.getEnd_date())); values.put(PRO_DESCR, project.getDescr()); values.put(PRO_DONE, project.isDone()); values.put(NO_TASKS, project.getNo_tasks()); values.put(NO_DONE_TASKS, project.getNo_done_task()); db.insert(TABLE_PROJECTS, null, values); } /** * Gets the project based on its id * * @param id * @return Project */ public Project getProject(int id) { String selectQuery = "SELECT * FROM " + TABLE_PROJECTS + " WHERE " + PRO_ID + "=" + id + ""; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(selectQuery, null); Project result = new Project(); if (c.moveToFirst()) { do { result = new Project(c.getInt(0), c.getString(1), this.StringToDate(c.getString(2)), c.getString(3), int_to_boolean(c.getInt(4)), c.getInt(5), c.getInt(6)); } while (c.moveToNext()); } return result; } /** * Gets the name of a project * * @param id * of the project * @return Project Name */ public String getProjectName(int id) { String selectQuery = "SELECT " + PRO_NAME + " FROM " + TABLE_PROJECTS + " WHERE " + PRO_ID + "=" + id + ""; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(selectQuery, null); String result = ""; if (c != null) { c.moveToFirst(); result = c.getString(0); } return result; } /** * Returns the corresponding project of a task. * * @param id * @return Name of the Project */ public String getProjectNameOfTask(int id) { return this.getProjectName(id); } /** * Gets all projects * * @return ArrayList of all projects */ public ArrayList<Project> getAllProjects() { String selectQuery = "SELECT * FROM " + TABLE_PROJECTS; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(selectQuery, null); ArrayList<Project> result = new ArrayList(); if (c != null) { if (c.moveToFirst()) { do { result.add(new Project(c.getInt(0), c.getString(1), this.StringToDate(c.getString(2)), c.getString(3), int_to_boolean(c .getInt(4)), c.getInt(5), c.getInt(6))); } while (c.moveToNext()); } } return result; } /** * We have a distinct table for the task-labe-relationhsip (n:m). This function adds an entry to this table. * * @param task * @param tag */ public void addTaskLabelMapper(int task, String tag) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TASK_ID, task); values.put(LABEL_ID, tag); db.insert(TABLE_MAP, null, values); } /** * Returns the number of task which have the given label. * * @param label * @return Number of Tasks */ public int getNumberOfTasks(Label label) { int result = 0; String query = "SELECT COUNT(" + TASK_ID + ") FROM " + TABLE_MAP + " WHERE " + LABEL_ID + "='" + label.getValue() + "'"; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(query, null); if (c != null) { c.moveToFirst(); result = c.getInt(0); } return result; } /** * Gets the number of tasks of a project. * * @param project * @return Number of Tasks */ public int getNumberOfTasks(Project project) { int result = 0; String query = "SELECT COUNT(" + KEY_ID + ") FROM " + TABLE_TASKS + " WHERE " + PROJECT_ID + "='" + project.getId() + "'"; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(query, null); if (c != null) { c.moveToFirst(); result = c.getInt(0); } return result; } /** * Returns all tasks which belong to the given project * * @param project * @return An ArrayList of Tasks */ public ArrayList<Task> getTasksOfProject(Project project) { ArrayList<Task> result = this.getTasksOfProject(project.getId()); return result; } /** * Returns all tasks which belong to the given project * * @param ProjectId * @return An ArrayList of Tasks */ public ArrayList<Task> getTasksOfProject(int projectId) { ArrayList<Task> result = new ArrayList(); String query = "SELECT * FROM " + TABLE_TASKS + " WHERE " + PROJECT_ID + "='" + projectId + "'"; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(query, null); if (c.moveToFirst()) { do { ArrayList<Label> tags = this.getLabelsForTask(c.getInt(0)); result.add(new Task(c.getInt(0), c.getString(1), tags, c.getString(4), this.StringToDate(c.getString(2)), c.getInt(8), c .getInt(3), this.int_to_boolean(c.getInt(6)), c.getInt(7), c.getInt(5), this.getProjectName(c.getInt(8)))); } while (c.moveToNext()); } return result; } /** * Returns all tasks which belong to a label * * @param label * @return */ public ArrayList<Task> getTasksOfLabel(Label label) { ArrayList<Task> result = this.getTasksOfLabel(label.getValue()); return result; } /** * Returns all tasks which belong to a label * * @param labelName * @return */ public ArrayList<Task> getTasksOfLabel(String labelname) { int[] task_ids = this.getTasksIdOfLabel(labelname); ArrayList<Task> result = new ArrayList(); for (int i = 0; i < task_ids.length; i++) { String query = "SELECT * FROM " + TABLE_TASKS + " WHERE " + KEY_ID + "=" + task_ids[i] + ""; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(query, null); if (c.moveToFirst()) { do { ArrayList<Label> tags = this.getLabelsForTask(c.getInt(0)); result.add(new Task(c.getInt(0), c.getString(1), tags, c.getString(4), this.StringToDate(c.getString(2)), c.getInt(8), c.getInt(3), this.int_to_boolean(c.getInt(6)), c.getInt(7), c.getInt(5), this.getProjectName(c.getInt(8)))); } while (c.moveToNext()); } } return result; } /** * Returns the task_ids which belong to the given label * * @param label * @return */ public int[] getTasksIdOfLabel(String labelname) { String query = "SELECT " + TASK_ID + " FROM " + TABLE_MAP + " WHERE " + LABEL_ID + "='" + labelname + "'"; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(query, null); int[] result = new int[c.getCount()]; int i = 0; if (c.moveToFirst()) { do { result[i] = c.getInt(0); i++; } while (c.moveToNext()); } return result; } /** * Returns true if the int is 1. Returns false if the int is 0. * * @param i * @return boolean */ // public Task[] getAllTasks() { // // String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_TASKS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + NAME + " TEXT," + END // + " INTEGER, " + IMPORTANCE + " INT," + DESCR + " TEXT," + ACTION + " text," + NOTIFICATION + " INTEGER," + STATUS // + " INTEGER," + PROJECT_ID + " INT, FOREIGN KEY(" + PROJECT_ID + ") REFERENCES " + TABLE_PROJECTS + " (" + PRO_ID + "))"; // db.execSQL(CREATE_CONTACTS_TABLE); // // String selectQuery = "SELECT * FROM " + TABLE_TASKS; // // SQLiteDatabase db = this.getWritableDatabase(); // Cursor c = db.rawQuery(selectQuery, null); // // ArrayList<Tasks> tasks; // // if (c.moveToFirst()) { // do { // ArrayList<Tag> tags = new ArrayList(); // String projectName = ""; // tasks.add(new Task(c.getInt(0), c.getString(1), tags, new Date(c.getInt(2)), c.getInt(3), c.getString(4), c.getInt(6), c // .getInt(7))); // // selectQuery = "SELECT t1.L_NAME FROM " + TABLE_LABELS + " t1 " + TABLE_MAP + " t2 WHERE t2." + TASK_ID + "= " // // + cursor.getInt(0) + " AND t1." + L_NAME + "=t2." + LABEL_ID + ""; // // Cursor c2 = db.rawQuery(selectQuery, null); // // if (c2.moveToFirst()) { // // do { // // // // } while (c2.moveToNext()); // // } // } while (c.moveToNext()); // } // } private boolean int_to_boolean(int i) { if (i == 0) { return false; } if (i == 1) { return true; } return false; } private int boolean_to_int(boolean b) { if (b) { return 1; } else { return 0; } } private Date StringToDate(String string) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = null; try { date = format.parse(string); } catch (ParseException e) { e.printStackTrace(); } return date; } private String DateToString(Date date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format.format(date); } private String numberToDoubleDigit(int integer) { if (integer < 10) { return "0" + integer; } else { return "" + integer; } } }