Example usage for android.content ContentValues getAsBoolean

List of usage examples for android.content ContentValues getAsBoolean

Introduction

In this page you can find the example usage for android.content ContentValues getAsBoolean.

Prototype

public Boolean getAsBoolean(String key) 

Source Link

Document

Gets a value and converts it to a Boolean.

Usage

From source file:org.anhonesteffort.flock.sync.addressbook.ContactFactory.java

protected static ComponentETagPair<VCard> getVCard(ContentValues rawContactValues) {
    String uidText = rawContactValues.getAsString(ContactsContract.RawContacts.SOURCE_ID);
    String eTagText = rawContactValues.getAsString(ContactsContract.RawContacts.SYNC1);
    Boolean starred = rawContactValues.getAsBoolean(ContactsContract.RawContacts.STARRED);

    VCard vCard = new VCard();
    vCard.setVersion(VCardVersion.V3_0);

    vCard.setUid(new Uid(uidText));

    if (starred != null)
        vCard.setExtendedProperty(PROPERTY_STARRED, starred ? "1" : "0");

    Optional<String> eTag = Optional.fromNullable(eTagText);

    return new ComponentETagPair<VCard>(vCard, eTag);
}

From source file:org.anhonesteffort.flock.sync.addressbook.ContactFactory.java

protected static void addEmailAddress(String path, VCard vCard, ContentValues emailValues)
        throws InvalidComponentException {
    Integer type = emailValues.getAsInteger(ContactsContract.CommonDataKinds.Email.TYPE);
    String label = emailValues.getAsString(ContactsContract.CommonDataKinds.Email.LABEL);
    String address = emailValues.getAsString(ContactsContract.CommonDataKinds.Email.ADDRESS);
    Boolean isPrimary = emailValues.getAsBoolean(ContactsContract.CommonDataKinds.Email.IS_PRIMARY);
    Boolean isSuperPrimary = emailValues.getAsBoolean(ContactsContract.CommonDataKinds.Email.IS_SUPER_PRIMARY);

    if (type != null && address != null) {
        Email email = new Email(address);

        switch (type) {
        case ContactsContract.CommonDataKinds.Email.TYPE_HOME:
            email.addType(EmailType.HOME);
            break;

        case ContactsContract.CommonDataKinds.Email.TYPE_WORK:
            email.addType(EmailType.WORK);
            break;

        case ContactsContract.CommonDataKinds.Email.TYPE_MOBILE:
            email.addType(EMAIL_TYPE_MOBILE);
            break;

        default:/*from  w w w  .  j  a  va 2  s .  co  m*/
            if (label != null)
                email.addType(EmailType.get(label));
            break;
        }

        if (isPrimary != null && isPrimary)
            email.addType(EmailType.PREF);
        else if (isSuperPrimary != null && isSuperPrimary)
            email.addType(EmailType.PREF);

        vCard.addEmail(email);
    } else {
        Log.e(TAG, "email type or address is null, not adding anything");
        throw new InvalidComponentException("email type or address is null", false,
                CardDavConstants.CARDDAV_NAMESPACE, path);
    }
}

From source file:org.anhonesteffort.flock.sync.addressbook.ContactFactory.java

protected static void addPhoneNumber(String path, VCard vCard, ContentValues phoneNumberValues)
        throws InvalidComponentException {
    Integer type = phoneNumberValues.getAsInteger(ContactsContract.CommonDataKinds.Phone.TYPE);
    String label = phoneNumberValues.getAsString(ContactsContract.CommonDataKinds.Phone.LABEL);
    String number = phoneNumberValues.getAsString(ContactsContract.CommonDataKinds.Phone.NUMBER);
    Boolean isPrimary = phoneNumberValues.getAsBoolean(ContactsContract.CommonDataKinds.Phone.IS_PRIMARY);
    Boolean isSuperPrimary = phoneNumberValues
            .getAsBoolean(ContactsContract.CommonDataKinds.Phone.IS_SUPER_PRIMARY);

    if (type != null && number != null) {
        Telephone telephone = new Telephone(number);

        switch (type) {
        case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
            telephone.addType(TelephoneType.CELL);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
            telephone.addType(TelephoneType.WORK);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
            telephone.addType(TelephoneType.HOME);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK:
            telephone.addType(TelephoneType.FAX);
            telephone.addType(TelephoneType.WORK);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME:
            telephone.addType(TelephoneType.FAX);
            telephone.addType(TelephoneType.HOME);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_PAGER:
            telephone.addType(TelephoneType.PAGER);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_MAIN:
            telephone.addType(TelephoneType.PREF);
            break;

        default://ww  w.ja  va2s.  co  m
            if (label != null)
                telephone.addType(TelephoneType.get(labelToPropertyName(label)));
        }

        if (isPrimary != null && isPrimary)
            telephone.addType(TelephoneType.PREF);
        else if (isSuperPrimary != null && isSuperPrimary)
            telephone.addType(TelephoneType.PREF);

        vCard.addTelephoneNumber(telephone);
    } else {
        Log.e(TAG, "phone type or number is null, not adding anything");
        throw new InvalidComponentException("phone type or number is null", false,
                CardDavConstants.CARDDAV_NAMESPACE, path);
    }
}

From source file:com.csipsimple.utils.Columns.java

public JSONObject contentValueToJSON(ContentValues cv) {
    JSONObject json = new JSONObject();
    try {//from ww w. ja  va  2s .co m
        for (int i = 0; i < names.length; i++) {
            if (!cv.containsKey(names[i])) {
                continue;
            }
            switch (types[i]) {
            case STRING:
                json.put(names[i], cv.getAsString(names[i]));
                break;
            case INT:
                json.put(names[i], cv.getAsInteger(names[i]));
                break;
            case LONG:
                json.put(names[i], cv.getAsLong(names[i]));
                break;
            case FLOAT:
                json.put(names[i], cv.getAsFloat(names[i]));
                break;
            case DOUBLE:
                json.put(names[i], cv.getAsDouble(names[i]));
                break;
            case BOOLEAN:
                json.put(names[i], cv.getAsBoolean(names[i]));
                break;
            }
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    return json;
}

From source file:com.csipsimple.backup.Columns.java

public JSONObject contentValueToJSON(ContentValues cv) {
    JSONObject json = new JSONObject();
    for (int i = 0; i < names.size(); i++) {
        if (!cv.containsKey(names.get(i))) {
            continue;
        }/*from  w  ww . java  2s.c o m*/
        try {
            String name = names.get(i);
            switch (types.get(i)) {
            case STRING:
                json.put(name, cv.getAsString(name));
                break;
            case INT:
                json.put(name, cv.getAsInteger(name));
                break;
            case LONG:
                json.put(name, cv.getAsLong(name));
                break;
            case FLOAT:
                json.put(name, cv.getAsFloat(name));
                break;
            case DOUBLE:
                json.put(name, cv.getAsDouble(name));
                break;
            case BOOLEAN:
                json.put(name, cv.getAsBoolean(name));
                break;
            default:
                Log.w("Col", "Invalid type, can't unserialize " + types.get(i));
            }
        } catch (JSONException e) {
            Log.e("Col", "Invalid type, can't unserialize ", e);
        }
    }

    return json;
}

From source file:com.android.mail.providers.Attachment.java

/**
 * Create an attachment from a {@link ContentValues} object.
 * The keys should be {@link AttachmentColumns}.
 */// w  ww .  ja  v  a 2 s .co  m
public Attachment(ContentValues values) {
    name = values.getAsString(AttachmentColumns.NAME);
    size = values.getAsInteger(AttachmentColumns.SIZE);
    uri = parseOptionalUri(values.getAsString(AttachmentColumns.URI));
    contentType = values.getAsString(AttachmentColumns.CONTENT_TYPE);
    state = values.getAsInteger(AttachmentColumns.STATE);
    destination = values.getAsInteger(AttachmentColumns.DESTINATION);
    downloadedSize = values.getAsInteger(AttachmentColumns.DOWNLOADED_SIZE);
    contentUri = parseOptionalUri(values.getAsString(AttachmentColumns.CONTENT_URI));
    thumbnailUri = parseOptionalUri(values.getAsString(AttachmentColumns.THUMBNAIL_URI));
    previewIntentUri = parseOptionalUri(values.getAsString(AttachmentColumns.PREVIEW_INTENT_URI));
    providerData = values.getAsString(AttachmentColumns.PROVIDER_DATA);
    supportsDownloadAgain = values.getAsBoolean(AttachmentColumns.SUPPORTS_DOWNLOAD_AGAIN);
    type = values.getAsInteger(AttachmentColumns.TYPE);
    flags = values.getAsInteger(AttachmentColumns.FLAGS);
    partId = values.getAsString(AttachmentColumns.CONTENT_ID);
}

From source file:com.chen.mail.providers.Attachment.java

/**
 * Create an attachment from a {@link ContentValues} object.
 * The keys should be {@link UIProvider.AttachmentColumns}.
 */// w ww  .j a v a  2  s.c  o m
public Attachment(ContentValues values) {
    name = values.getAsString(UIProvider.AttachmentColumns.NAME);
    size = values.getAsInteger(UIProvider.AttachmentColumns.SIZE);
    uri = parseOptionalUri(values.getAsString(UIProvider.AttachmentColumns.URI));
    contentType = values.getAsString(UIProvider.AttachmentColumns.CONTENT_TYPE);
    state = values.getAsInteger(UIProvider.AttachmentColumns.STATE);
    destination = values.getAsInteger(UIProvider.AttachmentColumns.DESTINATION);
    downloadedSize = values.getAsInteger(UIProvider.AttachmentColumns.DOWNLOADED_SIZE);
    contentUri = parseOptionalUri(values.getAsString(UIProvider.AttachmentColumns.CONTENT_URI));
    thumbnailUri = parseOptionalUri(values.getAsString(UIProvider.AttachmentColumns.THUMBNAIL_URI));
    previewIntentUri = parseOptionalUri(values.getAsString(UIProvider.AttachmentColumns.PREVIEW_INTENT_URI));
    providerData = values.getAsString(UIProvider.AttachmentColumns.PROVIDER_DATA);
    supportsDownloadAgain = values.getAsBoolean(UIProvider.AttachmentColumns.SUPPORTS_DOWNLOAD_AGAIN);
    type = values.getAsInteger(UIProvider.AttachmentColumns.TYPE);
    flags = values.getAsInteger(UIProvider.AttachmentColumns.FLAGS);
}

From source file:com.tct.mail.providers.Attachment.java

/**
 * Create an attachment from a {@link ContentValues} object.
 * The keys should be {@link AttachmentColumns}.
 *///www  . j  a v a2  s.  c  o m
public Attachment(ContentValues values) {
    name = values.getAsString(AttachmentColumns.NAME);
    size = values.getAsInteger(AttachmentColumns.SIZE);
    uri = parseOptionalUri(values.getAsString(AttachmentColumns.URI));
    contentType = values.getAsString(AttachmentColumns.CONTENT_TYPE);
    state = values.getAsInteger(AttachmentColumns.STATE);
    destination = values.getAsInteger(AttachmentColumns.DESTINATION);
    downloadedSize = values.getAsInteger(AttachmentColumns.DOWNLOADED_SIZE);
    contentUri = parseOptionalUri(values.getAsString(AttachmentColumns.CONTENT_URI));
    thumbnailUri = parseOptionalUri(values.getAsString(AttachmentColumns.THUMBNAIL_URI));
    previewIntentUri = parseOptionalUri(values.getAsString(AttachmentColumns.PREVIEW_INTENT_URI));
    providerData = values.getAsString(AttachmentColumns.PROVIDER_DATA);
    supportsDownloadAgain = values.getAsBoolean(AttachmentColumns.SUPPORTS_DOWNLOAD_AGAIN);
    type = values.getAsInteger(AttachmentColumns.TYPE);
    flags = values.getAsInteger(AttachmentColumns.FLAGS);
    partId = values.getAsString(AttachmentColumns.CONTENT_ID);
    //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_852100 MOD_S
    contentId = values.getAsString(AttachmentColumns.CONTENT_ID);
    //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_852100 MOD_E
    //TS: zhonghua.tuo 2015-3-3 EMAIL BUGFIX_936728 ADD_S
    realUri = parseOptionalUri(values.getAsString(AttachmentColumns.REAL_URI));
    //TS: zhonghua.tuo 2015-3-3 EMAIL BUGFIX_936728 ADD_E
    // TS: Gantao 2015-09-19 EMAIL BUGFIX_570084 ADD_S
    isInline = values.getAsInteger(AttachmentColumns.ISINLINE);
    // TS: Gantao 2015-09-19 EMAIL BUGFIX_570084 ADD_E
}

From source file:com.akop.bach.parser.XboxLiveParser.java

public void createAccount(BasicAccount account, ContentValues cv) {
    XboxLiveAccount xblAccount = (XboxLiveAccount) account;

    // Save changes to preferences
    xblAccount.setGamertag(cv.getAsString(Profiles.GAMERTAG));
    xblAccount.setLastSummaryUpdate(System.currentTimeMillis());
    xblAccount.setIconUrl(cv.getAsString(Profiles.ICON_URL));
    xblAccount.setGoldStatus(cv.getAsBoolean(Profiles.IS_GOLD));

    account.save(Preferences.get(mContext));

    // Add profile to database
    ContentResolver cr = mContext.getContentResolver();
    cr.insert(Profiles.CONTENT_URI, cv);
    cr.notifyChange(Profiles.CONTENT_URI, null);
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

private Uri insertSource(@NonNull final Uri uri, final ContentValues initialValues) {
    Context context = getContext();
    if (context == null) {
        return null;
    }/*from   w w  w. j  av a  2 s.  com*/
    if (!initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)
            || TextUtils.isEmpty(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME))) {
        throw new IllegalArgumentException("Initial values must contain component name " + initialValues);
    }
    ComponentName componentName = ComponentName
            .unflattenFromString(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME));
    if (componentName == null) {
        throw new IllegalArgumentException("Invalid component name: "
                + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME));
    }
    ApplicationInfo info;
    try {
        // Ensure the service is valid and extract the application info
        info = context.getPackageManager().getServiceInfo(componentName, 0).applicationInfo;
    } catch (PackageManager.NameNotFoundException e) {
        throw new IllegalArgumentException("Invalid component name "
                + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME), e);
    }
    // Make sure they are using the short string format
    initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString());

    // Only Muzei can set the IS_SELECTED field
    if (initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED)) {
        if (!context.getPackageName().equals(getCallingPackage())) {
            Log.w(TAG, "Only Muzei can set the " + MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED
                    + " column. Ignoring the value in " + initialValues);
            initialValues.remove(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED);
        }
    }

    // Disable network access callbacks if we're running on an API 24 device and the source app
    // targets API 24. This is to be consistent with the Behavior Changes in Android N
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE)
            && initialValues.getAsBoolean(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE)) {
        if (info.targetSdkVersion >= Build.VERSION_CODES.N) {
            Log.w(TAG,
                    "Sources targeting API 24 cannot receive network access callbacks. Changing "
                            + componentName + " to false for "
                            + MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE);
            initialValues.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, false);
        }
    }
    final SQLiteDatabase db = databaseHelper.getWritableDatabase();
    final long rowId = db.insert(MuzeiContract.Sources.TABLE_NAME,
            MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, initialValues);
    // If the insert succeeded, the row ID exists.
    if (rowId > 0) {
        // Creates a URI with the source ID pattern and the new row ID appended to it.
        final Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, rowId);
        notifyChange(sourceUri);
        return sourceUri;
    }
    // If the insert didn't succeed, then the rowID is <= 0
    throw new SQLException("Failed to insert row into " + uri);
}