android.content.ContentValues#get ( )源码实例Demo

下面列出了android.content.ContentValues#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: opentasks   文件: TaskProvider.java
/**
 * Validate the given category values.
 *
 * @param values
 *         The category properties to validate.
 *
 * @throws IllegalArgumentException
 *         if any of the values is invalid.
 */
private void validateCategoryValues(ContentValues values, boolean isNew, boolean isSyncAdapter)
{
    // row id can not be changed or set manually
    if (values.containsKey(Categories._ID))
    {
        throw new IllegalArgumentException("_ID can not be set manually");
    }

    if (isNew != values.containsKey(Categories.ACCOUNT_NAME) && (!isNew || values.get(Categories.ACCOUNT_NAME) != null))
    {
        throw new IllegalArgumentException("ACCOUNT_NAME is write-once and required on INSERT");
    }

    if (isNew != values.containsKey(Categories.ACCOUNT_TYPE) && (!isNew || values.get(Categories.ACCOUNT_TYPE) != null))
    {
        throw new IllegalArgumentException("ACCOUNT_TYPE is write-once and required on INSERT");
    }
}
 
源代码2 项目: opentasks-provider   文件: TaskProvider.java
/**
 * Validate the given category values.
 * 
 * @param values
 *            The category properties to validate.
 * @throws IllegalArgumentException
 *             if any of the values is invalid.
 */
private void validateCategoryValues(ContentValues values, boolean isNew, boolean isSyncAdapter)
{
	// row id can not be changed or set manually
	if (values.containsKey(Categories._ID))
	{
		throw new IllegalArgumentException("_ID can not be set manually");
	}

	if (isNew != values.containsKey(Categories.ACCOUNT_NAME) && (!isNew || values.get(Categories.ACCOUNT_NAME) != null))
	{
		throw new IllegalArgumentException("ACCOUNT_NAME is write-once and required on INSERT");
	}

	if (isNew != values.containsKey(Categories.ACCOUNT_TYPE) && (!isNew || values.get(Categories.ACCOUNT_TYPE) != null))
	{
		throw new IllegalArgumentException("ACCOUNT_TYPE is write-once and required on INSERT");
	}
}
 
源代码3 项目: search-samples   文件: RecipeContentProvider.java
public Uri insertNoteForRecipe(Uri uri, ContentValues values) {
    String sql = "INSERT INTO `" + RecipeNoteTable.TABLE + "` (`" + RecipeNoteTable
            .RECIPE_ID_COLUMN + "`, `" + RecipeNoteTable.TEXT_COLUMN + "`) VALUES ('" + uri
            .getLastPathSegment() + "', '" + values.get(RecipeNoteTable.TEXT_COLUMN) + "')";
    database.getWritableDatabase().execSQL(sql);
    return uri;
}
 
源代码4 项目: framework   文件: BaseModelProvider.java
private ContentValues[] generateValues(OModel model, ContentValues values) {
    OValues data_value = new OValues();
    OValues rel_value = new OValues();
    for (String key : values.keySet()) {
        OColumn column = model.getColumn(key);
        if (column != null) {
            if (column.getRelationType() == null) {
                data_value.put(key, values.get(key));
            } else {
                if (column.getRelationType() == OColumn.RelationType.ManyToOne) {
                    if (!(values.get(key) instanceof byte[]))
                        data_value.put(key, values.get(key));
                    else {
                        // Creating many to one record and assigning id to record
                        OModel m2oModel = model.createInstance(column.getType());
                        try {
                            OValues m2oVal = (OValues) OObjectUtils.byteToObject(
                                    (byte[]) values.get(key));
                            int id = m2oModel.insert(m2oVal);
                            data_value.put(key, id);
                        } catch (IOException | ClassNotFoundException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    rel_value.put(key, values.get(key));
                }
            }
        }
    }
    return new ContentValues[]{data_value.toContentValues(), rel_value.toContentValues()};
}
 
源代码5 项目: fdroidclient   文件: RepoProvider.java
@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {

    // Don't let people specify arbitrary priorities. Instead, we are responsible
    // for making sure that newly created repositories by default have the highest priority.
    values.put(Cols.PRIORITY, getMaxPriority() + 1);

    if (!values.containsKey(Cols.ADDRESS)) {
        throw new UnsupportedOperationException("Cannot add repo without an address.");
    }

    // The following fields have NOT NULL constraints in the DB, so need
    // to be present.

    if (!values.containsKey(Cols.IN_USE)) {
        values.put(Cols.IN_USE, 1);
    }

    if (!values.containsKey(Cols.MAX_AGE)) {
        values.put(Cols.MAX_AGE, 0);
    }

    if (!values.containsKey(Cols.VERSION)) {
        values.put(Cols.VERSION, 0);
    }

    if (!values.containsKey(Cols.NAME) || values.get(Cols.NAME) == null) {
        final String address = values.getAsString(Cols.ADDRESS);
        values.put(Cols.NAME, Repo.addressToName(address));
    }

    long id = db().insertOrThrow(getTableName(), null, values);
    Utils.debugLog(TAG, "Inserted repo. Notifying provider change: '" + uri + "'.");
    getContext().getContentResolver().notifyChange(uri, null);
    return getContentUri(id);
}
 
源代码6 项目: timecat   文件: TimeCatContentProvider.java
@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
    String[] path= uri.getPath().split(SEPARATOR);
    String type=path[1];
    String key=path[2];
    Object obj= (Object) values.get(VALUE);
    if (obj!=null)
        SPHelperImpl.save(getContext(),key,obj);
    return null;
}
 
源代码7 项目: Meteorite   文件: Insert.java
@NonNull
public Insert<TModel> columnValues(@NonNull ContentValues contentValues) {
    java.util.Set<Map.Entry<String, Object>> entries = contentValues.valueSet();
    int count = 0;
    String[] columns = new String[contentValues.size()];
    Object[] values = new Object[contentValues.size()];
    for (Map.Entry<String, Object> entry : entries) {
        String key = entry.getKey();
        columns[count] = key;
        values[count] = contentValues.get(key);
        count++;
    }

    return columns(columns).values(values);
}
 
源代码8 项目: google-authenticator-android   文件: AccountDb.java
private boolean insertNewAccount(ContentValues values) {
  Preconditions.checkNotNull(values);
  Preconditions.checkNotNull(values.get(NAME_COLUMN));
  AccountIndex index =
      new AccountIndex((String) values.get(NAME_COLUMN), (String) values.get(ISSUER_COLUMN));
  if (indexExists(index)) {
    return false;  // An account with this name already exists
  }
  return mDatabase.insert(TABLE_NAME, null, values) != -1;
}
 
源代码9 项目: app-indexing   文件: RecipeContentProvider.java
public int updateNoteForRecipe(Uri uri, ContentValues values) {
    String sql = "UPDATE `" + RecipeNoteTable.TABLE + "` SET `" + RecipeNoteTable.TEXT_COLUMN
            + "` = '" + values.get(RecipeNoteTable.TEXT_COLUMN) + "' where `" +
            RecipeNoteTable.RECIPE_ID_COLUMN + "` = '" + uri.getLastPathSegment() + "'";
    database.getWritableDatabase().execSQL(sql);
    return 1;
}
 
源代码10 项目: app-indexing   文件: RecipeContentProvider.java
public int updateNoteForRecipe(Uri uri, ContentValues values) {
    String sql = "UPDATE `" + RecipeNoteTable.TABLE + "` SET `" + RecipeNoteTable.TEXT_COLUMN
            + "` = '" + values.get(RecipeNoteTable.TEXT_COLUMN) + "' where `" +
            RecipeNoteTable.RECIPE_ID_COLUMN + "` = '" + uri.getLastPathSegment() + "'";
    database.getWritableDatabase().execSQL(sql);
    return 1;
}
 
源代码11 项目: search-samples   文件: RecipeContentProvider.java
public Uri insertNoteForRecipe(Uri uri, ContentValues values) {
    String sql = "INSERT INTO `" + RecipeNoteTable.TABLE + "` (`" + RecipeNoteTable
            .RECIPE_ID_COLUMN + "`, `" + RecipeNoteTable.TEXT_COLUMN + "`) VALUES ('" + uri
            .getLastPathSegment() + "', '" + values.get(RecipeNoteTable.TEXT_COLUMN) + "')";
    database.getWritableDatabase().execSQL(sql);
    return uri;
}
 
源代码12 项目: android-galaxyzoo   文件: ItemsContentProvider.java
private static ContentValues getMappedContentValues(final ContentValues values, final Map<String, String> projectionMap) {
    final ContentValues result = new ContentValues();

    for (final String keyExternal : values.keySet()) {
        final String keyInternal = projectionMap.get(keyExternal);
        if (!TextUtils.isEmpty(keyInternal)) {
            final Object value = values.get(keyExternal);
            putValueInContentValues(result, keyInternal, value);
        }
    }

    return result;
}
 
源代码13 项目: Indic-Keyboard   文件: MetadataDbHelper.java
/**
 * Helper method to fill in an incomplete ContentValues with default values.
 * A wordlist ID and a locale are required, otherwise BadFormatException is thrown.
 * @return the same object that was passed in, completed with default values.
 */
public static ContentValues completeWithDefaultValues(final ContentValues result)
        throws BadFormatException {
    if (null == result.get(WORDLISTID_COLUMN) || null == result.get(LOCALE_COLUMN)) {
        throw new BadFormatException();
    }
    // 0 for the pending id, because there is none
    if (null == result.get(PENDINGID_COLUMN)) result.put(PENDINGID_COLUMN, 0);
    // This is a binary blob of a dictionary
    if (null == result.get(TYPE_COLUMN)) result.put(TYPE_COLUMN, TYPE_BULK);
    // This word list is unknown, but it's present, else we wouldn't be here, so INSTALLED
    if (null == result.get(STATUS_COLUMN)) result.put(STATUS_COLUMN, STATUS_INSTALLED);
    // No description unless specified, because we can't guess it
    if (null == result.get(DESCRIPTION_COLUMN)) result.put(DESCRIPTION_COLUMN, "");
    // File name - this is an asset, so it works as an already deleted file.
    //     hence, we need to supply a non-existent file name. Anything will
    //     do as long as it returns false when tested with File#exist(), and
    //     the empty string does not, so it's set to "_".
    if (null == result.get(LOCAL_FILENAME_COLUMN)) result.put(LOCAL_FILENAME_COLUMN, "_");
    // No remote file name : this can't be downloaded. Unless specified.
    if (null == result.get(REMOTE_FILENAME_COLUMN)) result.put(REMOTE_FILENAME_COLUMN, "");
    // 0 for the update date : 1970/1/1. Unless specified.
    if (null == result.get(DATE_COLUMN)) result.put(DATE_COLUMN, 0);
    // Raw checksum unknown unless specified
    if (null == result.get(RAW_CHECKSUM_COLUMN)) result.put(RAW_CHECKSUM_COLUMN, "");
    // Retry column 0 unless specified
    if (null == result.get(RETRY_COUNT_COLUMN)) result.put(RETRY_COUNT_COLUMN,
            DICTIONARY_RETRY_THRESHOLD);
    // Checksum unknown unless specified
    if (null == result.get(CHECKSUM_COLUMN)) result.put(CHECKSUM_COLUMN, "");
    // No filesize unless specified
    if (null == result.get(FILESIZE_COLUMN)) result.put(FILESIZE_COLUMN, 0);
    // Smallest possible version unless specified
    if (null == result.get(VERSION_COLUMN)) result.put(VERSION_COLUMN, 1);
    // Assume current format unless specified
    if (null == result.get(FORMATVERSION_COLUMN))
        result.put(FORMATVERSION_COLUMN, UpdateHandler.MAXIMUM_SUPPORTED_FORMAT_VERSION);
    // No flags unless specified
    if (null == result.get(FLAGS_COLUMN)) result.put(FLAGS_COLUMN, 0);
    return result;
}
 
源代码14 项目: Android-Keyboard   文件: MetadataDbHelper.java
/**
 * Helper method to fill in an incomplete ContentValues with default values.
 * A wordlist ID and a locale are required, otherwise BadFormatException is thrown.
 * @return the same object that was passed in, completed with default values.
 */
public static ContentValues completeWithDefaultValues(final ContentValues result)
        throws BadFormatException {
    if (null == result.get(WORDLISTID_COLUMN) || null == result.get(LOCALE_COLUMN)) {
        throw new BadFormatException();
    }
    // 0 for the pending id, because there is none
    if (null == result.get(PENDINGID_COLUMN)) result.put(PENDINGID_COLUMN, 0);
    // This is a binary blob of a dictionary
    if (null == result.get(TYPE_COLUMN)) result.put(TYPE_COLUMN, TYPE_BULK);
    // This word list is unknown, but it's present, else we wouldn't be here, so INSTALLED
    if (null == result.get(STATUS_COLUMN)) result.put(STATUS_COLUMN, STATUS_INSTALLED);
    // No description unless specified, because we can't guess it
    if (null == result.get(DESCRIPTION_COLUMN)) result.put(DESCRIPTION_COLUMN, "");
    // File name - this is an asset, so it works as an already deleted file.
    //     hence, we need to supply a non-existent file name. Anything will
    //     do as long as it returns false when tested with File#exist(), and
    //     the empty string does not, so it's set to "_".
    if (null == result.get(LOCAL_FILENAME_COLUMN)) result.put(LOCAL_FILENAME_COLUMN, "_");
    // No remote file name : this can't be downloaded. Unless specified.
    if (null == result.get(REMOTE_FILENAME_COLUMN)) result.put(REMOTE_FILENAME_COLUMN, "");
    // 0 for the update date : 1970/1/1. Unless specified.
    if (null == result.get(DATE_COLUMN)) result.put(DATE_COLUMN, 0);
    // Raw checksum unknown unless specified
    if (null == result.get(RAW_CHECKSUM_COLUMN)) result.put(RAW_CHECKSUM_COLUMN, "");
    // Retry column 0 unless specified
    if (null == result.get(RETRY_COUNT_COLUMN)) result.put(RETRY_COUNT_COLUMN,
            DICTIONARY_RETRY_THRESHOLD);
    // Checksum unknown unless specified
    if (null == result.get(CHECKSUM_COLUMN)) result.put(CHECKSUM_COLUMN, "");
    // No filesize unless specified
    if (null == result.get(FILESIZE_COLUMN)) result.put(FILESIZE_COLUMN, 0);
    // Smallest possible version unless specified
    if (null == result.get(VERSION_COLUMN)) result.put(VERSION_COLUMN, 1);
    // Assume current format unless specified
    if (null == result.get(FORMATVERSION_COLUMN))
        result.put(FORMATVERSION_COLUMN, UpdateHandler.MAXIMUM_SUPPORTED_FORMAT_VERSION);
    // No flags unless specified
    if (null == result.get(FLAGS_COLUMN)) result.put(FLAGS_COLUMN, 0);
    return result;
}
 
源代码15 项目: ArscEditor   文件: MainActivity.java
@Override
protected String doInBackground(String... params) {
	switch (ResType) {

	case ARSC:
		for (ContentValues resource : RESOURCES) {
			// 获取资源的键
			String NAME = (String) resource.get(MyObj.NAME);
			// 获取资源的值
			String VALUE = (String) resource.get(MyObj.VALUE);
			// 获取资源类型
			String TYPE = (String) resource.get(MyObj.TYPE);
			// 获取资源分支
			String CONFIG = (String) resource.get(MyObj.CONFIG);

			// 如果资源的Config开头存在-符号,并且Config列表中不存在该资源的Config元素,并且资源种类是params[0]的值
			if (CONFIG.startsWith("-") && !Configs.contains(CONFIG.substring(1)) && TYPE.equals(params[0]))
				// 向Config列表中添加元素
				Configs.add(CONFIG.substring(1));
			// 如果资源的Config开头不存在-符号,并且Config列表中不存在该资源的Config元素,并且资源种类是params[0]的值
			else if (!CONFIG.startsWith("-") && !Configs.contains(CONFIG) && TYPE.equals(params[0]))
				Configs.add(CONFIG);

			// 如果资源的Config开头存在-符号,并且Config列表中存在该资源的Config元素,并且Config是params[1]的值
			if (TYPE.equals(params[0]) && CONFIG.startsWith("-") && CONFIG.substring(1).equals(params[1])) {
				// 向储存字符串的列表中添加字符串成员
				txtOriginal.add(VALUE);
				// 向储存修改后的字符串的列表中添加空成员
				txtTranslated.add("");
				// 向储存资源的键的列表添加键
				txtTranslated_Key.add(NAME);
				// 如果资源的Config开头不存在-符号,并且Config列表中存在该资源的Config元素,并且Config是params[1]的值
			} else if (TYPE.equals(params[0]) && !CONFIG.startsWith("-") && CONFIG.equals(params[1])) {
				// 向储存字符串的列表中添加字符串成员
				txtOriginal.add(VALUE);
				// 向储存修改后的字符串的列表中添加空成员
				txtTranslated.add("");
				// 向储存资源的键的列表添加键
				txtTranslated_Key.add(NAME);
			}
		}
		break;
	case AXML:
		try {
			mAndRes.mAXMLDecoder.getStrings(txtOriginal);
			for (int i = 0; i < txtOriginal.size(); i++) {
				// 向储存修改后的字符串的列表中添加空成员
				txtTranslated.add("");
				// 向储存资源的键添加空成员
				txtTranslated_Key.add("");
			}
		} catch (CharacterCodingException e) {
			return e.toString();
		}
		break;
	case DEX:

		break;
	}
	// 返回一个成功的标志
	return getString(R.string.success);
}
 
源代码16 项目: AOSP-Kayboard-7.1.2   文件: MetadataDbHelper.java
/**
 * Helper method to fill in an incomplete ContentValues with default values.
 * A wordlist ID and a locale are required, otherwise BadFormatException is thrown.
 * @return the same object that was passed in, completed with default values.
 */
public static ContentValues completeWithDefaultValues(final ContentValues result)
        throws BadFormatException {
    if (null == result.get(WORDLISTID_COLUMN) || null == result.get(LOCALE_COLUMN)) {
        throw new BadFormatException();
    }
    // 0 for the pending id, because there is none
    if (null == result.get(PENDINGID_COLUMN)) result.put(PENDINGID_COLUMN, 0);
    // This is a binary blob of a dictionary
    if (null == result.get(TYPE_COLUMN)) result.put(TYPE_COLUMN, TYPE_BULK);
    // This word list is unknown, but it's present, else we wouldn't be here, so INSTALLED
    if (null == result.get(STATUS_COLUMN)) result.put(STATUS_COLUMN, STATUS_INSTALLED);
    // No description unless specified, because we can't guess it
    if (null == result.get(DESCRIPTION_COLUMN)) result.put(DESCRIPTION_COLUMN, "");
    // File name - this is an asset, so it works as an already deleted file.
    //     hence, we need to supply a non-existent file name. Anything will
    //     do as long as it returns false when tested with File#exist(), and
    //     the empty string does not, so it's set to "_".
    if (null == result.get(LOCAL_FILENAME_COLUMN)) result.put(LOCAL_FILENAME_COLUMN, "_");
    // No remote file name : this can't be downloaded. Unless specified.
    if (null == result.get(REMOTE_FILENAME_COLUMN)) result.put(REMOTE_FILENAME_COLUMN, "");
    // 0 for the update date : 1970/1/1. Unless specified.
    if (null == result.get(DATE_COLUMN)) result.put(DATE_COLUMN, 0);
    // Raw checksum unknown unless specified
    if (null == result.get(RAW_CHECKSUM_COLUMN)) result.put(RAW_CHECKSUM_COLUMN, "");
    // Retry column 0 unless specified
    if (null == result.get(RETRY_COUNT_COLUMN)) result.put(RETRY_COUNT_COLUMN,
            DICTIONARY_RETRY_THRESHOLD);
    // Checksum unknown unless specified
    if (null == result.get(CHECKSUM_COLUMN)) result.put(CHECKSUM_COLUMN, "");
    // No filesize unless specified
    if (null == result.get(FILESIZE_COLUMN)) result.put(FILESIZE_COLUMN, 0);
    // Smallest possible version unless specified
    if (null == result.get(VERSION_COLUMN)) result.put(VERSION_COLUMN, 1);
    // Assume current format unless specified
    if (null == result.get(FORMATVERSION_COLUMN))
        result.put(FORMATVERSION_COLUMN, UpdateHandler.MAXIMUM_SUPPORTED_FORMAT_VERSION);
    // No flags unless specified
    if (null == result.get(FLAGS_COLUMN)) result.put(FLAGS_COLUMN, 0);
    return result;
}
 
源代码17 项目: opentasks-provider   文件: UrlFieldAdapter.java
@Override
public URI getFrom(ContentValues values)
{
	return values.get(mFieldName) == null ? null : URI.create(values.getAsString(mFieldName));
}
 
源代码18 项目: kripton   文件: Database.java
/**
 * {@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 (!TextUtils.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);
		}
	}
}
 
源代码19 项目: opentasks-provider   文件: SimpleFieldAdapter.java
@Override
public boolean existsIn(ContentValues values)
{
	return values.get(fieldName()) != null;
}
 
源代码20 项目: opentasks   文件: UrlFieldAdapter.java
@Override
public URI getFrom(ContentValues values)
{
    return values.get(mFieldName) == null ? null : URI.create(values.getAsString(mFieldName));
}