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.resource.LocalCalendar.java

void populateAttendee(Event event, ContentValues values) {
    try {//from   w  w  w  . jav a2 s  . co m
        final Attendee attendee;
        final String email = values.getAsString(Attendees.ATTENDEE_EMAIL),
                idNS = values.getAsString(Attendees.ATTENDEE_ID_NAMESPACE),
                id = values.getAsString(Attendees.ATTENDEE_IDENTITY);
        if (idNS != null || id != null) {
            // attendee identified by namespace and ID
            attendee = new Attendee(new URI(idNS, id, null));
            if (email != null)
                attendee.getParameters().add(new iCalendar.Email(email));
        } else
            // attendee identified by email address
            attendee = new Attendee(new URI("mailto", email, null));
        final ParameterList params = attendee.getParameters();

        String cn = values.getAsString(Attendees.ATTENDEE_NAME);
        if (cn != null)
            params.add(new Cn(cn));

        // type
        int type = values.getAsInteger(Attendees.ATTENDEE_TYPE);
        params.add((type == Attendees.TYPE_RESOURCE) ? CuType.RESOURCE : CuType.INDIVIDUAL);

        // role
        int relationship = values.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP);
        switch (relationship) {
        case Attendees.RELATIONSHIP_ORGANIZER:
        case Attendees.RELATIONSHIP_ATTENDEE:
        case Attendees.RELATIONSHIP_PERFORMER:
        case Attendees.RELATIONSHIP_SPEAKER:
            params.add((type == Attendees.TYPE_REQUIRED) ? Role.REQ_PARTICIPANT : Role.OPT_PARTICIPANT);
            params.add(new Rsvp(true));
            break;
        case Attendees.RELATIONSHIP_NONE:
            params.add(Role.NON_PARTICIPANT);
        }

        // status
        switch (values.getAsInteger(Attendees.ATTENDEE_STATUS)) {
        case Attendees.ATTENDEE_STATUS_INVITED:
            params.add(PartStat.NEEDS_ACTION);
            break;
        case Attendees.ATTENDEE_STATUS_ACCEPTED:
            params.add(PartStat.ACCEPTED);
            break;
        case Attendees.ATTENDEE_STATUS_DECLINED:
            params.add(PartStat.DECLINED);
            break;
        case Attendees.ATTENDEE_STATUS_TENTATIVE:
            params.add(PartStat.TENTATIVE);
            break;
        }

        event.getAttendees().add(attendee);
    } catch (URISyntaxException ex) {
        Log.e(TAG, "Couldn't parse attendee information, ignoring", ex);
    }
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

/**
 * Adjust the current URI values to align with those in a ContentValues which has been read
 * from a Server row in the database.  The path will be set to the principal-path value
 * so you may need to specify a different path on the actual request(s).
 *
  * Unless you're configuring the server you should probably use AcalRequestor.fromServerValues(serverData) or applyFromServer(serverData).
        /*from   w w  w  .j a  v a  2 s.com*/
 * @param cvServerData
 * @param simpleSetup true/false whether to use only the 'simple' values to initialise from
 */
public void applyFromServer(ContentValues cvServerData, boolean simpleSetup) {
    if (simpleSetup) {
        protocol = null;
        hostName = null;
        port = 0;
        path = null;
        authType = Servers.AUTH_NONE;
        interpretUriString(cvServerData.getAsString(Servers.SUPPLIED_USER_URL));
    } else {
        setHostName(cvServerData.getAsString(Servers.HOSTNAME));
        setPath(cvServerData.getAsString(Servers.PRINCIPAL_PATH));

        String portString = cvServerData.getAsString(Servers.PORT);
        int tmpPort = 0;
        if (portString != null && portString.length() > 0)
            tmpPort = Integer.parseInt(portString);
        setPortProtocol(tmpPort, cvServerData.getAsInteger(Servers.USE_SSL));

        setAuthType(cvServerData.getAsInteger(Servers.AUTH_TYPE));

    }
    if (hostName == null)
        hostName = "invalid";
    if (path == null)
        path = "/";

    authRequired = (authType != Servers.AUTH_NONE);
    username = cvServerData.getAsString(Servers.USERNAME);
    password = cvServerData.getAsString(Servers.PASSWORD);

    if (!initialised)
        initialise();
}

From source file:android.pim.vcard.VCardBuilder.java

public VCardBuilder appendPhones(final List<ContentValues> contentValuesList) {
    boolean phoneLineExists = false;
    if (contentValuesList != null) {
        Set<String> phoneSet = new HashSet<String>();
        for (ContentValues contentValues : contentValuesList) {
            final Integer typeAsObject = contentValues.getAsInteger(Phone.TYPE);
            final String label = contentValues.getAsString(Phone.LABEL);
            final Integer isPrimaryAsInteger = contentValues.getAsInteger(Phone.IS_PRIMARY);
            final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false);
            String phoneNumber = contentValues.getAsString(Phone.NUMBER);
            if (phoneNumber != null) {
                phoneNumber = phoneNumber.trim();
            }//from  w ww  .ja  v a 2  s .com
            if (TextUtils.isEmpty(phoneNumber)) {
                continue;
            }
            int type = (typeAsObject != null ? typeAsObject : DEFAULT_PHONE_TYPE);
            if (type == Phone.TYPE_PAGER) {
                phoneLineExists = true;
                if (!phoneSet.contains(phoneNumber)) {
                    phoneSet.add(phoneNumber);
                    appendTelLine(type, label, phoneNumber, isPrimary);
                }
            } else {
                // The entry "may" have several phone numbers when the contact entry is
                // corrupted because of its original source.
                //
                // e.g. I encountered the entry like the following.
                // "111-222-3333 (Miami)\n444-555-6666 (Broward; 305-653-6796 (Miami); ..."
                // This kind of entry is not able to be inserted via Android devices, but
                // possible if the source of the data is already corrupted.
                List<String> phoneNumberList = splitIfSeveralPhoneNumbersExist(phoneNumber);
                if (phoneNumberList.isEmpty()) {
                    continue;
                }
                phoneLineExists = true;
                for (String actualPhoneNumber : phoneNumberList) {
                    if (!phoneSet.contains(actualPhoneNumber)) {
                        final int format = VCardUtils.getPhoneNumberFormat(mVCardType);
                        final String formattedPhoneNumber = PhoneNumberUtils.formatNumber(actualPhoneNumber,
                                format);
                        phoneSet.add(actualPhoneNumber);
                        appendTelLine(type, label, formattedPhoneNumber, isPrimary);
                    }
                }
            }
        }
    }

    if (!phoneLineExists && mIsDoCoMo) {
        appendTelLine(Phone.TYPE_HOME, "", "", false);
    }

    return this;
}

From source file:com.hualu.wifistart.vcardsrc.VCardBuilder.java

public VCardBuilder appendPhones(final List<ContentValues> contentValuesList) {
    boolean phoneLineExists = false;
    if (contentValuesList != null) {
        Set<String> phoneSet = new HashSet<String>();
        for (ContentValues contentValues : contentValuesList) {
            final Integer typeAsObject = contentValues.getAsInteger(Phone.TYPE);
            final String label = contentValues.getAsString(Phone.LABEL);
            final Integer isPrimaryAsInteger = contentValues.getAsInteger(Phone.IS_PRIMARY);
            final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false);
            String phoneNumber = contentValues.getAsString(Phone.NUMBER);
            if (phoneNumber != null) {
                phoneNumber = phoneNumber.trim();
            }//from w  w  w  .  ja v  a2s. com
            if (TextUtils.isEmpty(phoneNumber)) {
                continue;
            }
            int type = (typeAsObject != null ? typeAsObject : DEFAULT_PHONE_TYPE);
            if (type == Phone.TYPE_PAGER) {
                phoneLineExists = true;
                if (!phoneSet.contains(phoneNumber)) {
                    phoneSet.add(phoneNumber);
                    appendTelLine(type, label, phoneNumber, isPrimary);
                }
            } else {
                // The entry "may" have several phone numbers when the contact entry is
                // corrupted because of its original source.
                //
                // e.g. I encountered the entry like the following.
                // "111-222-3333 (Miami)\n444-555-6666 (Broward; 305-653-6796 (Miami); ..."
                // This kind of entry is not able to be inserted via Android devices, but
                // possible if the source of the data is already corrupted.
                List<String> phoneNumberList = splitIfSeveralPhoneNumbersExist(phoneNumber);
                if (phoneNumberList.isEmpty()) {
                    continue;
                }
                phoneLineExists = true;
                for (String actualPhoneNumber : phoneNumberList) {
                    if (!phoneSet.contains(actualPhoneNumber)) {
                        // final int format = VCardUtils.getPhoneNumberFormat(mVCardType);
                        //final String formattedPhoneNumber =
                        //        PhoneNumberUtils.formatNumber(actualPhoneNumber, format);
                        // final int format = VCardUtils.getPhoneNumberFormat(mVCardType);
                        final String formattedPhoneNumber = PhoneNumberUtils.formatNumber(actualPhoneNumber);
                        phoneSet.add(actualPhoneNumber);
                        appendTelLine(type, label, formattedPhoneNumber, isPrimary);
                    }
                }
            }
        }
    }

    if (!phoneLineExists && mIsDoCoMo) {
        appendTelLine(Phone.TYPE_HOME, "", "", false);
    }

    return this;
}

From source file:android.pim.vcard.VCardBuilder.java

public VCardBuilder appendIms(final List<ContentValues> contentValuesList) {
    if (contentValuesList != null) {
        for (ContentValues contentValues : contentValuesList) {
            final Integer protocolAsObject = contentValues.getAsInteger(Im.PROTOCOL);
            if (protocolAsObject == null) {
                continue;
            }/*from ww w. j a va 2s  . com*/
            final String propertyName = VCardUtils.getPropertyNameForIm(protocolAsObject);
            if (propertyName == null) {
                continue;
            }
            String data = contentValues.getAsString(Im.DATA);
            if (data != null) {
                data = data.trim();
            }
            if (TextUtils.isEmpty(data)) {
                continue;
            }
            final String typeAsString;
            {
                final Integer typeAsInteger = contentValues.getAsInteger(Im.TYPE);
                switch (typeAsInteger != null ? typeAsInteger : Im.TYPE_OTHER) {
                case Im.TYPE_HOME: {
                    typeAsString = VCardConstants.PARAM_TYPE_HOME;
                    break;
                }
                case Im.TYPE_WORK: {
                    typeAsString = VCardConstants.PARAM_TYPE_WORK;
                    break;
                }
                case Im.TYPE_CUSTOM: {
                    final String label = contentValues.getAsString(Im.LABEL);
                    typeAsString = (label != null ? "X-" + label : null);
                    break;
                }
                case Im.TYPE_OTHER: // Ignore
                default: {
                    typeAsString = null;
                    break;
                }
                }
            }

            final List<String> parameterList = new ArrayList<String>();
            if (!TextUtils.isEmpty(typeAsString)) {
                parameterList.add(typeAsString);
            }
            final Integer isPrimaryAsInteger = contentValues.getAsInteger(Im.IS_PRIMARY);
            final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false);
            if (isPrimary) {
                parameterList.add(VCardConstants.PARAM_TYPE_PREF);
            }

            appendLineWithCharsetAndQPDetection(propertyName, parameterList, data);
        }
    }
    return this;
}

From source file:android.pim.vcard.VCardBuilder.java

private void appendPostalsForGeneric(final List<ContentValues> contentValuesList) {
    for (final ContentValues contentValues : contentValuesList) {
        if (contentValues == null) {
            continue;
        }//w  w w  . j a  v  a 2  s. c  o m
        final Integer typeAsInteger = contentValues.getAsInteger(StructuredPostal.TYPE);
        final int type = (typeAsInteger != null ? typeAsInteger : DEFAULT_POSTAL_TYPE);
        final String label = contentValues.getAsString(StructuredPostal.LABEL);
        final Integer isPrimaryAsInteger = contentValues.getAsInteger(StructuredPostal.IS_PRIMARY);
        final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false);
        appendPostalLine(type, label, contentValues, isPrimary, false);
    }
}

From source file:android.pim.vcard.VCardBuilder.java

private ContentValues getPrimaryContentValue(final List<ContentValues> contentValuesList) {
    ContentValues primaryContentValues = null;
    ContentValues subprimaryContentValues = null;
    for (ContentValues contentValues : contentValuesList) {
        if (contentValues == null) {
            continue;
        }// ww  w  .  j av  a2s . co  m
        Integer isSuperPrimary = contentValues.getAsInteger(StructuredName.IS_SUPER_PRIMARY);
        if (isSuperPrimary != null && isSuperPrimary > 0) {
            // We choose "super primary" ContentValues.
            primaryContentValues = contentValues;
            break;
        } else if (primaryContentValues == null) {
            // We choose the first "primary" ContentValues
            // if "super primary" ContentValues does not exist.
            final Integer isPrimary = contentValues.getAsInteger(StructuredName.IS_PRIMARY);
            if (isPrimary != null && isPrimary > 0 && containsNonEmptyName(contentValues)) {
                primaryContentValues = contentValues;
                // Do not break, since there may be ContentValues with "super primary"
                // afterword.
            } else if (subprimaryContentValues == null && containsNonEmptyName(contentValues)) {
                subprimaryContentValues = contentValues;
            }
        }
    }

    if (primaryContentValues == null) {
        if (subprimaryContentValues != null) {
            // We choose the first ContentValues if any "primary" ContentValues does not exist.
            primaryContentValues = subprimaryContentValues;
        } else {
            Log.e(LOG_TAG, "All ContentValues given from database is empty.");
            primaryContentValues = new ContentValues();
        }
    }

    return primaryContentValues;
}

From source file:android.pim.vcard.VCardBuilder.java

/**
 * Tries to append just one line. If there's no appropriate address
 * information, append an empty line./*w  w w.  j a v a2 s .  com*/
 */
private void appendPostalsForDoCoMo(final List<ContentValues> contentValuesList) {
    int currentPriority = Integer.MAX_VALUE;
    int currentType = Integer.MAX_VALUE;
    ContentValues currentContentValues = null;
    for (final ContentValues contentValues : contentValuesList) {
        if (contentValues == null) {
            continue;
        }
        final Integer typeAsInteger = contentValues.getAsInteger(StructuredPostal.TYPE);
        final Integer priorityAsInteger = sPostalTypePriorityMap.get(typeAsInteger);
        final int priority = (priorityAsInteger != null ? priorityAsInteger : Integer.MAX_VALUE);
        if (priority < currentPriority) {
            currentPriority = priority;
            currentType = typeAsInteger;
            currentContentValues = contentValues;
            if (priority == 0) {
                break;
            }
        }
    }

    if (currentContentValues == null) {
        Log.w(LOG_TAG, "Should not come here. Must have at least one postal data.");
        return;
    }

    final String label = currentContentValues.getAsString(StructuredPostal.LABEL);
    appendPostalLine(currentType, label, currentContentValues, false, true);
}

From source file:com.money.manager.ex.common.AllDataListFragment.java

private Money getTotalFromCursor(Cursor cursor) {
    Money total = MoneyFactory.fromString("0");
    int originalPosition = cursor.getPosition();
    AllDataAdapter adapter = getAllDataAdapter();
    CurrencyService currencyService = new CurrencyService(getContext());
    int baseCurrencyId = currencyService.getBaseCurrencyId();
    ContentValues values = new ContentValues();

    int currencyId;
    Money amount;/*w w  w  .ja  v  a2  s  .c  om*/
    Money converted;
    String transType;
    TransactionTypes transactionType;

    cursor.moveToPosition(Constants.NOT_SET);

    while (cursor.moveToNext()) {
        values.clear();

        // Read needed data.
        DatabaseUtils.cursorStringToContentValues(cursor, adapter.TRANSACTIONTYPE, values);
        DatabaseUtils.cursorIntToContentValues(cursor, adapter.CURRENCYID, values);
        DatabaseUtils.cursorIntToContentValues(cursor, adapter.TOCURRENCYID, values);
        DatabaseUtils.cursorDoubleToCursorValues(cursor, adapter.AMOUNT, values);
        DatabaseUtils.cursorDoubleToCursorValues(cursor, adapter.TOAMOUNT, values);

        transType = values.getAsString(adapter.TRANSACTIONTYPE);
        transactionType = TransactionTypes.valueOf(transType);

        if (transactionType.equals(TransactionTypes.Transfer)) {
            currencyId = values.getAsInteger(adapter.TOCURRENCYID);
            amount = MoneyFactory.fromString(values.getAsString(adapter.TOAMOUNT));
        } else {
            currencyId = values.getAsInteger(adapter.CURRENCYID);
            amount = MoneyFactory.fromString(values.getAsString(adapter.AMOUNT));
        }

        converted = currencyService.doCurrencyExchange(baseCurrencyId, amount, currencyId);
        total = total.add(converted);
    }

    cursor.moveToPosition(originalPosition);

    return total;
}

From source file:android.pim.vcard.VCardBuilder.java

public VCardBuilder appendEvents(final List<ContentValues> contentValuesList) {
    if (contentValuesList != null) {
        String primaryBirthday = null;
        String secondaryBirthday = null;
        for (final ContentValues contentValues : contentValuesList) {
            if (contentValues == null) {
                continue;
            }/*from   ww  w.j av a2s  .co  m*/
            final Integer eventTypeAsInteger = contentValues.getAsInteger(Event.TYPE);
            final int eventType;
            if (eventTypeAsInteger != null) {
                eventType = eventTypeAsInteger;
            } else {
                eventType = Event.TYPE_OTHER;
            }
            if (eventType == Event.TYPE_BIRTHDAY) {
                final String birthdayCandidate = contentValues.getAsString(Event.START_DATE);
                if (birthdayCandidate == null) {
                    continue;
                }
                final Integer isSuperPrimaryAsInteger = contentValues.getAsInteger(Event.IS_SUPER_PRIMARY);
                final boolean isSuperPrimary = (isSuperPrimaryAsInteger != null ? (isSuperPrimaryAsInteger > 0)
                        : false);
                if (isSuperPrimary) {
                    // "super primary" birthday should the prefered one.
                    primaryBirthday = birthdayCandidate;
                    break;
                }
                final Integer isPrimaryAsInteger = contentValues.getAsInteger(Event.IS_PRIMARY);
                final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false);
                if (isPrimary) {
                    // We don't break here since "super primary" birthday may exist later.
                    primaryBirthday = birthdayCandidate;
                } else if (secondaryBirthday == null) {
                    // First entry is set to the "secondary" candidate.
                    secondaryBirthday = birthdayCandidate;
                }
            } else if (mUsesAndroidProperty) {
                // Event types other than Birthday is not supported by vCard.
                appendAndroidSpecificProperty(Event.CONTENT_ITEM_TYPE, contentValues);
            }
        }
        if (primaryBirthday != null) {
            appendLineWithCharsetAndQPDetection(VCardConstants.PROPERTY_BDAY, primaryBirthday.trim());
        } else if (secondaryBirthday != null) {
            appendLineWithCharsetAndQPDetection(VCardConstants.PROPERTY_BDAY, secondaryBirthday.trim());
        }
    }
    return this;
}