本文整理汇总了Java中android.content.ContentValues.size方法的典型用法代码示例。如果您正苦于以下问题:Java ContentValues.size方法的具体用法?Java ContentValues.size怎么用?Java ContentValues.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentValues
的用法示例。
在下文中一共展示了ContentValues.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCorrectValues
import android.content.ContentValues; //导入方法依赖的package包/类
/**获取正确的的ContentValues,防止数据库操作出错
* @param values
* @return
*/
public ContentValues getCorrectValues(ContentValues values) {
if (values == null || values.size() <= 0) {
return null;
}
//去除所有空key
Set<String> set = values.keySet();
for (String key : set) {
if (StringUtil.isNotEmpty(key, true) == false) {
values.remove(key);
}
}
return values;
}
示例2: setupRequestBody
import android.content.ContentValues; //导入方法依赖的package包/类
private static RequestBody setupRequestBody(ContentValues values){
RequestBody requestBody=null;
if (values != null && values.size() > 0) {
FormBody.Builder formEncoding = new FormBody.Builder();
Set<String> keySet = values.keySet();
for (String key : keySet) {
try {
values.getAsString(key);
formEncoding.add(key, values.getAsString(key));
} catch (Exception ex) {
Log.d("GonnectLog","Error Happend While Setting Up Request Body : "+ex.getMessage());
}
}
requestBody = formEncoding.build();
}
return requestBody;
}
示例3: getString
import android.content.ContentValues; //导入方法依赖的package包/类
private String getString(ContentValues values) {
if (values == null || values.size() <= 0) {
return "";
}
String s = "{\n";
for (String key : values.keySet()) {
s += (" " + key + ":" + values.get(key) + ",\n");
}
return s += "}";
}
示例4: updateWallpaper
import android.content.ContentValues; //导入方法依赖的package包/类
public void updateWallpaper(Wallpaper wallpaper) {
if (!openDatabase()) {
LogUtil.e("Database error: updateWallpaper() failed to open database");
return;
}
if (wallpaper == null) return;
ContentValues values = new ContentValues();
if (wallpaper.getSize() > 0) {
values.put(KEY_SIZE, wallpaper.getSize());
}
if (wallpaper.getMimeType() != null) {
values.put(KEY_MIME_TYPE, wallpaper.getMimeType());
}
if (wallpaper.getDimensions() != null) {
values.put(KEY_WIDTH, wallpaper.getDimensions().getWidth());
values.put(KEY_HEIGHT, wallpaper.getDimensions().getHeight());
}
if (wallpaper.getColor() != 0) {
values.put(KEY_COLOR, wallpaper.getColor());
}
if (values.size() > 0) {
mDatabase.get().mSQLiteDatabase.update(TABLE_WALLPAPERS,
values, KEY_URL +" = ?", new String[]{wallpaper.getUrl()});
}
}
示例5: update
import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public int update(String table, int conflictAlgorithm, ContentValues values, String whereClause,
Object[] whereArgs) {
// taken from SQLiteDatabase class.
if (values == null || values.size() == 0) {
throw new IllegalArgumentException("Empty values");
}
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
sql.append(CONFLICT_VALUES[conflictAlgorithm]);
sql.append(table);
sql.append(" SET ");
// move all bind args to one array
int setValuesSize = values.size();
int bindArgsSize = (whereArgs == null) ? setValuesSize : (setValuesSize + whereArgs.length);
Object[] bindArgs = new Object[bindArgsSize];
int i = 0;
for (String colName : values.keySet()) {
sql.append((i > 0) ? "," : "");
sql.append(colName);
bindArgs[i++] = values.get(colName);
sql.append("=?");
}
if (whereArgs != null) {
for (i = setValuesSize; i < bindArgsSize; i++) {
bindArgs[i] = whereArgs[i - setValuesSize];
}
}
if (!isEmpty(whereClause)) {
sql.append(" WHERE ");
sql.append(whereClause);
}
SupportSQLiteStatement stmt = compileStatement(sql.toString());
SimpleSQLiteQuery.bind(stmt, bindArgs);
return stmt.executeUpdateDelete();
}
示例6: forMessagesFlagReset
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Получение списка операций для сохранения уведомлений о том,
* что для сообщений были ОТМЕНЕНЫ атрибуты
*
* @param updates уведомления
* @return список операций
*/
public static ArrayList<ContentProviderOperation> forMessagesFlagReset(int accountId, @NonNull List<MessageFlagsResetUpdate> updates) {
ArrayList<ContentProviderOperation> operations = new ArrayList<>(updates.size());
for (MessageFlagsResetUpdate update : updates) {
ContentValues cv = new ContentValues();
if(hasFlag(update.mask, VKApiMessage.FLAG_DELETED)){
cv.put(MessageColumns.DELETED, 0);
}
if(hasFlag(update.mask, VKApiMessage.FLAG_IMPORTANT)){
cv.put(MessageColumns.IMPORTANT, 0);
}
if(hasFlag(update.mask, VKApiMessage.FLAG_UNREAD)){
cv.put(MessageColumns.READ_STATE, 1);
}
if(cv.size() > 0){
String where = MessageColumns._ID + " = ?";
String[] args = {String.valueOf(update.message_id)};
operations.add(ContentProviderOperation
.newUpdate(MessengerContentProvider.getMessageContentUriFor(accountId))
.withSelection(where, args)
.withValues(cv)
.build());
}
}
return operations;
}
示例7: matchesSafely
import android.content.ContentValues; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(ContentValues values, Description mismatchDescription)
{
if (values.size() != mExpectedValueCount)
{
mismatchDescription.appendText(String.format(Locale.ENGLISH, "had %d values", values.size()));
return false;
}
return true;
}
示例8: doInsertOrUpdate
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Inserts values into a table that has an unique id as identifier.
*
* @param table The affected table.
* @param values The values to be inserted/ updated.
* @param mId The identifier of the affected row.
*
* @return The number of rows affected on update, the rowId on insert, -1 on error.
*/
public int doInsertOrUpdate(String table, ContentValues values, Where where) {
int result;
open();
Cursor oldVersion = get(table, where, null);
if(oldVersion.moveToNext() && values.size() != 0) {
String whereClause = null;
if(where != null) {
whereClause = where.toString().replace(" WHERE ", "");
}
result = mDb.update(table, values, whereClause, null);
} else {
String nullColumnHack = null;
if(values.size() == 0) {
// if no fields are defined on a model instance the nullColumnHack
// needs to be utilized in order to insert an empty row.
nullColumnHack = Model.PK;
}
result = (int) mDb.insertOrThrow(table, nullColumnHack, values);
}
oldVersion.close();
close();
return result;
}
示例9: editSongTags
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Edit Song Tags
*
* @param context
* @param song
* @return
*/
public static boolean editSongTags(Context context, Song song) {
File f = new File(song.getmSongPath());
if (f.exists()) {
try {
AudioFile audioFile = AudioFileIO.read(f);
if (audioFile == null) {
return false;
}
TagOptionSingleton.getInstance().setAndroid(true);
Tag tag = audioFile.getTag();
if (tag == null) {
return false;
}
String year = song.getYear();
String title = song.getTitle();
String album = song.getAlbum();
String artist = song.getArtist();
String lyrics = song.getLyrics();
tag.deleteField(FieldKey.LYRICS);
tag.setField(FieldKey.LYRICS, Html.fromHtml(lyrics).toString());
ContentValues values = new ContentValues();
if (title != null){
tag.setField(FieldKey.TITLE, title);
values.put(MediaStore.Audio.Media.TITLE, title);
}
if (artist != null){
tag.setField(FieldKey.ARTIST, artist);
values.put(MediaStore.Audio.Media.ARTIST, artist);
}
if (album != null){
tag.setField(FieldKey.ALBUM, album);
Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[]{BaseColumns._ID,
MediaStore.Audio.AlbumColumns.ALBUM, MediaStore.Audio.AlbumColumns.ALBUM_KEY,
MediaStore.Audio.AlbumColumns.ARTIST}, MediaStore.Audio.AlbumColumns.ALBUM + " = ?",
new String[]{album}, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
if (cursor != null && cursor.moveToFirst()) {
long id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
values.put(MediaStore.Audio.Media.ALBUM_ID, id);
cursor.close();
} else {
values.put(MediaStore.Audio.Media.ALBUM, album);
}
}
if (song.getTrackNumber() != -1){
tag.setField(FieldKey.TRACK, String.valueOf(song.getTrackNumber()));
values.put(MediaStore.Audio.Media.TRACK, song.getTrackNumber());
}
if (year != null && year.length() > 0){
tag.setField(FieldKey.YEAR, "" + year);
values.put(MediaStore.Audio.Media.YEAR, year);
}
if (values.size() > 0) {
context.getContentResolver().update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values, android.provider.MediaStore.Audio.Media._ID + "=?", new String[]{String.valueOf(song.getId())});
}else {
return false;
}
audioFile.setTag(tag);
AudioFileIO.write(audioFile);
} catch (CannotReadException | CannotWriteException | InvalidAudioFrameException | TagException | IOException | ReadOnlyFileException e) {
e.printStackTrace();
}
return true;
} else {
return false;
}
}
示例10: update
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public int update(String table, int conflictAlgorithm, ContentValues values,
String whereClause, Object[] whereArgs) {
// taken from SQLiteDatabase class.
if (values == null || values.size() == 0) {
throw new IllegalArgumentException("Empty values");
}
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
sql.append(CONFLICT_VALUES[conflictAlgorithm]);
sql.append(table);
sql.append(" SET ");
// move all bind args to one array
int setValuesSize = values.size();
int bindArgsSize = (whereArgs == null) ? setValuesSize : (setValuesSize + whereArgs.length);
Object[] bindArgs = new Object[bindArgsSize];
int i = 0;
for (String colName : values.keySet()) {
sql.append((i > 0) ? "," : "");
sql.append(colName);
bindArgs[i++] = values.get(colName);
sql.append("=?");
}
if (whereArgs != null) {
for (i = setValuesSize; i < bindArgsSize; i++) {
bindArgs[i] = whereArgs[i - setValuesSize];
}
}
if (!isEmpty(whereClause)) {
sql.append(" WHERE ");
sql.append(whereClause);
}
SupportSQLiteStatement statement = compileStatement(sql.toString());
try {
SimpleSQLiteQuery.bind(statement, bindArgs);
return statement.executeUpdateDelete();
}
finally {
try {
statement.close();
}
catch (Exception e) {
throw new RuntimeException("Exception attempting to close statement", e);
}
}
}
示例11: insertWithOnConflict
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* General method for inserting a row into the database.
*
* @param table the table to insert the row into
* @param nullColumnHack optional; may be <code>null</code>.
* SQL doesn't allow inserting a completely empty row without
* naming at least one column name. If your provided <code>initialValues</code> is
* empty, no column names are known and an empty row can't be inserted.
* If not set to null, the <code>nullColumnHack</code> parameter
* provides the name of nullable column name to explicitly insert a NULL into
* in the case where your <code>initialValues</code> is empty.
* @param initialValues this map contains the initial column values for the
* row. The keys should be the column names and the values the
* column values
* @param conflictAlgorithm for insert conflict resolver
* @return the row ID of the newly inserted row OR <code>-1</code> if either the
* input parameter <code>conflictAlgorithm</code> = {@link #CONFLICT_IGNORE}
* or an error occurred.
*/
public long insertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm) {
acquireReference();
try {
StringBuilder sql = new StringBuilder();
sql.append("INSERT");
sql.append(CONFLICT_VALUES[conflictAlgorithm]);
sql.append(" INTO ");
sql.append(table);
sql.append('(');
int size = (initialValues != null && initialValues.size() > 0) ? initialValues.size() : 0;
if (size > 0) {
Object[] bindArgs = new Object[size];
int i = 0;
for (String colName : initialValues.keySet()) {
sql.append((i > 0) ? "," : "");
sql.append(colName);
bindArgs[i++] = initialValues.get(colName);
}
sql.append(')');
// 拼接VALUES语句
{
StringBuilder valuesSql = new StringBuilder();
valuesSql.append(" VALUES (");
for (i = 0; i < size; i++) {
valuesSql.append((i > 0) ? ",?" : "?");
}
valuesSql.append(')');
String valuesStr = KbSqlBuilder.bindArgs(valuesSql.toString(), bindArgs);
sql.append(valuesStr);
}
} else {
sql.append(nullColumnHack + ") VALUES (NULL");
sql.append(')');
}
// 执行语句
execSQL(sql.toString());
return 0;
} finally {
releaseReference();
}
}
示例12: updateWithOnConflict
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Convenience method for updating rows in the database.
*
* @param table the table to update in
* @param values a map from column names to new column values. null is a
* valid value that will be translated to NULL.
* @param whereClause the optional WHERE clause to apply when updating.
* Passing null will update all rows.
* @param whereArgs You may include ?s in the where clause, which
* will be replaced by the values from whereArgs. The values
* will be bound as Strings.
* @param conflictAlgorithm for update conflict resolver
* @return the number of rows affected
*/
public int updateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm) {
if (values == null || values.size() == 0) {
throw new IllegalArgumentException("Empty values");
}
acquireReference();
try {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
sql.append(CONFLICT_VALUES[conflictAlgorithm]);
sql.append(table);
sql.append(" SET ");
// move all bind args to one array
int setValuesSize = values.size();
int bindArgsSize = (whereArgs == null) ? setValuesSize : (setValuesSize + whereArgs.length);
Object[] bindArgs = new Object[bindArgsSize];
int i = 0;
for (String colName : values.keySet()) {
sql.append((i > 0) ? "," : "");
sql.append(colName);
bindArgs[i++] = values.get(colName);
sql.append("=?");
}
if (whereArgs != null) {
for (i = setValuesSize; i < bindArgsSize; i++) {
bindArgs[i] = whereArgs[i - setValuesSize];
}
}
if (!TextUtils.isEmpty(whereClause)) {
sql.append(" WHERE ");
sql.append(whereClause);
}
String afterSql = KbSqlBuilder.bindArgs(sql.toString(), bindArgs);
try {
Statement statement = mConnection.createStatement();
int rowCount = statement.executeUpdate(afterSql.toString());
if (!isTransaction) {
mConnection.commit();
}
return rowCount;
} catch (java.sql.SQLException e) {
throw new SQLException("", e);
}
} finally {
releaseReference();
}
}
示例13: validateFillUpAndUpdate
import android.content.ContentValues; //导入方法依赖的package包/类
private int validateFillUpAndUpdate(final Uri uri, final ContentValues contentValues, long id) {
if (contentValues.size() == 0) {
return UPDATE_NO_CHANGE;
}
validateFillUpBasics(contentValues, true, id);
if (contentValues.containsKey(FillUpEntry.COLUMN_VEHICLE)) {
throw new IllegalArgumentException("Cannot change vehicle of FillUp. Please, create a fresh new FillUp in this case.");
}
boolean isDeleteAndInsertNeeded = contentValues.containsKey(FillUpEntry.COLUMN_DATE)
|| contentValues.containsKey(FillUpEntry.COLUMN_FUEL_VOLUME)
|| contentValues.containsKey(FillUpEntry.COLUMN_DISTANCE_FROM_LAST)
|| contentValues.containsKey(FillUpEntry.COLUMN_IS_FULL_FILLUP);
if (!isDeleteAndInsertNeeded) {
// if only Not-Neighbour-Affecting values have been changed
final String selection = FillUpEntry._ID + "=?";
final String[] idArgument = new String[] { String.valueOf(id) };
getContext().getContentResolver().notifyChange(uri, null);
return mDbHelper.getWritableDatabase().update(
FillUpEntry.TABLE_NAME, contentValues, selection, idArgument);
} else {
// if date, distance or fuelVolume have been changed, it may affect neighbouring fillUps
SQLiteDatabase db = mDbHelper.getWritableDatabase();
db.beginTransactionNonExclusive();
FillUp fillUp = FillUpService.getFillUpById(id, getContext());
ContentValues recreatedValues = new ContentValues();
recreatedValues.putAll(contentValues);
if (!recreatedValues.containsKey(FillUpEntry.COLUMN_VEHICLE))
recreatedValues.put(FillUpEntry.COLUMN_VEHICLE, fillUp.getVehicle().getId());
if (!recreatedValues.containsKey(FillUpEntry.COLUMN_DISTANCE_FROM_LAST))
recreatedValues.put(FillUpEntry.COLUMN_DISTANCE_FROM_LAST, fillUp.getDistanceFromLastFillUp());
if (!recreatedValues.containsKey(FillUpEntry.COLUMN_FUEL_VOLUME))
recreatedValues.put(FillUpEntry.COLUMN_FUEL_VOLUME, fillUp.getFuelVolume().doubleValue());
if (!recreatedValues.containsKey(FillUpEntry.COLUMN_FUEL_PRICE_PER_LITRE))
recreatedValues.put(FillUpEntry.COLUMN_FUEL_PRICE_PER_LITRE, fillUp.getFuelPricePerLitre().doubleValue());
if (!recreatedValues.containsKey(FillUpEntry.COLUMN_FUEL_PRICE_TOTAL))
recreatedValues.put(FillUpEntry.COLUMN_FUEL_PRICE_TOTAL, fillUp.getFuelPriceTotal().doubleValue());
if (!recreatedValues.containsKey(FillUpEntry.COLUMN_IS_FULL_FILLUP))
recreatedValues.put(FillUpEntry.COLUMN_IS_FULL_FILLUP, fillUp.isFullFillUp() ? 1 : 0);
if (!recreatedValues.containsKey(FillUpEntry.COLUMN_DATE))
recreatedValues.put(FillUpEntry.COLUMN_DATE, fillUp.getDate().getTime());
if (!recreatedValues.containsKey(FillUpEntry.COLUMN_INFO))
recreatedValues.put(FillUpEntry.COLUMN_INFO, fillUp.getInfo());
deleteFillUpInTransaction(uri, db);
validateFillUpAndInsertInTransaction(uri, recreatedValues, db);
db.setTransactionSuccessful();
db.endTransaction();
db.close();
return 1;
}
}
示例14: onUpdate
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* The open interface for other classes in CRUD package to update. Using
* baseObj to decide which table to update, and id to decide a specific row.
* The value that need to update is stored in baseObj.
*
* @param baseObj
* Which table to update by model instance.
* @param id
* Which record to update.
* @return The number of rows affected.
* @throws java.lang.reflect.InvocationTargetException
* @throws IllegalAccessException
* @throws NoSuchMethodException
* @throws IllegalArgumentException
* @throws SecurityException
*/
int onUpdate(DataSupport baseObj, long id) throws SecurityException, IllegalArgumentException,
NoSuchMethodException, IllegalAccessException, InvocationTargetException {
List<Field> supportedFields = getSupportedFields(baseObj.getClassName());
List<Field> supportedGenericFields = getSupportedGenericFields(baseObj.getClassName());
updateGenericTables(baseObj, supportedGenericFields, id);
ContentValues values = new ContentValues();
putFieldsValue(baseObj, supportedFields, values);
putFieldsToDefaultValue(baseObj, values, id);
if (values.size() > 0) {
return mDatabase.update(baseObj.getTableName(), values, "id = " + id, null);
}
return 0;
}
示例15: doUpdateAllAction
import android.content.ContentValues; //导入方法依赖的package包/类
/**
* Do the action for updating multiple rows. It will check the validity of
* conditions, then update rows in database. If the format of conditions is
* invalid, throw DataSupportException.
*
* @param tableName
* Which table to delete from.
* @param conditions
* A string array representing the WHERE part of an SQL
* statement.
* @param values
* A map from column names to new column values. null is a valid
* value that will be translated to NULL.
* @return The number of rows affected.
*/
private int doUpdateAllAction(String tableName, ContentValues values, String... conditions) {
BaseUtility.checkConditionsCorrect(conditions);
if (values.size() > 0) {
return mDatabase.update(tableName, values, getWhereClause(conditions),
getWhereArgs(conditions));
}
return 0;
}