Android Open Source - HeadphoneController Db Helper






From Project

Back to project page HeadphoneController.

License

The source code is released under:

GNU General Public License

If you think the Android project HeadphoneController 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 ca.mbabic.headphonecontroller.db;
//  ww w .  j  ava 2 s . co  m
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper {

  /**
   * Db version number.
   */
  private static final int DB_VERSION = 1;
  
  /**
   * COMMAND table execution statement.
   */
  private static final String createCommandTableStmt = 
      "CREATE TABLE COMMAND("       +
        "id int PRIMARY KEY NOT NULL, "   +
        "key text NOT NULL, "      +
        "name text NOT NULL"      +
      ");";
  
  /**
   * CALLSTATE table creation statement.
   */
  private static final String createCallStateTableStmt =
      "CREATE TABLE CALLSTATE("       +
        "id int PRIMARY KEY NOT NULL, " +
        "name text NOT NULL"       +
      ");";
  
  /**
   * COMMAND_CALLSTATES table -- the table encoding the call states
   * in which a command can be executed -- creation statement.
   */
  private static final String createCommandCallStatesTableStmt =
      "CREATE TABLE COMMAND_CALLSTATES("            +
        "command_id int, "                   +
        "callstate_id int, "                 +
        "FOREIGN KEY (command_id) REFERENCES COMMAND(id), "  +
        "FOREIGN KEY (callstate_id) REFERENCE CALLSTATE(id)"+
      ");";
  
  /**
   * INPUTSEQUENCE table creation statement.
   */
  private static final String createInputSequenceTableStmt = 
      "CREATE TABLE INPUTSEQUENCE("     +
        "id int PRIMARY KEY NOT NULL, "   +
        "key text NOT NULL, "       +
        "name text NOT NULL"       +
      ");";
  
  /**
   * INPUTSEQUENCE_COMMANDS table -- the table encoding the commands
   * to be executed for the given input sequence in a particular call
   * state -- creation statement.
   */
  private static final String createISCommandsTableStmt = 
      "CREATE TABLE INPUTSEQUENCE_COMMANDS("   +
        "inputsequence_id int, "       +
        "command_id int, "           +
        "callstate_id int, "         +
        "FOREIGN KEY (inputsequence_id) REFERENCES INPUTSEQUENCE(id), " +
        "FOREIGN KEY (command_id) REFERENCES COMMAND(id), " +
        "FOREIGN KEY (callstate_id) REFERENCES CALLSTATE(id)" +
      ");";
  
  public DbHelper(Context context, String name) {
    super(context, name, null, DB_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    executeCreationStatements(db);    
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    
  }
  
  /**
   * Executes table creation statement.
   * @param db
   *     The database instance on which to execute the commands.
   */
  private void executeCreationStatements(SQLiteDatabase db) {
    
    db.execSQL(createCommandTableStmt);
    db.execSQL(createCallStateTableStmt);
    db.execSQL(createCommandCallStatesTableStmt);
    db.execSQL(createInputSequenceTableStmt);
    db.execSQL(createISCommandsTableStmt);
  }

}




Java Source Code List

ca.mbabic.headphonecontroller.ConfigurationFragment.java
ca.mbabic.headphonecontroller.HCApplication.java
ca.mbabic.headphonecontroller.HomeActivity.java
ca.mbabic.headphonecontroller.SelectCommandActivity.java
ca.mbabic.headphonecontroller.commands.CommandExecutor.java
ca.mbabic.headphonecontroller.commands.HCCommandContext.java
ca.mbabic.headphonecontroller.commands.HCCommandFactory.java
ca.mbabic.headphonecontroller.commands.HCCommand.java
ca.mbabic.headphonecontroller.commands.MuteMusicCommand.java
ca.mbabic.headphonecontroller.commands.NoOpCommand.java
ca.mbabic.headphonecontroller.commands.PlayPauseCommand.java
ca.mbabic.headphonecontroller.commands.PreviousCommand.java
ca.mbabic.headphonecontroller.commands.SkipCommand.java
ca.mbabic.headphonecontroller.configuration.HCConfigAdapter.java
ca.mbabic.headphonecontroller.configuration.HCConfigConstants.java
ca.mbabic.headphonecontroller.db.DbHelper.java
ca.mbabic.headphonecontroller.db.HCCallStateTable.java
ca.mbabic.headphonecontroller.db.HCCommandCallStateTable.java
ca.mbabic.headphonecontroller.db.HCCommandTable.java
ca.mbabic.headphonecontroller.db.HCDbAdapter.java
ca.mbabic.headphonecontroller.db.HCDbHelper.java
ca.mbabic.headphonecontroller.db.HCDbTable.java
ca.mbabic.headphonecontroller.db.HCInputSequenceCommandsTable.java
ca.mbabic.headphonecontroller.db.HCInputSequenceTable.java
ca.mbabic.headphonecontroller.models.HCCmd.java
ca.mbabic.headphonecontroller.models.HCInputSequence.java
ca.mbabic.headphonecontroller.services.MediaButtonListenerService.java
ca.mbabic.headphonecontroller.services.MediaButtonReceiver.java
ca.mbabic.headphonecontroller.services.MediaStateChangeReceiver.java
ca.mbabic.headphonecontroller.statemachine.FourPressState.java
ca.mbabic.headphonecontroller.statemachine.HCStateMachine.java
ca.mbabic.headphonecontroller.statemachine.HCState.java
ca.mbabic.headphonecontroller.statemachine.InactiveState.java
ca.mbabic.headphonecontroller.statemachine.OnePressState.java
ca.mbabic.headphonecontroller.statemachine.ThreePressState.java
ca.mbabic.headphonecontroller.statemachine.TwoPressState.java
ca.mbabic.headphonecontroller.views.CommandAdapter.java