Java Code Examples for android.content.ContentValues

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/repository/.

Source file: MeasurementRepository.java

  20 
vote

@Internal void save(List<Measurement> measurementsToSave,long sessionId,long streamId,SQLiteDatabase writableDatabase){
  ContentValues values=new ContentValues(6);
  values.put(MEASUREMENT_SESSION_ID,sessionId);
  values.put(MEASUREMENT_STREAM_ID,streamId);
  for (  Measurement measurement : measurementsToSave) {
    values.put(MEASUREMENT_LONGITUDE,measurement.getLongitude());
    values.put(MEASUREMENT_LATITUDE,measurement.getLatitude());
    values.put(MEASUREMENT_VALUE,measurement.getValue());
    values.put(MEASUREMENT_TIME,measurement.getTime().getTime());
    writableDatabase.insertOrThrow(MEASUREMENT_TABLE_NAME,null,values);
  }
}
 

Example 2

From project Airports, under directory /src/com/nadmm/airports/.

Source file: DatabaseManager.java

  18 
vote

public long addToFavoriteAirports(String siteNumber){
  SQLiteDatabase userDataDb=getUserDataDb();
  ContentValues values=new ContentValues();
  values.put(Favorites.TYPE,"APT");
  values.put(Favorites.LOCATION_ID,siteNumber);
  return userDataDb.insert(Favorites.TABLE_NAME,null,values);
}
 

Example 3

From project and-bible, under directory /AndBible/src/net/bible/service/db/bookmark/.

Source file: BookmarkDBAdapter.java

  18 
vote

public BookmarkDto insertBookmark(BookmarkDto bookmark){
  ContentValues newValues=new ContentValues();
  newValues.put(BookmarkColumn.KEY,bookmark.getKey().getOsisID());
  long newId=db.insert(Table.BOOKMARK,null,newValues);
  BookmarkDto newBookmark=getBookmarkDto(newId);
  return newBookmark;
}
 

Example 4

From project andlytics, under directory /src/com/github/andlyticsproject/.

Source file: ContentAdapter.java

  18 
vote

public void insertOrUpdateAdmobStats(Admob admob){
  ContentValues value=createAdmobContentValues(admob);
  long existingId=getAdmobStatsIdForDate(admob.getDate(),admob.getSiteId());
  if (existingId > -1) {
    context.getContentResolver().update(AdmobTable.CONTENT_URI,value,AdmobTable.KEY_ROWID + "=" + existingId,null);
  }
 else {
    context.getContentResolver().insert(AdmobTable.CONTENT_URI,value);
  }
}
 

Example 5

From project Android, under directory /app/src/main/java/com/github/mobile/persistence/.

Source file: Organizations.java

  18 
vote

@Override public void store(SQLiteDatabase db,List<User> orgs){
  db.delete("orgs",null,null);
  if (orgs.isEmpty())   return;
  ContentValues values=new ContentValues(3);
  for (  User user : orgs) {
    values.clear();
    values.put("id",user.getId());
    db.replace("orgs",null,values);
    values.put("name",user.getLogin());
    values.put("avatarurl",user.getAvatarUrl());
    db.replace("users",null,values);
  }
}
 

Example 6

From project android-bankdroid, under directory /src/com/liato/bankdroid/db/.

Source file: DBAdapter.java

  18 
vote

public void disableBank(long bankId){
  if (bankId == -1)   return;
  ContentValues initialValues=new ContentValues();
  initialValues.put("disabled",1);
  mDb.update("banks",initialValues,"_id=" + bankId,null);
}
 

Example 7

From project Android-Battery-Widget, under directory /src/com/em/batterywidget/storage/.

Source file: SQLiteDataBase.java

  18 
vote

public long insertEntry(Entry entry){
  ContentValues values=new ContentValues();
  values.put(Constants.KEY_TIME,entry.date.getTime());
  values.put(Constants.KEY_LEVEL,entry.level);
  return sqLiteDataBase.insert(Constants.DB_TABLE,null,values);
}
 

Example 8

From project android-client_1, under directory /src/com/googlecode/asmack/contacts/.

Source file: ContactDataMapper.java

  18 
vote

/** 
 * Save a single status update.
 * @param statusUpdate The status update to be stored.
 */
public void persist(StatusUpdate statusUpdate){
  ContentValues values=new ContentValues();
  try {
    put(values,statusUpdate);
    provider.insert(StatusUpdates.CONTENT_URI,values);
  }
 catch (  RemoteException e) {
    e.printStackTrace();
  }
}
 

Example 9

From project android-context, under directory /defunct/.

Source file: ContextBrowserActivity.java

  18 
vote

private void processAdd(DialogWrapper wrapper){
  ContentValues values=new ContentValues(2);
  values.put(ContextProvider.Cntxt.TITLE,wrapper.getTitle());
  values.put(ContextProvider.Cntxt.VALUE,wrapper.getValue());
  getContentResolver().insert(ContextProvider.Cntxt.CONTENT_URI,values);
  contextCursor.requery();
}
 

Example 10

From project android-cropimage, under directory /src/com/android/camera/gallery/.

Source file: Image.java

  18 
vote

protected void setDegreesRotated(int degrees){
  if (mRotation == degrees)   return;
  mRotation=degrees;
  ContentValues values=new ContentValues();
  values.put(ImageColumns.ORIENTATION,mRotation);
  mContentResolver.update(mUri,values,null,null);
}
 

Example 11

From project android-database-sqlcipher, under directory /dist/SQLCipherForAndroid-SDK/samples/basic/example/.

Source file: SQLDemoActivity.java

  18 
vote

private void addEvent(String title,SQLiteDatabase db){
  ContentValues values=new ContentValues();
  values.put(EventDataSQLHelper.TIME,System.currentTimeMillis());
  values.put(EventDataSQLHelper.TITLE,title);
  db.insert(EventDataSQLHelper.TABLE,null,values);
}
 

Example 12

From project Android-FFXIEQ, under directory /ffxieq/src/com/github/kanata3249/ffxieq/android/db/.

Source file: FFXIEQSettings.java

  18 
vote

public void useFilter(long id){
  ContentValues values=new ContentValues();
  SQLiteDatabase db=getWritableDatabase();
  values.put(C_LastUsed,System.currentTimeMillis());
  db.beginTransaction();
  try {
    db.update(TABLE_NAME_FILTERS,values,C_Id + " ='" + id+ "'",null);
    db.setTransactionSuccessful();
  }
  finally {
    db.endTransaction();
  }
  dataChanged();
}
 

Example 13

From project android-flash-cards, under directory /src/org/thomasamsler/android/flashcards/db/.

Source file: DataSource.java

  18 
vote

public void createCardSet(CardSet cardSet){
  try {
    ContentValues contentValues=new ContentValues();
    contentValues.put(DatabaseHelper.CST_CARD_SET_ID,cardSet.getExternalId());
    contentValues.put(DatabaseHelper.CST_TITLE,cardSet.getTitle());
    contentValues.put(DatabaseHelper.CST_CARD_COUNT,cardSet.getCardCount());
    SQLiteDatabase db=mDbH.getWritableDatabase();
    long id=db.insert(DatabaseHelper.TABLE_CARD_SETS,null,contentValues);
    cardSet.setId(id);
  }
 catch (  Exception e) {
    Log.e(LOG_TAG,"EXCEPTION: " + e.getMessage());
  }
}
 

Example 14

From project Android-GifStitch, under directory /src/com/phunkosis/gifstitch/helpers/.

Source file: ShareHelper.java

  18 
vote

public void addRow(String gifPath,String url){
  ContentValues values=new ContentValues();
  values.put(COL_GIFPATH,gifPath);
  values.put(COL_URL,url);
  try {
    SQLiteDatabase db=this.getWritableDatabase();
    db.insert(TABLE_NAME,null,values);
  }
 catch (  Exception ex) {
    Log.e("DB ERROR",ex.toString());
    ex.printStackTrace();
  }
}
 

Example 15

From project android-joedayz, under directory /Proyectos/TareasSQLite/src/com/androideity/tareasqlite/database/.

Source file: DBAdapter.java

  18 
vote

private ContentValues createContentValues(String category,String summary,String description){
  ContentValues values=new ContentValues();
  values.put(KEY_CATEGORY,category);
  values.put(KEY_SUMMARY,summary);
  values.put(KEY_DESCRIPTION,description);
  return values;
}
 

Example 16

From project android-sdk, under directory /src/main/java/com/mobeelizer/mobile/android/.

Source file: MobeelizerDatabaseImpl.java

  18 
vote

void lockModifiedFlag(){
  for (  MobeelizerAndroidModel model : modelsByName.values()) {
    model.lockModifiedFlag(database);
  }
  ContentValues values=new ContentValues();
  values.put(_FILE_MODIFIED,2);
  database.update(_FILE_TABLE_NAME,values,_FILE_MODIFIED + " = 1",null);
}
 

Example 17

From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/core/model/persistence/.

Source file: TaskPersister.java

  18 
vote

/** 
 * Toggle whether the task at the given cursor position is complete. The cursor is committed and re-queried after the update.
 * @param cursor cursor positioned at task to update
 * @return new value of task completeness
 */
public boolean toggleTaskComplete(Cursor cursor){
  Id taskId=readId(cursor,ID_INDEX);
  boolean isComplete=!readBoolean(cursor,COMPLETE_INDEX);
  ContentValues values=new ContentValues();
  writeBoolean(values,COMPLETE,isComplete);
  values.put(MODIFIED_DATE,System.currentTimeMillis());
  mResolver.update(getContentUri(),values,TaskProvider.Tasks._ID + "=?",new String[]{String.valueOf(taskId)});
  if (isComplete) {
    FlurryAgent.onEvent(cFlurryCompleteTaskEvent);
  }
  return isComplete;
}
 

Example 18

From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.

Source file: DBLog.java

  17 
vote

public static void insertMessage(Context c,String severity,String tag,String message){
  DBOpenHelper dbHelper=new DBOpenHelper(c);
  SQLiteDatabase db=dbHelper.getWritableDatabase();
  ContentValues values=new ContentValues();
  Date now=new Date();
  values.put("date_time",DateFormatters.ISO8601FORMAT.format(now));
  values.put("severity",severity);
  values.put("tag",tag);
  values.put("message",message);
  db.insert("log",null,values);
  if ((int)(Math.random() * 200) == 5) {
    Cursor results=db.rawQuery("SELECT COUNT(1) FROM log",null);
    results.moveToFirst();
    int noLines=results.getInt(0);
    results.close();
    if (noLines > 50) {
      String sql="DELETE FROM log WHERE `id` IN (SELECT `id` FROM log ORDER BY `id` ASC LIMIT " + (noLines - 50) + ")";
      Log.d("2DegreesDBLog","Deleting " + (noLines - 50) + "rows. Sql: "+ sql);
      db.execSQL(sql);
    }
  }
  db.close();
}
 

Example 19

From project ActionBarSherlock, under directory /samples/fragments/src/com/actionbarsherlock/sample/fragments/.

Source file: LoaderThrottleSupport.java

  17 
vote

/** 
 * Handler inserting new data.
 */
@Override public Uri insert(Uri uri,ContentValues initialValues){
  if (mUriMatcher.match(uri) != MAIN) {
    throw new IllegalArgumentException("Unknown URI " + uri);
  }
  ContentValues values;
  if (initialValues != null) {
    values=new ContentValues(initialValues);
  }
 else {
    values=new ContentValues();
  }
  if (values.containsKey(MainTable.COLUMN_NAME_DATA) == false) {
    values.put(MainTable.COLUMN_NAME_DATA,"");
  }
  SQLiteDatabase db=mOpenHelper.getWritableDatabase();
  long rowId=db.insert(MainTable.TABLE_NAME,null,values);
  if (rowId > 0) {
    Uri noteUri=ContentUris.withAppendedId(MainTable.CONTENT_ID_URI_BASE,rowId);
    getContext().getContentResolver().notifyChange(noteUri,null);
    return noteUri;
  }
  throw new SQLException("Failed to insert row into " + uri);
}
 

Example 20

From project aksunai, under directory /src/org/androidnerds/app/aksunai/data/.

Source file: ServerDbAdapter.java

  17 
vote

public long addServer(String title,String address,String username,String nick,String password,String port,String realName,String autoJoin,int autoConnect){
  SQLiteDatabase db=getWritableDatabase();
  ContentValues values=new ContentValues();
  values.put("title",title);
  values.put("address",address);
  values.put("username",username);
  values.put("nick",nick);
  values.put("password",password);
  values.put("port",port);
  values.put("real_name",realName);
  values.put("autojoin",autoJoin);
  values.put("autoconnect",autoConnect);
  long id=db.insert(DB_TABLE,null,values);
  db.close();
  return id;
}
 

Example 21

From project AlarmApp-Android, under directory /src/org/alarmapp/util/.

Source file: RingtoneUtil.java

  17 
vote

/** 
 * @return the uri of the newly installed ringtone
 */
private static Uri installSoundFile(File soundFile,String name){
  ContentValues values=new ContentValues();
  values.put(MediaStore.MediaColumns.DATA,soundFile.getAbsolutePath());
  values.put(MediaStore.MediaColumns.TITLE,name);
  values.put(MediaStore.MediaColumns.MIME_TYPE,"audio/ogg");
  values.put(MediaStore.MediaColumns.SIZE,soundFile.length());
  values.put(MediaStore.Audio.Media.ARTIST,"AlarmApp");
  values.put(MediaStore.Audio.Media.IS_RINGTONE,false);
  values.put(MediaStore.Audio.Media.IS_NOTIFICATION,false);
  values.put(MediaStore.Audio.Media.IS_ALARM,true);
  values.put(MediaStore.Audio.Media.IS_MUSIC,false);
  Uri uri=MediaStore.Audio.Media.getContentUriForPath(soundFile.getAbsolutePath());
  ContentResolver mCr=AlarmApp.getInstance().getContentResolver();
  Uri contentUri=mCr.insert(uri,values);
  LogEx.verbose("Installed Ringtone uri is " + contentUri);
  return Uri.parse(soundFile.getAbsolutePath());
}
 

Example 22

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/db/.

Source file: AmenDaoImpl.java

  17 
vote

public void insertOrUpdate(Amen amen){
  SQLiteDatabase db=dbHelper.getWritableDatabase();
  Amen exists=findById(amen.getId());
  ContentValues cv=new ContentValues();
  cv.put(AmenDBHelper.KEY_ID,amen.getId());
  cv.put(AmenDBHelper.KEY_USER_ID,amen.getUserId());
  cv.put(AmenDBHelper.KEY_STATEMENT_ID,amen.getStatement().getId());
  cv.put(AmenDBHelper.KEY_CREATED_AT,amen.getCreatedAt().getTime());
  if (exists == null) {
    Log.d(TAG,"Inserting amen: " + amen);
    db.insert(AmenDBHelper.AMEN_TABLE,"name",cv);
  }
 else {
    Log.d(TAG,"Updating amen: " + amen);
    db.update(AmenDBHelper.AMEN_TABLE,cv,AmenDBHelper.KEY_ID + "=?",new String[]{amen.getId() + ""});
  }
  if (amen.getStatement() != null) {
    insertOrUpdate(amen.getStatement());
  }
  if (amen.getUser() != null) {
    insertOrUpdate(amen.getUser());
  }
}