Example usage for android.content ContentValues getAsString

List of usage examples for android.content ContentValues getAsString

Introduction

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

Prototype

public String getAsString(String key) 

Source Link

Document

Gets a value and converts it to a String.

Usage

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

private void appendPhoneticNameFields(final ContentValues contentValues) {
    final String phoneticFamilyName;
    final String phoneticMiddleName;
    final String phoneticGivenName;
    {/*from ww  w . ja  v  a  2  s.  c o  m*/
        final String tmpPhoneticFamilyName = contentValues.getAsString(StructuredName.PHONETIC_FAMILY_NAME);
        final String tmpPhoneticMiddleName = contentValues.getAsString(StructuredName.PHONETIC_MIDDLE_NAME);
        final String tmpPhoneticGivenName = contentValues.getAsString(StructuredName.PHONETIC_GIVEN_NAME);
        if (mNeedsToConvertPhoneticString) {
            phoneticFamilyName = VCardUtils.toHalfWidthString(tmpPhoneticFamilyName);
            phoneticMiddleName = VCardUtils.toHalfWidthString(tmpPhoneticMiddleName);
            phoneticGivenName = VCardUtils.toHalfWidthString(tmpPhoneticGivenName);
        } else {
            phoneticFamilyName = tmpPhoneticFamilyName;
            phoneticMiddleName = tmpPhoneticMiddleName;
            phoneticGivenName = tmpPhoneticGivenName;
        }
    }

    if (TextUtils.isEmpty(phoneticFamilyName) && TextUtils.isEmpty(phoneticMiddleName)
            && TextUtils.isEmpty(phoneticGivenName)) {
        if (mIsDoCoMo) {
            mBuilder.append(VCardConstants.PROPERTY_SOUND);
            mBuilder.append(VCARD_PARAM_SEPARATOR);
            mBuilder.append(VCardConstants.PARAM_TYPE_X_IRMC_N);
            mBuilder.append(VCARD_DATA_SEPARATOR);
            mBuilder.append(VCARD_ITEM_SEPARATOR);
            mBuilder.append(VCARD_ITEM_SEPARATOR);
            mBuilder.append(VCARD_ITEM_SEPARATOR);
            mBuilder.append(VCARD_ITEM_SEPARATOR);
            mBuilder.append(VCARD_END_OF_LINE);
        }
        return;
    }

    // Try to emit the field(s) related to phonetic name.
    if (mIsV30) {
        final String sortString = VCardUtils.constructNameFromElements(mVCardType, phoneticFamilyName,
                phoneticMiddleName, phoneticGivenName);
        mBuilder.append(VCardConstants.PROPERTY_SORT_STRING);
        if (shouldAppendCharsetParam(sortString)) {
            mBuilder.append(VCARD_PARAM_SEPARATOR);
            mBuilder.append(mVCardCharsetParameter);
        }
        mBuilder.append(VCARD_DATA_SEPARATOR);
        mBuilder.append(escapeCharacters(sortString));
        mBuilder.append(VCARD_END_OF_LINE);
    } else if (mIsJapaneseMobilePhone) {
        // Note: There is no appropriate property for expressing
        //       phonetic name in vCard 2.1, while there is in
        //       vCard 3.0 (SORT-STRING).
        //       We chose to use DoCoMo's way when the device is Japanese one
        //       since it is supported by
        //       a lot of Japanese mobile phones. This is "X-" property, so
        //       any parser hopefully would not get confused with this.
        //
        //       Also, DoCoMo's specification requires vCard composer to use just the first
        //       column.
        //       i.e.
        //       o  SOUND;X-IRMC-N:Miyakawa Daisuke;;;;
        //       x  SOUND;X-IRMC-N:Miyakawa;Daisuke;;;
        mBuilder.append(VCardConstants.PROPERTY_SOUND);
        mBuilder.append(VCARD_PARAM_SEPARATOR);
        mBuilder.append(VCardConstants.PARAM_TYPE_X_IRMC_N);

        boolean reallyUseQuotedPrintable = (!mRefrainsQPToNameProperties
                && !(VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticFamilyName)
                        && VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticMiddleName)
                        && VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticGivenName)));

        final String encodedPhoneticFamilyName;
        final String encodedPhoneticMiddleName;
        final String encodedPhoneticGivenName;
        if (reallyUseQuotedPrintable) {
            encodedPhoneticFamilyName = encodeQuotedPrintable(phoneticFamilyName);
            encodedPhoneticMiddleName = encodeQuotedPrintable(phoneticMiddleName);
            encodedPhoneticGivenName = encodeQuotedPrintable(phoneticGivenName);
        } else {
            encodedPhoneticFamilyName = escapeCharacters(phoneticFamilyName);
            encodedPhoneticMiddleName = escapeCharacters(phoneticMiddleName);
            encodedPhoneticGivenName = escapeCharacters(phoneticGivenName);
        }

        if (shouldAppendCharsetParam(encodedPhoneticFamilyName, encodedPhoneticMiddleName,
                encodedPhoneticGivenName)) {
            mBuilder.append(VCARD_PARAM_SEPARATOR);
            mBuilder.append(mVCardCharsetParameter);
        }
        mBuilder.append(VCARD_DATA_SEPARATOR);
        {
            boolean first = true;
            if (!TextUtils.isEmpty(encodedPhoneticFamilyName)) {
                mBuilder.append(encodedPhoneticFamilyName);
                first = false;
            }
            if (!TextUtils.isEmpty(encodedPhoneticMiddleName)) {
                if (first) {
                    first = false;
                } else {
                    mBuilder.append(' ');
                }
                mBuilder.append(encodedPhoneticMiddleName);
            }
            if (!TextUtils.isEmpty(encodedPhoneticGivenName)) {
                if (!first) {
                    mBuilder.append(' ');
                }
                mBuilder.append(encodedPhoneticGivenName);
            }
        }
        mBuilder.append(VCARD_ITEM_SEPARATOR);
        mBuilder.append(VCARD_ITEM_SEPARATOR);
        mBuilder.append(VCARD_ITEM_SEPARATOR);
        mBuilder.append(VCARD_ITEM_SEPARATOR);
        mBuilder.append(VCARD_END_OF_LINE);
    }

    if (mUsesDefactProperty) {
        if (!TextUtils.isEmpty(phoneticGivenName)) {
            final boolean reallyUseQuotedPrintable = (mShouldUseQuotedPrintable
                    && !VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticGivenName));
            final String encodedPhoneticGivenName;
            if (reallyUseQuotedPrintable) {
                encodedPhoneticGivenName = encodeQuotedPrintable(phoneticGivenName);
            } else {
                encodedPhoneticGivenName = escapeCharacters(phoneticGivenName);
            }
            mBuilder.append(VCardConstants.PROPERTY_X_PHONETIC_FIRST_NAME);
            if (shouldAppendCharsetParam(phoneticGivenName)) {
                mBuilder.append(VCARD_PARAM_SEPARATOR);
                mBuilder.append(mVCardCharsetParameter);
            }
            if (reallyUseQuotedPrintable) {
                mBuilder.append(VCARD_PARAM_SEPARATOR);
                mBuilder.append(VCARD_PARAM_ENCODING_QP);
            }
            mBuilder.append(VCARD_DATA_SEPARATOR);
            mBuilder.append(encodedPhoneticGivenName);
            mBuilder.append(VCARD_END_OF_LINE);
        }
        if (!TextUtils.isEmpty(phoneticMiddleName)) {
            final boolean reallyUseQuotedPrintable = (mShouldUseQuotedPrintable
                    && !VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticMiddleName));
            final String encodedPhoneticMiddleName;
            if (reallyUseQuotedPrintable) {
                encodedPhoneticMiddleName = encodeQuotedPrintable(phoneticMiddleName);
            } else {
                encodedPhoneticMiddleName = escapeCharacters(phoneticMiddleName);
            }
            mBuilder.append(VCardConstants.PROPERTY_X_PHONETIC_MIDDLE_NAME);
            if (shouldAppendCharsetParam(phoneticMiddleName)) {
                mBuilder.append(VCARD_PARAM_SEPARATOR);
                mBuilder.append(mVCardCharsetParameter);
            }
            if (reallyUseQuotedPrintable) {
                mBuilder.append(VCARD_PARAM_SEPARATOR);
                mBuilder.append(VCARD_PARAM_ENCODING_QP);
            }
            mBuilder.append(VCARD_DATA_SEPARATOR);
            mBuilder.append(encodedPhoneticMiddleName);
            mBuilder.append(VCARD_END_OF_LINE);
        }
        if (!TextUtils.isEmpty(phoneticFamilyName)) {
            final boolean reallyUseQuotedPrintable = (mShouldUseQuotedPrintable
                    && !VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticFamilyName));
            final String encodedPhoneticFamilyName;
            if (reallyUseQuotedPrintable) {
                encodedPhoneticFamilyName = encodeQuotedPrintable(phoneticFamilyName);
            } else {
                encodedPhoneticFamilyName = escapeCharacters(phoneticFamilyName);
            }
            mBuilder.append(VCardConstants.PROPERTY_X_PHONETIC_LAST_NAME);
            if (shouldAppendCharsetParam(phoneticFamilyName)) {
                mBuilder.append(VCARD_PARAM_SEPARATOR);
                mBuilder.append(mVCardCharsetParameter);
            }
            if (reallyUseQuotedPrintable) {
                mBuilder.append(VCARD_PARAM_SEPARATOR);
                mBuilder.append(VCARD_PARAM_ENCODING_QP);
            }
            mBuilder.append(VCARD_DATA_SEPARATOR);
            mBuilder.append(encodedPhoneticFamilyName);
            mBuilder.append(VCARD_END_OF_LINE);
        }
    }
}

From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java

@Override
public Uri insert(final Uri uri, final ContentValues values) {
    try {//from   ww w . j  a  va  2s . c o m
        final int tableId = getTableId(uri);
        final String table = getTableNameById(tableId);
        switch (tableId) {
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATION:
        case TABLE_ID_DIRECT_MESSAGES:
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES:
            return null;
        }
        if (table == null)
            return null;
        final long rowId;
        if (tableId == TABLE_ID_CACHED_USERS) {
            final Expression where = Expression.equals(CachedUsers.USER_ID,
                    values.getAsLong(CachedUsers.USER_ID));
            mDatabaseWrapper.update(table, values, where.getSQL(), null);
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } else if (tableId == TABLE_ID_SEARCH_HISTORY) {
            values.put(SearchHistory.RECENT_QUERY, System.currentTimeMillis());
            final Expression where = Expression.equalsArgs(SearchHistory.QUERY);
            final String[] args = { values.getAsString(SearchHistory.QUERY) };
            mDatabaseWrapper.update(table, values, where.getSQL(), args);
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } else if (tableId == TABLE_ID_CACHED_RELATIONSHIPS) {
            final long accountId = values.getAsLong(CachedRelationships.ACCOUNT_ID);
            final long userId = values.getAsLong(CachedRelationships.USER_ID);
            final Expression where = Expression.and(
                    Expression.equals(CachedRelationships.ACCOUNT_ID, accountId),
                    Expression.equals(CachedRelationships.USER_ID, userId));
            if (mDatabaseWrapper.update(table, values, where.getSQL(), null) > 0) {
                final String[] projection = { CachedRelationships._ID };
                final Cursor c = mDatabaseWrapper.query(table, projection, where.getSQL(), null, null, null,
                        null);
                if (c.moveToFirst()) {
                    rowId = c.getLong(0);
                } else {
                    rowId = 0;
                }
                c.close();
            } else {
                rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values,
                        SQLiteDatabase.CONFLICT_IGNORE);
            }
        } else if (shouldReplaceOnConflict(tableId)) {
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        } else {
            rowId = mDatabaseWrapper.insert(table, null, values);
        }
        onDatabaseUpdated(tableId, uri);
        onNewItemsInserted(uri, tableId, values, rowId);
        return Uri.withAppendedPath(uri, String.valueOf(rowId));
    } catch (final SQLException e) {
        throw new IllegalStateException(e);
    }
}

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   w  w  w  .  j a  v  a2 s .c om*/
            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:edu.stanford.mobisocial.dungbeetle.DBHelper.java

long addToOutgoing(SQLiteDatabase db, String appId, String to, String type, JSONObject json) {
    if (DBG) {/*from   ww w  .j  a  va  2  s .com*/
        Log.d(TAG, "Adding to outgoing; to: " + to + ", json: " + json);
    }
    try {
        long timestamp = new Date().getTime();
        prepareForSending(json, type, timestamp, appId);
        ContentValues cv = new ContentValues();
        cv.put(DbObject._ID, getNextId());
        cv.put(DbObject.APP_ID, appId);
        cv.put(DbObject.FEED_NAME, "friend");
        cv.put(DbObject.CONTACT_ID, Contact.MY_ID);
        cv.put(DbObject.DESTINATION, to);
        cv.put(DbObject.TYPE, type);
        cv.put(DbObject.JSON, json.toString());
        cv.put(DbObject.SEQUENCE_ID, 0);
        cv.put(DbObject.TIMESTAMP, timestamp);
        if (cv.getAsString(DbObject.JSON).length() > SIZE_LIMIT)
            throw new RuntimeException("Messasge size is too large for sending");
        return db.insertOrThrow(DbObject.TABLE, null, cv);
    } catch (Exception e) {
        // TODO, too spammy
        //e.printStackTrace(System.err);
        return -1;
    }
}

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

From source file:org.runnerup.view.DetailActivity.java

void fillHeaderData() {
    // Fields from the database (projection)
    // Must include the _id column for the adapter to work
    String[] from = new String[] { DB.ACTIVITY.START_TIME, DB.ACTIVITY.DISTANCE, DB.ACTIVITY.TIME,
            DB.ACTIVITY.COMMENT, DB.ACTIVITY.SPORT };

    Cursor c = mDB.query(DB.ACTIVITY.TABLE, from, "_id == " + mID, null, null, null, null, null);
    c.moveToFirst();//from w  w  w  .jav  a2 s  .co  m
    ContentValues tmp = DBHelper.get(c);
    c.close();

    long st = 0;
    if (tmp.containsKey(DB.ACTIVITY.START_TIME)) {
        st = tmp.getAsLong(DB.ACTIVITY.START_TIME);
        setTitle("RunnerUp - " + formatter.formatDateTime(Formatter.TXT_LONG, st));
    }
    float d = 0;
    if (tmp.containsKey(DB.ACTIVITY.DISTANCE)) {
        d = tmp.getAsFloat(DB.ACTIVITY.DISTANCE);
        activityDistance.setText(formatter.formatDistance(Formatter.TXT_LONG, (long) d));
    } else {
        activityDistance.setText("");
    }

    float t = 0;
    if (tmp.containsKey(DB.ACTIVITY.TIME)) {
        t = tmp.getAsFloat(DB.ACTIVITY.TIME);
        activityTime.setText(formatter.formatElapsedTime(Formatter.TXT_SHORT, (long) t));
    } else {
        activityTime.setText("");
    }

    if (d != 0 && t != 0) {
        activityPace.setText(formatter.formatPace(Formatter.TXT_LONG, t / d));
    } else {
        activityPace.setText("");
    }

    if (tmp.containsKey(DB.ACTIVITY.COMMENT)) {
        notes.setText(tmp.getAsString(DB.ACTIVITY.COMMENT));
    }

    if (tmp.containsKey(DB.ACTIVITY.SPORT)) {
        sport.setValue(tmp.getAsInteger(DB.ACTIVITY.SPORT));
    }
}

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:org.getlantern.firetweet.provider.FiretweetDataProvider.java

@Override
public Uri insert(final Uri uri, final ContentValues values) {
    try {//from www.  j av  a  2s  . co  m
        final int tableId = getTableId(uri);
        final String table = getTableNameById(tableId);
        checkWritePermission(tableId, table);
        switch (tableId) {
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATION:
        case TABLE_ID_DIRECT_MESSAGES:
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES:
            return null;
        }
        if (table == null)
            return null;
        final long rowId;
        if (tableId == TABLE_ID_CACHED_USERS) {
            final Expression where = Expression.equals(CachedUsers.USER_ID,
                    values.getAsLong(CachedUsers.USER_ID));
            mDatabaseWrapper.update(table, values, where.getSQL(), null);
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } else if (tableId == TABLE_ID_SEARCH_HISTORY) {
            values.put(SearchHistory.RECENT_QUERY, System.currentTimeMillis());
            final Expression where = Expression.equalsArgs(SearchHistory.QUERY);
            final String[] args = { values.getAsString(SearchHistory.QUERY) };
            mDatabaseWrapper.update(table, values, where.getSQL(), args);
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } else if (tableId == TABLE_ID_CACHED_RELATIONSHIPS) {
            final long accountId = values.getAsLong(CachedRelationships.ACCOUNT_ID);
            final long userId = values.getAsLong(CachedRelationships.USER_ID);
            final Expression where = Expression.and(
                    Expression.equals(CachedRelationships.ACCOUNT_ID, accountId),
                    Expression.equals(CachedRelationships.USER_ID, userId));
            if (mDatabaseWrapper.update(table, values, where.getSQL(), null) > 0) {
                final String[] projection = { CachedRelationships._ID };
                final Cursor c = mDatabaseWrapper.query(table, projection, where.getSQL(), null, null, null,
                        null);
                if (c.moveToFirst()) {
                    rowId = c.getLong(0);
                } else {
                    rowId = 0;
                }
                c.close();
            } else {
                rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values,
                        SQLiteDatabase.CONFLICT_IGNORE);
            }
        } else if (shouldReplaceOnConflict(tableId)) {
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        } else {
            rowId = mDatabaseWrapper.insert(table, null, values);
        }
        onDatabaseUpdated(tableId, uri);
        onNewItemsInserted(uri, tableId, values, rowId);
        return Uri.withAppendedPath(uri, String.valueOf(rowId));
    } catch (final SQLException e) {
        Crashlytics.logException(e);
        throw new IllegalStateException(e);
    }
}

From source file:ch.ethz.twimight.net.opportunistic.ScanningService.java

/**
 * Creates content values for a Tweet from a JSON object TODO: Move this to
 * where it belongs/* w  ww .j  av  a2  s .c  o m*/
 * 
 * @param o
 * @return
 * @throws JSONException
 */
protected ContentValues getTweetCV(JSONObject o) throws JSONException {

    ContentValues cv = new ContentValues();

    if (o.has(Tweets.COL_CERTIFICATE))
        cv.put(Tweets.COL_CERTIFICATE, o.getString(Tweets.COL_CERTIFICATE));

    if (o.has(Tweets.COL_SIGNATURE))
        cv.put(Tweets.COL_SIGNATURE, o.getString(Tweets.COL_SIGNATURE));

    if (o.has(Tweets.COL_CREATED_AT))
        cv.put(Tweets.COL_CREATED_AT, o.getLong(Tweets.COL_CREATED_AT));

    if (o.has(Tweets.COL_TEXT)) {
        cv.put(Tweets.COL_TEXT, o.getString(Tweets.COL_TEXT));
        cv.put(Tweets.COL_TEXT_PLAIN, Html.fromHtml(o.getString(Tweets.COL_TEXT)).toString());
    }

    if (o.has(Tweets.COL_USER_TID)) {
        cv.put(Tweets.COL_USER_TID, o.getLong(Tweets.COL_USER_TID));
    }

    if (o.has(Tweets.COL_TID)) {
        cv.put(Tweets.COL_TID, o.getLong(Tweets.COL_TID));
    }

    if (o.has(Tweets.COL_REPLY_TO_TWEET_TID))
        cv.put(Tweets.COL_REPLY_TO_TWEET_TID, o.getLong(Tweets.COL_REPLY_TO_TWEET_TID));

    if (o.has(Tweets.COL_LAT))
        cv.put(Tweets.COL_LAT, o.getDouble(Tweets.COL_LAT));

    if (o.has(Tweets.COL_LNG))
        cv.put(Tweets.COL_LNG, o.getDouble(Tweets.COL_LNG));

    if (o.has(Tweets.COL_SOURCE))
        cv.put(Tweets.COL_SOURCE, o.getString(Tweets.COL_SOURCE));

    if (o.has(Tweets.COL_MEDIA_URIS)) {
        String userID = cv.getAsString(Tweets.COL_USER_TID);
        photoPath = PHOTO_PATH + "/" + userID;
        String photoFileName = o.getString(Tweets.COL_MEDIA_URIS);
        File targetFile = sdCardHelper.getFileFromSDCard(photoPath, photoFileName);

        cv.put(Tweets.COL_MEDIA_URIS, Uri.fromFile(targetFile).toString());

    }

    if (o.has(Tweets.COL_HTML_PAGES))
        cv.put(Tweets.COL_HTML_PAGES, o.getString(Tweets.COL_HTML_PAGES));

    if (o.has(TwitterUsers.COL_SCREEN_NAME)) {
        cv.put(Tweets.COL_SCREEN_NAME, o.getString(TwitterUsers.COL_SCREEN_NAME));
    }

    return cv;
}

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.  ja v  a 2s .c om*/
 */
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);
}