Example usage for android.content ContentValues getAsInteger

List of usage examples for android.content ContentValues getAsInteger

Introduction

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

Prototype

public Integer getAsInteger(String key) 

Source Link

Document

Gets a value and converts it to an Integer.

Usage

From source file:at.bitfire.davdroid.model.CollectionInfo.java

private static Boolean getAsBooleanOrNull(ContentValues values, String field) {
    Integer i = values.getAsInteger(field);
    return (i == null) ? null : (i != 0);
}

From source file:com.partypoker.poker.engagement.reach.EngagementReachContent.java

/**
 * Parse boolean from content values.//from  w ww .j a v  a 2s  .  co  m
 * @param values content values.
 * @param key key.
 * @return boolean value.
 */
static boolean parseBoolean(ContentValues values, String key) {
    Integer val = values.getAsInteger(key);
    return val != null && val == 1;
}

From source file:at.bitfire.davdroid.model.CollectionInfo.java

public static CollectionInfo fromDB(ContentValues values) {
    CollectionInfo info = new CollectionInfo();
    info.id = values.getAsLong(Collections.ID);
    info.serviceID = values.getAsLong(Collections.SERVICE_ID);

    info.url = values.getAsString(Collections.URL);
    info.readOnly = values.getAsInteger(Collections.READ_ONLY) != 0;
    info.displayName = values.getAsString(Collections.DISPLAY_NAME);
    info.description = values.getAsString(Collections.DESCRIPTION);

    info.color = values.getAsInteger(Collections.COLOR);

    info.timeZone = values.getAsString(Collections.TIME_ZONE);
    info.supportsVEVENT = getAsBooleanOrNull(values, Collections.SUPPORTS_VEVENT);
    info.supportsVTODO = getAsBooleanOrNull(values, Collections.SUPPORTS_VTODO);

    info.selected = values.getAsInteger(Collections.SYNC) != 0;
    return info;/* www  .j  av  a  2 s  .c o m*/
}

From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachInteractiveContent.java

/**
 * Parse boolean from content values.//  ww  w  .  j  a v  a  2  s.  co m
 * @param values content values.
 * @param key key.
 * @return boolean value.
 */
private static boolean parseBoolean(ContentValues values, String key) {
    Integer val = values.getAsInteger(key);
    return val != null && val == 1;
}

From source file:org.anhonesteffort.flock.sync.calendar.EventFactory.java

protected static void addReminder(String path, Calendar component, ContentValues reminderValues)
        throws InvalidComponentException {
    Integer minutes = reminderValues.getAsInteger(CalendarContract.Reminders.MINUTES);

    if (minutes != null) {
        VAlarm vAlarm = new VAlarm(new Dur(0, 0, -minutes, 0));
        PropertyList alarmProps = vAlarm.getProperties();

        alarmProps.add(Action.DISPLAY);

        VEvent vEvent = (VEvent) component.getComponent(VEvent.VEVENT);
        VToDo vToDo = (VToDo) component.getComponent(VEvent.VTODO);

        if (vEvent != null && vEvent.getSummary() != null) {
            alarmProps.add(new Description(vEvent.getSummary().getValue()));
            vEvent.getAlarms().add(vAlarm);
        } else if (vToDo != null && vToDo.getSummary() != null) {
            alarmProps.add(new Description(vToDo.getSummary().getValue()));
            vToDo.getAlarms().add(vAlarm);
        }//from w  w w.ja  v a2s .  c  o  m
    } else {
        Log.e(TAG, "reminder minutes is null");
        throw new InvalidComponentException("reminder minutes is null", false, CalDavConstants.CALDAV_NAMESPACE,
                path);
    }
}

From source file:org.barbon.mangaget.fragments.ChapterList.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    DB db = DB.getInstance(getActivity());
    ContentValues chapter = db.getChapter(id);
    int status = chapter.getAsInteger(DB.DOWNLOAD_STATUS);

    if (status == DB.DOWNLOAD_REQUESTED || status == DB.DOWNLOAD_STARTED)
        Download.stopChapterDownload(getActivity(), id);
    else if (status == DB.DOWNLOAD_STOPPED)
        Download.startChapterDownload(getActivity(), id);
    else//from   w w  w.j a v  a2 s.c  o  m
        showChapter(id);
}

From source file:org.barbon.mangaget.fragments.ChapterList.java

private void showChapter(long chapterId) {
    DB db = DB.getInstance(getActivity());
    ContentValues chapter = db.getChapter(chapterId);

    // unobtrusive alert if chapter has not been downloaded
    if (chapter.getAsInteger(DB.DOWNLOAD_STATUS) != DB.DOWNLOAD_COMPLETE) {
        Toast.makeText(getActivity(), R.string.chapter_not_downloaded, Toast.LENGTH_SHORT).show();

        return;//from  w w w  .  j  av  a  2  s.  c om
    }

    Intent view = Utils.viewChapterIntent(getActivity(), chapterId);

    getActivity().startActivity(view);
}

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

protected static void addEvent(String path, VCard vCard, ContentValues eventValues)
        throws InvalidComponentException {
    Integer eventType = eventValues.getAsInteger(ContactsContract.CommonDataKinds.Event.TYPE);
    String eventLabel = eventValues.getAsString(ContactsContract.CommonDataKinds.Event.LABEL);
    String eventStartDate = eventValues.getAsString(ContactsContract.CommonDataKinds.Event.START_DATE);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);

    if (eventType != null && eventStartDate != null) {
        try {/*from   w  w w. java2 s. com*/

            if (eventType == ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY) {
                Birthday birthday = new Birthday(formatter.parse(eventStartDate));
                vCard.setBirthday(birthday);
            }

        } catch (ParseException e) {
            throw new InvalidComponentException("caught exception while parsing birthday", false,
                    CardDavConstants.CARDDAV_NAMESPACE, path);
        }

        if (eventType == ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY)
            vCard.setExtendedProperty(PROPERTY_EVENT_ANNIVERSARY, eventStartDate);
        else if (eventType == ContactsContract.CommonDataKinds.Event.TYPE_OTHER)
            vCard.setExtendedProperty(PROPERTY_EVENT_OTHER, eventStartDate);
        else if (eventType == ContactsContract.CommonDataKinds.Event.TYPE_CUSTOM)
            vCard.setExtendedProperty(PROPERTY_EVENT_CUSTOM, eventStartDate)
                    .setParameter(PARAMETER_EVENT_CUSTOM_LABEL, eventLabel);
    } else {
        Log.e(TAG, "event type or event start date is null, not adding anything");
        throw new InvalidComponentException("event type or event start date is null", false,
                CardDavConstants.CARDDAV_NAMESPACE, path);
    }
}

From source file:com.abcvoipsip.ui.favorites.FavAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    ContentValues cv = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(cursor, cv);

    int type = ContactsWrapper.TYPE_CONTACT;
    if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) {
        type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE);
    }/*from   www.ja  v  a  2 s.c o m*/

    if (type == ContactsWrapper.TYPE_GROUP) {
        showViewForHeader(view, true);
        TextView tv = (TextView) view.findViewById(R.id.header_text);
        ImageView icon = (ImageView) view.findViewById(R.id.header_icon);
        PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view
                .findViewById(R.id.header_presence_spinner);

        tv.setText(cv.getAsString(SipProfile.FIELD_DISPLAY_NAME));
        icon.setImageResource(WizardUtils.getWizardIconRes(cv.getAsString(SipProfile.FIELD_WIZARD)));
        presSpinner.setProfileId(cv.getAsLong(BaseColumns._ID));

    } else {
        showViewForHeader(view, false);
        ContactsWrapper.getInstance().bindContactView(view, context, cursor);

    }
}

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:/* w  ww.j av a  2 s. c om*/
            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);
    }
}