Example usage for android.database MatrixCursor MatrixCursor

List of usage examples for android.database MatrixCursor MatrixCursor

Introduction

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

Prototype

public MatrixCursor(String[] columnNames) 

Source Link

Document

Constructs a new cursor.

Usage

From source file:com.itllp.barleylegalhomebrewers.ontap.test.EventListFragmentTests.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    /* These tests rely on a linkseam testing version of 
     * OnTapContentProvider *///from w  w  w .j  a v  a  2 s.  c  o m
    instrumentation = getInstrumentation();
    context = getInstrumentation().getContext();
    intent = new Intent(context, EventListActivity.class);
    instrumentation.waitForIdleSync();
    mockCursor = new MatrixCursor(COLUMN_NAMES);
}

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

public static Cursor prepareSearchViewCursor(List<? extends IPoisClass> places, String query) {
    String req_columns[] = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_INTENT_DATA };
    MatrixCursor mcursor = new MatrixCursor(req_columns);
    int i = 0;//w  w w . j  a  va  2s.c o m
    if (places != null) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(IPoisClass.class, new IPoisClass.MyInterfaceAdapter());
        Gson gson = gsonBuilder.create();

        // Better Use AndroidUtils.fillTextBox instead of regular expression
        // Regular expression
        // ?i ignore case
        Pattern patternTitle = Pattern.compile(String.format("((?i)%s)", query));
        // Matches X words before query and Y words after
        Pattern patternDescription = Pattern.compile(
                String.format("(([^\\s]+\\s+){0,%d}[^\\s]*)((?i)%s)([^\\s]*(\\s+[^\\s]+){0,%d})", 2, query, 2));
        for (IPoisClass p : places) {
            String name = "", description = "";
            Matcher m;
            m = patternTitle.matcher(p.name());
            // Makes matched query bold using HTML format
            // $1 returns the regular's expression outer parenthesis value
            name = m.replaceAll("<b>$1</b>");

            m = patternDescription.matcher(p.description());
            if (m.find()) {
                // Makes matched query bold using HTML format
                description = String.format(" %s<b>%s</b>%s", m.group(1), m.group(3), m.group(4));
            }

            mcursor.addRow(new String[] { Integer.toString(i++), name + description,
                    gson.toJson(p, IPoisClass.class) });
        }
    }
    return mcursor;
}

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  w  ww. j  a va  2s .c  o  m*/
    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:com.rappsantiago.weighttracker.profile.WeightProgressCursorLoader.java

@Override
protected Cursor onLoadInBackground() {

    MatrixCursor matrixCursor = new MatrixCursor(COLS_WEIGHT_PROGRESS);

    double initialWeight = Util.getInitialWeight(getContext());

    double currentWeight = Util.getCurrentWeight(getContext());

    double targetWeight = Util.getTargetWeight(getContext());

    double percentComplete = Util.computePercentComplete(initialWeight, currentWeight, targetWeight);

    double remainingWeight = Util.computeRemainingValue(currentWeight, targetWeight);

    double weightLost = Util.computeValueLost(initialWeight, currentWeight);

    double initialBodyFatIndex = Util.getInitialBodyFatIndex(getContext());

    double currentBodyFatIndex = Util.getCurrentBodyFatIndex(getContext());

    double targetBodyFatIndex = Util.getTargetBodyFatIndex(getContext());

    double remainingBodyFatIndex = Util.computeRemainingValue(currentBodyFatIndex, targetBodyFatIndex);

    double currentFatMass = (currentBodyFatIndex / 100) * currentWeight;

    double currentMuscleMass = ((100 - currentBodyFatIndex) / 100) * currentWeight;

    matrixCursor.addRow(new Object[] { 1, initialWeight, currentWeight, percentComplete, remainingWeight,
            weightLost, initialBodyFatIndex, currentBodyFatIndex, remainingBodyFatIndex, currentFatMass,
            currentMuscleMass });//w  w w. ja  v a 2s.c om

    return matrixCursor;
}

From source file:fr.seeks.SuggestionProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    String query = uri.getLastPathSegment();

    if (query == null || query.equals("") || query.equals("search_suggest_query"))
        return null;

    Log.v(TAG, "Request '" + query + "' for '" + uri + "'");

    MatrixCursor matrix = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_TITLE, KEY_DESCRIPTION, KEY_QUERY, KEY_ACTION, KEY_URL });

    Boolean instant_suggest = mPrefs.getBoolean("instant_suggest", false);
    if (instant_suggest) {
        setCursorOfQuery(uri, query, matrix);
    } else {/*  ww  w  . j  a va2 s .com*/
        perhapsSetCursorOfQuery(uri, query, matrix);
    }
    matrix.setNotificationUri(getContext().getContentResolver(), uri);

    return matrix;
}

From source file:com.itllp.barleylegalhomebrewers.ontap.test.BeerListFragmentTests.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    /* These tests rely on a linkseam testing version of 
     * OnTapContentProvider *//*from   w  w w . ja  va  2 s . c o m*/
    instrumentation = getInstrumentation();
    context = instrumentation.getTargetContext();
    intent = new Intent(context, BeerListActivity.class);
    mockCursor = new MatrixCursor(COLUMN_NAMES);
}

From source file:com.aniruddhc.acemusic.player.Dialogs.AddToPlaylistDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mContext = getActivity().getApplicationContext();

    //Retrieve the arguments.
    ADD_TYPE = getArguments().getString("ADD_TYPE");

    if (ADD_TYPE.equals("ARTIST")) {
        ARTIST = getArguments().getString("ARTIST");
    } else if (ADD_TYPE.equals("ALBUM_ARTIST")) {
        ALBUM_ARTIST = getArguments().getString("ALBUM_ARTIST");
    } else if (ADD_TYPE.equals("ALBUM")) {
        ARTIST = getArguments().getString("ARTIST");
        ALBUM = getArguments().getString("ALBUM");
    } else if (ADD_TYPE.equals("SONG")) {
        ARTIST = getArguments().getString("ARTIST");
        ALBUM = getArguments().getString("ALBUM");
        SONG = getArguments().getString("SONG");
    } else if (ADD_TYPE.equals("GENRE")) {
        GENRE = getArguments().getString("GENRE");
    } else if (ADD_TYPE.equals("ALBUM_BY_ALBUM_ARTIST")) {
        ALBUM = getArguments().getString("ALBUM");
        ALBUM_ARTIST = getArguments().getString("ALBUM_ARTIST");
    }// ww w .  ja v a2  s  .co m

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    String columns[] = { DBAccessHelper.PLAYLIST_NAME, DBAccessHelper._ID, DBAccessHelper.PLAYLIST_FILE_PATH,
            DBAccessHelper.PLAYLIST_SOURCE, DBAccessHelper.PLAYLIST_ID };
    MatrixCursor matrixCursor = new MatrixCursor(columns);
    matrixCursor.addRow(
            new String[] { getActivity().getResources().getString(R.string.new_playlist), "0", "0", "0", "0" });

    DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity().getApplicationContext());
    Cursor userPlaylistsCursor = playlistsDBHelper.getAllSongsInAlbum(null, null);
    final MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, userPlaylistsCursor });

    //Set the dialog title.
    builder.setTitle(R.string.add_to_playlist);
    builder.setCursor(mergeCursor, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Index 0 is the dummy playlist that will open the "New Playlist" dialog.
            if (which == 0) {
                showNewPlaylistDialog();
            } else {
                mergeCursor.moveToPosition(which);
                String playlistName = mergeCursor
                        .getString(mergeCursor.getColumnIndex(DBAccessHelper.PLAYLIST_NAME));
                String playlistId = mergeCursor
                        .getString(mergeCursor.getColumnIndex(DBAccessHelper.PLAYLIST_ID));

                AsyncAddSongsToPlaylistTask task = new AsyncAddSongsToPlaylistTask(mContext, playlistName,
                        playlistId, ARTIST, ALBUM, SONG, GENRE, ALBUM_ARTIST, ADD_TYPE);
                task.execute();

            }

        }

    }, DBAccessHelper.PLAYLIST_NAME);

    return builder.create();
}

From source file:com.grayfox.android.app.widget.CategoryCursorAdapter.java

private MatrixCursor createCursor() {
    return new MatrixCursor(new String[] { CursorColums._ID, CursorColums.CATEGORY_NAME,
            CursorColums.CATEGORY_ICON_URL, CursorColums.CATEGORY_FOURSQUARE_ID });
}

From source file:com.andrew.apolloMod.helpers.AddIdCursorLoader.java

@Override
public Cursor loadInBackground() {

    Cursor mediaCursor = getContext().getContentResolver().query(mUri, mProjection, mSelection, mSelectionArgs,
            mSortOrder);/* w w  w.j  av a  2s .  c o m*/
    //Get cursor filled with Audio Id's
    String[] projection = new String[] { BaseColumns._ID, AlbumColumns.ALBUM };
    Uri uri = Audio.Albums.EXTERNAL_CONTENT_URI;
    String sortOrder = Audio.Albums.DEFAULT_SORT_ORDER;
    Cursor albumCursor = getContext().getContentResolver().query(uri, projection, null, null, sortOrder);

    //Matrix cursor to hold final data to be returned to calling context
    MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID, MediaColumns.TITLE,
            AudioColumns.ARTIST, AudioColumns.ALBUM, AudioColumns.ALBUM_ID });
    //Map data from Audio Id cursor to the ALbumName Colum
    ContentQueryMap mQueryMap = new ContentQueryMap(albumCursor, AlbumColumns.ALBUM, false, null);

    Map<String, ContentValues> data = mQueryMap.getRows();
    if (mediaCursor != null) {
        while (mediaCursor.moveToNext()) {
            String id = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(BaseColumns._ID));
            String title = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(MediaColumns.TITLE));
            String artist = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(AudioColumns.ARTIST));
            String album = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(AudioColumns.ALBUM));

            ContentValues tData = data.get(album);
            String albumid = (String) tData.get(BaseColumns._ID);
            cursor.addRow(new String[] { id, title, artist, album, albumid });
        }
        mediaCursor.close();
    }

    if (cursor != null) {
        // Ensure the cursor window is filled
        registerContentObserver(cursor, mObserver);
    }
    return cursor;
}

From source file:com.rightscale.provider.rest.ServerTemplatesResource.java

private Cursor buildCursor(JSONArray array) throws JSONException {
    MatrixCursor result = new MatrixCursor(COLUMNS);

    for (int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        MatrixCursor.RowBuilder row = result.newRow();
        buildRow(row, object);//from  ww  w. ja v  a2 s  .co m
    }

    return result;
}