Example usage for android.content ContentValues getAsLong

List of usage examples for android.content ContentValues getAsLong

Introduction

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

Prototype

public Long getAsLong(String key) 

Source Link

Document

Gets a value and converts it to a Long.

Usage

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

public long load(String synchronizerName) {
    String from[] = new String[] { "_id", DB.ACCOUNT.NAME, DB.ACCOUNT.AUTH_CONFIG, DB.ACCOUNT.FLAGS };
    String args[] = { synchronizerName };
    Cursor c = mDB.query(DB.ACCOUNT.TABLE, from, DB.ACCOUNT.NAME + " = ?", args, null, null, null, null);
    long id = -1;
    if (c.moveToFirst()) {
        ContentValues config = DBHelper.get(c);
        id = config.getAsLong("_id");
        add(config);/*from   w  ww  .j  av  a  2  s  . co m*/
    }
    c.close();
    return id;
}

From source file:at.bitfire.davdroid.resource.LocalAddressBook.java

protected void populateGroupMembership(Contact c, ContentValues row) throws RemoteException {
    List<String> categories = c.getCategories();

    long rowID = row.getAsLong(GroupMembership.GROUP_ROW_ID);
    String sourceID = row.getAsString(GroupMembership.GROUP_SOURCE_ID);

    // either a row ID or a source ID must be available
    String where, whereArg;//from ww  w  .  j a  v  a2s  .c  om
    if (sourceID == null) {
        where = Groups._ID + "=?";
        whereArg = String.valueOf(rowID);
    } else {
        where = Groups.SOURCE_ID + "=?";
        whereArg = sourceID;
    }
    where += " AND " + Groups.DELETED + "=0"; // ignore deleted groups
    Log.d(TAG, "Populating group from " + where + " " + whereArg);

    // fetch group
    @Cleanup
    Cursor cursorGroups = providerClient.query(Groups.CONTENT_URI, new String[] { Groups.TITLE }, where,
            new String[] { whereArg }, null);
    if (cursorGroups != null && cursorGroups.moveToNext()) {
        String title = cursorGroups.getString(0);

        if (sourceID == null) { // Group wasn't created by DAVdroid
            // SOURCE_ID IS NULL <=> _ID IS NOT NULL
            Log.d(TAG, "Setting SOURCE_ID of non-DAVdroid group to title: " + title);

            ContentValues v = new ContentValues(1);
            v.put(Groups.SOURCE_ID, title);
            v.put(Groups.GROUP_IS_READ_ONLY, 0);
            v.put(Groups.GROUP_VISIBLE, 1);
            providerClient.update(syncAdapterURI(Groups.CONTENT_URI), v, Groups._ID + "=?",
                    new String[] { String.valueOf(rowID) });

            sourceID = title;
        }

        // add group to CATEGORIES
        if (sourceID != null)
            categories.add(sourceID);
    } else
        Log.d(TAG, "Group not found (maybe deleted)");
}

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

protected void populateEvent(Event e, ContentValues values) {
    e.setUid(values.getAsString(entryColumnUID()));

    e.setSummary(values.getAsString(Events.TITLE));
    e.setLocation(values.getAsString(Events.EVENT_LOCATION));
    e.setDescription(values.getAsString(Events.DESCRIPTION));

    final boolean allDay = values.getAsInteger(Events.ALL_DAY) != 0;
    final long tsStart = values.getAsLong(Events.DTSTART);
    final String duration = values.getAsString(Events.DURATION);

    String tzId = null;/* w w w.  j  ava2  s .  c om*/
    Long tsEnd = values.getAsLong(Events.DTEND);
    if (allDay) {
        e.setDtStart(tsStart, null);
        if (tsEnd == null) {
            Dur dur = new Dur(duration);
            java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart));
            tsEnd = dEnd.getTime();
        }
        e.setDtEnd(tsEnd, null);

    } else {
        // use the start time zone for the end time, too
        // because apps like Samsung Planner allow the user to change "the" time zone but change the start time zone only
        tzId = values.getAsString(Events.EVENT_TIMEZONE);
        e.setDtStart(tsStart, tzId);
        if (tsEnd != null)
            e.setDtEnd(tsEnd, tzId);
        else if (!StringUtils.isEmpty(duration))
            e.setDuration(new Duration(new Dur(duration)));
    }

    // recurrence
    try {
        String strRRule = values.getAsString(Events.RRULE);
        if (!StringUtils.isEmpty(strRRule))
            e.setRrule(new RRule(strRRule));

        String strRDate = values.getAsString(Events.RDATE);
        if (!StringUtils.isEmpty(strRDate)) {
            RDate rDate = new RDate();
            rDate.setValue(strRDate);
            e.getRdates().add(rDate);
        }

        String strExRule = values.getAsString(Events.EXRULE);
        if (!StringUtils.isEmpty(strExRule)) {
            ExRule exRule = new ExRule();
            exRule.setValue(strExRule);
            e.setExrule(exRule);
        }

        String strExDate = values.getAsString(Events.EXDATE);
        if (!StringUtils.isEmpty(strExDate)) {
            // always empty, see https://code.google.com/p/android/issues/detail?id=172411
            ExDate exDate = new ExDate();
            exDate.setValue(strExDate);
            e.getExdates().add(exDate);
        }
    } catch (ParseException ex) {
        Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex);
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Invalid recurrence rules, ignoring", ex);
    }

    if (values.containsKey(Events.ORIGINAL_INSTANCE_TIME)) {
        // this event is an exception of a recurring event
        long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME);
        boolean originalAllDay = values.getAsInteger(Events.ORIGINAL_ALL_DAY) != 0;
        Date originalDate = originalAllDay ? new Date(originalInstanceTime)
                : new DateTime(originalInstanceTime);
        if (originalDate instanceof DateTime)
            ((DateTime) originalDate).setUtc(true);
        e.setRecurrenceId(new RecurrenceId(originalDate));
    }

    // status
    if (values.containsKey(Events.STATUS))
        switch (values.getAsInteger(Events.STATUS)) {
        case Events.STATUS_CONFIRMED:
            e.setStatus(Status.VEVENT_CONFIRMED);
            break;
        case Events.STATUS_TENTATIVE:
            e.setStatus(Status.VEVENT_TENTATIVE);
            break;
        case Events.STATUS_CANCELED:
            e.setStatus(Status.VEVENT_CANCELLED);
        }

    // availability
    e.setOpaque(values.getAsInteger(Events.AVAILABILITY) != Events.AVAILABILITY_FREE);

    // set ORGANIZER only when there are attendees
    if (values.getAsInteger(Events.HAS_ATTENDEE_DATA) != 0 && values.containsKey(Events.ORGANIZER))
        try {
            e.setOrganizer(new Organizer(new URI("mailto", values.getAsString(Events.ORGANIZER), null)));
        } catch (URISyntaxException ex) {
            Log.e(TAG, "Error when creating ORGANIZER URI, ignoring", ex);
        }

    // classification
    switch (values.getAsInteger(Events.ACCESS_LEVEL)) {
    case Events.ACCESS_CONFIDENTIAL:
    case Events.ACCESS_PRIVATE:
        e.setForPublic(false);
        break;
    case Events.ACCESS_PUBLIC:
        e.setForPublic(true);
    }
}

From source file:at.bitfire.davdroid.resource.LocalCalendar.java

protected void populateEvent(Event e, ContentValues values) {
    e.setUid(values.getAsString(entryColumnUID()));

    e.summary = values.getAsString(Events.TITLE);
    e.location = values.getAsString(Events.EVENT_LOCATION);
    e.description = values.getAsString(Events.DESCRIPTION);

    final boolean allDay = values.getAsInteger(Events.ALL_DAY) != 0;
    final long tsStart = values.getAsLong(Events.DTSTART);
    final String duration = values.getAsString(Events.DURATION);

    String tzId;/*from  w w  w . j  av  a 2  s  . c  o  m*/
    Long tsEnd = values.getAsLong(Events.DTEND);
    if (allDay) {
        e.setDtStart(tsStart, null);
        if (tsEnd == null) {
            Dur dur = new Dur(duration);
            java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart));
            tsEnd = dEnd.getTime();
        }
        e.setDtEnd(tsEnd, null);

    } else {
        // use the start time zone for the end time, too
        // because apps like Samsung Planner allow the user to change "the" time zone but change the start time zone only
        tzId = values.getAsString(Events.EVENT_TIMEZONE);
        e.setDtStart(tsStart, tzId);
        if (tsEnd != null)
            e.setDtEnd(tsEnd, tzId);
        else if (!StringUtils.isEmpty(duration))
            e.duration = new Duration(new Dur(duration));
    }

    // recurrence
    try {
        String strRRule = values.getAsString(Events.RRULE);
        if (!StringUtils.isEmpty(strRRule))
            e.rrule = new RRule(strRRule);

        String strRDate = values.getAsString(Events.RDATE);
        if (!StringUtils.isEmpty(strRDate)) {
            RDate rDate = (RDate) DateUtils.androidStringToRecurrenceSet(strRDate, RDate.class, allDay);
            e.getRdates().add(rDate);
        }

        String strExRule = values.getAsString(Events.EXRULE);
        if (!StringUtils.isEmpty(strExRule)) {
            ExRule exRule = new ExRule();
            exRule.setValue(strExRule);
            e.exrule = exRule;
        }

        String strExDate = values.getAsString(Events.EXDATE);
        if (!StringUtils.isEmpty(strExDate)) {
            ExDate exDate = (ExDate) DateUtils.androidStringToRecurrenceSet(strExDate, ExDate.class, allDay);
            e.getExdates().add(exDate);
        }
    } catch (ParseException ex) {
        Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex);
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Invalid recurrence rules, ignoring", ex);
    }

    if (values.containsKey(Events.ORIGINAL_INSTANCE_TIME)) {
        // this event is an exception of a recurring event
        long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME);

        boolean originalAllDay = false;
        if (values.containsKey(Events.ORIGINAL_ALL_DAY))
            originalAllDay = values.getAsInteger(Events.ORIGINAL_ALL_DAY) != 0;

        Date originalDate = originalAllDay ? new Date(originalInstanceTime)
                : new DateTime(originalInstanceTime);
        if (originalDate instanceof DateTime)
            ((DateTime) originalDate).setUtc(true);
        e.recurrenceId = new RecurrenceId(originalDate);
    }

    // status
    if (values.containsKey(Events.STATUS))
        switch (values.getAsInteger(Events.STATUS)) {
        case Events.STATUS_CONFIRMED:
            e.status = Status.VEVENT_CONFIRMED;
            break;
        case Events.STATUS_TENTATIVE:
            e.status = Status.VEVENT_TENTATIVE;
            break;
        case Events.STATUS_CANCELED:
            e.status = Status.VEVENT_CANCELLED;
        }

    // availability
    e.opaque = values.getAsInteger(Events.AVAILABILITY) != Events.AVAILABILITY_FREE;

    // set ORGANIZER if there's attendee data
    if (values.getAsInteger(Events.HAS_ATTENDEE_DATA) != 0)
        try {
            e.organizer = new Organizer(new URI("mailto", values.getAsString(Events.ORGANIZER), null));
        } catch (URISyntaxException ex) {
            Log.e(TAG, "Error when creating ORGANIZER mailto URI, ignoring", ex);
        }

    // classification
    switch (values.getAsInteger(Events.ACCESS_LEVEL)) {
    case Events.ACCESS_CONFIDENTIAL:
    case Events.ACCESS_PRIVATE:
        e.forPublic = false;
        break;
    case Events.ACCESS_PUBLIC:
        e.forPublic = true;
    }
}

From source file:com.csipsimple.ui.favorites.FavAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    ContentValues cv = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(cursor, cv);

    int type = ContactsWrapper.TYPE_CONTACT;
    if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) {
        type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE);
    }/*w  ww. j a  v  a2s. c  o m*/

    showViewForType(view, type);

    if (type == ContactsWrapper.TYPE_GROUP) {
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.header_text);
        ImageView icon = (ImageView) view.findViewById(R.id.header_icon);
        PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view
                .findViewById(R.id.header_presence_spinner);

        // Get datas
        SipProfile acc = new SipProfile(cursor);

        final Long profileId = cv.getAsLong(BaseColumns._ID);
        final String groupName = acc.android_group;
        final String displayName = acc.display_name;
        final String wizard = acc.wizard;
        final boolean publishedEnabled = (acc.publish_enabled == 1);
        final String domain = acc.getDefaultDomain();

        // Bind datas to view
        tv.setText(displayName);
        icon.setImageResource(WizardUtils.getWizardIconRes(wizard));
        presSpinner.setProfileId(profileId);

        // Extra menu view if not already set
        ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner);

        MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled);
        MenuBuilder menuBuilder;
        if (menuViewWrapper.getTag() == null) {

            final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);

            ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext);
            mActionMenuPresenter.setReserveOverflow(true);
            menuBuilder = new MenuBuilder(context);
            menuBuilder.setCallback(newMcb);
            MenuInflater inflater = new MenuInflater(context);
            inflater.inflate(R.menu.fav_menu, menuBuilder);
            menuBuilder.addMenuPresenter(mActionMenuPresenter);
            ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper);
            UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null);
            menuViewWrapper.addView(menuView, layoutParams);
            menuViewWrapper.setTag(menuBuilder);
        } else {
            menuBuilder = (MenuBuilder) menuViewWrapper.getTag();
            menuBuilder.setCallback(newMcb);
        }
        menuBuilder.findItem(R.id.share_presence).setTitle(
                publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing);
        menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName));

    } else if (type == ContactsWrapper.TYPE_CONTACT) {
        ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor);
        ci.userData = cursor.getPosition();
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.contact_name);
        QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo);
        TextView statusText = (TextView) view.findViewById(R.id.status_text);
        ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon);

        // Bind
        if (ci.contactId != null) {
            tv.setText(ci.displayName);
            badge.assignContactUri(ci.callerInfo.contactContentUri);
            ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(),
                    ci.callerInfo, R.drawable.ic_contact_picture_holo_dark);

            statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusText.setText(ci.status);
            statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence));
        }
        View v;
        v = view.findViewById(R.id.contact_view);
        v.setTag(ci);
        v.setOnClickListener(mPrimaryActionListener);
        v = view.findViewById(R.id.secondary_action_icon);
        v.setTag(ci);
        v.setOnClickListener(mSecondaryActionListener);
    } else if (type == ContactsWrapper.TYPE_CONFIGURE) {
        // We only bind if it's the correct type
        View v = view.findViewById(R.id.configure_view);
        v.setOnClickListener(this);
        ConfigureObj cfg = new ConfigureObj();
        cfg.profileId = cv.getAsLong(BaseColumns._ID);
        v.setTag(cfg);
    }
}

From source file:com.fututel.ui.favorites.FavAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    ContentValues cv = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(cursor, cv);

    int type = ContactsWrapper.TYPE_CONTACT;
    if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) {
        type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE);
    }/*from w w  w  .ja v a2  s .co  m*/

    showViewForType(view, type);

    if (type == ContactsWrapper.TYPE_GROUP) {
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.header_text);
        ImageView icon = (ImageView) view.findViewById(R.id.header_icon);
        PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view
                .findViewById(R.id.header_presence_spinner);

        // Get datas
        SipProfile acc = new SipProfile(cursor);

        final Long profileId = cv.getAsLong(BaseColumns._ID);
        final String groupName = acc.android_group;
        final String displayName = acc.display_name;
        final String wizard = acc.wizard;
        final boolean publishedEnabled = (acc.publish_enabled == 1);
        final String domain = acc.getDefaultDomain();

        // Bind datas to view
        tv.setText(displayName);
        icon.setImageResource(WizardUtils.getWizardIconRes(wizard));
        presSpinner.setProfileId(profileId);

        // Extra menu view if not already set
        ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner);

        MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled);
        MenuBuilder menuBuilder;
        if (menuViewWrapper.getTag() == null) {

            final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);

            ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext);
            mActionMenuPresenter.setReserveOverflow(true);
            menuBuilder = new MenuBuilder(context);
            menuBuilder.setCallback(newMcb);
            MenuInflater inflater = new MenuInflater(context);
            inflater.inflate(R.menu.fav_menu, menuBuilder);
            menuBuilder.addMenuPresenter(mActionMenuPresenter);
            ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper);
            UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null);
            menuViewWrapper.addView(menuView, layoutParams);
            menuViewWrapper.setTag(menuBuilder);
        } else {
            menuBuilder = (MenuBuilder) menuViewWrapper.getTag();
            menuBuilder.setCallback(newMcb);
        }
        menuBuilder.findItem(R.id.share_presence).setTitle(
                publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing);
        menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName));

    } else if (type == ContactsWrapper.TYPE_CONTACT) {
        ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor);
        ci.userData = cursor.getPosition();
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.contact_name);
        QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo);
        TextView statusText = (TextView) view.findViewById(R.id.status_text);
        ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon);

        // Bind
        if (ci.contactId != null) {
            tv.setText(ci.displayName);
            badge.assignContactUri(ci.callerInfo.contactContentUri);
            ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(),
                    ci.callerInfo, R.drawable.ic_contact_picture_holo_light);

            statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusText.setText(ci.status);
            statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence));
        }
        View v;
        v = view.findViewById(R.id.contact_view);
        v.setTag(ci);
        v.setOnClickListener(mPrimaryActionListener);
        v = view.findViewById(R.id.secondary_action_icon);
        v.setTag(ci);
        v.setOnClickListener(mSecondaryActionListener);
    } else if (type == ContactsWrapper.TYPE_CONFIGURE) {
        // We only bind if it's the correct type
        View v = view.findViewById(R.id.configure_view);
        v.setOnClickListener(this);
        ConfigureObj cfg = new ConfigureObj();
        cfg.profileId = cv.getAsLong(BaseColumns._ID);
        v.setTag(cfg);
    }
}

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

private void processDM(JSONObject o) {
    Log.i(TAG, "processing DM");
    try {/*  w  w w  .jav  a2 s .c o  m*/

        ContentValues dmValues = getDmContentValues(o);
        if (!dmValues.getAsLong(DirectMessages.COL_SENDER).toString()
                .equals(LoginActivity.getTwitterId(getApplicationContext()))) {

            ContentValues cvUser = getUserCV(o);
            // insert the tweet
            Uri insertUri = Uri.parse("content://" + DirectMessages.DM_AUTHORITY + "/" + DirectMessages.DMS
                    + "/" + DirectMessages.DMS_LIST + "/" + DirectMessages.DMS_SOURCE_DISASTER);
            getContentResolver().insert(insertUri, dmValues);

            // insert the user
            Uri insertUserUri = Uri.parse(
                    "content://" + TwitterUsers.TWITTERUSERS_AUTHORITY + "/" + TwitterUsers.TWITTERUSERS);
            getContentResolver().insert(insertUserUri, cvUser);

        }

    } catch (JSONException e1) {
        Log.e(TAG, "Exception while receiving disaster dm ", e1);
    }

}

From source file:edu.cens.loci.ui.PlaceViewActivity.java

/**
 * Build up the entries to display on the screen.
 *
 * @param personCursor the URI for the contact being displayed
 */// w  ww.j a v  a2  s . c om
private final void buildEntries() {

    final Context context = this;
    final Sources sources = Sources.getInstance(context);

    ArrayList<ViewEntry> items = new ArrayList<ViewEntry>();

    int typeIcon = R.drawable.icon_question;
    String typeString = "Unknown";

    if (mPlace.type == Places.TYPE_GPS) {
        typeIcon = R.drawable.icon_satellite;
        typeString = "GPS";
    } else if (mPlace.type == Places.TYPE_WIFI) {
        typeIcon = R.drawable.icon_wifi;
        typeString = "Wi-Fi";
    }

    // detection type
    items.add(new ViewEntry(LIST_ACTION_NO_ACTION, typeIcon, "Dectection Sensor", typeString, null));

    // recent visit time
    String recentVisitTime = getRecentVisitSubstring(); //"May 4, 3:00pm, 1hr";
    items.add(new ViewEntry(LIST_ACTION_VIEW_VISITS, R.drawable.ic_clock_strip_desk_clock, "View recent visits",
            recentVisitTime, null));

    for (Entity entity : mEntities) {
        final ContentValues entValues = entity.getEntityValues();
        final String accountType = entValues.getAsString(Places.ACCOUNT_TYPE);
        final long placeId = entValues.getAsLong(Places._ID);

        for (NamedContentValues subValue : entity.getSubValues()) {
            final ContentValues entryValues = subValue.values;
            entryValues.put(Places.Data.PLACE_ID, placeId);
            final long dataId = entryValues.getAsLong(Data._ID);
            final String mimeType = entryValues.getAsString(Data.MIMETYPE);
            if (mimeType == null)
                continue;

            final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this,
                    PlacesSource.LEVEL_MIMETYPES);
            if (kind == null)
                continue;

            //Log.e(TAG, "buildEntries: dataId=" + dataId + ", mimeType=" + mimeType);

            // public ViewEntry(int action, int icon, String text, String subtext, Intent intent) {

            if (WifiFingerprint.CONTENT_ITEM_TYPE.equals(mimeType)) {
                String fingerprint = entryValues.getAsString(WifiFingerprint.FINGERPRINT);
                long timestamp = entryValues.getAsLong(WifiFingerprint.TIMESTAMP);
                String subtext = "Captured at " + MyDateUtils.getAbrv_MMM_d_h_m(timestamp);
                //Log.d(TAG, fingerprint);
                //String apsAbstract = getWifiInfoSubstring(5, fingerprint); 
                ViewEntry item = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless,
                        "View Wi-Fi APs", subtext, null);
                item.extra_string = fingerprint;
                mWifiEntries.add(item);
            } else if (GpsCircleArea.CONTENT_ITEM_TYPE.equals(mimeType)) {
                double lat = entryValues.getAsDouble(GpsCircleArea.LATITUDE);
                double lon = entryValues.getAsDouble(GpsCircleArea.LONGITUDE);
                float rad = entryValues.getAsFloat(GpsCircleArea.RADIUS);
                //Log.d(TAG, "lat=" + lat + ",lon=" + lon + ",rad=" + rad);
                ViewEntry item = new ViewEntry(-1, -1, null, null, null);
                item.extra_double1 = lat;
                item.extra_double2 = lon;
                item.extra_float1 = rad;
                mGpsEntries.add(item);
            } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                String uri = "geo:0,0?q=" + TextUtils.htmlEncode(item.data);
                item.intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                item.action = LIST_ACTION_POSTAL;
                item.text = item.label;
                item.subtext = item.data;
                mPostalEntries.add(item);
            } else if (Keyword.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.text = item.data;
                item.subtext = null;
                mTagEntries.add(item);
            } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.text = item.label;
                item.subtext = item.data;
                mOtherEntries.add(item);
            } else if (Website.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.uri = null;
                item.action = LIST_ACTION_WEBSITE;
                item.text = item.label;
                item.subtext = item.data;
                item.intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.data));
                mWebsiteEntries.add(item);
            }
        }
    }

    for (ViewEntry item : mWifiEntries) {
        items.add(item);
    }
    mWifiEntries.clear();
    for (ViewEntry item : mPostalEntries) {
        items.add(item);
    }
    mPostalEntries.clear();
    for (ViewEntry item : mTagEntries) {
        items.add(item);
    }
    mTagEntries.clear();
    for (ViewEntry item : mWebsiteEntries) {
        items.add(item);
    }
    mWebsiteEntries.clear();
    for (ViewEntry item : mOtherEntries) {
        items.add(item);
    }
    mOtherEntries.clear();
    // Log.d(TAG, "size of items = " + items.size());

    ViewEntryAdapter adapter = new ViewEntryAdapter(this, R.layout.place_view_list_item, items);
    mListView.setAdapter(adapter);
}

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

@Override
public int bulkInsert(final Uri uri, @NonNull final ContentValues[] valuesArray) {
    try {//from   w ww  . j  a  v  a  2s  . co  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 0;
        }
        int result = 0;
        final long[] newIds = new long[valuesArray.length];
        if (table != null) {
            mDatabaseWrapper.beginTransaction();
            if (tableId == TABLE_ID_CACHED_USERS) {
                for (final ContentValues values : valuesArray) {
                    final Expression where = Expression.equals(CachedUsers.USER_ID,
                            values.getAsLong(CachedUsers.USER_ID));
                    mDatabaseWrapper.update(table, values, where.getSQL(), null);
                    newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values,
                            SQLiteDatabase.CONFLICT_IGNORE);
                }
            } else if (tableId == TABLE_ID_SEARCH_HISTORY) {
                for (final ContentValues values : valuesArray) {
                    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);
                    newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values,
                            SQLiteDatabase.CONFLICT_IGNORE);
                }
            } else if (shouldReplaceOnConflict(tableId)) {
                for (final ContentValues values : valuesArray) {
                    newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values,
                            SQLiteDatabase.CONFLICT_REPLACE);
                }
            } else {
                for (final ContentValues values : valuesArray) {
                    newIds[result++] = mDatabaseWrapper.insert(table, null, values);
                }
            }
            mDatabaseWrapper.setTransactionSuccessful();
            mDatabaseWrapper.endTransaction();
        }
        if (result > 0) {
            onDatabaseUpdated(tableId, uri);
        }
        onNewItemsInserted(uri, tableId, valuesArray, newIds);
        return result;
    } catch (final SQLException e) {
        throw new IllegalStateException(e);
    }
}

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

public Set<String> feedSynchronizersSet(Context ctx) {
    Set<String> set = new HashSet<String>();
    String[] from = new String[] { "_id", DB.ACCOUNT.NAME, DB.ACCOUNT.ENABLED, DB.ACCOUNT.AUTH_CONFIG,
            DB.ACCOUNT.FLAGS };//  w ww.  ja va  2s  . c om

    SQLiteDatabase db = DBHelper.getReadableDatabase(ctx);
    Cursor c = db.query(DB.ACCOUNT.TABLE, from, null, null, null, null, null);
    if (c.moveToFirst()) {
        do {
            final ContentValues tmp = DBHelper.get(c);
            final Synchronizer synchronizer = add(tmp);
            final String name = tmp.getAsString(DB.ACCOUNT.NAME);
            final long flags = tmp.getAsLong(DB.ACCOUNT.FLAGS);
            if (isConfigured(name) && Bitfield.test(flags, DB.ACCOUNT.FLAG_FEED)
                    && synchronizer.checkSupport(Synchronizer.Feature.FEED)) {
                set.add(name);
            }
        } while (c.moveToNext());
    }
    c.close();
    DBHelper.closeDB(db);
    return set;
}