Example usage for android.database Cursor moveToPosition

List of usage examples for android.database Cursor moveToPosition

Introduction

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

Prototype

boolean moveToPosition(int position);

Source Link

Document

Move the cursor to an absolute position.

Usage

From source file:com.android.bluetooth.map.BluetoothMapContent.java

public void dumpMmsTable() {
    if (D)//from www  .  jav a  2 s. com
        Log.d(TAG, "**** Dump of mms table ****");
    Cursor c = mResolver.query(Mms.CONTENT_URI, MMS_PROJECTION, null, null, "_id DESC");
    if (c != null) {
        if (D)
            Log.d(TAG, "c.getCount() = " + c.getCount());
        c.moveToPosition(-1);
        while (c.moveToNext()) {
            printMms(c);
            long id = c.getLong(c.getColumnIndex(BaseColumns._ID));
            printMmsAddr(id);
            printMmsParts(id);
        }
        c.close();
    } else {
        Log.d(TAG, "query failed");
    }
}

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

/**
 * This method combines the current cursor with the specified playlist cursor.
 * @param newCursor/*from   w  ww.  j  a  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();

}

From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncGetGooglePlayMusicMetadataTask.java

public String getMetadataFromGooglePlayMusicApp() {

    //Grab a handle on the mApp.
    Uri googlePlayMusicContentProviderUri = Uri.parse("content://com.google.android.music.MusicContent/audio");
    String[] projection = { "title", "artist", "album", "AlbumArtist", "duration", "track", "year", "Genre",
            "TrackType AS track_type", /*"_count",*/ "Rating", "AlbumArtLocation AS album_art",
            "SourceType AS source_type", "SourceId", "ArtistArtLocation", /*, "artistId",*/ "StoreAlbumId" };

    /* source_type values:
     * 0: Local file (not used).//from   ww w.  j  a  v  a2 s  .c  o m
     * 1: Unknown.
     * 2: Personal, free GMusic library (used).
     * 3: All Access (not used).
     */
    String selection = "source_type=2 AND track_type=0";

    //Catch any exceptions that may be thrown as a result of unknown columns in GMusic's content mApp.
    Cursor cursor = null;
    boolean projectionFailed = false;
    try {
        cursor = mContext.getContentResolver().query(googlePlayMusicContentProviderUri, projection, selection,
                null, null);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();

        //Problematic columns are commented out here.
        String[] failSafeProjection = { "title", "artist", "album", "AlbumArtist", "duration", "track", "year",
                "Genre", "TrackType AS track_type", /*"_count",*/ "Rating",
                "AlbumArtLocation AS album_art", /* "SourceType AS source_type", */
                "SourceId", /* "ArtistArtLocation", "artistId",*/ "StoreAlbumId" };

        cursor = mContext.getContentResolver().query(googlePlayMusicContentProviderUri, failSafeProjection,
                "track_type=0", null, null);
        projectionFailed = true;

    }

    //Clear out all the current Google Play Music songs in the database.
    mApp.getDBAccessHelper().deleteAllGooglePlayMusicSongs();

    //Insert the songs and their metadata into Jams' local database.
    /* To improve database insertion performance, we'll use a single transaction 
     * for the entire operation. SQLite journals each database insertion and 
     * creates a new transaction by default. We'll override this functionality 
     * and create a single transaction for all the database record insertions. 
     * In theory, this should reduce NAND memory overhead times and result in 
     * a 2x to 5x performance increase.
     */
    try {
        //We'll initialize the DB transaction manually.
        mApp.getDBAccessHelper().getWritableDatabase().beginTransaction();

        //Avoid "Divide by zero" errors.
        int scanningSongsIncrement;
        if (cursor != null) {
            if (cursor.getCount() != 0) {
                scanningSongsIncrement = 800000 / cursor.getCount();
            } else {
                scanningSongsIncrement = 800000 / 1;
            }

        } else {
            return "FAIL";
        }

        currentTask = mContext.getResources().getString(R.string.syncing_with_google_play_music);
        for (int i = 0; i < cursor.getCount(); i++) {

            cursor.moveToPosition(i);
            currentProgressValue = currentProgressValue + scanningSongsIncrement;
            publishProgress();

            //Get the song's metadata.
            String songTitle = cursor.getString(cursor.getColumnIndex("title"));
            String songArtist = cursor.getString(cursor.getColumnIndex("Artist"));
            String songAlbum = cursor.getString(cursor.getColumnIndex("Album"));
            String songAlbumArtist = cursor.getString(cursor.getColumnIndex("AlbumArtist"));
            String songDuration = cursor.getString(cursor.getColumnIndex("Duration"));
            String songTrackNumber = cursor.getString(cursor.getColumnIndex("Track"));
            String songYear = cursor.getString(cursor.getColumnIndex("Year"));
            String songGenre = cursor.getString(cursor.getColumnIndex("Genre"));
            //String songPlayCount = cursor.getString(cursor.getColumnIndex("_count"));
            String songRating = cursor.getString(cursor.getColumnIndex("Rating"));
            String songSource = DBAccessHelper.GMUSIC;
            String songAlbumArtPath = cursor.getString(cursor.getColumnIndex("album_art"));
            String songID = cursor.getString(cursor.getColumnIndex("SourceId"));
            //String artistID = cursor.getString(cursor.getColumnIndex("artistId"));
            String storeAlbumID = cursor.getString(cursor.getColumnIndex("StoreAlbumId"));

            String songArtistArtPath = "";
            if (projectionFailed == false) {
                songArtistArtPath = cursor.getString(cursor.getColumnIndex("ArtistArtLocation"));
            } else {
                //Fall back on album art.
                songArtistArtPath = cursor.getString(cursor.getColumnIndex("album_art"));
            }

            //Prepare the genres ArrayList.
            if (!genresList.contains(songGenre)) {
                genresList.add(songGenre);
            }

            //Filter out track numbers and remove any bogus values.
            if (songTrackNumber != null) {
                if (songTrackNumber.contains("/")) {
                    int index = songTrackNumber.lastIndexOf("/");
                    songTrackNumber = songTrackNumber.substring(0, index);
                }

            }

            if (songYear.equals("0")) {
                songYear = "";
            }

            //Check if any of the other tags were empty/null and set them to "Unknown xxx" values.
            if (songArtist == null || songArtist.isEmpty() || songArtist.equals(" ")) {
                songArtist = "Unknown Artist";
            }

            if (songAlbumArtist == null || songAlbumArtist.isEmpty() || songAlbumArtist.equals(" ")) {
                songAlbumArtist = "Unknown Album Artist";
            }

            if (songAlbum == null || songAlbum.isEmpty() || songAlbum.equals(" ")) {
                songAlbum = "Unknown Album";
            }

            if (songGenre == null || songGenre.isEmpty() || songGenre.equals(" ")) {
                songGenre = "Unknown Genre";
            }

            ContentValues values = new ContentValues();
            values.put(DBAccessHelper.SONG_TITLE, songTitle);
            values.put(DBAccessHelper.SONG_ARTIST, songArtist);
            values.put(DBAccessHelper.SONG_ALBUM, songAlbum);
            values.put(DBAccessHelper.SONG_ALBUM_ARTIST, songAlbumArtist);
            values.put(DBAccessHelper.SONG_DURATION, songDuration);
            values.put(DBAccessHelper.SONG_FILE_PATH, songID);
            values.put(DBAccessHelper.SONG_TRACK_NUMBER, songTrackNumber);
            values.put(DBAccessHelper.SONG_GENRE, songGenre);
            //values.put(DBAccessHelper.SONG_PLAY_COUNT, songPlayCount);
            values.put(DBAccessHelper.SONG_YEAR, songYear);
            values.put(DBAccessHelper.SONG_LAST_MODIFIED, "");
            values.put(DBAccessHelper.BLACKLIST_STATUS, "FALSE"); //Keep the song whitelisted by default.
            values.put(DBAccessHelper.ADDED_TIMESTAMP, date.getTime());
            values.put(DBAccessHelper.RATING, songRating);
            values.put(DBAccessHelper.SONG_SOURCE, songSource);
            values.put(DBAccessHelper.SONG_ALBUM_ART_PATH, songAlbumArtPath);
            values.put(DBAccessHelper.SONG_ID, songID);
            values.put(DBAccessHelper.ARTIST_ART_LOCATION, songArtistArtPath);
            //values.put(DBAccessHelper.ARTIST_ID, artistID);
            values.put(DBAccessHelper.ALBUM_ID, storeAlbumID);

            /* We're gonna have to save the song ID into the SONG_FILE_PATH 
             * field. Google Play Music playlist songs don't have a file path, but we're using a 
             * JOIN in PlaylistsFlippedFragment that relies on this field, so we'll need to use the 
             * song ID as a placeholder instead.
             */
            values.put(DBAccessHelper.SONG_FILE_PATH, songID);

            //Add all the entries to the database to build the songs library.
            mApp.getDBAccessHelper().getWritableDatabase().insert(DBAccessHelper.MUSIC_LIBRARY_TABLE, null,
                    values);

        }

        mApp.getDBAccessHelper().getWritableDatabase().setTransactionSuccessful();

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        //Close the transaction.
        mApp.getDBAccessHelper().getWritableDatabase().endTransaction();

        if (cursor != null) {
            cursor.close();
            cursor = null;
        }

    }

    /****************************************************************************
     * BUILD PLAYLISTS LIBRARY
     ****************************************************************************/
    //getPlaylistsWebClient();
    //getPlaylistsMobileClient();

    //Update the genres library.
    updateGenreSongCount();

    return "SUCCESS";
}

From source file:com.jelly.music.player.AsyncTasks.AsyncGetGooglePlayMusicMetadataTask.java

public String getMetadataFromGooglePlayMusicApp() {

    //Grab a handle on the mApp.
    Uri googlePlayMusicContentProviderUri = Uri.parse("content://com.google.android.music.MusicContent/audio");
    String[] projection = { "title", "artist", "album", "AlbumArtist", "duration", "track", "year", "Genre",
            "TrackType AS track_type", /*"_count",*/ "Rating", "AlbumArtLocation AS album_art",
            "SourceType AS source_type", "SourceId", "ArtistArtLocation", /*, "artistId",*/ "StoreAlbumId" };

    /* source_type values:
     * 0: Local file (not used).//from  ww  w .  j a v  a  2 s.c  o m
     * 1: Unknown.
     * 2: Personal, free GMusic library (used).
     * 3: All Access (not used).
     */
    String selection = "source_type=2 AND track_type=0";

    //Catch any exceptions that may be thrown as a result of unknown columns in GMusic's content mApp.
    Cursor cursor = null;
    boolean projectionFailed = false;
    try {
        cursor = mContext.getContentResolver().query(googlePlayMusicContentProviderUri, projection, selection,
                null, null);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();

        //Problematic columns are commented out here.
        String[] failSafeProjection = { "title", "artist", "album", "AlbumArtist", "duration", "track", "year",
                "Genre", "TrackType AS track_type", /*"_count",*/ "Rating",
                "AlbumArtLocation AS album_art", /* "SourceType AS source_type", */
                "SourceId", /* "ArtistArtLocation", "artistId",*/ "StoreAlbumId" };

        cursor = mContext.getContentResolver().query(googlePlayMusicContentProviderUri, failSafeProjection,
                "track_type=0", null, null);
        projectionFailed = true;

    }

    //Clear out all the current Google Play Music songs in the database.
    mApp.getDBAccessHelper().deleteAllGooglePlayMusicSongs();

    //Insert the songs and their metadata into jelly' local database.
    /* To improve database insertion performance, we'll use a single transaction 
     * for the entire operation. SQLite journals each database insertion and 
     * creates a new transaction by default. We'll override this functionality 
     * and create a single transaction for all the database record insertions. 
     * In theory, this should reduce NAND memory overhead times and result in 
     * a 2x to 5x performance increase.
     */
    try {
        //We'll initialize the DB transaction manually.
        mApp.getDBAccessHelper().getWritableDatabase().beginTransaction();

        //Avoid "Divide by zero" errors.
        int scanningSongsIncrement;
        if (cursor != null) {
            if (cursor.getCount() != 0) {
                scanningSongsIncrement = 800000 / cursor.getCount();
            } else {
                scanningSongsIncrement = 800000 / 1;
            }

        } else {
            return "FAIL";
        }

        currentTask = mContext.getResources().getString(R.string.syncing_with_google_play_music);
        for (int i = 0; i < cursor.getCount(); i++) {

            cursor.moveToPosition(i);
            currentProgressValue = currentProgressValue + scanningSongsIncrement;
            publishProgress();

            //Get the song's metadata.
            String songTitle = cursor.getString(cursor.getColumnIndex("title"));
            String songArtist = cursor.getString(cursor.getColumnIndex("Artist"));
            String songAlbum = cursor.getString(cursor.getColumnIndex("Album"));
            String songAlbumArtist = cursor.getString(cursor.getColumnIndex("AlbumArtist"));
            String songDuration = cursor.getString(cursor.getColumnIndex("Duration"));
            String songTrackNumber = cursor.getString(cursor.getColumnIndex("Track"));
            String songYear = cursor.getString(cursor.getColumnIndex("Year"));
            String songGenre = cursor.getString(cursor.getColumnIndex("Genre"));
            //String songPlayCount = cursor.getString(cursor.getColumnIndex("_count"));
            String songRating = cursor.getString(cursor.getColumnIndex("Rating"));
            String songSource = DBAccessHelper.GMUSIC;
            String songAlbumArtPath = cursor.getString(cursor.getColumnIndex("album_art"));
            String songID = cursor.getString(cursor.getColumnIndex("SourceId"));
            //String artistID = cursor.getString(cursor.getColumnIndex("artistId"));
            String storeAlbumID = cursor.getString(cursor.getColumnIndex("StoreAlbumId"));

            String songArtistArtPath = "";
            if (projectionFailed == false) {
                songArtistArtPath = cursor.getString(cursor.getColumnIndex("ArtistArtLocation"));
            } else {
                //Fall back on album art.
                songArtistArtPath = cursor.getString(cursor.getColumnIndex("album_art"));
            }

            //Prepare the genres ArrayList.
            if (!genresList.contains(songGenre)) {
                genresList.add(songGenre);
            }

            //Filter out track numbers and remove any bogus values.
            if (songTrackNumber != null) {
                if (songTrackNumber.contains("/")) {
                    int index = songTrackNumber.lastIndexOf("/");
                    songTrackNumber = songTrackNumber.substring(0, index);
                }

            }

            if (songYear.equals("0")) {
                songYear = "";
            }

            //Check if any of the other tags were empty/null and set them to "Unknown xxx" values.
            if (songArtist == null || songArtist.isEmpty() || songArtist.equals(" ")) {
                songArtist = "Unknown Artist";
            }

            if (songAlbumArtist == null || songAlbumArtist.isEmpty() || songAlbumArtist.equals(" ")) {
                songAlbumArtist = "Unknown Album Artist";
            }

            if (songAlbum == null || songAlbum.isEmpty() || songAlbum.equals(" ")) {
                songAlbum = "Unknown Album";
            }

            if (songGenre == null || songGenre.isEmpty() || songGenre.equals(" ")) {
                songGenre = "Unknown Genre";
            }

            ContentValues values = new ContentValues();
            values.put(DBAccessHelper.SONG_TITLE, songTitle);
            values.put(DBAccessHelper.SONG_ARTIST, songArtist);
            values.put(DBAccessHelper.SONG_ALBUM, songAlbum);
            values.put(DBAccessHelper.SONG_ALBUM_ARTIST, songAlbumArtist);
            values.put(DBAccessHelper.SONG_DURATION, songDuration);
            values.put(DBAccessHelper.SONG_FILE_PATH, songID);
            values.put(DBAccessHelper.SONG_TRACK_NUMBER, songTrackNumber);
            values.put(DBAccessHelper.SONG_GENRE, songGenre);
            //values.put(DBAccessHelper.SONG_PLAY_COUNT, songPlayCount);
            values.put(DBAccessHelper.SONG_YEAR, songYear);
            values.put(DBAccessHelper.SONG_LAST_MODIFIED, "");
            values.put(DBAccessHelper.BLACKLIST_STATUS, "FALSE"); //Keep the song whitelisted by default.
            values.put(DBAccessHelper.ADDED_TIMESTAMP, date.getTime());
            values.put(DBAccessHelper.RATING, songRating);
            values.put(DBAccessHelper.SONG_SOURCE, songSource);
            values.put(DBAccessHelper.SONG_ALBUM_ART_PATH, songAlbumArtPath);
            values.put(DBAccessHelper.SONG_ID, songID);
            values.put(DBAccessHelper.ARTIST_ART_LOCATION, songArtistArtPath);
            //values.put(DBAccessHelper.ARTIST_ID, artistID);
            values.put(DBAccessHelper.ALBUM_ID, storeAlbumID);

            /* We're gonna have to save the song ID into the SONG_FILE_PATH 
             * field. Google Play Music playlist songs don't have a file path, but we're using a 
             * JOIN in PlaylistsFlippedFragment that relies on this field, so we'll need to use the 
             * song ID as a placeholder instead.
             */
            values.put(DBAccessHelper.SONG_FILE_PATH, songID);

            //Add all the entries to the database to build the songs library.
            mApp.getDBAccessHelper().getWritableDatabase().insert(DBAccessHelper.MUSIC_LIBRARY_TABLE, null,
                    values);

        }

        mApp.getDBAccessHelper().getWritableDatabase().setTransactionSuccessful();

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        //Close the transaction.
        mApp.getDBAccessHelper().getWritableDatabase().endTransaction();

        if (cursor != null) {
            cursor.close();
            cursor = null;
        }

    }

    /****************************************************************************
     * BUILD PLAYLISTS LIBRARY
     ****************************************************************************/
    //getPlaylistsWebClient();
    //getPlaylistsMobileClient();

    //Update the genres library.
    updateGenreSongCount();

    return "SUCCESS";
}

From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java

private void setupAccountSpinner(Spinner spinner) {
    final Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT;

    final Cursor cursorProviders = managedQuery(uri, PROVIDER_PROJECTION,
            Imps.Provider.CATEGORY + "=?" + " AND " + Imps.Provider.ACTIVE_ACCOUNT_USERNAME
                    + " NOT NULL" /* selection */,
            new String[] { ImApp.IMPS_CATEGORY } /* selection args */, Imps.Provider.DEFAULT_SORT_ORDER);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_dropdown_item,
            cursorProviders, new String[] { Imps.Provider.ACTIVE_ACCOUNT_USERNAME },
            new int[] { android.R.id.text1 });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    if (cursorProviders.getCount() > 0) {
        cursorProviders.moveToFirst();/*w  ww .j  av a  2  s .co m*/
        mLastProviderId = cursorProviders.getLong(PROVIDER_ID_COLUMN);
        mLastAccountId = cursorProviders.getLong(ACTIVE_ACCOUNT_ID_COLUMN);

        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                cursorProviders.moveToPosition(arg2);

                mLastProviderId = cursorProviders.getLong(PROVIDER_ID_COLUMN);
                mLastAccountId = cursorProviders.getLong(ACTIVE_ACCOUNT_ID_COLUMN);
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });
    } else {
        spinner.setVisibility(View.GONE);
    }

}

From source file:org.getlantern.firetweet.util.Utils.java

public static boolean isOfficialKeyAccount(final Context context, final long accountId) {
    if (context == null)
        return false;
    final String[] projection = { Accounts.CONSUMER_KEY, Accounts.CONSUMER_SECRET };
    final String selection = Expression.equals(Accounts.ACCOUNT_ID, accountId).getSQL();
    final Cursor c = context.getContentResolver().query(Accounts.CONTENT_URI, projection, selection, null,
            null);//from   w  ww  .j  a  v  a  2  s . co m
    try {
        if (c.moveToPosition(0))
            return TwitterContentUtils.isOfficialKey(context, c.getString(0), c.getString(1));
    } finally {
        c.close();
    }
    return false;
}

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

/**
 * delete item/*  w  w  w.  ja v a2  s.c o  m*/
 */
void deleteItem(int position) {
    Cursor c = mItemsView.mCursorItems;
    c.moveToPosition(position);

    String listId = mListUri.getLastPathSegment();
    String itemId = c.getString(mStringItemsITEMID);
    ShoppingUtils.deleteItem(this, itemId, listId);

    // c.requery();
    mItemsView.requery();
    fillAutoCompleteTextViewAdapter(mEditText);
}

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

/**
 * removeItemFromList//  w ww  .  j a v a 2  s . c  o m
 */
void removeItemFromList(int position) {
    Cursor c = mItemsView.mCursorItems;
    c.moveToPosition(position);
    // Remember old values before delete (for share below)
    String itemName = c.getString(mStringItemsITEMNAME);
    long oldstatus = c.getLong(mStringItemsSTATUS);

    // Delete item by changing its state
    ContentValues values = new ContentValues();
    values.put(Contains.STATUS, Status.REMOVED_FROM_LIST);
    if (PreferenceActivity.getResetQuantity(getApplicationContext())) {
        values.put(Contains.QUANTITY, "");
    }
    getContentResolver().update(Contains.CONTENT_URI, values, "_id = ?",
            new String[] { c.getString(mStringItemsCONTAINSID) });

    // c.requery();

    mItemsView.requery();

    // If we share items, mark item on other lists:
    // TODO ???
    /*
     * String recipients =
     * mCursorListFilter.getString(mStringListFilterSHARECONTACTS); if (!
     * recipients.equals("")) { String shareName =
     * mCursorListFilter.getString(mStringListFilterSHARENAME); long
     * newstatus = Shopping.Status.BOUGHT;
     * 
     * Log.i(TAG, "Update shared item. " + " recipients: " + recipients +
     * ", shareName: " + shareName + ", status: " + newstatus);
     * mGTalkSender.sendItemUpdate(recipients, shareName, itemName,
     * itemName, oldstatus, newstatus); }
     */
}

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

/**
 * move item//w  w  w .  ja v a2s . c o  m
 */
void moveItem(int position, int targetListId) {
    Cursor c = mItemsView.mCursorItems;
    mItemsView.mCursorItems.requery();
    c.moveToPosition(position);

    long listId = getSelectedListId();
    if (false && listId < 0) {
        // No valid list - probably view is not active
        // and no item is selected.
        return;
    }
    listId = Integer.parseInt(mListUri.getLastPathSegment());

    // Attach item to new list, preserving all other fields
    String containsId = c.getString(mStringItemsCONTAINSID);
    ContentValues cv = new ContentValues(1);
    cv.put(Contains.LIST_ID, targetListId);
    getContentResolver().update(Uri.withAppendedPath(Contains.CONTENT_URI, containsId), cv, null, null);

    mItemsView.requery();
}

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

/**
 * copy item//from  w w  w.jav a2s.  c  o  m
 */
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();
}