Example usage for android.database Cursor deactivate

List of usage examples for android.database Cursor deactivate

Introduction

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

Prototype

@Deprecated
void deactivate();

Source Link

Document

Deactivates the Cursor, making all calls on it fail until #requery is called.

Usage

From source file:mobisocial.musubi.BootstrapActivity.java

private void ensureRingtone() {
    SharedPreferences settings = getSharedPreferences(SettingsActivity.PREFS_NAME, 0);
    if (settings.getString("ringtone", null) != null) {
        return;//from w  w  w. ja  v  a2 s  .  co  m
    }

    RingtoneManager ringtoneManager = new RingtoneManager(this);
    ringtoneManager.setType(RingtoneManager.TYPE_NOTIFICATION);
    String ringtoneUri = null;
    String backupUri = null;
    Cursor cursor = ringtoneManager.getCursor();
    try {
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String ringtone = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
            if (ringtone.equalsIgnoreCase("dDeneb")) {
                ringtoneUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/"
                        + cursor.getString(RingtoneManager.ID_COLUMN_INDEX);

                break;
            }
            if (backupUri == null) {
                backupUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/"
                        + cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
            }
            cursor.moveToNext();
        }
    } finally {
        cursor.deactivate();
    }

    SharedPreferences.Editor editor = settings.edit();
    if (ringtoneUri != null) {
        editor.putString("ringtone", ringtoneUri);
    } else {
        if (backupUri != null) {
            editor.putString("ringtone", backupUri.toString());
        } else {
            editor.putString("ringtone", "none");
        }
    }
    editor.commit();
}

From source file:com.android.music.TrackBrowserFragment.java

private void setTitle() {

    CharSequence fancyName = null;
    if (mAlbumId != null) {
        int numresults = mTrackCursor != null ? mTrackCursor.getCount() : 0;
        if (numresults > 0) {
            mTrackCursor.moveToFirst();//from   ww  w . j a v a  2s .  c om
            int idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
            fancyName = mTrackCursor.getString(idx);
            // For compilation albums show only the album title,
            // but for regular albums show "artist - album".
            // To determine whether something is a compilation
            // album, do a query for the artist + album of the
            // first item, and see if it returns the same number
            // of results as the album query.
            String where = MediaStore.Audio.Media.ALBUM_ID + "='" + mAlbumId + "' AND "
                    + MediaStore.Audio.Media.ARTIST_ID + "=" + mTrackCursor
                            .getLong(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID));
            Cursor cursor = MusicUtils.query(getActivity(), MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    new String[] { MediaStore.Audio.Media.ALBUM }, where, null, null);
            if (cursor != null) {
                if (cursor.getCount() != numresults) {
                    // compilation album
                    fancyName = mTrackCursor.getString(idx);
                }
                cursor.deactivate();
            }
            if (fancyName == null || fancyName.equals(MediaStore.UNKNOWN_STRING)) {
                fancyName = getString(R.string.unknown_album_name);
            }
        }
    } else if (mPlaylist != null) {
        if (mPlaylist.equals("nowplaying")) {
            if (MusicUtils.getCurrentShuffleMode() == MediaPlaybackService.SHUFFLE_AUTO) {
                fancyName = getText(R.string.partyshuffle_title);
            } else {
                fancyName = getText(R.string.nowplaying_title);
            }
        } else if (mPlaylist.equals("podcasts")) {
            fancyName = getText(R.string.podcasts_title);
        } else if (mPlaylist.equals("recentlyadded")) {
            fancyName = getText(R.string.recentlyadded_title);
        } else {
            String[] cols = new String[] { MediaStore.Audio.Playlists.NAME };
            Cursor cursor = MusicUtils.query(getActivity(),
                    ContentUris.withAppendedId(Playlists.EXTERNAL_CONTENT_URI, Long.valueOf(mPlaylist)), cols,
                    null, null, null);
            if (cursor != null) {
                if (cursor.getCount() != 0) {
                    cursor.moveToFirst();
                    fancyName = cursor.getString(0);
                }
                cursor.deactivate();
            }
        }
    } else if (mGenre != null) {
        String[] cols = new String[] { MediaStore.Audio.Genres.NAME };
        Cursor cursor = MusicUtils.query(getActivity(),
                ContentUris.withAppendedId(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, Long.valueOf(mGenre)),
                cols, null, null, null);
        if (cursor != null) {
            if (cursor.getCount() != 0) {
                cursor.moveToFirst();
                fancyName = cursor.getString(0);
            }
            cursor.deactivate();
        }
    }

    if (fancyName != null) {
        getActivity().setTitle(fancyName);
    } else {
        getActivity().setTitle(R.string.tracks_title);
    }
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

protected void showStoresFilter(final View v) {
    QuickSelectMenu popup = new QuickSelectMenu(this, v);

    Menu menu = popup.getMenu();//from w w w .ja  v  a2  s  .  c o  m
    if (menu == null) {
        return;
    }
    Cursor c = getContentResolver().query(
            Stores.QUERY_BY_LIST_URI.buildUpon().appendPath(this.mListUri.getLastPathSegment()).build(),
            new String[] { Stores._ID, Stores.NAME }, null, null, "stores.name COLLATE NOCASE ASC");
    int i_store, count = c.getCount();
    if (count == 0) {
        c.deactivate();
        c.close();
        Toast.makeText(this, R.string.no_stores_available, Toast.LENGTH_SHORT).show();
        return;
    }

    // prepend the "no filter" option
    menu.add(0, -1, Menu.NONE, R.string.unfiltered);

    // get the list of stores
    c.moveToFirst();
    for (i_store = 0; i_store < count; i_store++) {
        long id = c.getLong(0);
        String name = c.getString(1);
        menu.add(0, (int) id, Menu.NONE, name);
        c.moveToNext();
    }
    c.deactivate();
    c.close();

    popup.setOnItemSelectedListener(new QuickSelectMenu.OnItemSelectedListener() {
        public void onItemSelected(CharSequence name, int id) {
            // set the selected store filter
            // update the filter summary? not until filter region collapsed.
            ContentValues values = new ContentValues();
            values.put(Lists.STORE_FILTER, (long) id);
            getContentResolver().update(mListUri, values, null, null);
            if (id == -1) {
                ((Button) v).setText(R.string.stores);
            } else {
                ((Button) v).setText(name);
            }
            fillItems(false);
        }
    });

    popup.show();
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * copy item/*w  w w .j av  a 2s. c  om*/
 */
void copyItem(int position) {
    Cursor c = mItemsView.mCursorItems;
    mItemsView.mCursorItems.requery();
    c.moveToPosition(position);
    String containsId = c.getString(mStringItemsCONTAINSID);
    Long newContainsId;
    Long newItemId;

    c = getContentResolver().query(
            Uri.withAppendedPath(Uri.withAppendedPath(Contains.CONTENT_URI, "copyof"), containsId),
            new String[] { "item_id", "contains_id" }, null, null, null);

    if (c.getCount() != 1) {
        return;
    }

    c.moveToFirst();
    newItemId = c.getLong(0);
    newContainsId = c.getLong(1);
    c.deactivate();
    c.close();

    editItem(newItemId, newContainsId, FieldType.ITEMNAME);

    // mItemsView.requery();
}