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


Java ContentValues.getAsInteger方法代码示例

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


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

示例1: insertApp

import android.content.ContentValues; //导入方法依赖的package包/类
public static App insertApp(Context context, String packageName, String name, ContentValues additionalValues) {

        ContentValues values = new ContentValues();
        values.put(AppMetadataTable.Cols.REPO_ID, 1);
        values.put(AppMetadataTable.Cols.Package.PACKAGE_NAME, packageName);
        values.put(AppMetadataTable.Cols.NAME, name);

        // Required fields (NOT NULL in the database).
        values.put(AppMetadataTable.Cols.SUMMARY, "test summary");
        values.put(AppMetadataTable.Cols.DESCRIPTION, "test description");
        values.put(AppMetadataTable.Cols.LICENSE, "GPL?");
        values.put(AppMetadataTable.Cols.IS_COMPATIBLE, 1);

        values.putAll(additionalValues);

        // Don't hard code to 1, let consumers override it in additionalValues then ask for it back.
        int repoId = values.getAsInteger(AppMetadataTable.Cols.REPO_ID);

        Uri uri = AppProvider.getContentUri();

        context.getContentResolver().insert(uri, values);
        App app = AppProvider.Helper.findSpecificApp(context.getContentResolver(), packageName,
                repoId, AppMetadataTable.Cols.ALL);
        assertNotNull(app);
        return app;
    }
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:27,代码来源:Assert.java

示例2: execute

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public void execute(final Context context) {
    if (null == mWordList) { // This should never happen
        Log.e(TAG, "DisableAction with a null word list!");
        return;
    }
    DebugLogUtils.l("Disabling word list : " + mWordList);
    final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
    final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
            mWordList.mId, mWordList.mVersion);
    final int status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN);
    if (MetadataDbHelper.STATUS_INSTALLED == status) {
        // Disabling an installed word list
        MetadataDbHelper.markEntryAsDisabled(db, mWordList.mId, mWordList.mVersion);
    } else {
        if (MetadataDbHelper.STATUS_DOWNLOADING != status) {
            Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' : "
                    + status + " for a disable action. Fall back to marking as available.");
        }
        // The word list is still downloading. Cancel the download and revert the
        // word list status to "available".
        final DownloadManagerWrapper manager = new DownloadManagerWrapper(context);
        manager.remove(values.getAsLong(MetadataDbHelper.PENDINGID_COLUMN));
        MetadataDbHelper.markEntryAsAvailable(db, mWordList.mId, mWordList.mVersion);
    }
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:27,代码来源:ActionBatch.java

示例3: readFromValues

import android.content.ContentValues; //导入方法依赖的package包/类
public void readFromValues(ContentValues values) {
    itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
    container = values.getAsLong(LauncherSettings.Favorites.CONTAINER);
    screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
    cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX);
    cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY);
    spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX);
    spanY = values.getAsInteger(LauncherSettings.Favorites.SPANY);
    rank = values.getAsInteger(LauncherSettings.Favorites.RANK);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:11,代码来源:ItemInfo.java

示例4: update

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {

    // When the priority of a repo changes, we need to update the "preferred metadata" foreign
    // key in the package table to point to the best possible record in the app metadata table.
    // The full list of times when we need to recalculate the preferred metadata includes:
    //  * After the priority of a repo changes
    //  * After a repo is disabled
    //  * After a repo is enabled
    //  * After an update is performed
    // This code only checks for the priority changing. All other occasions we can't do the
    // recalculation right now, because we likely haven't added/removed the relevant apps
    // from the metadata table yet. Usually the repo details are updated, then a request is
    // made to do the heavier work (e.g. a repo update to get new list of apps from server).
    // After the heavier work is complete, then that process can request the preferred metadata
    // to be recalculated.
    boolean priorityChanged = false;
    if (values.containsKey(Cols.PRIORITY)) {
        Cursor priorityCursor = db().query(getTableName(), new String[]{Cols.PRIORITY},
                where, whereArgs, null, null, null);
        if (priorityCursor.getCount() > 0) {
            priorityCursor.moveToFirst();
            int oldPriority = priorityCursor.getInt(priorityCursor.getColumnIndex(Cols.PRIORITY));
            priorityChanged = oldPriority != values.getAsInteger(Cols.PRIORITY);
        }
        priorityCursor.close();
    }

    int numRows = db().update(getTableName(), values, where, whereArgs);

    if (priorityChanged) {
        AppProvider.Helper.recalculatePreferredMetadata(getContext());
    }

    Utils.debugLog(TAG, "Updated repo. Notifying provider change: '" + uri + "'.");
    getContext().getContentResolver().notifyChange(uri, null);
    return numRows;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:39,代码来源:RepoProvider.java

示例5: createFromContentValue

import android.content.ContentValues; //导入方法依赖的package包/类
public void createFromContentValue(ContentValues args) {
	Integer tmp_i;
	String tmp_s;
	
	tmp_i = args.getAsInteger(_ID);
	if (tmp_i != null) {
		id = tmp_i;
	}
	tmp_i = args.getAsInteger(FIELD_PRIORITY);
	if (tmp_i != null) {
		priority = tmp_i;
	}
	tmp_i = args.getAsInteger(FIELD_ACTION);
	if (tmp_i != null) {
		action = tmp_i;
	}
	
	
	tmp_s = args.getAsString(FIELD_MATCHES);
	if (tmp_s != null) {
		matchPattern = tmp_s;
	}
	tmp_s = args.getAsString(FIELD_REPLACE);
	if (tmp_s != null) {
		replacePattern = tmp_s;
	}
	
	tmp_i = args.getAsInteger(FIELD_ACCOUNT);
	if(tmp_i != null) {
		account = tmp_i;
	}
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:33,代码来源:Filter.java

示例6: populateEvent

import android.content.ContentValues; //导入方法依赖的package包/类
@Override
protected void populateEvent(ContentValues values) {
    super.populateEvent(values);
    fileName = values.getAsString(CalendarContract.Events._SYNC_ID);
    eTag = values.getAsString(COLUMN_ETAG);
    event.uid = values.getAsString(COLUMN_UID);

    event.sequence = values.getAsInteger(COLUMN_SEQUENCE);
    if (Build.VERSION.SDK_INT >= 17) {
        weAreOrganizer = values.getAsInteger(CalendarContract.Events.IS_ORGANIZER) != 0;
    } else {
        String organizer = values.getAsString(CalendarContract.Events.ORGANIZER);
        weAreOrganizer = organizer == null || organizer.equals(calendar.account.name);
    }
}
 
开发者ID:6thsolution,项目名称:EasyAppleSyncAdapter,代码行数:16,代码来源:LocalEvent.java

示例7: getDownloadManagerPendingIdFromWordlistId

import android.content.ContentValues; //导入方法依赖的package包/类
static private int getDownloadManagerPendingIdFromWordlistId(final Context context,
        final String clientId, final String wordlistId) {
    final SQLiteDatabase db = MetadataDbHelper.getDb(context, clientId);
    final ContentValues wordlistValues =
            MetadataDbHelper.getContentValuesOfLatestAvailableWordlistById(db, wordlistId);
    if (null == wordlistValues) {
        // We don't know anything about a word list with this id. Bug? This should never
        // happen, but still return to prevent a crash.
        Log.e(TAG, "Unexpected word list ID: " + wordlistId);
        return NOT_A_DOWNLOADMANAGER_PENDING_ID;
    }
    return wordlistValues.getAsInteger(MetadataDbHelper.PENDINGID_COLUMN);
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:14,代码来源:DictionaryDownloadProgressBar.java

示例8: insertPet

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * Helper method to add Pet to the database.
 * This method is called inside the INSERT method
 *
 * @param uri
 * @param values
 * @return
 */
private Uri insertPet(Uri uri, ContentValues values) {
    // sanity check the values
    String name = values.getAsString(PetEntry.COLUMN_NAME);
    Integer gender = values.getAsInteger(PetEntry.COLUMN_GENDER);
    Integer weight = values.getAsInteger(PetEntry.COLUMN_WEIGHT);

    // check name
    if (name.isEmpty()) {
        throw new IllegalArgumentException("Pet requires a name");
    }

    // check gender
    if (gender == null || !isValidGender(gender)) {
        throw new IllegalArgumentException("Pet requires valid gender");
    }

    // check weight
    if ((weight != null) && (weight < 0)) {
        throw new IllegalArgumentException("Pet requires valid weight");
    }


    // access the database in write mode
    SQLiteDatabase database = mPetDbHelper.getWritableDatabase();

    // insert the pet to database
    long id = database.insert(PetEntry.TABLE_NAME, null, values);

    if (id == -1) {
        Log.e(LOG_TAG, "Failed to insert row for " + uri);
        return null;
    }

    // Notify all listeners that the data changed
    getContext().getContentResolver().notifyChange(uri, null);

    return ContentUris.withAppendedId(uri, id);
}
 
开发者ID:gusbru,项目名称:pets,代码行数:47,代码来源:PetProvider.java

示例9: deleteDataFile

import android.content.ContentValues; //导入方法依赖的package包/类
private int deleteDataFile(final Uri uri) {
    final String wordlistId = uri.getLastPathSegment();
    final String clientId = getClientId(uri);
    final ContentValues wordList = getWordlistMetadataForWordlistId(clientId, wordlistId);
    if (null == wordList) {
        return 0;
    }
    final int status = wordList.getAsInteger(MetadataDbHelper.STATUS_COLUMN);
    final int version = wordList.getAsInteger(MetadataDbHelper.VERSION_COLUMN);
    if (MetadataDbHelper.STATUS_DELETING == status) {
        UpdateHandler.markAsDeleted(getContext(), clientId, wordlistId, version, status);
        return 1;
    }
    if (MetadataDbHelper.STATUS_INSTALLED == status) {
        final String result = uri.getQueryParameter(QUERY_PARAMETER_DELETE_RESULT);
        if (QUERY_PARAMETER_FAILURE.equals(result)) {
            if (DEBUG) {
                Log.d(TAG,
                        "Dictionary is broken, attempting to retry download & installation.");
            }
            UpdateHandler.markAsBrokenOrRetrying(getContext(), clientId, wordlistId, version);
        }
        final String localFilename =
                wordList.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
        final File f = getContext().getFileStreamPath(localFilename);
        // f.delete() returns true if the file was successfully deleted, false otherwise
        return f.delete() ? 1 : 0;
    }
    Log.e(TAG, "Attempt to delete a file whose status is " + status);
    return 0;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:32,代码来源:DictionaryProvider.java

示例10: createFromContentValues

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:39,代码来源:WordListMetadata.java

示例11: markEntryAsFinishedDownloadingAndInstalled

import android.content.ContentValues; //导入方法依赖的package包/类
/**
 * Marks a downloading entry as having successfully downloaded and being installed.
 *
 * The metadata database contains information about ongoing processes, typically ongoing
 * downloads. This marks such an entry as having finished and having installed successfully,
 * so it becomes INSTALLED.
 *
 * @param db the metadata database.
 * @param r content values about the entry to mark as processed.
 */
public static void markEntryAsFinishedDownloadingAndInstalled(final SQLiteDatabase db,
        final ContentValues r) {
    switch (r.getAsInteger(TYPE_COLUMN)) {
        case TYPE_BULK:
            DebugLogUtils.l("Ended processing a wordlist");
            // Updating a bulk word list is a three-step operation:
            // - Add the new entry to the table
            // - Remove the old entry from the table
            // - Erase the old file
            // We start by gathering the names of the files we should delete.
            final List<String> filenames = new LinkedList<>();
            final Cursor c = db.query(METADATA_TABLE_NAME,
                    new String[] { LOCAL_FILENAME_COLUMN },
                    LOCALE_COLUMN + " = ? AND " +
                    WORDLISTID_COLUMN + " = ? AND " + STATUS_COLUMN + " = ?",
                    new String[] { r.getAsString(LOCALE_COLUMN),
                            r.getAsString(WORDLISTID_COLUMN),
                            Integer.toString(STATUS_INSTALLED) },
                    null, null, null);
            try {
                if (c.moveToFirst()) {
                    // There should never be more than one file, but if there are, it's a bug
                    // and we should remove them all. I think it might happen if the power of
                    // the phone is suddenly cut during an update.
                    final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN);
                    do {
                        DebugLogUtils.l("Setting for removal", c.getString(filenameIndex));
                        filenames.add(c.getString(filenameIndex));
                    } while (c.moveToNext());
                }
            } finally {
                c.close();
            }
            r.put(STATUS_COLUMN, STATUS_INSTALLED);
            db.beginTransactionNonExclusive();
            // Delete all old entries. There should never be any stalled entries, but if
            // there are, this deletes them.
            db.delete(METADATA_TABLE_NAME,
                    WORDLISTID_COLUMN + " = ?",
                    new String[] { r.getAsString(WORDLISTID_COLUMN) });
            db.insert(METADATA_TABLE_NAME, null, r);
            db.setTransactionSuccessful();
            db.endTransaction();
            for (String filename : filenames) {
                try {
                    final File f = new File(filename);
                    f.delete();
                } catch (SecurityException e) {
                    // No permissions to delete. Um. Can't do anything.
                } // I don't think anything else can be thrown
            }
            break;
        default:
            // Unknown type: do nothing.
            break;
    }
 }
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:68,代码来源:MetadataDbHelper.java

示例12: findCallerInfo

import android.content.ContentValues; //导入方法依赖的package包/类
@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;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:66,代码来源:ContactsUtils3.java

示例13: insertUnderTransaction

import android.content.ContentValues; //导入方法依赖的package包/类
private Uri insertUnderTransaction(SQLiteDatabase db, Uri uri, ContentValues contentValues) {
    long id, noteId;
    String table;
    Uri resultUri;

    switch (uris.matcher.match(uri)) {
        case ProviderUris.LOCAL_DB_REPO:
            table = DbDbRepo.TABLE;
            break;

        case ProviderUris.REPOS:
            id = DbRepo.insert(db, contentValues.getAsString(ProviderContract.Repos.Param.REPO_URL));
            return ContentUris.withAppendedId(uri, id);

        case ProviderUris.BOOKS:
            table = DbBook.TABLE;
            long bid = db.insertOrThrow(table, null, contentValues);
            insertRootNote(db, bid);
            return ContentUris.withAppendedId(uri, bid);

        case ProviderUris.FILTERS:
            table = DbSearch.TABLE;
            ProviderFilters.updateWithNextPosition(db, contentValues);
            break;

        case ProviderUris.NOTES:
            return insertNote(db, uri, contentValues, Place.UNSPECIFIED);

        case ProviderUris.NOTE_ABOVE:
            return insertNote(db, uri, contentValues, Place.ABOVE);

        case ProviderUris.NOTE_UNDER:
            return insertNote(db, uri, contentValues, Place.UNDER);

        case ProviderUris.NOTE_BELOW:
            return insertNote(db, uri, contentValues, Place.BELOW);

        case ProviderUris.NOTES_PROPERTIES:
            noteId = contentValues.getAsLong(ProviderContract.NoteProperties.Param.NOTE_ID);
            String name = contentValues.getAsString(ProviderContract.NoteProperties.Param.NAME);
            String value = contentValues.getAsString(ProviderContract.NoteProperties.Param.VALUE);
            int pos = contentValues.getAsInteger(ProviderContract.NoteProperties.Param.POSITION);

            long nameId = DbPropertyName.getOrInsert(db, name);
            long valueId = DbPropertyValue.getOrInsert(db, value);
            long propertyId = DbProperty.getOrInsert(db, nameId, valueId);
            long notePropertyId = DbNoteProperty.getOrInsert(db, noteId, pos, propertyId);

            return ContentUris.withAppendedId(uri, notePropertyId);

        case ProviderUris.LOAD_BOOK_FROM_FILE:
            resultUri = loadBookFromFile(contentValues);

            return resultUri;

        case ProviderUris.CURRENT_ROOKS:
            resultUri = insertCurrentRook(db, uri, contentValues);
            return resultUri;

        case ProviderUris.BOOKS_ID_SAVED:
            resultUri = bookSavedToRepo(db, uri, contentValues);
            return resultUri;

        default:
            throw new IllegalArgumentException("URI is not recognized: " + uri);
    }

    id = db.insertOrThrow(table, null, contentValues);

    return ContentUris.withAppendedId(uri, id);
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:72,代码来源:Provider.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: validateVehicleAndInsert

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

        String name = contentValues.getAsString(VehicleEntry.COLUMN_NAME).trim();
        if (isNotVehicleNameUnique(name, null)) {
            throw new IllegalArgumentException("Vehicle name must be set and unique.");
        }

        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.");
        }

        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.");
        }

        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.");
        }

        SQLiteDatabase database = mDbHelper.getWritableDatabase();
        long id = database.insert(VehicleEntry.TABLE_NAME, null, contentValues);

        if (id == -1) {
            Log.e(LOG_TAG, "Failed to insert row for " + uri);
            return null;
        }

        getContext().getContentResolver().notifyChange(uri, null);
        return ContentUris.withAppendedId(uri, id);
    }
 
开发者ID:piskula,项目名称:FuelUp,代码行数:45,代码来源:VehicleProvider.java


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