Android Open Source - donatello-y-raphael Progress Adapter






From Project

Back to project page donatello-y-raphael.

License

The source code is released under:

MIT License

If you think the Android project donatello-y-raphael 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.example.ATracePath;
//from  www. j  ava  2 s  . c o m
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

/**
 * Created by ranrath on 22/09/14.
 */
public class ProgressAdapter {
    private SQLiteDatabase db;
    private DbHelper dbHelper;
    private Context context;

    public ProgressAdapter(Context context) {
        this.context = context;
    }

    private ProgressAdapter openToRead() {
        dbHelper = new DbHelper(context);
        db = dbHelper.getReadableDatabase();
        return this;
    }

    private ProgressAdapter openToWrite() {
        dbHelper = new DbHelper(context);
        db = dbHelper.getWritableDatabase();
        return this;
    }

    private void close() { db.close(); }

    public long insertBoard(int puzzleId, int packId, int challengeId) {
        String[] cols = DbHelper.TableProgressColumns;
        ContentValues values = new ContentValues();
        values.put(cols[1], puzzleId);
        values.put(cols[2], packId);
        values.put(cols[3], challengeId);
        values.put(cols[4], true);

        openToWrite();
        long value = db.insert(DbHelper.TableProgress, null, values);
        close();

        return value;
    }

    public boolean getBoardById(int puzzleID, int packID, int challengeID) {

        String[] cols = DbHelper.TableProgressColumns;
        openToRead();
        String query = cols[1] + "=" + puzzleID + " AND " + cols[2] + "=" + packID  + " AND " + cols[3] + "=" + challengeID;
        Cursor cursor = db.query(DbHelper.TableProgress, cols, query, null, null, null, null);
        int results = cursor.getCount();
        close();

        return results == 0 ? false : true;
    }

    public long resetProgress() {
        openToWrite();
        long value = db.delete(DbHelper.TableProgress, "1", null);
        close();
        return value;
    }
}




Java Source Code List

com.example.ATracePath.Board.java
com.example.ATracePath.Cellpath.java
com.example.ATracePath.Challenge.java
com.example.ATracePath.Coordinate.java
com.example.ATracePath.DbHelper.java
com.example.ATracePath.Global.java
com.example.ATracePath.LevelsActivity.java
com.example.ATracePath.MainActivity.java
com.example.ATracePath.MapsActivity.java
com.example.ATracePath.Pack.java
com.example.ATracePath.PlayActivity.java
com.example.ATracePath.ProgressAdapter.java
com.example.ATracePath.Puzzle.java
com.example.ATracePath.SettingsActivity.java