Java Code Examples for android.content.ContentValues#getAsLong()

The following examples show how to use android.content.ContentValues#getAsLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestProvider.java    From Popular-Movies-App with Apache License 2.0 6 votes vote down vote up
public void testMovieByIdQuery() {
    ContentValues testValues = insertTestValues();
    long testMovieId = testValues.getAsLong(MoviesContract.MovieEntry._ID);
    Uri testMovieUri = MoviesContract.MovieEntry.buildMovieUri(testMovieId);

    Cursor movie = mContext.getContentResolver().query(
            testMovieUri,
            null,
            null,
            null,
            null
    );
    if (movie == null) {
        fail("Get empty cursor by querying movie by id.");
    }
    TestUtilities.validateCursor("Error by querying movie by id.", movie, testValues);
    assertEquals("Movie by ID query returned more than one entry. ", movie.getCount(), 1);

    if (Build.VERSION.SDK_INT >= 19) {
        assertEquals("Error: Movie by ID Query did not properly set NotificationUri",
                movie.getNotificationUri(), testMovieUri);
    }
    movie.close();
}
 
Example 2
Source File: AntiRevoke.java    From WechatEnhancement with GNU General Public License v3.0 5 votes vote down vote up
private void handleMessageRecall(ContentValues contentValues) {
    long msgId = contentValues.getAsLong("msgId");
    Object msg = msgCacheMap.get(msgId);
    long createTime = XposedHelpers.getLongField(msg, "field_createTime");
    XposedHelpers.setIntField(msg, "field_type", contentValues.getAsInteger("type"));
    XposedHelpers.setObjectField(msg, "field_content",
            contentValues.getAsString("content") + "(已被阻止)");

    XposedHelpers.setLongField(msg, "field_createTime", createTime + 1L);
    XposedHelpers.callMethod(storageInsertClazz, HookParams.getInstance().MsgInfoStorageInsertMethod, msg, false);

}
 
Example 3
Source File: WeatherProvider.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Handles requests to insert a set of new rows. In Sunshine, we are only going to be
 * inserting multiple rows of data at a time from a weather forecast. There is no use case
 * for inserting a single row of data into our ContentProvider, and so we are only going to
 * implement bulkInsert. In a normal ContentProvider's implementation, you will probably want
 * to provide proper functionality for the insert method as well.
 *
 * @param uri    The content:// URI of the insertion request.
 * @param values An array of sets of column_name/value pairs to add to the database.
 *               This must not be {@code null}.
 *
 * @return The number of values that were inserted.
 */
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    switch (sUriMatcher.match(uri)) {

        case CODE_WEATHER:
            db.beginTransaction();
            int rowsInserted = 0;
            try {
                for (ContentValues value : values) {
                    long weatherDate =
                            value.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE);
                    if (!SunshineDateUtils.isDateNormalized(weatherDate)) {
                        throw new IllegalArgumentException("Date must be normalized to insert");
                    }

                    long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value);
                    if (_id != -1) {
                        rowsInserted++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }

            if (rowsInserted > 0) {
                getContext().getContentResolver().notifyChange(uri, null);
            }

            return rowsInserted;

        default:
            return super.bulkInsert(uri, values);
    }
}
 
Example 4
Source File: WeatherProvider.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Handles requests to insert a set of new rows. In Sunshine, we are only going to be
 * inserting multiple rows of data at a time from a weather forecast. There is no use case
 * for inserting a single row of data into our ContentProvider, and so we are only going to
 * implement bulkInsert. In a normal ContentProvider's implementation, you will probably want
 * to provide proper functionality for the insert method as well.
 *
 * @param uri    The content:// URI of the insertion request.
 * @param values An array of sets of column_name/value pairs to add to the database.
 *               This must not be {@code null}.
 *
 * @return The number of values that were inserted.
 */
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    switch (sUriMatcher.match(uri)) {

        case CODE_WEATHER:
            db.beginTransaction();
            int rowsInserted = 0;
            try {
                for (ContentValues value : values) {
                    long weatherDate =
                            value.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE);
                    if (!SunshineDateUtils.isDateNormalized(weatherDate)) {
                        throw new IllegalArgumentException("Date must be normalized to insert");
                    }

                    long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value);
                    if (_id != -1) {
                        rowsInserted++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }

            if (rowsInserted > 0) {
                getContext().getContentResolver().notifyChange(uri, null);
            }

            return rowsInserted;

        default:
            return super.bulkInsert(uri, values);
    }
}
 
Example 5
Source File: ProviderSchematic.java    From cathode with Apache License 2.0 5 votes vote down vote up
@NotifyInsert(paths = Path.MOVIE_CAST)
public static Uri[] notifyInsert(ContentValues values) {
  final long movieId = values.getAsLong(MovieCastColumns.MOVIE_ID);
  final long personId = values.getAsLong(MovieCastColumns.PERSON_ID);
  return new Uri[] {
      fromMovie(movieId), withPerson(personId),
  };
}
 
Example 6
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static long replace(
        String tableName,
        ContentValues values)
{
    long featureId = values.getAsLong(FIELD_FEATURE_ID);
    int featureOperation = values.getAsInteger(FIELD_OPERATION);
    long attachId = values.getAsLong(FIELD_ATTACH_ID);
    int attachOperation = values.getAsInteger(FIELD_ATTACH_OPERATION);

    String selection = FIELD_FEATURE_ID + " = " + featureId + " AND " +
            FIELD_OPERATION + " = " + featureOperation + " AND " +
            FIELD_ATTACH_ID + " = " + attachId + " AND " +
            FIELD_ATTACH_OPERATION + " = " + attachOperation;

    Cursor cursor = query(tableName, selection, null, "1");
    long res = 0;

    if (null != cursor) {
        res = cursor.getCount();
        cursor.close();
    }

    if (res > 0) {
        return res;
    }

    return insert(tableName, values);
}
 
Example 7
Source File: WordListMetadata.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a WordListMetadata from the contents of a ContentValues.
 *
 * If this lacks any required field, IllegalArgumentException is thrown.
 */
public static WordListMetadata createFromContentValues(@Nonnull final ContentValues values) {
    final String id = values.getAsString(MetadataDbHelper.WORDLISTID_COLUMN);
    final Integer type = values.getAsInteger(MetadataDbHelper.TYPE_COLUMN);
    final String description = values.getAsString(MetadataDbHelper.DESCRIPTION_COLUMN);
    final Long lastUpdate = values.getAsLong(MetadataDbHelper.DATE_COLUMN);
    final Long fileSize = values.getAsLong(MetadataDbHelper.FILESIZE_COLUMN);
    final String rawChecksum = values.getAsString(MetadataDbHelper.RAW_CHECKSUM_COLUMN);
    final String checksum = values.getAsString(MetadataDbHelper.CHECKSUM_COLUMN);
    final int retryCount = values.getAsInteger(MetadataDbHelper.RETRY_COUNT_COLUMN);
    final String localFilename = values.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
    final String remoteFilename = values.getAsString(MetadataDbHelper.REMOTE_FILENAME_COLUMN);
    final Integer version = values.getAsInteger(MetadataDbHelper.VERSION_COLUMN);
    final Integer formatVersion = values.getAsInteger(MetadataDbHelper.FORMATVERSION_COLUMN);
    final Integer flags = values.getAsInteger(MetadataDbHelper.FLAGS_COLUMN);
    final String locale = values.getAsString(MetadataDbHelper.LOCALE_COLUMN);
    if (null == id
            || null == type
            || null == description
            || null == lastUpdate
            || null == fileSize
            || null == checksum
            || null == localFilename
            || null == remoteFilename
            || null == version
            || null == formatVersion
            || null == flags
            || null == locale) {
        throw new IllegalArgumentException();
    }
    return new WordListMetadata(id, type, description, lastUpdate, fileSize, rawChecksum,
            checksum, retryCount, localFilename, remoteFilename, version, formatVersion,
            flags, locale);
}
 
Example 8
Source File: WeatherProvider.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Handles requests to insert a set of new rows. In Sunshine, we are only going to be
 * inserting multiple rows of data at a time from a weather forecast. There is no use case
 * for inserting a single row of data into our ContentProvider, and so we are only going to
 * implement bulkInsert. In a normal ContentProvider's implementation, you will probably want
 * to provide proper functionality for the insert method as well.
 *
 * @param uri    The content:// URI of the insertion request.
 * @param values An array of sets of column_name/value pairs to add to the database.
 *               This must not be {@code null}.
 *
 * @return The number of values that were inserted.
 */
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    switch (sUriMatcher.match(uri)) {

        case CODE_WEATHER:
            db.beginTransaction();
            int rowsInserted = 0;
            try {
                for (ContentValues value : values) {
                    long weatherDate =
                            value.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE);
                    if (!SunshineDateUtils.isDateNormalized(weatherDate)) {
                        throw new IllegalArgumentException("Date must be normalized to insert");
                    }

                    long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value);
                    if (_id != -1) {
                        rowsInserted++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }

            if (rowsInserted > 0) {
                getContext().getContentResolver().notifyChange(uri, null);
            }

            return rowsInserted;

        default:
            return super.bulkInsert(uri, values);
    }
}
 
Example 9
Source File: WeatherProvider.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Handles requests to insert a set of new rows. In Sunshine, we are only going to be
 * inserting multiple rows of data at a time from a weather forecast. There is no use case
 * for inserting a single row of data into our ContentProvider, and so we are only going to
 * implement bulkInsert. In a normal ContentProvider's implementation, you will probably want
 * to provide proper functionality for the insert method as well.
 *
 * @param uri    The content:// URI of the insertion request.
 * @param values An array of sets of column_name/value pairs to add to the database.
 *               This must not be {@code null}.
 *
 * @return The number of values that were inserted.
 */
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    switch (sUriMatcher.match(uri)) {

        case CODE_WEATHER:
            db.beginTransaction();
            int rowsInserted = 0;
            try {
                for (ContentValues value : values) {
                    long weatherDate =
                            value.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE);
                    if (!SunshineDateUtils.isDateNormalized(weatherDate)) {
                        throw new IllegalArgumentException("Date must be normalized to insert");
                    }

                    long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value);
                    if (_id != -1) {
                        rowsInserted++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }

            if (rowsInserted > 0) {
                getContext().getContentResolver().notifyChange(uri, null);
            }

            return rowsInserted;

        default:
            return super.bulkInsert(uri, values);
    }
}
 
Example 10
Source File: ProviderSchematic.java    From cathode with Apache License 2.0 5 votes vote down vote up
@NotifyInsert(paths = Path.SHOW_CREW)
public static Uri[] notifyInsert(ContentValues values) {
  final long showId = values.getAsLong(ShowCrewColumns.SHOW_ID);
  final long personId = values.getAsLong(ShowCrewColumns.PERSON_ID);
  return new Uri[] {
      fromShow(showId), withPerson(personId),
  };
}
 
Example 11
Source File: ChromeBrowserProvider.java    From 365browser with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: TestSunshineDatabase.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
 * Tests to ensure that inserts into your database results in automatically incrementing row
 * IDs and that row IDs are not reused.
 * <p>
 * If the INTEGER PRIMARY KEY column is not explicitly given a value, then it will be filled
 * automatically with an unused integer, usually one more than the largest _ID currently in
 * use. This is true regardless of whether or not the AUTOINCREMENT keyword is used.
 * <p>
 * If the AUTOINCREMENT keyword appears after INTEGER PRIMARY KEY, that changes the automatic
 * _ID assignment algorithm to prevent the reuse of _IDs over the lifetime of the database.
 * In other words, the purpose of AUTOINCREMENT is to prevent the reuse of _IDs from previously
 * deleted rows.
 * <p>
 * To test this, we first insert a row into the database and get its _ID. Then, we'll delete
 * that row, change the data that we're going to insert, and insert the changed data into the
 * database again. If AUTOINCREMENT isn't set up properly in the WeatherDbHelper's table
 * create statement, then the _ID of the first insert will be reused. However, if AUTOINCREMENT
 * is setup properly, that older ID will NOT be reused, and the test will pass.
 */
@Test
public void testDuplicateDateInsertBehaviorShouldReplace() {

    /* Obtain weather values from TestUtilities */
    ContentValues testWeatherValues = TestUtilities.createTestWeatherContentValues();

    /*
     * Get the original weather ID of the testWeatherValues to ensure we use a different
     * weather ID for our next insert.
     */
    long originalWeatherId = testWeatherValues.getAsLong(REFLECTED_COLUMN_WEATHER_ID);

    /* Insert the ContentValues with old weather ID into database */
    database.insert(
            WeatherContract.WeatherEntry.TABLE_NAME,
            null,
            testWeatherValues);

    /*
     * We don't really care what this ID is, just that it is different than the original and
     * that we can use it to verify our "new" weather entry has been made.
     */
    long newWeatherId = originalWeatherId + 1;

    testWeatherValues.put(REFLECTED_COLUMN_WEATHER_ID, newWeatherId);

    /* Insert the ContentValues with new weather ID into database */
    database.insert(
            WeatherContract.WeatherEntry.TABLE_NAME,
            null,
            testWeatherValues);

    /* Query for a weather record with our new weather ID */
    Cursor newWeatherIdCursor = database.query(
            REFLECTED_TABLE_NAME,
            new String[]{REFLECTED_COLUMN_DATE},
            null,
            null,
            null,
            null,
            null);

    String recordWithNewIdNotFound =
            "New record did not overwrite the previous record for the same date.";
    assertTrue(recordWithNewIdNotFound,
            newWeatherIdCursor.getCount() == 1);

    /* Always close the cursor after you're done with it */
    newWeatherIdCursor.close();
}
 
Example 13
Source File: TestSunshineDatabase.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
     * Tests to ensure that inserts into your database results in automatically
     * incrementing row IDs.
>>>>>>> 4174cf2... S07.02-Exercise-PreventInvalidInserts
     */
    @Test
    public void testIntegerAutoincrement() {

        /* First, let's ensure we have some values in our table initially */
        testInsertSingleRecordIntoWeatherTable();

        /* Obtain weather values from TestUtilities */
        ContentValues testWeatherValues = TestUtilities.createTestWeatherContentValues();

        /* Get the date of the testWeatherValues to ensure we use a different date later */
        long originalDate = testWeatherValues.getAsLong(REFLECTED_COLUMN_DATE);

        /* Insert ContentValues into database and get a row ID back */
        long firstRowId = database.insert(
                REFLECTED_TABLE_NAME,
                null,
                testWeatherValues);

        /* Delete the row we just inserted to see if the database will reuse the rowID */
        database.delete(
                REFLECTED_TABLE_NAME,
                "_ID == " + firstRowId,
                null);

        /*
         * Now we need to change the date associated with our test content values because the
         * database policy is to replace identical dates on conflict.
         */
        long dayAfterOriginalDate = originalDate + TimeUnit.DAYS.toMillis(1);
        testWeatherValues.put(REFLECTED_COLUMN_DATE, dayAfterOriginalDate);

        /* Insert ContentValues into database and get another row ID back */
        long secondRowId = database.insert(
                REFLECTED_TABLE_NAME,
                null,
                testWeatherValues);

        String sequentialInsertsDoNotAutoIncrementId =
                "IDs were reused and shouldn't be if autoincrement is setup properly.";
        assertNotSame(sequentialInsertsDoNotAutoIncrementId,
                firstRowId, secondRowId);
    }
 
Example 14
Source File: TestSunshineDatabase.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
     * Tests to ensure that inserts into your database results in automatically
     * incrementing row IDs.
>>>>>>> 4174cf2... S07.02-Exercise-PreventInvalidInserts
     */
    @Test
    public void testIntegerAutoincrement() {

        /* First, let's ensure we have some values in our table initially */
        testInsertSingleRecordIntoWeatherTable();

        /* Obtain weather values from TestUtilities */
        ContentValues testWeatherValues = TestUtilities.createTestWeatherContentValues();

        /* Get the date of the testWeatherValues to ensure we use a different date later */
        long originalDate = testWeatherValues.getAsLong(REFLECTED_COLUMN_DATE);

        /* Insert ContentValues into database and get a row ID back */
        long firstRowId = database.insert(
                REFLECTED_TABLE_NAME,
                null,
                testWeatherValues);

        /* Delete the row we just inserted to see if the database will reuse the rowID */
        database.delete(
                REFLECTED_TABLE_NAME,
                "_ID == " + firstRowId,
                null);

        /*
         * Now we need to change the date associated with our test content values because the
         * database policy is to replace identical dates on conflict.
         */
        long dayAfterOriginalDate = originalDate + TimeUnit.DAYS.toMillis(1);
        testWeatherValues.put(REFLECTED_COLUMN_DATE, dayAfterOriginalDate);

        /* Insert ContentValues into database and get another row ID back */
        long secondRowId = database.insert(
                REFLECTED_TABLE_NAME,
                null,
                testWeatherValues);

        String sequentialInsertsDoNotAutoIncrementId =
                "IDs were reused and shouldn't be if autoincrement is setup properly.";
        assertNotSame(sequentialInsertsDoNotAutoIncrementId,
                firstRowId, secondRowId);
    }
 
Example 15
Source File: DateTimeFieldAdapter.java    From opentasks with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 16
Source File: ContactsUtils14.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CallerInfo findSelfInfo(Context ctxt) {
    
    
    CallerInfo callerInfo = new CallerInfo();

    String[] projection = new String[] {
                Profile._ID,
                Profile.DISPLAY_NAME,
                Profile.PHOTO_ID,
                Profile.PHOTO_URI
        };
    Cursor cursor = ctxt.getContentResolver().query(Profile.CONTENT_URI, projection, 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(Profile.DISPLAY_NAME) ) {
                    callerInfo.name = cv.getAsString(Profile.DISPLAY_NAME);
                }
                

                if(cv.containsKey(Profile._ID) ) {
                    callerInfo.personId = cv.getAsLong(Profile._ID);
                    callerInfo.contactContentUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, callerInfo.personId);
                }
                
                if(cv.containsKey(Profile.PHOTO_ID)) {
                    Long photoId = cv.getAsLong(Profile.PHOTO_ID);
                    if(photoId != null) {
                        callerInfo.photoId = photoId;
                    }
                }
                
                if(cv.containsKey(Profile.PHOTO_URI)) {
                    String photoUri = cv.getAsString(Profile.PHOTO_URI);
                    if(!TextUtils.isEmpty(photoUri)) {
                        callerInfo.photoUri = Uri.parse(photoUri);
                    }
                }

                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();
        }
    }
    
    
    return callerInfo;
}
 
Example 17
Source File: LongFieldAdapter.java    From opentasks-provider with Apache License 2.0 4 votes vote down vote up
@Override
public Long getFrom(ContentValues values)
{
	return values.getAsLong(mFieldName);
}
 
Example 18
Source File: TestSunshineDatabase.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
     * Tests to ensure that inserts into your database results in automatically
     * incrementing row IDs.
>>>>>>> 4174cf2... S07.02-Exercise-PreventInvalidInserts
     */
    @Test
    public void testIntegerAutoincrement() {

        /* First, let's ensure we have some values in our table initially */
        testInsertSingleRecordIntoWeatherTable();

        /* Obtain weather values from TestUtilities */
        ContentValues testWeatherValues = TestUtilities.createTestWeatherContentValues();

        /* Get the date of the testWeatherValues to ensure we use a different date later */
        long originalDate = testWeatherValues.getAsLong(REFLECTED_COLUMN_DATE);

        /* Insert ContentValues into database and get a row ID back */
        long firstRowId = database.insert(
                REFLECTED_TABLE_NAME,
                null,
                testWeatherValues);

        /* Delete the row we just inserted to see if the database will reuse the rowID */
        database.delete(
                REFLECTED_TABLE_NAME,
                "_ID == " + firstRowId,
                null);

        /*
         * Now we need to change the date associated with our test content values because the
         * database policy is to replace identical dates on conflict.
         */
        long dayAfterOriginalDate = originalDate + TimeUnit.DAYS.toMillis(1);
        testWeatherValues.put(REFLECTED_COLUMN_DATE, dayAfterOriginalDate);

        /* Insert ContentValues into database and get another row ID back */
        long secondRowId = database.insert(
                REFLECTED_TABLE_NAME,
                null,
                testWeatherValues);

        String sequentialInsertsDoNotAutoIncrementId =
                "IDs were reused and shouldn't be if autoincrement is setup properly.";
        assertNotSame(sequentialInsertsDoNotAutoIncrementId,
                firstRowId, secondRowId);
    }
 
Example 19
Source File: AlarmState.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
public AlarmState(ContentValues values)
{
    rowID = values.getAsLong(AlarmDatabaseAdapter.KEY_STATE_ALARMID);
    state = values.getAsInteger(AlarmDatabaseAdapter.KEY_STATE);
}
 
Example 20
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Convenience function for retrieving a single settings value as a
 * Long.
 *
 * @param name The name of the setting to retrieve.
 * @param def The value to return if the setting is not defined.
 * @return The setting's current value or 'def' if it is not
 *         defined.
 */
private long getLong(String name, long def) {
    ContentValues values = getValues(name);
    return values != null ? values.getAsLong(VALUE) : def;
}