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


Java ContentValues.containsKey方法代码示例

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


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

示例1: addBookmark

import android.content.ContentValues; //导入方法依赖的package包/类
private long addBookmark(ContentValues values) {
    String url = values.getAsString(BookmarkColumns.URL);
    String title = values.getAsString(BookmarkColumns.TITLE);
    boolean isFolder = false;
    if (values.containsKey(BOOKMARK_IS_FOLDER_PARAM)) {
        isFolder = values.getAsBoolean(BOOKMARK_IS_FOLDER_PARAM);
    }
    long parentId = INVALID_BOOKMARK_ID;
    if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) {
        parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM);
    }
    long id = nativeAddBookmark(mNativeChromeBrowserProvider, url, title, isFolder, parentId);
    if (id == INVALID_BOOKMARK_ID) return id;

    if (isFolder) {
        updateLastModifiedBookmarkFolder(id);
    } else {
        updateLastModifiedBookmarkFolder(parentId);
    }
    return id;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:22,代码来源:ChromeBrowserProvider.java

示例2: insert

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public Uri insert(Uri uri, ContentValues values) {
    boolean saveAntiFeatures = false;
    String[] antiFeatures = null;
    if (values.containsKey(Cols.AntiFeatures.ANTI_FEATURES)) {
        saveAntiFeatures = true;
        String antiFeaturesString = values.getAsString(Cols.AntiFeatures.ANTI_FEATURES);
        antiFeatures = Utils.parseCommaSeparatedString(antiFeaturesString);
        values.remove(Cols.AntiFeatures.ANTI_FEATURES);
    }

    removeFieldsFromOtherTables(values);
    validateFields(Cols.ALL, values);
    long newId = db().insertOrThrow(getTableName(), null, values);

    if (saveAntiFeatures) {
        ensureAntiFeatures(antiFeatures, newId);
    }

    if (!isApplyingBatch()) {
        getContext().getContentResolver().notifyChange(uri, null);
    }
    return getApkUri(newId);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:25,代码来源:ApkProvider.java

示例3: put

import android.content.ContentValues; //导入方法依赖的package包/类
/**插入数据
 * @param column - 列名称
 * @param value - 筛选数据的条件值
 * @param values - 一行键值对数据
 */
public void put(String column, String value, ContentValues values) {
	ContentValues oldValues = get(column, value);
	if (oldValues != null && oldValues.containsKey(COLUMN_ID)
			&& StringUtil.isNotEmpty(oldValues.get(COLUMN_ID), true)) {//数据存在且有效
		update(column, value, values);
	} else {
		insert(values);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:SQLHelper.java

示例4: validateExpenseAndUpdate

import android.content.ContentValues; //导入方法依赖的package包/类
private int validateExpenseAndUpdate(final Uri uri, final ContentValues contentValues, long id) {

        if (contentValues.containsKey(ExpenseEntry.COLUMN_INFO)) {
            String info = contentValues.getAsString(ExpenseEntry.COLUMN_INFO).trim();
            if (info.isEmpty()) {
                throw new IllegalArgumentException("Expense info must be set.");
            }
        }

        if (contentValues.containsKey(ExpenseEntry.COLUMN_PRICE)) {
            Double price = contentValues.getAsDouble(ExpenseEntry.COLUMN_PRICE);
            if (price == null || price < 0) {
                throw new IllegalArgumentException("Wrong price " + price);
            }
        }

        if (contentValues.containsKey(ExpenseEntry.COLUMN_VEHICLE)) {
            Long vehicleId = contentValues.getAsLong(ExpenseEntry.COLUMN_VEHICLE);
            String selectionVehicle = VehicleEntry._ID + "=?";
            String[] selectionVehicleArgs = new String[] { String.valueOf(vehicleId) };
            Cursor cursor = mDbHelper.getReadableDatabase().query(VehicleEntry.TABLE_NAME, FuelUpContract.ALL_COLUMNS_VEHICLES, selectionVehicle, selectionVehicleArgs, null, null, null);
            if (cursor == null || cursor.getCount() != 1) {
                if (cursor != null)
                    cursor.close();
                throw new IllegalArgumentException("Vehicle with id=" + vehicleId + " does not exist.");
            }
            cursor.close();
        }

        final String selection = ExpenseEntry._ID + "=?";
        final String[] idArgument = new String[] { String.valueOf(id) };

        getContext().getContentResolver().notifyChange(uri, null);
        return mDbHelper.getWritableDatabase().update(
                ExpenseEntry.TABLE_NAME, contentValues, selection, idArgument);
    }
 
开发者ID:piskula,项目名称:FuelUp,代码行数:37,代码来源:VehicleProvider.java

示例5: copyStringWithDefault

import android.content.ContentValues; //导入方法依赖的package包/类
private static final void copyStringWithDefault(String key, ContentValues from,
                                                ContentValues to, String defaultValue) {
    copyString(key, from, to);
    if (!to.containsKey(key)) {
        to.put(key, defaultValue);
    }
}
 
开发者ID:redleaf2002,项目名称:downloadmanager,代码行数:8,代码来源:DownloadProvider.java

示例6: copyStringWithDefault

import android.content.ContentValues; //导入方法依赖的package包/类
private static final void copyStringWithDefault(String key, ContentValues from,
        ContentValues to, String defaultValue) {
    copyString(key, from, to);
    if (!to.containsKey(key)) {
        to.put(key, defaultValue);
    }
}
 
开发者ID:limpoxe,项目名称:Android-DownloadManager,代码行数:8,代码来源:DownloadProvider.java

示例7: fromContentValues

import android.content.ContentValues; //导入方法依赖的package包/类
static BookmarkRow fromContentValues(ContentValues values) {
    BookmarkRow row = new BookmarkRow();
    if (values.containsKey(BookmarkColumns.URL)) {
        row.mUrl = values.getAsString(BookmarkColumns.URL);
    }
    if (values.containsKey(BookmarkColumns.BOOKMARK)) {
        row.mIsBookmark = values.getAsInteger(BookmarkColumns.BOOKMARK) != 0;
    }
    if (values.containsKey(BookmarkColumns.CREATED)) {
        row.mCreated = values.getAsLong(BookmarkColumns.CREATED);
    }
    if (values.containsKey(BookmarkColumns.DATE)) {
        row.mDate = values.getAsLong(BookmarkColumns.DATE);
    }
    if (values.containsKey(BookmarkColumns.FAVICON)) {
        row.mFavicon = values.getAsByteArray(BookmarkColumns.FAVICON);
        // We need to know that the caller set the favicon column.
        if (row.mFavicon == null) {
            row.mFavicon = new byte[0];
        }
    }
    if (values.containsKey(BookmarkColumns.TITLE)) {
        row.mTitle = values.getAsString(BookmarkColumns.TITLE);
    }
    if (values.containsKey(BookmarkColumns.VISITS)) {
        row.mVisits = values.getAsInteger(BookmarkColumns.VISITS);
    }
    if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) {
        row.mParentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM);
    }
    return row;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:33,代码来源:ChromeBrowserProvider.java

示例8: update

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    if (MATCHER.match(uri) != CODE_APK_FROM_REPO) {
        throw new UnsupportedOperationException("Cannot update anything other than a single apk.");
    }

    boolean saveAntiFeatures = false;
    String[] antiFeatures = null;
    if (values.containsKey(Cols.AntiFeatures.ANTI_FEATURES)) {
        saveAntiFeatures = true;
        String antiFeaturesString = values.getAsString(Cols.AntiFeatures.ANTI_FEATURES);
        antiFeatures = Utils.parseCommaSeparatedString(antiFeaturesString);
        values.remove(Cols.AntiFeatures.ANTI_FEATURES);
    }

    validateFields(Cols.ALL, values);
    removeFieldsFromOtherTables(values);

    QuerySelection query = new QuerySelection(where, whereArgs);
    query = query.add(querySingleWithAppId(uri));

    int numRows = db().update(getTableName(), values, query.getSelection(), query.getArgs());

    if (saveAntiFeatures) {
        // Get the database ID of the row we just updated, so that we can join relevant anti features to it.
        Cursor result = db().query(getTableName(), new String[]{Cols.ROW_ID},
                query.getSelection(), query.getArgs(), null, null, null);
        if (result != null) {
            result.moveToFirst();
            long apkId = result.getLong(0);
            ensureAntiFeatures(antiFeatures, apkId);
            result.close();
        }
    }

    if (!isApplyingBatch()) {
        getContext().getContentResolver().notifyChange(uri, null);
    }
    return numRows;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:41,代码来源:ApkProvider.java

示例9: contentValueToJSON

import android.content.ContentValues; //导入方法依赖的package包/类
public JSONObject contentValueToJSON(ContentValues cv) {
	JSONObject json = new JSONObject();
	for (int i = 0; i < names.size(); i++) {
		if (!cv.containsKey(names.get(i))) {
			continue;
		}
		try {
		    String name = names.get(i);
			switch (types.get(i)) {
			case STRING:
				json.put(name, cv.getAsString(name));
				break;
			case INT:
				json.put(name, cv.getAsInteger(name));
				break;
			case LONG:
				json.put(name, cv.getAsLong(name));
				break;
			case FLOAT:
				json.put(name, cv.getAsFloat(name));
				break;
			case DOUBLE:
				json.put(name, cv.getAsDouble(name));
				break;
			case BOOLEAN:
				json.put(name, cv.getAsBoolean(name));
				break;
			default:
				Log.w("Col", "Invalid type, can't unserialize " + types.get(i));
			}
		} catch (JSONException e) {
			Log.e("Col", "Invalid type, can't unserialize ", e);
		}
	}

	return json;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:38,代码来源:Columns.java

示例10: fromContentValues

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * Create a new {@link Cheese} from the specified {@link ContentValues}.
 *
 * @param values A {@link ContentValues} that at least contain {@link #COLUMN_NAME}.
 * @return A newly created {@link Cheese} instance.
 */
public static Cheese fromContentValues(ContentValues values) {
    final Cheese cheese = new Cheese();
    if (values.containsKey(COLUMN_ID)) {
        cheese.id = values.getAsLong(COLUMN_ID);
    }
    if (values.containsKey(COLUMN_NAME)) {
        cheese.name = values.getAsString(COLUMN_NAME);
    }
    return cheese;
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:17,代码来源:Cheese.java

示例11: insert

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public Uri insert(Uri uri, ContentValues values) {
  switch (matcher.match(uri)) {
  case ALARMS:
    if (!values.containsKey(AlarmEntry.TIME))
      throw new IllegalArgumentException("Missing time");
    // New alarms are always created enabled, but without a label, repeat,
    // nor optional settings.
    values.put(AlarmEntry.ENABLED, true);
    values.put(AlarmEntry.NAME, "");
    values.put(AlarmEntry.DAY_OF_WEEK, 0);
    Uri result = ContentUris.withAppendedId(
        ALARMS_URI, db.insertOrThrow(AlarmEntry.TABLE_NAME, null, values));
    getContext().getContentResolver().notifyChange(uri, null);
    return result;
  case SETTINGS_ID:
    final long alarmid = ContentUris.parseId(uri);
    if (values.containsKey(SettingsEntry.ALARM_ID)) {
      if (values.getAsLong(SettingsEntry.ALARM_ID) != alarmid)
        throw new IllegalArgumentException(
            "ID does not match url: " + alarmid + " vs " + uri);
    } else {
      values.put(SettingsEntry.ALARM_ID, alarmid);
    }
    // Fill in missing fields with defaults.
    final DbUtil.Settings defaults =
      DbUtil.Settings.get(getContext(), DbUtil.Settings.DEFAULTS_ID);
    if (!values.containsKey(SettingsEntry.TONE_URL))
      values.put(SettingsEntry.TONE_URL, defaults.tone_url.toString());
    if (!values.containsKey(SettingsEntry.TONE_NAME))
      values.put(SettingsEntry.TONE_NAME, defaults.tone_name);
    if (!values.containsKey(SettingsEntry.SNOOZE))
      values.put(SettingsEntry.SNOOZE, defaults.snooze);
    if (!values.containsKey(SettingsEntry.VIBRATE))
      values.put(SettingsEntry.VIBRATE, defaults.vibrate);
    if (!values.containsKey(SettingsEntry.VOLUME_STARTING))
      values.put(SettingsEntry.VOLUME_STARTING, defaults.volume_starting);
    if (!values.containsKey(SettingsEntry.VOLUME_ENDING))
      values.put(SettingsEntry.VOLUME_ENDING, defaults.volume_ending);
    if (!values.containsKey(SettingsEntry.VOLUME_TIME))
      values.put(SettingsEntry.VOLUME_TIME, defaults.volume_time);

    db.insertOrThrow(SettingsEntry.TABLE_NAME, null, values);
    getContext().getContentResolver().notifyChange(uri, null);
    return uri;
  default:
    throw new IllegalArgumentException("Unknown URI " + uri);
  }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:50,代码来源:AlarmClockProvider.java

示例12: insert

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public synchronized Uri insert(Uri uri, ContentValues values) {
    /*
     * Validates the incoming URI. Only the full provider URI is allowed for
     * inserts.
     */
    if (URI_MATCHER.match(uri) != URI_HISTORY)
        throw new IllegalArgumentException("UNKNOWN URI " + uri);

    // Gets the current time in milliseconds
    long now = new Date().getTime();

    /*
     * If the values map doesn't contain the creation date/ modification
     * date, sets the value to the current time.
     */
    for (String col : new String[] { HistoryContract.COLUMN_CREATE_TIME,
            HistoryContract.COLUMN_MODIFICATION_TIME })
        if (!values.containsKey(col))
            values.put(col, DbUtils.formatNumber(now));

    // Opens the database object in "write" mode.
    SQLiteDatabase db = mHistoryHelper.getWritableDatabase();

    // Performs the insert and returns the ID of the new note.
    long rowId = db.insert(HistoryContract.TABLE_NAME, null, values);

    // If the insert succeeded, the row ID exists.
    if (rowId > 0) {
        /*
         * Creates a URI with the note ID pattern and the new row ID
         * appended to it.
         */
        Uri noteUri = ContentUris.withAppendedId(
                HistoryContract.genContentIdUriBase(getContext()), rowId);

        /*
         * Notifies observers registered against this provider that the data
         * changed.
         */
        getContext().getContentResolver().notifyChange(noteUri, null);
        return noteUri;
    }

    /*
     * If the insert didn't succeed, then the rowID is <= 0. Throws an
     * exception.
     */
    throw new SQLException("Failed to insert row into " + uri);
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:51,代码来源:HistoryProvider.java

示例13: updatePet

import android.content.ContentValues; //导入方法依赖的package包/类
private int updatePet(Uri uri, ContentValues values, String selection, String[] selectionArgs) {

        // NAME - sanity check
        if (values.containsKey(PetEntry.COLUMN_NAME)) {
            String name = values.getAsString(PetEntry.COLUMN_NAME);
            if (name == null) {
                throw new IllegalArgumentException("Pet requires a name");
            }
        }

        // GENDER - sanity check
        if (values.containsKey(PetEntry.COLUMN_GENDER)) {
            Integer gender = values.getAsInteger(PetEntry.COLUMN_GENDER);
            if (gender == null || !isValidGender(gender)) {
                throw new IllegalArgumentException("Pet requires valid gender");
            }
        }

        // WEIGHT - sanity check
        if (values.containsKey(PetEntry.COLUMN_WEIGHT)) {
            Integer weight = values.getAsInteger(PetEntry.COLUMN_WEIGHT);
            if (weight != null && weight < 0) {
                throw new IllegalArgumentException("Pet requires valid weight");
            }
        }

        // connect with the database
        SQLiteDatabase database = mPetDbHelper.getWritableDatabase();

        // if there is no value, do not try to update
        if (values.size() == 0) {
            return 0;
        }

        // perform the update in the database
        int rowsUpdated = database.update(PetEntry.TABLE_NAME, values, selection, selectionArgs);

        // notify listeners that the data changed, if necessary
        if (rowsUpdated > 0) {
            getContext().getContentResolver().notifyChange(uri, null);
        }

        // return the number of update lines
        return rowsUpdated;
    }
 
开发者ID:gusbru,项目名称:pets,代码行数:46,代码来源:PetProvider.java

示例14: validateVehicleAndUpdate

import android.content.ContentValues; //导入方法依赖的package包/类
private int validateVehicleAndUpdate(final Uri uri, final ContentValues contentValues, final long id) {

        if (contentValues.containsKey(VehicleEntry.COLUMN_NAME)) {
            String name = contentValues.getAsString(VehicleEntry.COLUMN_NAME).trim();
            if (isNotVehicleNameUnique(name, id)) {
                return VEHICLE_UPDATE_NAME_NOT_UNIQUE;
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_TYPE)) {
            Integer typeId = contentValues.getAsInteger(VehicleEntry.COLUMN_TYPE);
            if (typeId == null) {
                throw new IllegalArgumentException("Vehicle Type must be set.");
            }
            if (typeNotExists(typeId)) {
                throw new IllegalArgumentException("Vehicle Type must exists.");
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_VOLUME_UNIT)) {
            String volumeUnit = contentValues.getAsString(VehicleEntry.COLUMN_VOLUME_UNIT);
            List<String> allowedVolumeUnits = Arrays.asList(VolumeUnit.LITRE.name(), VolumeUnit.GALLON_UK.name(), VolumeUnit.GALLON_US.name());
            if (volumeUnit == null) {
                throw new IllegalArgumentException("Vehicle volumeUnit must be set.");
            }
            if (!allowedVolumeUnits.contains(volumeUnit)) {
                throw new IllegalArgumentException("VolumeUnit value is not allowed.");
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_CURRENCY)) {
            String currency = contentValues.getAsString(VehicleEntry.COLUMN_CURRENCY).toUpperCase();
            Currency currencyInstance = Currency.getInstance(currency);
            if (!CurrencyUtil.getSupportedCurrencies().contains(currencyInstance)) {
                throw new IllegalArgumentException("This currency is not supported by this app.");
            }
            if (currencyInstance == null) {
                throw new IllegalArgumentException("Currency '" + currency + "' is not supported by system.");
            }
        }

        final String selection = VehicleEntry._ID + "=?";
        final String[] idArgument = new String[] { String.valueOf(id) };

        getContext().getContentResolver().notifyChange(uri, null);
        return mDbHelper.getWritableDatabase().update(
                VehicleEntry.TABLE_NAME, contentValues, selection, idArgument);
    }
 
开发者ID:piskula,项目名称:FuelUp,代码行数:49,代码来源:VehicleProvider.java

示例15: isEnabled

import android.content.ContentValues; //导入方法依赖的package包/类
private boolean isEnabled(ContentValues values, boolean def) {
	return values == null || !values.containsKey(VALUE) ? def : values.getAsBoolean(VALUE);
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:4,代码来源:SyncControl15.java


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