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:org.anhonesteffort.flock.sync.addressbook.ContactFactory.java

protected static void addPostalAddress(String path, VCard vCard, ContentValues addressValues)
        throws InvalidComponentException {
    Integer addressType = addressValues.getAsInteger(ContactsContract.CommonDataKinds.StructuredPostal.TYPE);
    String formattedAddress = addressValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS);
    String label = addressValues.getAsString(ContactsContract.CommonDataKinds.StructuredPostal.LABEL);
    String street = addressValues.getAsString(ContactsContract.CommonDataKinds.StructuredPostal.STREET);
    String poBox = addressValues.getAsString(ContactsContract.CommonDataKinds.StructuredPostal.POBOX);
    String neighborhood = addressValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredPostal.NEIGHBORHOOD);
    String city = addressValues.getAsString(ContactsContract.CommonDataKinds.StructuredPostal.CITY);
    String region = addressValues.getAsString(ContactsContract.CommonDataKinds.StructuredPostal.REGION);
    String postcode = addressValues.getAsString(ContactsContract.CommonDataKinds.StructuredPostal.POBOX);
    String country = addressValues.getAsString(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY);

    if (addressType != null && formattedAddress != null) {
        Address address = new Address();
        address.setLabel(formattedAddress);

        switch (addressType) {
        case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME:
            address.addType(AddressType.HOME);
            break;

        case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK:
            address.addType(AddressType.WORK);
            break;

        case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_CUSTOM:
            if (label != null)
                AddressType.get(label);//www.  j ava 2 s.com
            break;
        }

        if (street != null)
            address.setStreetAddress(street);

        if (poBox != null)
            address.setPoBox(poBox);

        if (neighborhood != null)
            address.setExtendedAddress(neighborhood);

        if (city != null)
            address.setLocality(city);

        if (region != null)
            address.setRegion(region);

        if (postcode != null)
            address.setPostalCode(postcode);

        if (country != null)
            address.setCountry(country);

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

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

private void reload() {
    DB db = DB.getInstance(getActivity());
    ContentValues manga = db.getManga(currentManga);
    ContentValues metadata = db.getMangaMetadata(currentManga);
    List<Integer> missingList = new ArrayList<Integer>();
    int lastChapter = Utils.mangaChapterInfo(getActivity(), currentManga, missingList);

    title.setText(manga.getAsString(DB.MANGA_TITLE));

    if (metadata.size() != 0) {
        setInProgress(false);// w  w  w  .j a va 2 s .c  o  m

        if (metadata.containsKey("genres"))
            genres.setText(metadata.getAsString("genres"));
        else
            genres.setText(R.string.not_available);

        if (metadata.containsKey("summary"))
            summary.setText(metadata.getAsString("summary"));
        else
            summary.setText(R.string.not_available);

        last.setText(Utils.formatChapterNumber(lastChapter));

        if (missingList.size() > 0) {
            missing.setVisibility(View.VISIBLE);
            missing_label.setVisibility(View.VISIBLE);
            missing.setText(Utils.formatMissingChapters(missingList));
        } else {
            missing.setVisibility(View.GONE);
            missing_label.setVisibility(View.GONE);
        }

    } else {
        Download.startMangaUpdate(getActivity(), currentManga);
    }
}

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

/**
 * Parse a campaign.//from  w  w w  .  j  ava 2 s  .  c om
 * @param campaignId already parsed campaign id.
 * @param values content data.
 * @throws JSONException if payload parsing failure.
 */
EngagementReachContent(com.microsoft.azure.engagement.reach.CampaignId campaignId, ContentValues values)
        throws JSONException {
    /* Parse base fields */
    mCampaignId = campaignId;
    mDlc = values.getAsInteger(DLC);
    mDlcId = values.getAsString(DLC_ID);
    mCategory = values.getAsString(CATEGORY);
    Long expiry = values.getAsLong(TTL);
    if (expiry != null) {
        expiry *= 1000L;
        if (parseBoolean(values, USER_TIME_ZONE))
            expiry -= TimeZone.getDefault().getOffset(expiry);
    }
    mExpiry = expiry;
    if (values.containsKey(PAYLOAD))
        setPayload(new JSONObject(values.getAsString(PAYLOAD)));
}

From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java

private ContentValues[] parseAttendees(String eventId, JSONArray attendees) throws JSONException {
    int length = attendees.length();
    ContentValues[] array = new ContentValues[length];
    HashMap<String, String> imageUrls = new HashMap<>();
    for (int i = 0; i < length; ++i) {
        JSONObject attendee = attendees.getJSONObject(i);
        array[i] = new ContentValues();
        array[i].put(Table.Attendee.EVENT_ID, eventId);
        array[i].put(Table.Attendee.NAME, attendee.getString("name"));
        array[i].put(Table.Attendee.ID, attendee.getString("id"));
        array[i].put(Table.Attendee.EMAIL, attendee.getString("email"));
        String plusid = attendee.getString("plusid");
        if (!TextUtils.isEmpty(plusid)) {
            array[i].put(Table.Attendee.PLUSID, plusid);
            imageUrls.put(plusid, "null");
        }//  w w w. java  2s  .  com
        long checkinTime = attendee.getLong("checkinTime");
        if (0 == checkinTime) {
            array[i].putNull(Table.Attendee.CHECKIN);
        } else {
            array[i].put(Table.Attendee.CHECKIN, checkinTime);
        }
        array[i].putNull(Table.Attendee.IMAGE_URL);
    }
    // Fetch all the Google+ Image URLs at once if necessary
    if (mApiClient != null && mApiClient.isConnected() && !imageUrls.isEmpty()) {
        People.LoadPeopleResult result = Plus.PeopleApi.load(mApiClient, imageUrls.keySet()).await();
        PersonBuffer personBuffer = result.getPersonBuffer();
        if (personBuffer != null) {
            // Copy URLs into the HashMap
            for (Person person : personBuffer) {
                if (person.hasImage()) {
                    imageUrls.put(extractId(person.getUrl()), person.getImage().getUrl());
                }
            }
            // Fill the missing URLs in the array of ContentValues
            for (ContentValues values : array) {
                if (values.containsKey(Table.Attendee.PLUSID)) {
                    String plusId = values.getAsString(Table.Attendee.PLUSID);
                    String imageUrl = imageUrls.get(plusId);
                    if (!TextUtils.isEmpty(imageUrl)) {
                        values.put(Table.Attendee.IMAGE_URL, imageUrl);
                    }
                }
            }
        }
    }
    return array;
}

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

public JSONObject contentValueToJSON(ContentValues cv) {
    JSONObject json = new JSONObject();
    try {//from   w ww. ja v  a2s  . c  o 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:org.anhonesteffort.flock.sync.addressbook.ContactFactory.java

protected static void addInstantMessaging(String path, VCard vCard, ContentValues imValues)
        throws InvalidComponentException {
    Integer type = imValues.getAsInteger(ContactsContract.CommonDataKinds.Im.TYPE);
    Integer protocol = imValues.getAsInteger(ContactsContract.CommonDataKinds.Im.PROTOCOL);
    String customProtocol = imValues.getAsString(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL);
    String handle = imValues.getAsString(ContactsContract.CommonDataKinds.Im.DATA);

    if (type != null && protocol != null && handle != null) {
        Impp impp;//from   ww w .  j av  a  2s.  c o  m

        switch (protocol) {
        case ContactsContract.CommonDataKinds.Im.PROTOCOL_AIM:
            impp = Impp.aim(handle);
            break;

        case ContactsContract.CommonDataKinds.Im.PROTOCOL_MSN:
            impp = Impp.msn(handle);
            break;

        case ContactsContract.CommonDataKinds.Im.PROTOCOL_YAHOO:
            impp = Impp.yahoo(handle);
            break;

        case ContactsContract.CommonDataKinds.Im.PROTOCOL_SKYPE:
            impp = Impp.skype(handle);
            break;

        case ContactsContract.CommonDataKinds.Im.PROTOCOL_ICQ:
            impp = Impp.icq(handle);
            break;

        case ContactsContract.CommonDataKinds.Im.PROTOCOL_QQ:
            impp = new Impp("qq", handle);
            break;

        case ContactsContract.CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK:
            impp = new Impp("google-talk", handle);
            break;

        case ContactsContract.CommonDataKinds.Im.PROTOCOL_NETMEETING:
            impp = new Impp("netmeeting", handle);
            break;

        case ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM:
            impp = new Impp(customProtocol, handle);
            break;

        default:
            impp = Impp.xmpp(handle);
            break;
        }

        impp.addType(ImppType.PERSONAL);

        vCard.addImpp(impp);
    } else {
        Log.e(TAG, "im type, protocol, or handle is null, not adding anything");
        throw new InvalidComponentException("im type, protocol, or handle is null", false,
                CardDavConstants.CARDDAV_NAMESPACE, path);
    }
}

From source file:org.blanco.techmun.android.cproviders.ComentariosFetcher.java

public boolean publishComentario(ContentValues values) {
    HttpPost request = new HttpPost("http://tec-ch-mun-2011.herokuapp.com/application/publicarcomentario");

    HttpResponse response = null;/*ww  w.j  ava 2s. c om*/
    try {
        //prepare the entity for the request
        List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>();
        parameters.add(new BasicNameValuePair("comentario.evento.id", values.getAsString("eventoId")));
        parameters.add(new BasicNameValuePair("comentario.comentario", values.getAsString("comentario")));
        if (values.containsKey("autor")) {
            parameters.add(new BasicNameValuePair("comentario.autor", values.getAsString("autor")));
        }
        if (values.containsKey("contacto")) {
            parameters.add(new BasicNameValuePair("comentario.contacto", values.getAsString("contacto")));
        }

        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters);
        request.setEntity(entity);

        response = httpClient.execute(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            return true;
        }
    } catch (Exception ex) {
        Log.e("techmun", "Error publishComentario. Comment not sent", ex);
    }
    return false;
}

From source file:org.runnerup.export.RunKeeperUploader.java

@Override
public void init(ContentValues config) {
    String authConfig = config.getAsString(DB.ACCOUNT.AUTH_CONFIG);
    id = config.getAsLong("_id");
    if (authConfig != null) {
        try {/*  w  w  w . jav a2 s .  c o  m*/
            JSONObject tmp = new JSONObject(authConfig);
            access_token = tmp.optString("access_token", null);
            feed_access_token = tmp.optString("feed_access_token", null);
            if (feed_access_token == null) {
                feed_username = tmp.optString("username", null);
                feed_password = tmp.optString("password", null);
            } else {
                feed_username = null;
                feed_password = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.runnerup.export.EndomondoSynchronizer.java

@Override
public void init(ContentValues config) {
    id = config.getAsLong("_id");
    String auth = config.getAsString(DB.ACCOUNT.AUTH_CONFIG);
    if (auth != null) {
        try {/*from   w ww .j  a  v a  2s .  c o m*/
            JSONObject tmp = new JSONObject(auth);
            username = tmp.optString("username", null);
            password = tmp.optString("password", null);
            deviceId = tmp.optString("deviceId", null);
            authToken = tmp.optString("authToken", null);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Updates the tables with relation to the person table.
  * @param values Values/* www .  j  a  v a  2 s  . c  o  m*/
 * @param table Table
 * @param relationColumn Name of relation column
 * @return Affected rows
 */
public int updatePersonChildren(List<ContentValues> values, String table, String relationColumn) {
    int affectedRows = 0;
    for (ContentValues item : values) {
        // prepare relations to locale IDs
        String relationUUID = item.getAsString(relationColumn);
        item.remove(relationColumn);
        item.put(relationColumn, getPersonIDByUUID(relationUUID));
        // update table
        affectedRows += updateTable(item, table);
    }
    return affectedRows;
}