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

The following examples show how to use android.content.ContentValues#getAsInteger() . 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: ActionBatch.java    From Android-Keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(final Context context) {
    if (null == mWordList) {
        Log.e(TAG, "EnableAction with a null parameter!");
        return;
    }
    DebugLogUtils.l("Enabling word list");
    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_DISABLED != status
            && MetadataDbHelper.STATUS_DELETING != status) {
        Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + " : " + status
              + " for an enable action. Cancelling");
        return;
    }
    MetadataDbHelper.markEntryAsEnabled(db, mWordList.mId, mWordList.mVersion);
}
 
Example 2
Source File: AlarmDatabaseAdapter.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
public String addAlarmCSV_row( ContentValues alarm )
{
    String quote = "\"";
    String separator = ", ";
    //noinspection UnnecessaryLocalVariable
    String line = alarm.getAsString(KEY_ALARM_TYPE) + separator +
                  alarm.getAsInteger(KEY_ALARM_ENABLED) + separator +
                  alarm.getAsLong(KEY_ALARM_DATETIME_ADJUSTED) + separator +
                  alarm.getAsLong(KEY_ALARM_DATETIME) + separator +
                  alarm.getAsInteger(KEY_ALARM_DATETIME_HOUR) + separator +
                  alarm.getAsInteger(KEY_ALARM_DATETIME_MINUTE) + separator +
                  quote + alarm.getAsString(KEY_ALARM_LABEL) + quote + separator +
                  alarm.getAsInteger(KEY_ALARM_REPEATING) + separator +
                  quote + alarm.getAsString(KEY_ALARM_REPEATING_DAYS) + quote + separator +
                  alarm.getAsString(KEY_ALARM_SOLAREVENT) + separator +
                  alarm.getAsString(KEY_ALARM_TIMEZONE) + separator +
                  quote + alarm.getAsString(KEY_ALARM_PLACELABEL) + quote + separator +
                  alarm.getAsString(KEY_ALARM_LATITUDE) + separator +
                  alarm.getAsString(KEY_ALARM_LONGITUDE) + separator +
                  alarm.getAsString(KEY_ALARM_ALTITUDE) + separator +
                  alarm.getAsInteger(KEY_ALARM_VIBRATE) + separator +
                  alarm.getAsString(KEY_ALARM_RINGTONE_NAME) + separator +
                  alarm.getAsString(KEY_ALARM_RINGTONE_URI);
    return line;
}
 
Example 3
Source File: DateTimeFieldAdapter.java    From opentasks-provider with Apache License 2.0 6 votes vote down vote up
@Override
public DateTime getFrom(ContentValues values)
{
	Long timestamp = values.getAsLong(mTimestampField);
	if (timestamp == null)
	{
		// if the time stamp is null we return null
		return null;
	}
	// create a new Time for the given time zone, falling back to UTC if none is given
	String timezone = mTzField == null ? null : values.getAsString(mTzField);
	DateTime value = new DateTime(timezone == null ? DateTime.UTC : TimeZone.getTimeZone(timezone), timestamp);

	// cache mAlldayField locally
	String allDayField = mAllDayField;

	// set the allday flag appropriately
	Integer allDayInt = allDayField == null ? null : values.getAsInteger(allDayField);

	if ((allDayInt != null && allDayInt != 0) || (allDayField == null && mAllDayDefault))
	{
		value = value.toAllDay();
	}

	return value;
}
 
Example 4
Source File: Assert.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
 
Example 5
Source File: PredatorDbHelper.java    From Capstone-Project with MIT License 6 votes vote down vote up
public int addInstallLinks(ContentValues contentValues) {
    // Create and/or open the database for writing
    SQLiteDatabase db = getWritableDatabase();

    // It's a good idea to wrap our insert in a transaction. This helps with performance and ensures
    // consistency of the database.
    db.beginTransaction();
    try {
        db.insertOrThrow(PredatorContract.InstallLinksEntry.TABLE_NAME, null, contentValues);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Logger.e(TAG, "Error while trying to add install link to database", e);
    } finally {
        db.endTransaction();
    }
    return contentValues.getAsInteger(PredatorContract.InstallLinksEntry.COLUMN_POST_ID);
}
 
Example 6
Source File: ChromeBrowserProvider.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static BookmarkRow fromContentValues(ContentValues values) {
    BookmarkRow row = new BookmarkRow();
    if (values.containsKey(BookmarkColumns.URL)) {
        row.url = values.getAsString(BookmarkColumns.URL);
    }
    if (values.containsKey(BookmarkColumns.BOOKMARK)) {
        row.isBookmark = values.getAsInteger(BookmarkColumns.BOOKMARK) != 0;
    }
    if (values.containsKey(BookmarkColumns.CREATED)) {
        row.created = values.getAsLong(BookmarkColumns.CREATED);
    }
    if (values.containsKey(BookmarkColumns.DATE)) {
        row.date = values.getAsLong(BookmarkColumns.DATE);
    }
    if (values.containsKey(BookmarkColumns.FAVICON)) {
        row.favicon = values.getAsByteArray(BookmarkColumns.FAVICON);
        // We need to know that the caller set the favicon column.
        if (row.favicon == null) {
            row.favicon = new byte[0];
        }
    }
    if (values.containsKey(BookmarkColumns.TITLE)) {
        row.title = values.getAsString(BookmarkColumns.TITLE);
    }
    if (values.containsKey(BookmarkColumns.VISITS)) {
        row.visits = values.getAsInteger(BookmarkColumns.VISITS);
    }
    if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) {
        row.parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM);
    }
    return row;
}
 
Example 7
Source File: Filter.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
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;
	}
}
 
Example 8
Source File: AlarmHandler.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the content of the alarm prior to insert and update transactions.
 *
 * @param db
 *         The {@link SQLiteDatabase}.
 * @param taskId
 *         The id of the task this property belongs to.
 * @param propertyId
 *         The id of the property if <code>isNew</code> is <code>false</code>. If <code>isNew</code> is <code>true</code> this value is ignored.
 * @param isNew
 *         Indicates that the content is new and not an update.
 * @param values
 *         The {@link ContentValues} to validate.
 * @param isSyncAdapter
 *         Indicates that the transaction was triggered from a SyncAdapter.
 *
 * @return The valid {@link ContentValues}.
 *
 * @throws IllegalArgumentException
 *         if the {@link ContentValues} are invalid.
 */
@Override
public ContentValues validateValues(SQLiteDatabase db, long taskId, long propertyId, boolean isNew, ContentValues values, boolean isSyncAdapter)
{
    // row id can not be changed or set manually
    if (values.containsKey(Property.Alarm.PROPERTY_ID))
    {
        throw new IllegalArgumentException("_ID can not be set manually");
    }

    if (!values.containsKey(Property.Alarm.MINUTES_BEFORE))
    {
        throw new IllegalArgumentException("alarm property requires a time offset");
    }

    if (!values.containsKey(Property.Alarm.REFERENCE) || values.getAsInteger(Property.Alarm.REFERENCE) < 0)
    {
        throw new IllegalArgumentException("alarm property requires a valid reference date ");
    }

    if (!values.containsKey(Property.Alarm.ALARM_TYPE))
    {
        throw new IllegalArgumentException("alarm property requires an alarm type");
    }

    return values;
}
 
Example 9
Source File: ItemInfo.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: AlarmHandler.java    From opentasks-provider with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the content of the alarm prior to insert and update transactions.
 * 
 * @param db
 *            The {@link SQLiteDatabase}.
 * @param taskId
 *            The id of the task this property belongs to.
 * @param propertyId
 *            The id of the property if <code>isNew</code> is <code>false</code>. If <code>isNew</code> is <code>true</code> this value is ignored.
 * @param isNew
 *            Indicates that the content is new and not an update.
 * @param values
 *            The {@link ContentValues} to validate.
 * @param isSyncAdapter
 *            Indicates that the transaction was triggered from a SyncAdapter.
 * 
 * @return The valid {@link ContentValues}.
 * 
 * @throws IllegalArgumentException
 *             if the {@link ContentValues} are invalid.
 */
@Override
public ContentValues validateValues(SQLiteDatabase db, long taskId, long propertyId, boolean isNew, ContentValues values, boolean isSyncAdapter)
{
	// row id can not be changed or set manually
	if (values.containsKey(Property.Alarm.PROPERTY_ID))
	{
		throw new IllegalArgumentException("_ID can not be set manually");
	}

	if (!values.containsKey(Property.Alarm.MINUTES_BEFORE))
	{
		throw new IllegalArgumentException("alarm property requires a time offset");
	}

	if (!values.containsKey(Property.Alarm.REFERENCE) || values.getAsInteger(Property.Alarm.REFERENCE) < 0)
	{
		throw new IllegalArgumentException("alarm property requires a valid reference date ");
	}

	if (!values.containsKey(Property.Alarm.ALARM_TYPE))
	{
		throw new IllegalArgumentException("alarm property requires an alarm type");
	}

	return values;
}
 
Example 11
Source File: ChromeBrowserProvider.java    From delion 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: InventoryDaoAndroid.java    From pos with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public int getStockSumById(int id) {
	String queryString = "SELECT * FROM " + DatabaseContents.TABLE_STOCK_SUM + " WHERE _id = " + id;
	List<Object> objectList = (database.select(queryString));
	ContentValues content = (ContentValues) objectList.get(0);
	int quantity = content.getAsInteger("quantity");
	Log.d("inventoryDaoAndroid", "stock sum of "+ id + " is " + quantity);
	return quantity;
}
 
Example 13
Source File: WordListMetadata.java    From Android-Keyboard 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 14
Source File: TimezoneFieldAdapter.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether this is an "all-day timezone".
 *
 * @return <code>true</code> if the cursor points to an all-day date.
 */
public boolean isAllDay(ContentValues values)
{
    if (mAllDayFieldName == null)
    {
        return false;
    }

    Integer allday = values.getAsInteger(mAllDayFieldName);
    return allday != null && allday > 0;
}
 
Example 15
Source File: BooleanFieldAdapter.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean getFrom(ContentValues values)
{
    Integer value = values.getAsInteger(mFieldName);

    return value != null && value > 0;
}
 
Example 16
Source File: IntegerFieldAdapter.java    From opentasks with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getFrom(ContentValues values)
{
    // return the value as Integer
    return values.getAsInteger(mFieldName);
}
 
Example 17
Source File: IntegerFieldAdapter.java    From opentasks-provider with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getFrom(ContentValues values)
{
	// return the value as Integer
	return values.getAsInteger(mFieldName);
}
 
Example 18
Source File: ActionBatch.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(final Context context) {
    if (null == mWordList) { // This should never happen
        Log.e(TAG, "UpdateAction with a null parameter!");
        return;
    }
    DebugLogUtils.l("Downloading word list");
    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);
    final DownloadManagerWrapper manager = new DownloadManagerWrapper(context);
    if (MetadataDbHelper.STATUS_DOWNLOADING == status) {
        // The word list is still downloading. Cancel the download and revert the
        // word list status to "available".
        manager.remove(values.getAsLong(MetadataDbHelper.PENDINGID_COLUMN));
        MetadataDbHelper.markEntryAsAvailable(db, mWordList.mId, mWordList.mVersion);
    } else if (MetadataDbHelper.STATUS_AVAILABLE != status
            && MetadataDbHelper.STATUS_RETRYING != status) {
        // Should never happen
        Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' : " + status
                + " for an upgrade action. Fall back to download.");
    }
    // Download it.
    DebugLogUtils.l("Upgrade word list, downloading", mWordList.mRemoteFilename);

    // This is an upgraded word list: we should download it.
    // Adding a disambiguator to circumvent a bug in older versions of DownloadManager.
    // DownloadManager also stupidly cuts the extension to replace with its own that it
    // gets from the content-type. We need to circumvent this.
    final String disambiguator = "#" + System.currentTimeMillis()
            + ApplicationUtils.getVersionName(context) + ".dict";
    final Uri uri = Uri.parse(mWordList.mRemoteFilename + disambiguator);
    final Request request = new Request(uri);

    final Resources res = context.getResources();
    request.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE);
    request.setTitle(mWordList.mDescription);
    request.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
    request.setVisibleInDownloadsUi(
            res.getBoolean(R.bool.dict_downloads_visible_in_download_UI));

    final long downloadId = UpdateHandler.registerDownloadRequest(manager, request, db,
            mWordList.mId, mWordList.mVersion);
    Log.i(TAG, String.format("Starting the dictionary download with version:"
                    + " %d and Url: %s", mWordList.mVersion, uri));
    DebugLogUtils.l("Starting download of", uri, "with id", downloadId);
    PrivateLog.log("Starting download of " + uri + ", id : " + downloadId);
}
 
Example 19
Source File: DingDingHandler.java    From xposed-rimet with Apache License 2.0 3 votes vote down vote up
@Override
public boolean onRecallMessage(ContentValues contentValues) {

    if (!mEnableRecall || contentValues == null) return false;

    Integer integer = contentValues.getAsInteger("recall");

    return integer != null && integer == 1;
}
 
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 an
 * Integer.
 *
 * @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 int getInteger(String name, int def) {
    ContentValues values = getValues(name);
    return values != null ? values.getAsInteger(VALUE) : def;
}