Example usage for android.database MatrixCursor close

List of usage examples for android.database MatrixCursor close

Introduction

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

Prototype

@Override
    public void close() 

Source Link

Usage

From source file:Main.java

/**
 * Creates new cursor, closes it and returns it ^^
 * //from   w  w w . j  a  v  a  2s .c  o  m
 * @return the newly closed cursor.
 */
public static MatrixCursor newClosedCursor() {
    MatrixCursor cursor = new MatrixCursor(new String[0]);
    cursor.close();
    return cursor;
}

From source file:com.nextgis.maplibui.control.PhotoGallery.java

public static void getAttaches(IGISApplication app, VectorLayer layer, long featureId, Map<String, Integer> map,
        boolean excludeSign) {
    Uri uri = Uri.parse("content://" + app.getAuthority() + "/" + layer.getPath().getName() + "/" + featureId
            + "/" + Constants.URI_ATTACH);
    MatrixCursor attachCursor = (MatrixCursor) layer.query(uri,
            new String[] { VectorLayer.ATTACH_DATA, VectorLayer.ATTACH_ID }, FIELD_ID + " = " + featureId, null,
            null, null);/*from   w w  w. j a v  a 2 s. c  om*/

    if (attachCursor.moveToFirst()) {
        do {
            if (excludeSign && attachCursor.getInt(1) == Integer.MAX_VALUE)
                continue;

            map.put(attachCursor.getString(0), attachCursor.getInt(1));
        } while (attachCursor.moveToNext());
    }

    attachCursor.close();
}

From source file:com.esri.android.mapsapp.MapFragment.java

/**
 * Displays the search view layout//from www .j a va  2 s  .  co m
 * 
 */
private void showSearchBoxLayout() {

    // Inflating the layout from the xml file
    mSearchBox = mInflater.inflate(R.layout.searchview, null);
    // Inflate navigation drawer button on SearchView
    navButton = (ImageButton) mSearchBox.findViewById(R.id.btn_nav_menu);
    // Get the navigation drawer from Activity
    mDrawerLayout = (DrawerLayout) getActivity().findViewById(R.id.maps_app_activity_drawer_layout);
    mDrawerList = (ListView) getActivity().findViewById(R.id.maps_app_activity_left_drawer);

    // Set click listener to open/close drawer
    navButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
                mDrawerLayout.closeDrawer(mDrawerList);
            } else {
                mDrawerLayout.openDrawer(mDrawerList);
            }

        }
    });

    // Setting the layout parameters to the layout
    mSearchBox.setLayoutParams(mlayoutParams);

    // Initializing the searchview and the image view
    mSearchview = (SearchView) mSearchBox.findViewById(R.id.searchView1);

    ImageView iv_route = (ImageView) mSearchBox.findViewById(R.id.imageView1);

    mSearchview.setIconifiedByDefault(false);
    mSearchview.setQueryHint(SEARCH_HINT);

    applySuggestionCursor();

    //      navButton = (Button)mSearchBox.findViewById(R.id.navbutton);

    // Adding the layout to the map conatiner
    mMapContainer.addView(mSearchBox);

    // Setup the listener for the route onclick
    iv_route.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showRoutingDialogFragment();

        }
    });

    // Setup the listener when the search button is pressed on the keyboard
    mSearchview.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            onSearchButtonClicked(query);
            mSearchview.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (mLocator == null)
                return false;
            getSuggestions(newText);
            return true;
        }
    });

    // Add the compass after getting the height of the layout
    mSearchBox.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            addCompass(mSearchBox.getHeight());
            mSearchBox.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }

    });

    mSearchview.setOnSuggestionListener(new SearchView.OnSuggestionListener() {

        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            // Obtain the content of the selected suggesting place via cursor
            MatrixCursor cursor = (MatrixCursor) mSearchview.getSuggestionsAdapter().getItem(position);
            int indexColumnSuggestion = cursor.getColumnIndex(COLUMN_NAME_ADDRESS);
            final String address = cursor.getString(indexColumnSuggestion);

            suggestionClickFlag = true;
            // Find the Location of the suggestion
            new FindLocationTask(address).execute(address);

            cursor.close();

            return true;
        }
    });

}

From source file:com.av.remusic.service.MediaService.java

private void updateCursor(final long trackId) {

    MusicInfo info = mPlaylistInfo.get(trackId);
    if (mPlaylistInfo.get(trackId) != null) {
        MatrixCursor cursor = new MatrixCursor(PROJECTION);
        cursor.addRow(new Object[] { info.songId, info.artist, info.albumName, info.musicName, info.data,
                info.albumData, info.albumId, info.artistId });
        cursor.moveToFirst();/*ww  w . j a v a2s .  c  o  m*/
        mCursor = cursor;
        cursor.close();
    }
}

From source file:com.adityarathi.muo.services.AudioPlaybackService.java

/**
 * This method combines the current cursor with the specified playlist cursor.
 * @param newCursor/* w w  w.  ja v  a 2s. c o  m*/
 */
public void enqueuePlaylistCursor(Cursor newCursor) {

    String[] matrixCursorColumns = { DBAccessHelper.SONG_ARTIST, DBAccessHelper.SONG_ALBUM,
            DBAccessHelper.SONG_TITLE, DBAccessHelper.SONG_FILE_PATH, DBAccessHelper.SONG_DURATION,
            DBAccessHelper.SONG_GENRE, DBAccessHelper.SONG_ID, DBAccessHelper.SONG_ALBUM_ART_PATH,
            DBAccessHelper.SONG_SOURCE };

    //Create an empty matrix getCursor() with the specified columns.
    MatrixCursor mMatrixCursor = new MatrixCursor(matrixCursorColumns);

    //Make a copy of the old getCursor() and copy it's contents over to the matrix getCursor().
    Cursor tempCursor = getCursor();

    tempCursor.moveToFirst();
    MediaMetadataRetriever mMMDR = new MediaMetadataRetriever();
    for (int i = 0; i < tempCursor.getCount(); i++) {
        tempCursor.moveToPosition(i);

        //Check which type of getCursor() the service currently has.
        if (getCursor().getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) {

            //We'll have to manually extract the info from the audio file.
            /*            String songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.PLAYLIST_SONG_FILE_PATH));
                                
                        try {
                           mMMDR.setDataSource(songFilePath);
                        } catch (Exception e) {
                           //Skip the song if there's a problem with reading it.
                           continue;
                        }*/

            String songArtist = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
            String songAlbum = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
            String songTitle = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
            String songDuration = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
            String songGenre = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);

            mMatrixCursor
                    .addRow(new Object[] { songArtist, songAlbum, songTitle, "", songDuration, songGenre });

        } else {

            mMatrixCursor.addRow(
                    new Object[] { tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ALBUM)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_TITLE)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_DURATION)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_GENRE)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ID)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_SOURCE)) });

        }

    }

    tempCursor.close();

    //Copy the contents of the new getCursor() over to the MatrixCursor.
    if (newCursor.getCount() > 0) {

        String songArtist = "";
        String songAlbum = "";
        String songTitle = "";
        String filePath = "";
        String songDuration = "";
        for (int j = 0; j < newCursor.getCount(); j++) {
            /*            newCursor.moveToPosition(j);
                        filePath = newCursor.getString(newCursor.getColumnIndex(DBAccessHelper.PLAYLIST_SONG_FILE_PATH));
                                
                        try {
                           mMMDR.setDataSource(filePath);
                        } catch (Exception e) {
                           continue;
                        }*/

            //Get the metadata from the song file.
            songArtist = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
            songAlbum = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
            songTitle = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
            songDuration = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
            String songGenre = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);

            mMatrixCursor.addRow(
                    new Object[] { songArtist, songAlbum, songTitle, filePath, songDuration, songGenre });

        }

    }

    mEnqueuePerformed = true;
    newCursor.close();
    mCursor = (Cursor) mMatrixCursor;
    mMatrixCursor.close();

}