コード例 #1
0
  /**
   * Set/remove as favorite using SharedPreferences, can't repeat names The type of operation is
   * switched by a boolean
   */
  public static void handlePreference(String where, String key, String value, boolean add) {

    SharedPreferences prefs = mContext.getSharedPreferences(where, Context.MODE_PRIVATE);
    Editor editor = prefs.edit();

    if (!add) {
      Log.i("OUT", "Removing " + key);
      editor.remove(key);
    } else {
      Log.i("OUT", "Putting favorite " + key);
      editor.putString(key, value);
    }

    editor.commit();
  }
コード例 #2
0
  // update new position
  public static void updateDB(String tableName, long id, String newValue) {

    mDb = mDbHelper.getReadableDatabase();

    // New value for one column
    ContentValues values = new ContentValues();
    values.put(tableName, newValue);

    int count = mDb.update(FeedEntry.TABLE_NAME, values, FeedEntry._ID + " = '" + id + "'", null);

    Log.i(
        "OUT",
        "Updated: " + count + " with " + tableName + " updated with " + newValue + " where " + id);

    mDb.close();
  }
コード例 #3
0
  /**
   * ********************************************* HISTORY TABLE
   * *****************************************************
   */
  public static void writeDBHistory(
      String name, String path, String time, String type, String date) {

    // Gets the data repository in write mode
    mDb = mDbHelper.getWritableDatabase();

    Log.i("OUT", "Adding: " + name);

    // Create a new map of values, where column names are the keys
    ContentValues values = new ContentValues();
    values.put(FeedEntry.HISTORY_MODEL, name);
    values.put(FeedEntry.HISTORY_PATH, path);
    values.put(FeedEntry.HISTORY_TIME, time);
    values.put(FeedEntry.HISTORY_PRINTER, type);
    values.put(FeedEntry.HISTORY_DATE, date);

    mDb.insert(FeedEntry.TABLE_HISTORY_NAME, null, values);
    mDb.close();
  }
コード例 #4
0
  // Add a new element to the permanent database
  public static long writeDb(
      String name, String address, String position, String type, String network) {

    // Gets the data repository in write mode
    mDb = mDbHelper.getWritableDatabase();

    Log.i("OUT", "Adding: " + name);
    // Create a new map of values, where column names are the keys
    ContentValues values = new ContentValues();
    values.put(FeedEntry.DEVICES_NAME, name);
    values.put(FeedEntry.DEVICES_ADDRESS, address);
    values.put(FeedEntry.DEVICES_POSITION, position);
    values.put(FeedEntry.DEVICES_DISPLAY, name);
    values.put(FeedEntry.DEVICES_TYPE, type);
    values.put(FeedEntry.DEVICES_NETWORK, network);

    long id = mDb.insert(FeedEntry.TABLE_NAME, null, values);
    mDb.close();

    MainActivity.refreshDevicesCount();

    return id;
  }