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:at.bitfire.vcard4android.AndroidContact.java

protected void populateOrganization(ContentValues row) {
    String company = row.getAsString(Organization.COMPANY),
            department = row.getAsString(Organization.DEPARTMENT), title = row.getAsString(Organization.TITLE),
            role = row.getAsString(Organization.JOB_DESCRIPTION);

    if (!TextUtils.isEmpty(company) || !TextUtils.isEmpty(department)) {
        ezvcard.property.Organization org = new ezvcard.property.Organization();
        if (!TextUtils.isEmpty(company))
            org.addValue(company);/*  w  w  w .j ava2s.  c  o m*/
        if (!TextUtils.isEmpty(department))
            org.addValue(department);
        contact.organization = org;
    }

    if (!TextUtils.isEmpty(title))
        contact.jobTitle = title;
    if (!TextUtils.isEmpty(role))
        contact.jobDescription = role;
}

From source file:com.granita.icloudcalsync.resource.LocalAddressBook.java

protected void populateEvent(Contact c, ContentValues row) throws RemoteException {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    try {//w ww .jav a  2s. c  o  m
        Date date = formatter.parse(row.getAsString(CommonDataKinds.Event.START_DATE));
        switch (row.getAsInteger(CommonDataKinds.Event.TYPE)) {
        case CommonDataKinds.Event.TYPE_ANNIVERSARY:
            c.setAnniversary(new Anniversary(date));
            break;
        case CommonDataKinds.Event.TYPE_BIRTHDAY:
            c.setBirthDay(new Birthday(date));
            break;
        }
    } catch (ParseException e) {
        Log.w(TAG, "Couldn't parse local birthday/anniversary date", e);
    }
}

From source file:org.tigase.mobile.roster.RosterFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    final Long id = extractId(menuInfo);

    if (id != null && id != -1) {
        RosterItem r = getJid(id);//  ww w  . j  a va 2 s.c  o  m
        final boolean sessionEstablished = r != null && isSessionEstablished(r.getSessionObject());

        MenuInflater m = new MenuInflater(getActivity());
        try {
            Presence p = r.getSessionObject().getPresence().getBestPresence(r.getJid());
            if (p != null && p.getType() == null) {
                SubMenu sm = menu.addSubMenu(R.id.contactsOnlineGroup, Menu.NONE, Menu.NONE, "Chat with");
                prepareResources(sm, id);
            }
        } catch (Exception e) {
        }
        m.inflate(R.menu.roster_context_menu, menu);

        JaxmppCore jaxmpp = this.getMulti().get(r.getSessionObject());
        if (jaxmpp != null && sessionEstablished) {
            GeolocationModule module = jaxmpp.getModule(GeolocationModule.class);
            if (module != null) {
                ContentValues location = module.getLocationForJid(r.getJid());
                if (location != null) {
                    Double lat = location.getAsDouble(GeolocationTableMetaData.FIELD_LAT);
                    Double lon = location.getAsDouble(GeolocationTableMetaData.FIELD_LON);
                    String uriStr = null;
                    if (lon == null || lat == null) {
                        String str = "";
                        String val = location.getAsString(GeolocationTableMetaData.FIELD_STREET);
                        Log.v(TAG, "Street = " + String.valueOf(val));
                        if (val != null) {
                            str += val;
                        }
                        val = location.getAsString(GeolocationTableMetaData.FIELD_LOCALITY);
                        Log.v(TAG, "Locality = " + String.valueOf(val));
                        if (val != null) {
                            if (!isEmpty(str)) {
                                str += " ";
                            }
                            str += val;
                        }
                        val = location.getAsString(GeolocationTableMetaData.FIELD_COUNTRY);
                        Log.v(TAG, "Country = " + String.valueOf(val));
                        if (val != null) {
                            if (!isEmpty(str)) {
                                str += " ";
                            }
                            str += val;
                        }

                        if (!isEmpty(str)) {
                            str = str.replace(' ', '+');
                            uriStr = "geo:0,0?q=" + str;
                        }
                    } else {
                        Log.v(TAG, "latitude = " + String.valueOf(lat));
                        Log.v(TAG, "longitude = " + String.valueOf(lon));
                        uriStr = "geo:" + String.valueOf(lat) + "," + String.valueOf(lon) + "?z=14";
                    }
                    if (uriStr != null) {
                        uriStr += "(" + RosterDisplayTools.getDisplayName(r) + ")";
                        Log.v(TAG, "created geolocation uri = " + uriStr);
                        Uri uri = Uri.parse(uriStr);
                        MenuItem item = menu.add(R.string.geolocation_show);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        item.setIntent(intent);
                    }
                }
            }
        }

        menu.setGroupVisible(R.id.contactsOnlineGroup, sessionEstablished);
    }
}

From source file:com.wheelly.fragments.LocationsMapFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    BusProvider.getInstance().register(this);

    inSelectMode = getActivity().getIntent().hasExtra(LocationActivity.LOCATION_ID_EXTRA);

    // Getting Google Play availability status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());

    // Showing status
    if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available

        int requestCode = 10;
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), requestCode);
        dialog.show();//from   w  w  w.  j av a  2s .  c  om

    } else { // Google Play Services are available

        // Getting GoogleMap object from the fragment
        googleMap = getMap();
    }

    ApiAdapterFactory.getApiAdapter().configureMapViewContextualMenu(this, new MapContextActionCallback() {
        private EditText editText;

        @Override
        public void onPrepare(Menu menu, Marker marker) {
            configureTitleWidget(marker);
        }

        @SuppressLint("NewApi")
        @Override
        public void onCreate(Menu menu) {
            editText = (EditText) menu.add(0, 0, 0, "name").setIcon(android.R.drawable.ic_menu_edit)
                    .setActionView(R.layout.location_edit).getActionView().findViewById(R.id.location_name);

            menu.add(0, 1, 0, R.string.item_add).setIcon(android.R.drawable.ic_menu_save);
        }

        private void configureTitleWidget(Marker marker) {
            if (null != marker && null != editText) {
                try {
                    final long id = Long.parseLong(marker.getSnippet());
                    editText.setText(new LocationBroker(getActivity()).loadOrCreate(id).getAsString("name"));
                } catch (NumberFormatException nfex) {
                    LocationUtils.resolveAddress(getActivity(), marker.getPosition(), "",
                            new AddressResolveCallback() {
                                @Override
                                public void onResolved(Address address) {
                                    if (getResources().getString(R.string.new_location)
                                            .equals(editText.getText().toString()) && null != address) {
                                        editText.setText(LocationUtils.formatAddress(address));
                                    }
                                }
                            });
                }
            }
        }

        @Override
        public boolean onClick(MenuItem item, Marker marker) {
            if (null != marker) {
                final ContentValues myLocation = new ContentValues();

                try {
                    final long id = Long.parseLong(marker.getSnippet());
                    myLocation.put(BaseColumns._ID, id);
                } catch (NumberFormatException nfex) {
                    myLocation.put("provider", "fusion");
                }

                if (null != editText) {
                    myLocation.put("name", editText.getText().toString());
                }

                myLocation.put("latitude", marker.getPosition().latitude);
                myLocation.put("longitude", marker.getPosition().longitude);
                myLocation.put("datetime", System.currentTimeMillis());

                LocationUtils.resolveAddress(getActivity(), marker.getPosition(),
                        myLocation.getAsString("name"), new AddressResolveCallback() {
                            @Override
                            public void onResolved(Address address) {
                                if (null != address) {
                                    myLocation.put("resolved_address", LocationUtils.formatAddress(address));
                                }

                                new LocationBroker(getActivity()).updateOrInsert(myLocation);
                            }
                        });

                return true;
            }
            return false;
        }
    });
}

From source file:at.bitfire.vcard4android.AndroidContact.java

protected void populateWebsite(ContentValues row) {
    Url url = new Url(row.getAsString(Website.URL));
    if (row.containsKey(Website.TYPE))
        switch (row.getAsInteger(Website.TYPE)) {
        case Website.TYPE_HOMEPAGE:
            url.setType(Contact.URL_TYPE_HOMEPAGE);
            break;
        case Website.TYPE_BLOG:
            url.setType(Contact.URL_TYPE_BLOG);
            break;
        case Website.TYPE_PROFILE:
            url.setType(Contact.URL_TYPE_PROFILE);
            break;
        case Website.TYPE_HOME:
            url.setType("home");
            break;
        case Website.TYPE_WORK:
            url.setType("work");
            break;
        case Website.TYPE_FTP:
            url.setType(Contact.URL_TYPE_FTP);
            break;
        case Website.TYPE_CUSTOM:
            String label = row.getAsString(Website.LABEL);
            if (!TextUtils.isEmpty(label))
                url.setType(labelToXName(label));
            break;
        }/* w ww.  j  ava 2s  .  com*/
    contact.getURLs().add(url);
}

From source file:org.ohmage.db.DbHelper.java

/**
 * Used by the ContentProvider to insert a campaign and also insert into
 * interested tables. Don't use this directly; if you do, none of the
 * contentobservers, etc. that are listening to Campaigns, Surveys, or
 * SurveyPrompts will be notified.//from   ww w.java  2s .c o  m
 * 
 * @param values
 *            a ContentValues collection, preferably generated by calling
 *            {@link Campaign}'s toCV() method
 * @return the ID of the inserted record
 */
public long addCampaign(SQLiteDatabase db, ContentValues values) {

    long rowId = -1; // the row ID for the campaign that we'll eventually be
                     // returning

    try {
        // start the transaction that will include inserting the campaign +
        // surveys + survey prompts
        db.beginTransaction();

        // hold onto some variables for processing
        String configurationXml = values.getAsString(Campaigns.CAMPAIGN_CONFIGURATION_XML);
        String campaignUrn = values.getAsString(Campaigns.CAMPAIGN_URN);

        // actually insert the campaign
        rowId = db.insert(Tables.CAMPAIGNS, null, values);

        if (configurationXml != null) {
            // xml parsing below, inserts into Surveys and SurveyPrompts
            if (populateSurveysFromCampaignXML(db, campaignUrn, configurationXml)) {
                // i think we're done now; finish up the transaction
                db.setTransactionSuccessful();
            }
            // else we fail and the transaction gets rolled back
        } else {
            db.setTransactionSuccessful();
        }
    } finally {
        db.endTransaction();
    }

    return rowId;
}

From source file:at.bitfire.vcard4android.AndroidContact.java

protected void populateRelation(ContentValues row) {
    String name = row.getAsString(Relation.NAME);

    if (TextUtils.isEmpty(name))
        return;//  ww w .java 2 s . c o m

    Related related = new Related();
    related.setText(name);

    if (row.containsKey(Relation.TYPE))
        switch (row.getAsInteger(Relation.TYPE)) {
        case Relation.TYPE_ASSISTANT:
        case Relation.TYPE_MANAGER:
            related.addType(RelatedType.CO_WORKER);
            break;
        case Relation.TYPE_BROTHER:
        case Relation.TYPE_SISTER:
            related.addType(RelatedType.SIBLING);
            break;
        case Relation.TYPE_CHILD:
            related.addType(RelatedType.CHILD);
            break;
        case Relation.TYPE_DOMESTIC_PARTNER:
            related.addType(RelatedType.CO_RESIDENT);
            break;
        case Relation.TYPE_FRIEND:
            related.addType(RelatedType.FRIEND);
            break;
        case Relation.TYPE_FATHER:
        case Relation.TYPE_MOTHER:
        case Relation.TYPE_PARENT:
            related.addType(RelatedType.PARENT);
            break;
        case Relation.TYPE_PARTNER:
        case Relation.TYPE_SPOUSE:
            related.addType(RelatedType.SWEETHEART);
            break;
        case Relation.TYPE_RELATIVE:
            related.addType(RelatedType.KIN);
            break;
        }

    contact.getRelations().add(related);
}

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

@SuppressWarnings("null")
public Uploader add(ContentValues config) {
    if (config == null) {
        System.err.println("Add null!");
        assert (false);
        return null;
    }/*from ww w. jav  a2  s  . com*/

    String uploaderName = config.getAsString(DB.ACCOUNT.NAME);
    if (uploaderName == null) {
        System.err.println("name not found!");
        return null;
    }
    if (uploaders.containsKey(uploaderName)) {
        return uploaders.get(uploaderName);
    }
    Uploader uploader = null;
    if (uploaderName.contentEquals(RunKeeperUploader.NAME)) {
        uploader = new RunKeeperUploader(this);
    } else if (uploaderName.contentEquals(GarminUploader.NAME)) {
        uploader = new GarminUploader(this);
    } else if (uploaderName.contentEquals(FunBeatUploader.NAME)) {
        uploader = new FunBeatUploader(this);
    } else if (uploaderName.contentEquals(MapMyRunUploader.NAME)) {
        uploader = new MapMyRunUploader(this);
    } else if (uploaderName.contentEquals(NikePlus.NAME)) {
        uploader = new NikePlus(this);
    } else if (uploaderName.contentEquals(JoggSE.NAME)) {
        uploader = new JoggSE(this);
    } else if (uploaderName.contentEquals(Endomondo.NAME)) {
        uploader = new Endomondo(this);
    } else if (uploaderName.contentEquals(RunningAHEAD.NAME)) {
        uploader = new RunningAHEAD(this);
    } else if (uploaderName.contentEquals(RunnerUpLive.NAME)) {
        uploader = new RunnerUpLive(context);
    } else if (uploaderName.contentEquals(DigifitUploader.NAME)) {
        uploader = new DigifitUploader(this);
    } else if (uploaderName.contentEquals(Strava.NAME)) {
        uploader = new Strava(this);
    } else if (uploaderName.contentEquals(Facebook.NAME)) {
        uploader = new Facebook(context, this);
    } else if (uploaderName.contentEquals(GooglePlus.NAME)) {
        uploader = new GooglePlus(this);
    } else if (uploaderName.contentEquals(RuntasticUploader.NAME)) {
        uploader = new RuntasticUploader(this);
    } else if (uploaderName.contentEquals(GoogleFitUploader.NAME)) {
        uploader = new GoogleFitUploader(context, this);
    }

    if (uploader != null) {
        if (!config.containsKey(DB.ACCOUNT.FLAGS)) {
            if (BuildConfig.DEBUG) {
                String s = null;
                s.charAt(3);
            }
        }
        uploader.init(config);
        uploaders.put(uploaderName, uploader);
        uploadersById.put(uploader.getId(), uploader);
    }
    return uploader;
}

From source file:at.bitfire.vcard4android.AndroidContact.java

protected void populateSipAddress(ContentValues row) {
    try {/* w  ww  . j  av a  2s  .c o  m*/
        Impp impp = new Impp("sip:" + row.getAsString(SipAddress.SIP_ADDRESS));
        if (row.containsKey(SipAddress.TYPE))
            switch (row.getAsInteger(SipAddress.TYPE)) {
            case SipAddress.TYPE_HOME:
                impp.addType(ImppType.HOME);
                break;
            case SipAddress.TYPE_WORK:
                impp.addType(ImppType.WORK);
                break;
            case SipAddress.TYPE_CUSTOM:
                String customType = row.getAsString(SipAddress.LABEL);
                if (!TextUtils.isEmpty(customType))
                    impp.addType(ImppType.get(labelToXName(customType)));
            }
        contact.getImpps().add(impp);
    } catch (IllegalArgumentException e) {
        Constants.log.warn("Ignoring invalid locally stored SIP address");
    }
}

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

private void preloadImages(final ContentValues... values) {
    if (values == null)
        return;/*  w  w  w.j  a v  a  2s . c  om*/
    for (final ContentValues v : values) {
        if (mPreferences.getBoolean(KEY_PRELOAD_PROFILE_IMAGES, false)) {
            mImagePreloader.preloadImage(v.getAsString(Statuses.USER_PROFILE_IMAGE_URL));
            mImagePreloader.preloadImage(v.getAsString(DirectMessages.SENDER_PROFILE_IMAGE_URL));
            mImagePreloader.preloadImage(v.getAsString(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL));
        }
        if (mPreferences.getBoolean(KEY_PRELOAD_PREVIEW_IMAGES, false)) {
            final String textHtml = v.getAsString(Statuses.TEXT_HTML);
            for (final String link : MediaPreviewUtils.getSupportedLinksInStatus(textHtml)) {
                mImagePreloader.preloadImage(link);
            }
        }
    }
}