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

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

源代码1 项目: android-chromium   文件: ChromeBrowserProvider.java
private long addBookmark(ContentValues values) {
    String url = values.getAsString(Browser.BookmarkColumns.URL);
    String title = values.getAsString(Browser.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;
}
 
源代码2 项目: EverMemo   文件: Memo.java
public static Memo build(ContentValues values) {
	Memo memo = new Memo();
	if (values.containsKey("_id")) {
		memo._id = values.getAsInteger("_id");
	}
	memo.mGuid = values.getAsString("guid");
	memo.mEnid = values.getAsString("enid");
	memo.mWallId = values.getAsInteger("wallid");
	memo.mOrder = values.getAsInteger("orderid");
	memo.mSyncStatus = values.getAsInteger("syncstatus");
	memo.setContent(values.getAsString("content"));
	memo.mAttributes = values.getAsString("attributes");
	memo.mStatus = values.getAsString("status");
	memo.mCreatedTime = values.getAsLong("createdtime");
	memo.mUpdatedTime = values.getAsLong("updatedtime");
	memo.mLastSyncTime = values.getAsLong("lastsynctime");
	memo.mCursorPosition = values.getAsInteger("cursorposition");
	return memo;
}
 
@Override
public TaskAdapter duplicate()
{
	ContentValues newValues = new ContentValues(mValues);

	// copy all columns (except _ID) that are not in the values yet
	for (int i = 0, count = mCursor.getColumnCount(); i < count; ++i)
	{
		String column = mCursor.getColumnName(i);
		if (!newValues.containsKey(column) && !TaskContract.Tasks._ID.equals(column))
		{
			newValues.put(column, mCursor.getString(i));
		}
	}

	return new ContentValuesTaskAdapter(newValues);
}
 
源代码4 项目: 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);
}
 
源代码5 项目: android-chromium   文件: ChromeBrowserProvider.java
static SearchRow fromContentValues(ContentValues values) {
    SearchRow row = new SearchRow();
    if (values.containsKey(SearchColumns.SEARCH)) {
        row.term = values.getAsString(SearchColumns.SEARCH);
    }
    if (values.containsKey(SearchColumns.DATE)) {
        row.date = values.getAsLong(SearchColumns.DATE);
    }
    return row;
}
 
源代码6 项目: LB-Launcher   文件: LauncherProvider.java
private static long dbInsertAndCheck(DatabaseHelper helper,
        SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) {
    if (values == null) {
        throw new RuntimeException("Error: attempting to insert null values");
    }
    if (!values.containsKey(LauncherSettings.ChangeLogColumns._ID)) {
        throw new RuntimeException("Error: attempting to add item without specifying an id");
    }
    helper.checkId(table, values);
    return db.insert(table, nullColumnHack, values);
}
 
源代码7 项目: sana.mobile   文件: TableHelper.java
/**
 * Sets the creation and modification time to the current date time
 * formatted as {@link org.sana.api.IModel#DATE_FORMAT}
 */
@Override
public ContentValues onInsert(ContentValues values) {
    ContentValues validValues = new ContentValues();
    String value = new SimpleDateFormat(IModel.DATE_FORMAT,
            Locale.US).format(new Date());
    if (!values.containsKey(BaseContract.UUID))
        throw new IllegalArgumentException("Can not insert without uuid");
    //validValues.put(BaseContract.UUID, UUID.randomUUID().toString());
    validValues.put(BaseContract.CREATED, value);
    validValues.put(BaseContract.MODIFIED, value);
    validValues.putAll(values);
    return validValues;
}
 
源代码8 项目: Trebuchet   文件: LauncherProvider.java
@Thunk boolean initializeExternalAdd(ContentValues values) {
    // 1. Ensure that externally added items have a valid item id
    long id = generateNewItemId();
    values.put(LauncherSettings.Favorites._ID, id);

    // 2. In the case of an app widget, and if no app widget id is specified, we
    // attempt allocate and bind the widget.
    Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
    if (itemType != null &&
            itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET &&
            !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) {

        final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
        ComponentName cn = ComponentName.unflattenFromString(
                values.getAsString(Favorites.APPWIDGET_PROVIDER));

        if (cn != null) {
            try {
                int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
                values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
                if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) {
                    return false;
                }
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to initialize external widget", e);
                return false;
            }
        } else {
            return false;
        }
    }

    // Add screen id if not present
    long screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
    if (!addScreenIdIfNecessary(screenId)) {
        return false;
    }
    return true;
}
 
源代码9 项目: assertj-android   文件: ContentValuesAssert.java
private boolean containsEntry(ContentValues actual, ContentValuesEntry entry) {
  if (entry == null) {
    throw new NullPointerException("Entries to look for should not be null");
  }
  String key = entry.getKey();
  if (!actual.containsKey(key)) {
    return false;
  }
  return areEqual(actual.get(key), entry.getValue());
}
 
源代码10 项目: delion   文件: ChromeBrowserProvider.java
static SearchRow fromContentValues(ContentValues values) {
    SearchRow row = new SearchRow();
    if (values.containsKey(SearchColumns.SEARCH)) {
        row.mTerm = values.getAsString(SearchColumns.SEARCH);
    }
    if (values.containsKey(SearchColumns.DATE)) {
        row.mDate = values.getAsLong(SearchColumns.DATE);
    }
    return row;
}
 
@Override
public DateTime[] getFrom(Cursor cursor, ContentValues values)
{
	int tsIdx;
	int tzIdx;
	String datetimeList;
	String timeZoneId = null;

	if (values != null && values.containsKey(mDateTimeListFieldName))
	{
		if (values.getAsLong(mDateTimeListFieldName) == null)
		{
			// the date times are null, so we return null
			return null;
		}
		datetimeList = values.getAsString(mDateTimeListFieldName);
	}
	else if (cursor != null && (tsIdx = cursor.getColumnIndex(mDateTimeListFieldName)) >= 0)
	{
		if (cursor.isNull(tsIdx))
		{
			// the date times are null, so we return null
			return null;
		}
		datetimeList = cursor.getString(tsIdx);
	}
	else
	{
		throw new IllegalArgumentException("Missing date time list column.");
	}

	if (mTimeZoneFieldName != null)
	{
		if (values != null && values.containsKey(mTimeZoneFieldName))
		{
			timeZoneId = values.getAsString(mTimeZoneFieldName);
		}
		else if (cursor != null && (tzIdx = cursor.getColumnIndex(mTimeZoneFieldName)) >= 0)
		{
			timeZoneId = cursor.getString(tzIdx);
		}
		else
		{
			throw new IllegalArgumentException("Missing timezone column.");
		}
	}

	// create a new TimeZone for the given time zone string
	TimeZone timeZone = timeZoneId == null ? null : TimeZone.getTimeZone(timeZoneId);

	String[] datetimes = SEPARATOR_PATTERN.split(datetimeList);

	DateTime[] result = new DateTime[datetimes.length];
	for (int i = 0, count = datetimes.length; i < count; ++i)
	{
		DateTime value = DateTime.parse(timeZone, datetimes[i]);

		if (!value.isAllDay() && value.isFloating())
		{
			throw new IllegalArgumentException("DateTime values must not be floating, unless they are all-day.");
		}

		result[i] = value;
		if (i > 0 && result[0].isAllDay() != value.isAllDay())
		{
			throw new IllegalArgumentException("DateTime values must all be of the same type.");
		}
	}

	return result;
}
 
源代码12 项目: Silence   文件: MmsDatabase.java
private Pair<Long, Long> insertMessageInbox(MasterSecret masterSecret, IncomingMediaMessage retrieved,
                                            String contentLocation, long threadId, long mailbox)
    throws MmsException
{
  if (threadId == -1 || retrieved.isGroupMessage()) {
    try {
      threadId = getThreadIdFor(retrieved);
    } catch (RecipientFormattingException e) {
      Log.w("MmsDatabase", e);
      if (threadId == -1)
        throw new MmsException(e);
    }
  }
  ContentValues contentValues = new ContentValues();

  contentValues.put(DATE_SENT, retrieved.getSentTimeMillis());
  contentValues.put(ADDRESS, retrieved.getAddresses().getFrom());

  contentValues.put(MESSAGE_BOX, mailbox);
  contentValues.put(MESSAGE_TYPE, PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF);
  contentValues.put(THREAD_ID, threadId);
  contentValues.put(CONTENT_LOCATION, contentLocation);
  contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
  contentValues.put(DATE_RECEIVED, generatePduCompatTimestamp());
  contentValues.put(PART_COUNT, retrieved.getAttachments().size());
  contentValues.put(SUBSCRIPTION_ID, retrieved.getSubscriptionId());
  contentValues.put(READ, 0);

  if (!contentValues.containsKey(DATE_SENT)) {
    contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
  }

  long messageId = insertMediaMessage(masterSecret, retrieved.getAddresses(),
                                      retrieved.getBody(), retrieved.getAttachments(),
                                      contentValues);

  DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
  DatabaseFactory.getThreadDatabase(context).update(threadId, true);
  notifyConversationListeners(threadId);
  jobManager.add(new TrimThreadJob(context, threadId));

  return new Pair<>(messageId, threadId);
}
 
private ContentValues parseObject(JsonParser parser, SQLiteDatabase tempDb, String parentId, int seq) throws JsonParseException, IOException {
	// TODO : Grab id of root topic here, and store it in shared prefs, in case it ever
	//        changes. Currently we assume "root" and a change would be catastrophic.
	ContentValues result = new ContentValues();
	ChildArrayResults childResults = null;
	boolean badKind = false;
	
	result.put("parentTopic_id", parentId);
	result.put("seq", seq);
	
	while (parser.nextValue() != JsonToken.END_OBJECT) {
		
		// Allows us to burn through the rest of the object once we discover it's an exercise or something else we don't care about.
		if (badKind) continue;
		
		String fieldName = parser.getCurrentName();
		
		// Keys present will determine object type.
		if (stringFields.contains(fieldName)) {
			// Use getValueAsString over getText; getText returns "null" while getValueAsString returns null.
			String value = parser.getValueAsString();
			result.put(fieldName, value);
			
			if ("id".equals(fieldName)) {
				if (childResults != null) {
					addParentIdToChildren(tempDb, childResults, value);
				}
			}
		} else if (intFields.contains(fieldName)) {
			result.put(fieldName, parser.getIntValue());
		} else if (booleanFields.contains(fieldName)) {
			result.put(fieldName, parser.getBooleanValue());
		} else if ("children".equals(fieldName)) {
			childResults = parseChildArray(parser, tempDb, result.containsKey("id") ? result.getAsString("id") : null);
			result.put("video_count", childResults.videoCount);
			result.put("child_kind", childResults.childKind);
			result.put("thumb_id", childResults.thumbId);
		} else if ("download_urls".equals(fieldName)) {
			parseDownloadUrls(parser, result);
		} else if (null == fieldName) {
			// Noop. Just in case.
		} else {
			JsonToken next = parser.getCurrentToken();
			if (next == JsonToken.START_OBJECT || next == JsonToken.START_ARRAY) {
				// Skip this object or array, leaving us pointing at the matching end_object / end_array token.
				parser.skipChildren();
			}
		}
	}
	
	// Ignore types we don't need.
	if (badKind) {
		return null;
	}
	
	// Having parsed this whole object, we can insert it.
	if (result.containsKey("kind")) {
		String kind = result.getAsString("kind");
		if ("Topic".equals(kind)) {
			if (result.containsKey("id")) {
				result.put("_id", result.getAsString("id"));
				result.remove("id");
			}
			if (result.containsKey("child_kind")) {
				String child_kind = result.getAsString("child_kind");
				if ("Topic".equals(child_kind) || "Video".equals(child_kind)) {
					insertTopic(tempDb, result);
				}
			}
		} else if ("Video".equals(kind)) {
			if (result.containsKey("id")) {
				result.put("video_id", result.getAsString("id"));
				result.remove("id");
			}
			insertTopicVideo(tempDb, result);
			insertVideo(tempDb, result);
		}
	}
	
	return result;
}
 
源代码14 项目: CSipSimple   文件: ContactsUtils3.java
@Override
public CallerInfo findCallerInfo(Context ctxt, String number) {
    Uri searchUri = Uri
            .withAppendedPath(Phones.CONTENT_FILTER_URL, Uri.encode(number));

    CallerInfo callerInfo = new CallerInfo();

    Cursor cursor = ctxt.getContentResolver().query(searchUri, null, null, null, null);
    if (cursor != null) {
        try {
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                ContentValues cv = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(cursor, cv);
                callerInfo.contactExists = true;
                if (cv.containsKey(Phones.DISPLAY_NAME)) {
                    callerInfo.name = cv.getAsString(Phones.DISPLAY_NAME);
                }

                callerInfo.phoneNumber = cv.getAsString(Phones.NUMBER);

                if (cv.containsKey(Phones.TYPE)
                        && cv.containsKey(Phones.LABEL)) {
                    callerInfo.numberType = cv.getAsInteger(Phones.TYPE);
                    callerInfo.numberLabel = cv.getAsString(Phones.LABEL);
                    callerInfo.phoneLabel = Phones.getDisplayLabel(ctxt,
                            callerInfo.numberType, callerInfo.numberLabel)
                            .toString();
                }

                if (cv.containsKey(Phones.PERSON_ID)) {
                    callerInfo.personId = cv.getAsLong(Phones.PERSON_ID);
                    callerInfo.contactContentUri = ContentUris.withAppendedId(
                            People.CONTENT_URI, callerInfo.personId);
                }

                if (cv.containsKey(Phones.CUSTOM_RINGTONE)) {
                    String ringtoneUriString = cv.getAsString(Phones.CUSTOM_RINGTONE);
                    if (!TextUtils.isEmpty(ringtoneUriString)) {
                        callerInfo.contactRingtoneUri = Uri.parse(ringtoneUriString);
                    }
                }

                if (callerInfo.name != null && callerInfo.name.length() == 0) {
                    callerInfo.name = null;
                }

            }

        } catch (Exception e) {
            Log.e(THIS_FILE, "Exception while retrieving cursor infos", e);
        } finally {
            cursor.close();
        }

    }

    // if no query results were returned with a viable number,
    // fill in the original number value we used to query with.
    if (TextUtils.isEmpty(callerInfo.phoneNumber)) {
        callerInfo.phoneNumber = number;
    }

    return callerInfo;
}
 
源代码15 项目: opentasks   文件: DateTimeIterableFieldAdapter.java
@Override
public Iterable<DateTime> getFrom(Cursor cursor, ContentValues values)
{
    int tsIdx;
    int tzIdx;
    String datetimeList;
    String timeZoneId = null;

    if (values != null && values.containsKey(mDateTimeListFieldName))
    {
        if (values.getAsString(mDateTimeListFieldName) == null)
        {
            // the date times are null, so we return null
            return EmptyIterable.instance();
        }
        datetimeList = values.getAsString(mDateTimeListFieldName);
    }
    else if (cursor != null && (tsIdx = cursor.getColumnIndex(mDateTimeListFieldName)) >= 0)
    {
        if (cursor.isNull(tsIdx))
        {
            // the date times are null, so we return an empty Iterable.
            return EmptyIterable.instance();
        }
        datetimeList = cursor.getString(tsIdx);
    }
    else
    {
        throw new IllegalArgumentException("Missing date time list column.");
    }

    if (mTimeZoneFieldName != null)
    {
        if (values != null && values.containsKey(mTimeZoneFieldName))
        {
            timeZoneId = values.getAsString(mTimeZoneFieldName);
        }
        else if (cursor != null && (tzIdx = cursor.getColumnIndex(mTimeZoneFieldName)) >= 0)
        {
            timeZoneId = cursor.getString(tzIdx);
        }
        else
        {
            throw new IllegalArgumentException("Missing timezone column.");
        }
    }

    // create a new TimeZone for the given time zone string
    TimeZone timeZone = timeZoneId == null ? null : TimeZone.getTimeZone(timeZoneId);

    return new DateTimeList(timeZone, datetimeList);
}
 
源代码16 项目: fdroidclient   文件: Repo.java
public void setValues(ContentValues values) {

        if (values.containsKey(Cols._ID)) {
            id = toInt(values.getAsInteger(Cols._ID));
        }

        if (values.containsKey(Cols.LAST_ETAG)) {
            lastetag = values.getAsString(Cols.LAST_ETAG);
        }

        if (values.containsKey(Cols.ADDRESS)) {
            address = values.getAsString(Cols.ADDRESS);
        }

        if (values.containsKey(Cols.DESCRIPTION)) {
            description = values.getAsString(Cols.DESCRIPTION);
        }

        if (values.containsKey(Cols.FINGERPRINT)) {
            fingerprint = values.getAsString(Cols.FINGERPRINT);
        }

        if (values.containsKey(Cols.IN_USE)) {
            inuse = toInt(values.getAsInteger(Cols.IN_USE)) == 1;
        }

        if (values.containsKey(Cols.LAST_UPDATED)) {
            final String dateString = values.getAsString(Cols.LAST_UPDATED);
            lastUpdated = Utils.parseTime(dateString, Utils.parseDate(dateString, null));
        }

        if (values.containsKey(Cols.MAX_AGE)) {
            maxage = toInt(values.getAsInteger(Cols.MAX_AGE));
        }

        if (values.containsKey(Cols.VERSION)) {
            version = toInt(values.getAsInteger(Cols.VERSION));
        }

        if (values.containsKey(Cols.NAME)) {
            name = values.getAsString(Cols.NAME);
        }

        if (values.containsKey(Cols.SIGNING_CERT)) {
            signingCertificate = values.getAsString(Cols.SIGNING_CERT);
        }

        if (values.containsKey(Cols.PRIORITY)) {
            priority = toInt(values.getAsInteger(Cols.PRIORITY));
        }

        if (values.containsKey(Cols.IS_SWAP)) {
            isSwap = toInt(values.getAsInteger(Cols.IS_SWAP)) == 1;
        }

        if (values.containsKey(Cols.USERNAME)) {
            username = values.getAsString(Cols.USERNAME);
        }

        if (values.containsKey(Cols.PASSWORD)) {
            password = values.getAsString(Cols.PASSWORD);
        }

        if (values.containsKey(Cols.TIMESTAMP)) {
            timestamp = toInt(values.getAsInteger(Cols.TIMESTAMP));
        }

        if (values.containsKey(Cols.ICON)) {
            icon = values.getAsString(Cols.ICON);
        }

        if (values.containsKey(Cols.MIRRORS)) {
            mirrors = Utils.parseCommaSeparatedString(values.getAsString(Cols.MIRRORS));
        }

        if (values.containsKey(Cols.USER_MIRRORS)) {
            userMirrors = Utils.parseCommaSeparatedString(values.getAsString(Cols.USER_MIRRORS));
        }

        if (values.containsKey(Cols.DISABLED_MIRRORS)) {
            disabledMirrors = Utils.parseCommaSeparatedString(values.getAsString(Cols.DISABLED_MIRRORS));
        }

        if (values.containsKey(Cols.PUSH_REQUESTS)) {
            pushRequests = toInt(values.getAsInteger(Cols.PUSH_REQUESTS));
        }
    }
 
源代码17 项目: framework   文件: BaseModelProvider.java
@Override
public int update(@NonNull Uri uri, ContentValues all_values, String selection, String[] selectionArgs) {
    OModel model = getModel(uri);
    setMatcher(model, uri);
    ContentValues[] values = generateValues(model, all_values);
    ContentValues value_to_update = values[0];
    if (!value_to_update.containsKey("_write_date")) {
        value_to_update.put("_write_date", ODateUtils.getUTCDate());
    }
    if (!value_to_update.containsKey("_is_dirty")) {
        value_to_update.put("_is_dirty", "true");
    }
    int count = 0;
    int match = matcher.match(uri);
    switch (match) {
        case COLLECTION:
            SQLiteDatabase db = model.getWritableDatabase();
            count = db.update(model.getTableName(), value_to_update, selection, selectionArgs);
            // Updating relation columns
            if (values[1].size() > 0) {
                storeUpdateRelationRecords(model, values[1], selection, selectionArgs);
            }

            break;
        case SINGLE_ROW:
            String row_id = uri.getLastPathSegment();
            db = model.getWritableDatabase();
            count = db.update(model.getTableName(), value_to_update, OColumn.ROW_ID + "  = ?", new String[]{row_id});
            // Updating relation columns for record
            if (values[1].size() > 0) {
                storeUpdateRelationRecords(model, values[1], OColumn.ROW_ID + "  = ?", new String[]{row_id});
            }
            break;
        case UriMatcher.NO_MATCH:
            break;
        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    notifyDataChange(uri);
    return count;
}
 
源代码18 项目: hr   文件: BaseModelProvider.java
@Override
public int update(Uri uri, ContentValues all_values, String selection, String[] selectionArgs) {
    setModel(uri);
    setMatcher(uri);
    ContentValues[] values = generateValues(all_values);
    ContentValues value_to_update = values[0];
    if (!value_to_update.containsKey("_write_date")) {
        value_to_update.put("_write_date", ODateUtils.getUTCDate());
    }
    if (!value_to_update.containsKey("_is_dirty")) {
        value_to_update.put("_is_dirty", "true");
    }
    int count = 0;
    int match = matcher.match(uri);
    switch (match) {
        case COLLECTION:
            SQLiteDatabase db = mModel.getWritableDatabase();
            count = db.update(mModel.getTableName(), value_to_update, selection, selectionArgs);
            // Updating relation columns
            if (values[1].size() > 0) {
                storeUpdateRelationRecords(values[1], selection, selectionArgs);
            }

            break;
        case SINGLE_ROW:
            String row_id = uri.getLastPathSegment();
            db = mModel.getWritableDatabase();
            count = db.update(mModel.getTableName(), value_to_update, OColumn.ROW_ID + "  = ?", new String[]{row_id});
            // Updating relation columns for record
            if (values[1].size() > 0) {
                storeUpdateRelationRecords(values[1], OColumn.ROW_ID + "  = ?", new String[]{row_id});
            }
            break;
        case UriMatcher.NO_MATCH:
            break;
        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    notifyDataChange(uri);
    return count;
}
 
源代码19 项目: Silence   文件: MmsDatabase.java
public Pair<Long, Long> insertMessageInbox(@NonNull NotificationInd notification, int subscriptionId) {
  SQLiteDatabase     db              = databaseHelper.getWritableDatabase();
  MmsAddressDatabase addressDatabase = DatabaseFactory.getMmsAddressDatabase(context);
  long                 threadId       = getThreadIdFor(notification);
  ContentValues        contentValues  = new ContentValues();
  ContentValuesBuilder contentBuilder = new ContentValuesBuilder(contentValues);

  Log.w(TAG, "Message received type: " + notification.getMessageType());

  contentBuilder.add(CONTENT_LOCATION, notification.getContentLocation());
  contentBuilder.add(DATE_SENT, System.currentTimeMillis());
  contentBuilder.add(EXPIRY, notification.getExpiry());
  contentBuilder.add(MESSAGE_SIZE, notification.getMessageSize());
  contentBuilder.add(TRANSACTION_ID, notification.getTransactionId());
  contentBuilder.add(MESSAGE_TYPE, notification.getMessageType());

  if (notification.getFrom() != null) {
    contentBuilder.add(ADDRESS, notification.getFrom().getTextString());
  } else {
    contentBuilder.add(ADDRESS, null);
  }

  long dateReceived = generatePduCompatTimestamp();

  contentValues.put(MESSAGE_BOX, Types.BASE_INBOX_TYPE);
  contentValues.put(THREAD_ID, threadId);
  contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
  contentValues.put(DATE_RECEIVED, dateReceived);
  contentValues.put(READ, Util.isDefaultSmsProvider(context) ? 0 : 1);
  contentValues.put(SUBSCRIPTION_ID, subscriptionId);

  if (!contentValues.containsKey(DATE_SENT))
    contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));

  if (contentValues.getAsLong(DATE_SENT) <= 0)
    contentValues.put(DATE_SENT, dateReceived);

  long messageId = db.insert(TABLE_NAME, null, contentValues);

  if (notification.getFrom() != null) {
    addressDatabase.insertAddressesForId(messageId, MmsAddresses.forFrom(Util.toIsoString(notification.getFrom().getTextString())));
  }

  return new Pair<>(messageId, threadId);
}
 
源代码20 项目: opentasks   文件: DateTimeFieldAdapter.java
@Override
public DateTime getFrom(Cursor cursor, ContentValues values)
{
    int tsIdx;
    int tzIdx;
    int adIdx;
    long timestamp;
    String timeZoneId = null;
    Integer allDay = 0;

    if (values != null && values.containsKey(mTimestampField))
    {
        if (values.getAsLong(mTimestampField) == null)
        {
            // if the time stamp is null we return null
            return null;
        }
        timestamp = values.getAsLong(mTimestampField);
    }
    else if (cursor != null && (tsIdx = cursor.getColumnIndex(mTimestampField)) >= 0)
    {
        if (cursor.isNull(tsIdx))
        {
            // if the time stamp is null we return null
            return null;
        }
        timestamp = cursor.getLong(tsIdx);
    }
    else
    {
        throw new IllegalArgumentException("Missing timestamp column.");
    }

    if (mTzField != null)
    {
        if (values != null && values.containsKey(mTzField))
        {
            timeZoneId = values.getAsString(mTzField);
        }
        else if (cursor != null && (tzIdx = cursor.getColumnIndex(mTzField)) >= 0)
        {
            timeZoneId = cursor.getString(tzIdx);
        }
        else
        {
            throw new IllegalArgumentException("Missing timezone column.");
        }
    }

    if (mAllDayField != null)
    {
        if (values != null && values.containsKey(mAllDayField))
        {
            allDay = values.getAsInteger(mAllDayField);
        }
        else if (cursor != null && (adIdx = cursor.getColumnIndex(mAllDayField)) >= 0)
        {
            allDay = cursor.getInt(adIdx);
        }
        else
        {
            throw new IllegalArgumentException("Missing timezone column.");
        }
    }

    // create a new Time for the given time zone, falling back to UTC if none is given
    DateTime value = new DateTime(timeZoneId == null ? DateTime.UTC : TimeZone.getTimeZone(timeZoneId), timestamp);

    if (allDay != 0)
    {
        value = value.toAllDay();
    }
    return value;
}