Android Open Source - SpeechWriter Note Card Data Source






From Project

Back to project page SpeechWriter.

License

The source code is released under:

MIT License

If you think the Android project SpeechWriter 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 edu.psu.rcy5017.speechwriter.datasource;
/* w  w w.  ja  v a 2 s . c  om*/
import java.util.ArrayList;
import java.util.List;

import edu.psu.rcy5017.speechwriter.DatabaseHelper;
import edu.psu.rcy5017.speechwriter.model.NoteCard;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

public class NoteCardDataSource extends DataSource<NoteCard> {
    
    private static final String TAG = "NoteCardDataSource";
    
    private String[] allColumns = { DatabaseHelper.COLUMN_ID,
            DatabaseHelper.NOTECARD_TITLE, DatabaseHelper.SPEECH_ID };

    public NoteCardDataSource(Context context) {
        super(context);
    }
    
    /**
     * Creates a new note card in the database.
     * @param title the title of the note card
     * @param speech the speech that the note card belongs to
     * @return the note card created
     */
    public NoteCard createNoteCard(String title, long speechID) {
        final int DEFAULT_ORDER = 0;
        final ContentValues values = new ContentValues();
        values.put(DatabaseHelper.NOTECARD_TITLE, title);
        values.put(DatabaseHelper.NOTECARD_ORDER, DEFAULT_ORDER);
        values.put(DatabaseHelper.SPEECH_ID, speechID);
        long insertId = getDatabase().insert(DatabaseHelper.NOTECARD_TABLE_NAME, null,
                values);
        Cursor cursor = getDatabase().query(DatabaseHelper.NOTECARD_TABLE_NAME,
                allColumns, DatabaseHelper.COLUMN_ID + " = " + insertId, null,
                null, null, null);
        cursor.moveToFirst();
        NoteCard noteCard = cursorToNoteCard(cursor);
        cursor.close();
        return noteCard;
    }
        
    /**
     * Renames the note card in the database.
     * @param noteCard the note card to rename
     * @param newTitle the new title to rename this notecard
     * @return the number of rows affected
     */
    public int renameNotecard(NoteCard noteCard, String newTitle) {
        final ContentValues args = new ContentValues();
        args.put(DatabaseHelper.NOTECARD_TITLE, newTitle);
        return getDatabase().update(
                DatabaseHelper.NOTECARD_TABLE_NAME, args, DatabaseHelper.COLUMN_ID + "=" + noteCard.getId(), null);
    }
         
    /**
     * Converts a cursor to a note card.
     * @param cursor the cursor to convert
     * @return the note card
     */
    private NoteCard cursorToNoteCard(Cursor cursor) {
        final long newNoteCardId = cursor.getLong(0);
        final String newNoteCardTitle = cursor.getString(1);
        final long newNoteCardSpeechId = cursor.getLong(2);
        final NoteCard noteCard = new NoteCard(newNoteCardId, newNoteCardTitle, newNoteCardSpeechId);
        
        return noteCard;
    }

    @Override
    public List<NoteCard> getAll(long parentID) {
        final List<NoteCard> noteCards = new ArrayList<NoteCard>();
        
        final String selection = DatabaseHelper.SPEECH_ID + "=" + parentID;
        Cursor cursor = getDatabase().query(DatabaseHelper.NOTECARD_TABLE_NAME,
                allColumns, selection, null, null, null, DatabaseHelper.NOTE_ORDER);

        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            NoteCard noteCard = cursorToNoteCard(cursor);
            noteCards.add(noteCard);
            cursor.moveToNext();
        }
        // make sure to close the cursor
        cursor.close();
        return noteCards;
    }

    @Override
    public void deleteObject(NoteCard noteCardToDelete) {
        long id = noteCardToDelete.getId();
        Log.d(TAG, "Note card deleted with id: " + id);
        getDatabase().delete(DatabaseHelper.NOTECARD_TABLE_NAME, DatabaseHelper.COLUMN_ID
                + " = " + id, null);
    }

    @Override
    public int ubdateOrder(NoteCard noteCardToUpdate, int newOrder) {
        final ContentValues args = new ContentValues();
        args.put(DatabaseHelper.NOTECARD_ORDER, newOrder);
        return getDatabase().update(
                DatabaseHelper.NOTECARD_TABLE_NAME, args, DatabaseHelper.COLUMN_ID + "=" + noteCardToUpdate.getId(), null);
    }

}




Java Source Code List

com.ericharlow.DragNDrop.DragListener.java
com.ericharlow.DragNDrop.DragNDropAdapter.java
com.ericharlow.DragNDrop.DragNDropListView.java
com.ericharlow.DragNDrop.DropListener.java
com.ericharlow.DragNDrop.RemoveListener.java
edu.psu.rcy5017.speechwriter.DatabaseHelper.java
edu.psu.rcy5017.speechwriter.activity.EditTextActivity.java
edu.psu.rcy5017.speechwriter.activity.MainActivity.java
edu.psu.rcy5017.speechwriter.activity.NoteCardListActivity.java
edu.psu.rcy5017.speechwriter.activity.NoteListActivity.java
edu.psu.rcy5017.speechwriter.activity.OptionsActivity.java
edu.psu.rcy5017.speechwriter.activity.SpeechListActivity.java
edu.psu.rcy5017.speechwriter.activity.SpeechRecordingListActivity.java
edu.psu.rcy5017.speechwriter.activity.SplashScreenActivity.java
edu.psu.rcy5017.speechwriter.adapter.TabsPagerAdapter.java
edu.psu.rcy5017.speechwriter.constant.DefaultValues.java
edu.psu.rcy5017.speechwriter.constant.MiscConstants.java
edu.psu.rcy5017.speechwriter.constant.RequestCodes.java
edu.psu.rcy5017.speechwriter.controller.AudioCntl.java
edu.psu.rcy5017.speechwriter.controller.OptionsCntl.java
edu.psu.rcy5017.speechwriter.datasource.DataSource.java
edu.psu.rcy5017.speechwriter.datasource.NoteCardDataSource.java
edu.psu.rcy5017.speechwriter.datasource.NoteDataSource.java
edu.psu.rcy5017.speechwriter.datasource.SpeechDataSource.java
edu.psu.rcy5017.speechwriter.datasource.SpeechRecordingDataSource.java
edu.psu.rcy5017.speechwriter.fragment.NoteCardFragement.java
edu.psu.rcy5017.speechwriter.listener.ChangeFontSizeListener.java
edu.psu.rcy5017.speechwriter.listener.DragListenerImpl.java
edu.psu.rcy5017.speechwriter.listener.DropListenerImpl.java
edu.psu.rcy5017.speechwriter.listener.DropReorderListener.java
edu.psu.rcy5017.speechwriter.listener.RemoveListenerImpl.java
edu.psu.rcy5017.speechwriter.model.NoteCard.java
edu.psu.rcy5017.speechwriter.model.Note.java
edu.psu.rcy5017.speechwriter.model.SpeechRecording.java
edu.psu.rcy5017.speechwriter.model.Speech.java
edu.psu.rcy5017.speechwriter.task.ChangeNoteTextTask.java
edu.psu.rcy5017.speechwriter.task.CreateNoteCardTask.java
edu.psu.rcy5017.speechwriter.task.CreateNoteTask.java
edu.psu.rcy5017.speechwriter.task.CreateSpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.CreateSpeechTask.java
edu.psu.rcy5017.speechwriter.task.DeleteTask.java
edu.psu.rcy5017.speechwriter.task.GetAllTask.java
edu.psu.rcy5017.speechwriter.task.NoteCardTask.java
edu.psu.rcy5017.speechwriter.task.NoteTask.java
edu.psu.rcy5017.speechwriter.task.RenameNoteCardTask.java
edu.psu.rcy5017.speechwriter.task.RenameSpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.RenameSpeechTask.java
edu.psu.rcy5017.speechwriter.task.SpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.SpeechTask.java
edu.psu.rcy5017.speechwriter.task.UpdateOrderTask.java