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:export.MapMyRunUploader.java

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

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

protected static void addAttendee(String path, Calendar component, ContentValues attendeeValues)
        throws InvalidComponentException {
    VEvent vEvent = (VEvent) component.getComponent(VEvent.VEVENT);
    if (vEvent == null) {
        Log.e(TAG, "unable to add attendee to component with no VEVENT");
        throw new InvalidComponentException("unable to add attendee to component with no VEVENT", false,
                CalDavConstants.CALDAV_NAMESPACE, path);
    }/*w w w .  j  ava  2s. c o m*/

    String email = attendeeValues.getAsString(CalendarContract.Attendees.ATTENDEE_EMAIL);
    String name = attendeeValues.getAsString(CalendarContract.Attendees.ATTENDEE_NAME);
    Integer type = attendeeValues.getAsInteger(CalendarContract.Attendees.ATTENDEE_TYPE);
    Integer relationship = attendeeValues.getAsInteger(CalendarContract.Attendees.ATTENDEE_RELATIONSHIP);
    Integer status = attendeeValues.getAsInteger(CalendarContract.Attendees.ATTENDEE_STATUS);

    if (StringUtils.isEmpty(email)) {
        Log.e(TAG, "attendee email is null or empty");
        throw new InvalidComponentException("attendee email is null or empty", false,
                CalDavConstants.CALDAV_NAMESPACE, path);
    }

    try {

        Attendee attendee = new Attendee(new URI("mailto", email, null));
        ParameterList attendeeParams = attendee.getParameters();

        attendeeParams.add(CuType.INDIVIDUAL);

        if (StringUtils.isNotEmpty(name))
            attendeeParams.add(new Cn(name));

        if (relationship != null && relationship == CalendarContract.Attendees.RELATIONSHIP_ORGANIZER)
            attendeeParams.add(Role.CHAIR);
        else if (type != null && type == CalendarContract.Attendees.TYPE_REQUIRED)
            attendeeParams.add(Role.REQ_PARTICIPANT);
        else
            attendeeParams.add(Role.OPT_PARTICIPANT);

        if (status != null) {
            switch (status) {
            case CalendarContract.Attendees.ATTENDEE_STATUS_INVITED:
                attendeeParams.add(PartStat.NEEDS_ACTION);
                break;

            case CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED:
                attendeeParams.add(PartStat.ACCEPTED);
                break;

            case CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED:
                attendeeParams.add(PartStat.DECLINED);
                break;

            case CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE:
                attendeeParams.add(PartStat.TENTATIVE);
                break;
            }
        }
        vEvent.getProperties().add(attendee);

    } catch (URISyntaxException e) {
        Log.e(TAG, "caught exception while adding email to attendee", e);
        throw new InvalidComponentException("caught exception while adding email to attendee", false,
                CalDavConstants.CALDAV_NAMESPACE, path, e);
    }
}

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://from   ww  w  . j av  a 2s  .co  m
            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);
    }
}

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 {// www  .  j  a  v  a2s. c o  m

            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:org.onebusaway.android.ui.ArrivalsListAdapterStyleA.java

@Override
protected void initView(View view, ArrivalInfo stopInfo) {
    final Context context = getContext();
    final ObaArrivalInfo arrivalInfo = stopInfo.getInfo();

    TextView route = (TextView) view.findViewById(R.id.route);
    TextView destination = (TextView) view.findViewById(R.id.destination);
    TextView time = (TextView) view.findViewById(R.id.time);
    TextView status = (TextView) view.findViewById(R.id.status);
    TextView etaView = (TextView) view.findViewById(R.id.eta);
    TextView minView = (TextView) view.findViewById(R.id.eta_min);
    ViewGroup realtimeView = (ViewGroup) view.findViewById(R.id.eta_realtime_indicator);
    ImageView moreView = (ImageView) view.findViewById(R.id.more_horizontal);
    moreView.setColorFilter(context.getResources().getColor(R.color.switch_thumb_normal_material_dark));
    ImageView starView = (ImageView) view.findViewById(R.id.route_favorite);
    starView.setColorFilter(context.getResources().getColor(R.color.navdrawer_icon_tint));
    starView.setImageResource(/*from  w  ww  .j av a  2 s  .  co m*/
            stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off);

    route.setText(arrivalInfo.getShortName());
    destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign()));
    status.setText(stopInfo.getStatusText());

    long eta = stopInfo.getEta();
    if (eta == 0) {
        etaView.setText(R.string.stop_info_eta_now);
        minView.setVisibility(View.GONE);
    } else {
        etaView.setText(String.valueOf(eta));
        minView.setVisibility(View.VISIBLE);
    }

    status.setBackgroundResource(R.drawable.round_corners_style_b_status);
    GradientDrawable d = (GradientDrawable) status.getBackground();

    Integer colorCode = stopInfo.getColor();
    int color = context.getResources().getColor(colorCode);
    if (stopInfo.getPredicted()) {
        // Show real-time indicator
        UIUtils.setRealtimeIndicatorColorByResourceCode(realtimeView, colorCode, android.R.color.transparent);
        realtimeView.setVisibility(View.VISIBLE);
    } else {
        realtimeView.setVisibility(View.INVISIBLE);
    }

    etaView.setTextColor(color);
    minView.setTextColor(color);
    d.setColor(color);

    // Set padding on status view
    int pSides = UIUtils.dpToPixels(context, 5);
    int pTopBottom = UIUtils.dpToPixels(context, 2);
    status.setPadding(pSides, pTopBottom, pSides, pTopBottom);

    time.setText(DateUtils.formatDateTime(context, stopInfo.getDisplayTime(),
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT));

    ContentValues values = null;
    if (mTripsForStop != null) {
        values = mTripsForStop.getValues(arrivalInfo.getTripId());
    }
    if (values != null) {
        String reminderName = values.getAsString(ObaContract.Trips.NAME);

        TextView reminder = (TextView) view.findViewById(R.id.reminder);
        if (reminderName.length() == 0) {
            reminderName = context.getString(R.string.trip_info_noname);
        }
        reminder.setText(reminderName);
        Drawable d2 = reminder.getCompoundDrawables()[0];
        d2 = DrawableCompat.wrap(d2);
        DrawableCompat.setTint(d2.mutate(), view.getResources().getColor(R.color.button_material_dark));
        reminder.setCompoundDrawables(d2, null, null, null);
        reminder.setVisibility(View.VISIBLE);
    } else {
        // Explicitly set this to invisible because we might be reusing
        // this view.
        View reminder = view.findViewById(R.id.reminder);
        reminder.setVisibility(View.GONE);
    }
}

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

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

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

public void propertyValues(List<String> values) {
    if (values == null || values.size() == 0) {
        mCurrentPropNode.propValue_bytes = null;
        mCurrentPropNode.propValue_vector.clear();
        mCurrentPropNode.propValue_vector.add("");
        mCurrentPropNode.propValue = "";
        return;//  ww w .j  ava2 s .c om
    }

    ContentValues paramMap = mCurrentPropNode.paramMap;

    String targetCharset = CharsetUtils.nameForDefaultVendor(paramMap.getAsString("CHARSET"));
    String encoding = paramMap.getAsString("ENCODING");

    if (targetCharset == null || targetCharset.length() == 0) {
        targetCharset = mTargetCharset;
    }

    for (String value : values) {
        mCurrentPropNode.propValue_vector.add(handleOneValue(value, targetCharset, encoding));
    }

    mCurrentPropNode.propValue = listToString(mCurrentPropNode.propValue_vector);
}

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

@Override
public void init(ContentValues config) {
    String authConfig = config.getAsString(DB.ACCOUNT.AUTH_CONFIG);
    if (authConfig != null) {
        try {/*from   w  w  w  .  j  ava2s  . co m*/
            JSONObject tmp = new JSONObject(authConfig);
            access_token = tmp.optString("access_token", null);
            token_now = tmp.optLong("token_now");
            expire_time = tmp.optLong("expire_time");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    id = config.getAsLong("_id");
    if (config.containsKey(DB.ACCOUNT.FLAGS)) {
        long flags = config.getAsLong(DB.ACCOUNT.FLAGS);
        if (Bitfield.test(flags, DB.ACCOUNT.FLAG_SKIP_MAP)) {
            skipMapInPost = true;
        }
    }
}

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

protected static void addPhoneNumber(String path, VCard vCard, ContentValues phoneNumberValues)
        throws InvalidComponentException {
    Integer type = phoneNumberValues.getAsInteger(ContactsContract.CommonDataKinds.Phone.TYPE);
    String label = phoneNumberValues.getAsString(ContactsContract.CommonDataKinds.Phone.LABEL);
    String number = phoneNumberValues.getAsString(ContactsContract.CommonDataKinds.Phone.NUMBER);
    Boolean isPrimary = phoneNumberValues.getAsBoolean(ContactsContract.CommonDataKinds.Phone.IS_PRIMARY);
    Boolean isSuperPrimary = phoneNumberValues
            .getAsBoolean(ContactsContract.CommonDataKinds.Phone.IS_SUPER_PRIMARY);

    if (type != null && number != null) {
        Telephone telephone = new Telephone(number);

        switch (type) {
        case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
            telephone.addType(TelephoneType.CELL);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
            telephone.addType(TelephoneType.WORK);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
            telephone.addType(TelephoneType.HOME);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK:
            telephone.addType(TelephoneType.FAX);
            telephone.addType(TelephoneType.WORK);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME:
            telephone.addType(TelephoneType.FAX);
            telephone.addType(TelephoneType.HOME);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_PAGER:
            telephone.addType(TelephoneType.PAGER);
            break;

        case ContactsContract.CommonDataKinds.Phone.TYPE_MAIN:
            telephone.addType(TelephoneType.PREF);
            break;

        default:/*  w  w w  .  j  a v a  2s.  co m*/
            if (label != null)
                telephone.addType(TelephoneType.get(labelToPropertyName(label)));
        }

        if (isPrimary != null && isPrimary)
            telephone.addType(TelephoneType.PREF);
        else if (isSuperPrimary != null && isSuperPrimary)
            telephone.addType(TelephoneType.PREF);

        vCard.addTelephoneNumber(telephone);
    } else {
        Log.e(TAG, "phone type or number is null, not adding anything");
        throw new InvalidComponentException("phone type or number is null", false,
                CardDavConstants.CARDDAV_NAMESPACE, path);
    }
}

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

protected static ComponentETagPair<Calendar> getEventComponent(String path, ContentValues eventValues)
        throws InvalidComponentException {
    Calendar calendar = new Calendar();
    VEvent vEvent = new VEvent();
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();

    calendar.getProperties().add(Version.VERSION_2_0);
    handleAttachPropertiesForCopiedRecurrenceWithExceptions(eventValues, vEvent);

    String uidText = eventValues.getAsString(CalendarContract.Events._SYNC_ID);
    if (!StringUtils.isEmpty(uidText)) {
        Uid eventUid = new Uid(uidText);
        vEvent.getProperties().add(eventUid);
    }/*w w  w  .ja va  2 s .  c  o  m*/

    try {

        String organizerText = eventValues.getAsString(CalendarContract.Events.ORGANIZER);
        if (StringUtils.isNotEmpty(organizerText)) {
            URI organizerEmail = new URI("mailto", organizerText, null);
            Organizer organizer = new Organizer(organizerEmail);
            vEvent.getProperties().add(organizer);
        }

    } catch (URISyntaxException e) {
        Log.e(TAG, "caught exception while parsing URI from organizerText", e);
        throw new InvalidComponentException("caught exception while parsing URI from organizerText", false,
                CalDavConstants.CALDAV_NAMESPACE, path, e);
    }

    String summaryText = eventValues.getAsString(CalendarContract.Events.TITLE);
    if (StringUtils.isNotEmpty(summaryText)) {
        Summary summary = new Summary(summaryText);
        vEvent.getProperties().add(summary);
    }

    String locationText = eventValues.getAsString(CalendarContract.Events.EVENT_LOCATION);
    if (StringUtils.isNotEmpty(locationText)) {
        Location location = new Location(locationText);
        vEvent.getProperties().add(location);
    }

    String descriptionText = eventValues.getAsString(CalendarContract.Events.DESCRIPTION);
    if (StringUtils.isNotEmpty(descriptionText)) {
        Description description = new Description(descriptionText);
        vEvent.getProperties().add(description);
    }

    Integer status = eventValues.getAsInteger(CalendarContract.Events.STATUS);
    Long originalInstanceTime = eventValues.getAsLong(CalendarContract.Events.ORIGINAL_INSTANCE_TIME);
    if (status != null && status != CalendarContract.Events.STATUS_CANCELED && originalInstanceTime != null
            && originalInstanceTime > 0) {
        handleAddPropertiesForEditExceptionToRecurring(path, eventValues, vEvent);
    }

    if (status != null && status == CalendarContract.Events.STATUS_CONFIRMED)
        vEvent.getProperties().add(Status.VEVENT_CONFIRMED);
    else if (status != null && status == CalendarContract.Events.STATUS_CANCELED)
        handleAddPropertiesForDeletionExceptionToRecurring(path, eventValues, vEvent);
    else
        vEvent.getProperties().add(Status.VEVENT_TENTATIVE);

    Integer availability = eventValues.getAsInteger(CalendarContract.Events.AVAILABILITY);
    if (availability != null && availability == CalendarContract.Events.AVAILABILITY_BUSY)
        vEvent.getProperties().add(Transp.OPAQUE);
    else
        vEvent.getProperties().add(Transp.TRANSPARENT);

    Long dtStartMilliseconds = eventValues.getAsLong(CalendarContract.Events.DTSTART);
    if (dtStartMilliseconds == null)
        dtStartMilliseconds = eventValues.getAsLong(CalendarContract.Events.ORIGINAL_INSTANCE_TIME);

    if (dtStartMilliseconds != null) {
        DtStart dtStart = new DtStart(new Date(dtStartMilliseconds));
        String dtStartTZText = eventValues.getAsString(CalendarContract.Events.EVENT_TIMEZONE);

        if (dtStartTZText != null) {
            DateTime startDate = new DateTime(dtStartMilliseconds);
            TimeZone startTimeZone = registry.getTimeZone(dtStartTZText);
            startDate.setTimeZone(startTimeZone);

            dtStart = new DtStart(startDate);
        }

        vEvent.getProperties().add(dtStart);
    } else {
        Log.e(TAG, "no start date found on event");
        throw new InvalidComponentException("no start date found on event", false,
                CalDavConstants.CALDAV_NAMESPACE, path);
    }

    Long dtEndMilliseconds = eventValues.getAsLong(CalendarContract.Events.DTEND);
    if (dtEndMilliseconds != null && dtEndMilliseconds > 0) {
        DtEnd dtEnd = new DtEnd(new Date(dtEndMilliseconds));
        String dtStartTZText = eventValues.getAsString(CalendarContract.Events.EVENT_TIMEZONE);

        if (dtStartTZText != null) {
            DateTime endDate = new DateTime(dtEndMilliseconds);
            TimeZone endTimeZone = registry.getTimeZone(dtStartTZText);
            endDate.setTimeZone(endTimeZone);

            dtEnd = new DtEnd(endDate);
        }

        vEvent.getProperties().add(dtEnd);
    }

    String durationText = eventValues.getAsString(CalendarContract.Events.DURATION);
    if (StringUtils.isNotEmpty(durationText)) {
        Dur dur = new Dur(durationText);
        Duration duration = new Duration(dur);
        vEvent.getProperties().add(duration);
    }

    try {

        String rRuleText = eventValues.getAsString(CalendarContract.Events.RRULE);
        if (StringUtils.isNotEmpty(rRuleText)) {
            RRule rRule = new RRule(rRuleText);
            vEvent.getProperties().add(rRule);
        }

        String rDateText = eventValues.getAsString(CalendarContract.Events.RDATE);
        if (StringUtils.isNotEmpty(rDateText)) {
            RDate rDate = new RDate();
            rDate.setValue(rDateText);
            vEvent.getProperties().add(rDate);
        }

        String exRuleText = eventValues.getAsString(CalendarContract.Events.EXRULE);
        if (StringUtils.isNotEmpty(exRuleText)) {
            ExRule exRule = new ExRule();
            exRule.setValue(exRuleText);
            vEvent.getProperties().add(exRule);
        }

        String exDateText = eventValues.getAsString(CalendarContract.Events.EXDATE);
        if (StringUtils.isNotEmpty(exDateText)) {
            ExDate exDate = new ExDate();
            exDate.setValue(exDateText);
            vEvent.getProperties().add(exDate);
        }

    } catch (ParseException e) {
        Log.e(TAG, "caught exception while parsing recurrence rule stuff from event values", e);
        throw new InvalidComponentException(
                "caught exception while parsing recurrence rule stuff from event values", false,
                CalDavConstants.CALDAV_NAMESPACE, path, e);
    }

    calendar.getComponents().add(vEvent);
    Optional<String> eTag = Optional.fromNullable(eventValues.getAsString(CalendarContract.Events.SYNC_DATA1));

    return new ComponentETagPair<Calendar>(calendar, eTag);
}