当前位置: 首页>>代码示例>>Java>>正文


Java ContentValues类代码示例

本文整理汇总了Java中android.content.ContentValues的典型用法代码示例。如果您正苦于以下问题:Java ContentValues类的具体用法?Java ContentValues怎么用?Java ContentValues使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContentValues类属于android.content包,在下文中一共展示了ContentValues类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insert

import android.content.ContentValues; //导入依赖的package包/类
@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
    final SQLiteDatabase db = mCardsDBHelper.getWritableDatabase();

    Uri returnUri = null;
    int match = sUriMatcher.match(uri);
    switch (match) {
        case TRANSACTIONS: // Since insert and query all has same url
            long transactionId = db.insert(DatabaseContract.TABLE_TRANSACTIONS, null, values);
            if (transactionId > 0) {
                returnUri = ContentUris.withAppendedId(DatabaseContract.CONTENT_URI, transactionId);
                getContext().getContentResolver().notifyChange(uri, null);
            } else {
                throw new SQLException("Can't create ID");
            }
            break;
        default:
            throw new UnsupportedOperationException("This URI is not supported");
    }
    return returnUri;
}
 
开发者ID:talCrafts,项目名称:Udhari,代码行数:23,代码来源:TxProvider.java

示例2: bulkInsert

import android.content.ContentValues; //导入依赖的package包/类
/**
 * 调用插件里的Provider
 *
 * @see android.content.ContentResolver#bulkInsert(Uri, ContentValues[])
 */
public static int bulkInsert(Context c, Uri uri, ContentValues[] values) {
    if (c == null) {
        return 0;
    }

    if (!RePluginFramework.mHostInitialized) {
        return c.getContentResolver().bulkInsert(uri, values);
    }

    try {
        Object obj = ProxyRePluginProviderClientVar.bulkInsert.call(null, c, uri, values);
        if (obj != null) {
            return (Integer) obj;
        }
    } catch (Exception e) {
        if (LogDebug.LOG) {
            e.printStackTrace();
        }
    }

    return -1;
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:28,代码来源:PluginProviderClient.java

示例3: validateCurrentRecord

import android.content.ContentValues; //导入依赖的package包/类
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
开发者ID:rashikaranpuria,项目名称:ubiquitous,代码行数:33,代码来源:TestUtilities.java

示例4: bulkInsert

import android.content.ContentValues; //导入依赖的package包/类
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    SQLiteDatabase sqLiteDatabase = this.ohaSQLHelper.getWritableDatabase();
    switch (sUriMatcher.match(uri)) {
        case CODE_ENERGY_USER_LOG:
            return bulkInsertEnergyUseLogs(uri, values, sqLiteDatabase);
        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:11,代码来源:OhaEnergyUseProvider.java

示例5: updateAttachmentThumbnail

import android.content.ContentValues; //导入依赖的package包/类
@VisibleForTesting
protected void updateAttachmentThumbnail(MasterSecret masterSecret, AttachmentId attachmentId, InputStream in, float aspectRatio)
    throws MmsException
{
  Log.w(TAG, "updating part thumbnail for #" + attachmentId);

  Pair<File, Long> thumbnailFile = setAttachmentData(masterSecret, in);

  SQLiteDatabase database = databaseHelper.getWritableDatabase();
  ContentValues  values   = new ContentValues(2);

  values.put(THUMBNAIL, thumbnailFile.first.getAbsolutePath());
  values.put(THUMBNAIL_ASPECT_RATIO, aspectRatio);

  database.update(TABLE_NAME, values, PART_ID_WHERE, attachmentId.toStrings());

  Cursor cursor = database.query(TABLE_NAME, new String[] {MMS_ID}, PART_ID_WHERE, attachmentId.toStrings(), null, null, null);

  try {
    if (cursor != null && cursor.moveToFirst()) {
      notifyConversationListeners(DatabaseFactory.getMmsDatabase(context).getThreadIdForMessage(cursor.getLong(cursor.getColumnIndexOrThrow(MMS_ID))));
    }
  } finally {
    if (cursor != null) cursor.close();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:27,代码来源:AttachmentDatabase.java

示例6: Update

import android.content.ContentValues; //导入依赖的package包/类
public boolean Update(@NonNull LucaMenu updateEntry) throws SQLException {
    ContentValues contentValues = new ContentValues();

    contentValues.put(KEY_ROW_ID, updateEntry.GetId());
    contentValues.put(KEY_WEEKDAY, updateEntry.GetWeekday().GetEnglishDay());
    contentValues.put(KEY_DAY, String.valueOf(updateEntry.GetDate().DayOfMonth()));
    contentValues.put(KEY_MONTH, String.valueOf(updateEntry.GetDate().Month()));
    contentValues.put(KEY_YEAR, String.valueOf(updateEntry.GetDate().Year()));
    contentValues.put(KEY_TITLE, updateEntry.GetTitle());
    contentValues.put(KEY_DESCRIPTION, updateEntry.GetDescription());
    contentValues.put(KEY_IS_ON_SERVER, String.valueOf(updateEntry.GetIsOnServer()));
    contentValues.put(KEY_SERVER_ACTION, updateEntry.GetServerDbAction().toString());

    _database.update(DATABASE_TABLE, contentValues, KEY_ROW_ID + "=" + updateEntry.GetId(), null);

    return true;
}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:18,代码来源:DatabaseMenuList.java

示例7: getImageContentUri

import android.content.ContentValues; //导入依赖的package包/类
public static Uri getImageContentUri(Context context, File imageFile) {
    String filePath = imageFile.getAbsolutePath();
    Cursor cursor = context.getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[]{MediaStore.Images.Media._ID},
            MediaStore.Images.Media.DATA + "=? ",
            new String[]{filePath}, null);
    if (cursor != null && cursor.moveToFirst()) {
        int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
        cursor.close();
        return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id);
    } else {
        if (imageFile.exists()) {
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.DATA, filePath);
            return context.getContentResolver().insert(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        } else {
            return null;
        }
    }
}
 
开发者ID:myinnos,项目名称:GiphyImageResultsPreview,代码行数:23,代码来源:Helper.java

示例8: updateDownload

import android.content.ContentValues; //导入依赖的package包/类
/**
 * This function will add a new file to the database if it does not exist.
 *
 * @param di DownloadInfo that we wish to store
 * @return the row id of the record to be updated/inserted, or -1
 */
public boolean updateDownload(DownloadInfo di) {
    ContentValues cv = new ContentValues();
    cv.put(DownloadColumns.INDEX, di.mIndex);
    cv.put(DownloadColumns.FILENAME, di.mFileName);
    cv.put(DownloadColumns.URI, di.mUri);
    cv.put(DownloadColumns.ETAG, di.mETag);
    cv.put(DownloadColumns.TOTALBYTES, di.mTotalBytes);
    cv.put(DownloadColumns.CURRENTBYTES, di.mCurrentBytes);
    cv.put(DownloadColumns.LASTMOD, di.mLastMod);
    cv.put(DownloadColumns.STATUS, di.mStatus);
    cv.put(DownloadColumns.CONTROL, di.mControl);
    cv.put(DownloadColumns.NUM_FAILED, di.mNumFailed);
    cv.put(DownloadColumns.RETRY_AFTER, di.mRetryAfter);
    cv.put(DownloadColumns.REDIRECT_COUNT, di.mRedirectCount);
    return updateDownload(di, cv);
}
 
开发者ID:snoozinsquatch,项目名称:unity-obb-downloader,代码行数:23,代码来源:DownloadsDB.java

示例9: insert

import android.content.ContentValues; //导入依赖的package包/类
public Uri insert(Uri uri, ContentValues values){
    db = tOpenHelper.getWritableDatabase();
    long id;
    switch(sUriMatcher.match(uri)){
        case ENTRY_LIST:
            id = db.insert(TodoEntry.TABLE_NAME, null, values);
            break;
        case LABEL_LIST:
            id = db.insert(TodoLabel.TABLE_NAME, null, values);
            break;
        case NOTIFICATION_LIST:
            id = db.insert(TodoNotification.TABLE_NAME, null, values);
            break;
        default:
            throw new IllegalArgumentException("Unsupported URI for insertion: " + uri);
    }
    Uri itemUri = ContentUris.withAppendedId(uri, id);
    getContext().getContentResolver().notifyChange(itemUri, null);
    return itemUri;
}
 
开发者ID:danlls,项目名称:Todule-android,代码行数:21,代码来源:ToduleProvider.java

示例10: update

import android.content.ContentValues; //导入依赖的package包/类
/**
 * ********** UPDATE ***********
 *
 * @param uri
 * @param values
 * @param selection
 * @param selectionArgs
 * @return
 */
@Override
public int update(@NonNull Uri uri, @Nullable ContentValues values,
                  @Nullable String selection, @Nullable String[] selectionArgs) {

    final int match = sUriMathcer.match(uri);
    switch (match) {
        case PETS:
            return updatePet(uri, values, selection, selectionArgs);
        case PETS_ID:
            // For PET_ID extract the pet ID from the URI
            String id = String.valueOf(ContentUris.parseId(uri));
            selection = PetEntry._ID + "=?";
            selectionArgs = new String[]{id};
            return updatePet(uri, values, selection, selectionArgs);
        default:
            throw new IllegalArgumentException("Update is not supported for " + uri);
    }
}
 
开发者ID:gusbru,项目名称:pets,代码行数:28,代码来源:PetProvider.java

示例11: insertEmoticonBeans

import android.content.ContentValues; //导入依赖的package包/类
public synchronized long insertEmoticonBeans(ContentValues[] values) {
    SQLiteDatabase db = mOpenDbHelper.getWritableDatabase();
    db.beginTransaction();
    int insertSuccessCount = values.length;
    try {
        for (ContentValues cv : values) {
            if (db.insert(TABLE_NAME_EMOTICONS, null, cv) < 0) {
                insertSuccessCount--;
            }
        }
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e("Keyboard", "insert error", e);
    }  finally {
        db.endTransaction();
    }
    return insertSuccessCount;
}
 
开发者ID:yangchaojiang,项目名称:ChatKeyboard-master,代码行数:19,代码来源:EmoticonDBHelper.java

示例12: getValues

import android.content.ContentValues; //导入依赖的package包/类
@Override
public ContentValues getValues() {
	ContentValues values = new ContentValues();

	values.put(HostDatabase.FIELD_HOST_NICKNAME, nickname);
	values.put(HostDatabase.FIELD_HOST_PROTOCOL, protocol);
	values.put(HostDatabase.FIELD_HOST_USERNAME, username);
	values.put(HostDatabase.FIELD_HOST_HOSTNAME, hostname);
	values.put(HostDatabase.FIELD_HOST_PORT, port);
	values.put(HostDatabase.FIELD_HOST_LASTCONNECT, lastConnect);
	values.put(HostDatabase.FIELD_HOST_COLOR, color);
	values.put(HostDatabase.FIELD_HOST_USEKEYS, Boolean.toString(useKeys));
	values.put(HostDatabase.FIELD_HOST_USEAUTHAGENT, useAuthAgent);
	values.put(HostDatabase.FIELD_HOST_POSTLOGIN, postLogin);
	values.put(HostDatabase.FIELD_HOST_PUBKEYID, pubkeyId);
	values.put(HostDatabase.FIELD_HOST_WANTSESSION, Boolean.toString(wantSession));
	values.put(HostDatabase.FIELD_HOST_DELKEY, delKey);
	values.put(HostDatabase.FIELD_HOST_FONTSIZE, fontSize);
	values.put(HostDatabase.FIELD_HOST_COMPRESSION, Boolean.toString(compression));
	values.put(HostDatabase.FIELD_HOST_ENCODING, encoding);
	values.put(HostDatabase.FIELD_HOST_STAYCONNECTED, Boolean.toString(stayConnected));
	values.put(HostDatabase.FIELD_HOST_QUICKDISCONNECT, Boolean.toString(quickDisconnect));

	return values;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:HostBean.java

示例13: update

import android.content.ContentValues; //导入依赖的package包/类
public void update(TimeLeft timeLeft) {

        SQLiteDatabase db = dbHelper.getWritableDatabase();
        ContentValues values = new ContentValues();

        values.put(TimeLeft.KEY_TITLE,timeLeft.getTitle());
        values.put(TimeLeft.KEY_BEGIN_TIME,timeLeft.getBeginDate());
        values.put(TimeLeft.KEY_DESCRIPTION,timeLeft.getContent());
        values.put(TimeLeft.KEY_IMPORTANCE,timeLeft.getImportance());
        values.put(TimeLeft.KEY_STATE,timeLeft.getState());
        values.put(TimeLeft.KEY_END_TIME,timeLeft.getEndDate());


        // It's a good practice to use parameter ?, instead of concatenate string

        db.update(TimeLeft.TABLE, values, TimeLeft.KEY_ID + " = ?", new String[] { String.valueOf(timeLeft.ID) });
        Log.e("timeLeft sta "+timeLeft.getState(),"has changed in db");
        db.close(); // Closing database connection
    }
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:20,代码来源:TimeLeftRepo.java

示例14: update

import android.content.ContentValues; //导入依赖的package包/类
public void update(byte[] groupId, String title, SignalServiceAttachmentPointer avatar) {
  ContentValues contentValues = new ContentValues();
  if (title != null) contentValues.put(TITLE, title);

  if (avatar != null) {
    contentValues.put(AVATAR_ID, avatar.getId());
    contentValues.put(AVATAR_CONTENT_TYPE, avatar.getContentType());
    contentValues.put(AVATAR_KEY, avatar.getKey());
  }

  databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues,
                                              GROUP_ID + " = ?",
                                              new String[] {GroupUtil.getEncodedId(groupId)});

  RecipientFactory.clearCache(context);
  notifyDatabaseListeners();
  notifyConversationListListeners();
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:19,代码来源:GroupDatabase.java

示例15: toValues

import android.content.ContentValues; //导入依赖的package包/类
public static ContentValues toValues(User user){
    if(user==null) return null;
    ContentValues values=new ContentValues();
    values.put(Users.USER_ID,user.getId());
    values.put(Users.USER_ART_URL,user.getAvatarUrl());
    values.put(Users.USER_NICKNAME,user.getNickName());
    values.put(Users.USER_FULLNAME,user.getFullName());
    values.put(Users.USER_DESCRIPTION,user.getDescription());
    values.put(Users.USER_FOLLOWINGS_COUNT,user.getFollowingCount());
    values.put(Users.USER_FOLLOWER_COUNT,user.getFollowersCount());
    values.put(Users.USER_TRACKS_COUNT,user.getTracksCount());
    values.put(Users.USER_LIKED_TRACKS_COUNT,user.getLikedTracksCount());
    values.put(Users.USER_IS_FOLLOWED,user.isFollowed()?1:0);
    values.put(Users.USER_PLAYLISTS_COUNT,user.getPlaylistsCount());
    return values;
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:17,代码来源:DatabaseUtils.java


注:本文中的android.content.ContentValues类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。