コード例 #1
0
  // Getting All Features
  public List<Feature> getAllFeatures() {
    List<Feature> featureList = new ArrayList<Feature>();
    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE_FEATURES;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
      do {
        Feature feature = new Feature();
        feature.setID(Integer.parseInt(cursor.getString(0)));
        feature.setName(cursor.getString(1));
        feature.setL1Norm(Double.parseDouble(cursor.getString(2)));
        feature.setL2Norm(Double.parseDouble(cursor.getString(3)));
        feature.setLinfNorm(Double.parseDouble(cursor.getString(4)));
        feature.setTimestamp(Double.parseDouble(cursor.getString(5)));
        feature.setDiffSecs(Double.parseDouble(cursor.getString(6)));
        feature.setMfccsAsString(cursor.getString(7));
        feature.setPsdAcrossFrequencyBandsAsString(cursor.getString(8));
        // Adding feature to list
        featureList.add(feature);
      } while (cursor.moveToNext());
    }

    db.close(); // Closing database connection
    // return feature list
    return featureList;
  }
コード例 #2
0
  // Adding new feature
  public void addFeature(Feature feature) {

    try {
      SQLiteDatabase db = this.getWritableDatabase();

      ContentValues values = new ContentValues();
      values.put(KEY_LABEL, feature.getName()); // Feature Name
      values.put(KEY_MFCC, feature.getMfccsAsString()); // Feature mfcc
      values.put(KEY_L1NORM, feature.getL1Norm());
      values.put(KEY_L2NORM, feature.getL2Norm());
      values.put(KEY_LINFNORM, feature.getLinfNorm());
      values.put(KEY_TIMESTAMP, feature.getTimestamp());
      values.put(KEY_DIFFSECS, feature.getDiffSecs());
      values.put(KEY_PSDACROSSFREQUENCYBANDS, feature.getPsdAcrossFrequencyBandsAsString());

      // Inserting Row
      db.insert(TABLE_FEATURES, null, values);
      Log.d(LogUtil.TAG, " New feature added");
    } catch (Exception e) {
      Log.d(LogUtil.TAG, " Exception while adding new feature.");
    }
    // db.close(); // Closing database connection, closing outside, need to fix
  }
コード例 #3
0
 // Deleting single feature
 public void deleteFeature(Feature feature) {
   SQLiteDatabase db = this.getWritableDatabase();
   db.delete(TABLE_FEATURES, KEY_ID + " = ?", new String[] {String.valueOf(feature.getID())});
   db.close();
 }