Android Open Source - SoundScheduler Rules Database Helper






From Project

Back to project page SoundScheduler.

License

The source code is released under:

GNU General Public License

If you think the Android project SoundScheduler 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

/*
 * Sound Scheduler/*w  w w . j  av  a  2 s .c o  m*/
 * Copyright (C) 2013 Victor Kifer
 */

package com.victorkifer.SoundScheduler.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.victorkifer.SoundScheduler.entities.Rule;

public class RulesDatabaseHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "rules.db";
    private static final int DATABASE_VERSION = 8;

    public static final String TABLE_RULES = "rules";
    public static final String RULES_COLUMN_ID = "_id";
    public static final String RULES_COLUMN_START = "start";
    public static final String RULES_COLUMN_END = "end";
    public static final String RULES_COLUMN_ACTIVE = "active";
    public static final String RULES_COLUMN_APPLIED = "applied";
    public static final String RULES_COLUMN_REPEAT = "repeat";
    public static final String RULES_COLUMN_STATE_BEFORE = "beforestate";
    public static final String RULES_COLUMN_STATE_TO_APPLY = "statetoapply";

    private static final String RULES_DATABASE_CREATE =
            "CREATE TABLE " + TABLE_RULES + "(" +
                    RULES_COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    RULES_COLUMN_START + " INTEGER NOT NULL, " +
                    RULES_COLUMN_END + " INTEGER NOT NULL, " +
                    RULES_COLUMN_ACTIVE + " INTEGER, " +
                    RULES_COLUMN_APPLIED + " INTEGER, " +
                    RULES_COLUMN_REPEAT + " INTEGER, " +
                    RULES_COLUMN_STATE_BEFORE + " INTEGER, " +
                    RULES_COLUMN_STATE_TO_APPLY + " INTEGER" +
            ");";

    public RulesDatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(RULES_DATABASE_CREATE);

        ContentValues values = new ContentValues();
        values.put(RULES_COLUMN_START, 0);
        values.put(RULES_COLUMN_END, 25200000);
        values.put(RULES_COLUMN_ACTIVE, 0);
        // repeat from monday to friday
        values.put(RULES_COLUMN_REPEAT, 31);
        values.put(RULES_COLUMN_APPLIED, 0);
        values.put(RULES_COLUMN_STATE_BEFORE, Rule.STATE_NULL);
        values.put(RULES_COLUMN_STATE_TO_APPLY, Rule.STATE_SILENT);

        db.insert(RulesDatabaseHelper.TABLE_RULES,
                null,
                values);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_RULES);
        onCreate(db);
    }
}




Java Source Code List

com.victorkifer.SoundScheduler.AboutActivity.java
com.victorkifer.SoundScheduler.EditRuleActivity.java
com.victorkifer.SoundScheduler.MainActivity.java
com.victorkifer.SoundScheduler.adapters.RuleListAdapter.java
com.victorkifer.SoundScheduler.database.RulesDataSource.java
com.victorkifer.SoundScheduler.database.RulesDatabaseHelper.java
com.victorkifer.SoundScheduler.entities.Rule.java
com.victorkifer.SoundScheduler.listeners.RuleDeleteListener.java
com.victorkifer.SoundScheduler.listeners.RuleItemStateListener.java
com.victorkifer.SoundScheduler.managers.SoundManager.java
com.victorkifer.SoundScheduler.receivers.BootCompleteReceiver.java
com.victorkifer.SoundScheduler.receivers.TimeChangeReceiver.java