Example usage for android.database MatrixCursor addRow

List of usage examples for android.database MatrixCursor addRow

Introduction

In this page you can find the example usage for android.database MatrixCursor addRow.

Prototype

public void addRow(Iterable<?> columnValues) 

Source Link

Document

Adds a new row to the end with the given column values.

Usage

From source file:com.dvdprime.mobile.android.adapter.DocumentSuggestionsAdapter.java

public static MatrixCursor getCursor2(String query) {
    //  ? ?? //w w w.j av  a  2  s.  co  m
    final String[] COLUMNS = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2 };

    MatrixCursor cursor = new MatrixCursor(COLUMNS);
    cursor.addRow(new Object[] { 1, query, " " });
    cursor.addRow(new Object[] { 2, query, "ID " });
    cursor.addRow(new Object[] { 4, query, "? " });
    cursor.addRow(new Object[] { 7, query, "  " });

    return cursor;
}

From source file:com.dvdprime.mobile.android.adapter.DocumentSuggestionsAdapter.java

public static MatrixCursor getCursor(String query) {
    //  ? ?? //from   w w w.  j  a va 2  s .  co  m
    final String[] COLUMNS = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2 };

    MatrixCursor cursor = new MatrixCursor(COLUMNS);
    cursor.addRow(new Object[] { 1, query, " " });
    cursor.addRow(new Object[] { 2, query, "ID " });
    cursor.addRow(new Object[] { 6, query, " " });
    cursor.addRow(new Object[] { 4, query, "? " });
    cursor.addRow(new Object[] { 7, query, "  " });

    return cursor;
}

From source file:com.dmsl.anyplace.nav.AnyPlaceSeachingHelper.java

public static Cursor prepareSearchViewCursor(List<? extends IPoisClass> places) {
    String req_columns[] = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2, SearchManager.SUGGEST_COLUMN_INTENT_DATA };
    MatrixCursor mcursor = new MatrixCursor(req_columns);
    int i = 0;/*w  w  w.  j  ava  2 s  . c  o m*/
    if (places != null) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(IPoisClass.class, new IPoisClass.MyInterfaceAdapter());
        Gson gson = gsonBuilder.create();
        for (IPoisClass p : places) {
            mcursor.addRow(new String[] { Integer.toString(i++), p.name(),
                    p.description().equals("") ? "no description" : p.description(),
                    gson.toJson(p, IPoisClass.class) });
        }
    }
    return mcursor;
}

From source file:com.deliciousdroid.client.DeliciousFeed.java

/**
 * Retrieves a list of tags for a Delicious user.
 * //from  w  w w .  ja v  a2  s.co m
 * @param username Username of the Delicious user.
 * @return The list of tags received from the server.
 * @throws JSONException If an error was encountered in deserializing the JSON object returned from 
 * the server.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 */
public static Cursor fetchFriendTags(String username)
        throws JSONException, IOException, AuthenticationException {

    final HttpGet post = new HttpGet(FETCH_TAGS_URI + username + "?count=100");

    final MatrixCursor tagCursor = new MatrixCursor(new String[] { Tag._ID, Tag.Name, Tag.Count });

    final HttpResponse resp = HttpClientFactory.getThreadSafeClient().execute(post);
    final String response = EntityUtils.toString(resp.getEntity());

    if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

        final JSONObject tags = new JSONObject(response);
        Iterator<?> i = tags.keys();
        while (i.hasNext()) {
            Object e = i.next();

            tagCursor.addRow(new Object[] { 0, e.toString(), tags.getInt(e.toString()) });
        }

        Log.d(TAG, response);

    } else {
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            Log.e(TAG, "Authentication exception in fetching friend status list");
            throw new AuthenticationException();
        } else {
            Log.e(TAG, "Server error in fetching friend status list");
            throw new IOException();
        }
    }
    return tagCursor;
}

From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java

/**
 * @return a new cursor based on the given cursor with all duplicate destinations removed.
 *
 * It's only intended to use for the alternate list, so...
 * - This method ignores all other fields and dedupe solely on the destination.  Normally,
 * if a cursor contains multiple contacts and they have the same destination, we'd still want
 * to show both.//from  www  .  java 2s. c o m
 * - This method creates a MatrixCursor, so all data will be kept in memory.  We wouldn't want
 * to do this if the original cursor is large, but it's okay here because the alternate list
 * won't be that big.
 */
// Visible for testing
/* package */ static Cursor removeDuplicateDestinations(Cursor original) {
    final MatrixCursor result = new MatrixCursor(original.getColumnNames(), original.getCount());
    final HashSet<String> destinationsSeen = new HashSet<String>();

    original.moveToPosition(-1);
    while (original.moveToNext()) {
        final String destination = original.getString(Query.DESTINATION);
        if (destinationsSeen.contains(destination)) {
            continue;
        }
        destinationsSeen.add(destination);

        result.addRow(new Object[] { original.getString(Query.NAME), original.getString(Query.DESTINATION),
                original.getInt(Query.DESTINATION_TYPE), original.getString(Query.DESTINATION_LABEL),
                original.getLong(Query.CONTACT_ID), original.getLong(Query.DATA_ID),
                original.getString(Query.PHOTO_THUMBNAIL_URI), original.getInt(Query.DISPLAY_NAME_SOURCE) });
    }

    return result;
}

From source file:com.laevatein.internal.loader.AlbumLoader.java

@Override
public Cursor loadInBackground() {
    Cursor albums = super.loadInBackground();
    MatrixCursor allAlbum = new MatrixCursor(PROJECTION);
    allAlbum.addRow(new String[] { Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, MEDIA_ID_DUMMY });

    return new MergeCursor(new Cursor[] { allAlbum, albums });
}

From source file:org.linphone.compatibility.ApiFivePlus.java

public static Cursor getGeneralContactCursor(ContentResolver cr, String select, boolean shouldGroupBy) {
    String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME };
    String query;//  w  w  w.j  a v a  2  s .  c o m

    query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")";

    Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null,
            " lower(" + Data.DISPLAY_NAME + ") COLLATE UNICODE ASC");

    if (!shouldGroupBy || cursor == null) {
        return cursor;
    }

    MatrixCursor result = new MatrixCursor(cursor.getColumnNames());
    Set<String> groupBy = new HashSet<String>();
    while (cursor.moveToNext()) {
        String name = cursor.getString(getCursorDisplayNameColumnIndex(cursor));
        if (!groupBy.contains(name)) {
            groupBy.add(name);
            Object[] newRow = new Object[cursor.getColumnCount()];

            int contactID = cursor.getColumnIndex(Data.CONTACT_ID);
            int displayName = cursor.getColumnIndex(Data.DISPLAY_NAME);

            newRow[contactID] = cursor.getString(contactID);
            newRow[displayName] = cursor.getString(displayName);

            result.addRow(newRow);
        }
    }
    cursor.close();
    return result;
}

From source file:com.laevatein.internal.loader.AlbumPhotoLoader.java

@Override
public Cursor loadInBackground() {
    Cursor result = super.loadInBackground();
    if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) {
        return result;
    }/*from w  w w .j  a  va2  s  . c o  m*/
    MatrixCursor dummy = new MatrixCursor(PROJECTION);
    dummy.addRow(new Object[] { Item.ITEM_ID_CAPTURE, Item.ITEM_DISPLAY_NAME_CAPTURE });
    return new MergeCursor(new Cursor[] { dummy, result });
}

From source file:io.valuesfeng.picker.loader.PictureLoader.java

@Override
public Cursor loadInBackground() {
    Cursor result = super.loadInBackground();
    if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) {
        return result;
    }//from ww w.  jav a 2 s .com
    MatrixCursor dummy = new MatrixCursor(PROJECTION);
    dummy.addRow(new Object[] { Picture.ITEM_ID_CAPTURE, Picture.ITEM_DISPLAY_NAME_CAPTURE });
    return new MergeCursor(new Cursor[] { dummy, result });
}

From source file:org.totschnig.myexpenses.dialog.SelectMainCategoryDialogFragment.java

@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor data) {
    if (getArguments().getBoolean(KEY_WITH_ROOT)) {
        MatrixCursor extras = new MatrixCursor(projection);
        extras.addRow(new String[] { "0", getString(R.string.transform_subcategory_to_main), });
        mCursor = new MergeCursor(new Cursor[] { extras, data });
    } else {//from   w w w.  j a  v  a 2s.c  o  m
        mCursor = data;
    }
    mAdapter.swapCursor(mCursor);
}