Android Open Source - myToDo Memo D A O






From Project

Back to project page myToDo.

License

The source code is released under:

Apache License

If you think the Android project myToDo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gutspot.apps.android.mytodo.dao;
/*  w  w  w . j a  va 2 s  .  c om*/
import java.util.Date;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.gutspot.apps.android.mytodo.model.Memo;

public class MemoDAO extends AbstractDAO<Memo> {

    private static final String TABLE_NAME = "memo";

    private static final String COLUMN_TODO_ID = "todo_id";
    private static final String COLUMN_CONTENT = "content";
    private static final String COLUMN_TEXT_COLOR = "text_color";
    private static final String COLUMN_BACKGROUND_COLOR = "background_color";
    private static final String COLUMN_CREATED = "created";

    public MemoDAO(Context context) {
        super(context, TABLE_NAME);
    }

    public Memo findFirstByToDoId(long toDoId) {
        String selection = COLUMN_TODO_ID + "=?";
        String[] selectionArgs = new String[] { String.valueOf(toDoId) };
        String orderBy = COLUMN_CREATED + " asc";
        String limit = "1";
        List<Memo> memos = this.find(selection, selectionArgs, null, null, orderBy, limit);
        if (memos.size() == 0) {
            return null;
        }
        return memos.get(0);
    }

    public List<Memo> findByToDoId(long toDoId) {
        String selection = COLUMN_TODO_ID + "=?";
        String[] selectionArgs = new String[] { String.valueOf(toDoId) };
        return this.find(selection, selectionArgs);
    }

    public int removeByToDoId(long toDoId) {
        String selection = COLUMN_TODO_ID + "=?";
        String[] selectionArgs = new String[] { String.valueOf(toDoId) };
        return remove(selection, selectionArgs);
    }

    @Override
    protected ContentValues createValues(Memo entity, ContectValuesState state) {
        ContentValues values = super.createValues(entity, state);

        values.put(COLUMN_TODO_ID, entity.getToDoId());
        values.put(COLUMN_CONTENT, entity.getContent());
        values.put(COLUMN_TEXT_COLOR, entity.getTextColor());
        values.put(COLUMN_BACKGROUND_COLOR, entity.getBackgroundColor());
        if (state == ContectValuesState.CREATE) {
            values.put(COLUMN_CREATED, entity.getCreated().getTime());
        }

        return values;
    }

    @Override
    protected Memo parseValuse(Cursor cursor) {
        Memo memo = new Memo(cursor.getLong(cursor.getColumnIndex(COLUMN_ID)),
                cursor.getLong(cursor.getColumnIndex(COLUMN_VERSION)));

        memo.setToDoId(cursor.getLong(cursor.getColumnIndex(COLUMN_TODO_ID)));
        memo.setContent(cursor.getString(cursor.getColumnIndex(COLUMN_CONTENT)));
        memo.setTextColor(cursor.getInt(cursor.getColumnIndex(COLUMN_TEXT_COLOR)));
        memo.setBackgroundColor(cursor.getInt(cursor.getColumnIndex(COLUMN_BACKGROUND_COLOR)));
        memo.setCreated(new Date(cursor.getLong(cursor.getColumnIndex(COLUMN_CREATED))));

        return memo;
    }

}




Java Source Code List

com.gutspot.apps.android.mytodo.MainActivity.java
com.gutspot.apps.android.mytodo.MemoActivity.java
com.gutspot.apps.android.mytodo.ToDoActivity.java
com.gutspot.apps.android.mytodo.adapter.MemoAdapter.java
com.gutspot.apps.android.mytodo.adapter.ToDoAdapter.java
com.gutspot.apps.android.mytodo.dao.AbstractDAO.java
com.gutspot.apps.android.mytodo.dao.MemoDAO.java
com.gutspot.apps.android.mytodo.dao.NoticeDAO.java
com.gutspot.apps.android.mytodo.dao.ToDoDAO.java
com.gutspot.apps.android.mytodo.dialog.DateTimeDialog.java
com.gutspot.apps.android.mytodo.dialog.MemoOptionsDialog.java
com.gutspot.apps.android.mytodo.dialog.ToDoOptionsDialog.java
com.gutspot.apps.android.mytodo.model.AbstractEntity.java
com.gutspot.apps.android.mytodo.model.Memo.java
com.gutspot.apps.android.mytodo.model.Notice.java
com.gutspot.apps.android.mytodo.model.ToDo.java
com.gutspot.apps.android.mytodo.utils.AlertUtil.java
com.gutspot.apps.android.mytodo.utils.DBOpenHelper.java
com.gutspot.apps.android.mytodo.utils.DateTimeUtil.java