Example usage for android.widget SimpleCursorAdapter setStringConversionColumn

List of usage examples for android.widget SimpleCursorAdapter setStringConversionColumn

Introduction

In this page you can find the example usage for android.widget SimpleCursorAdapter setStringConversionColumn.

Prototype

public void setStringConversionColumn(int stringConversionColumn) 

Source Link

Document

Defines the index of the column in the Cursor used to get a String representation of that Cursor.

Usage

From source file:com.xmobileapp.rockplayer.RockPlayer.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    /*/*ww  w.  j a v a 2 s. c o m*/
     * Shuffle
     */
    case 0:
        if (this.SHUFFLE)
            this.SHUFFLE = false;
        else
            this.SHUFFLE = true;
        try {
            playerServiceIface.setShuffle(this.SHUFFLE);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        RockOnPreferenceManager settings = new RockOnPreferenceManager(FILEX_PREFERENCES_PATH);
        settings.putBoolean("Shuffle", this.SHUFFLE);
        return true;
    /*
     * Search
     */
    case 1:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        //this.hideMainUI();
        this.showSongSearch();
        this.songSearchTextView.requestFocus();
        Cursor allSongsCursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, SONG_COLS, // we should minimize the number of columns
                null, // all songs
                null, // parameters to the previous parameter - which is null also 
                null // sort order, SQLite-like
        );
        SimpleCursorAdapter songAdapter = new SimpleCursorAdapter(this, R.layout.simple_dropdown_item_2line,
                allSongsCursor, new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST },
                new int[] { R.id.text1, R.id.text2 });
        FilterQueryProvider songSearchFilterProvider = new FilterQueryProvider() {
            @Override
            public Cursor runQuery(CharSequence constraint) {
                String whereClause = MediaStore.Audio.Media.TITLE + " LIKE '%" + constraint + "%'" + " OR "
                        + MediaStore.Audio.Media.ARTIST + " LIKE '%" + constraint + "%'";
                Log.i("SEARCH", whereClause);
                //whereClause = null;
                Cursor songsCursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                        SONG_COLS, // we should minimize the number of columns
                        whereClause, // songs where the title or artist name matches
                        null, // parameters to the previous parameter - which is null also 
                        null // sort order, SQLite-like
                );
                return songsCursor;
            }
        };
        songAdapter.setFilterQueryProvider(songSearchFilterProvider);
        this.songSearchTextView.setAdapter(songAdapter);
        songAdapter
                .setStringConversionColumn(allSongsCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
        //this.songSearchTextView.setOnKeyListener(songSearchKeyListener);
        return true;
    /*
     * Share
     */
    case 5:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        ShareSong shareSong = new ShareSong(context, songCursor);
        shareSong.shareByMail();
        return true;
    /*
     * Get Art
     */
    case 3:
        //           if(GRATIS){
        //              showLitePopup();
        //              return true;
        //           }
        albumReloadProgressDialog = new ProgressDialog(this);
        albumReloadProgressDialog.setIcon(R.drawable.ic_menu_music_library);
        albumReloadProgressDialog.setTitle("Loading Album Art");
        albumReloadProgressDialog.setMessage("Waiting for Last.FM connection");
        // TODO: set powered by Last.FM
        albumReloadProgressDialog.show();
        Thread albumArtThread = new Thread() {
            public void run() {
                try {
                    LastFmAlbumArtImporter lastFmArtImporter = new LastFmAlbumArtImporter(context);
                    lastFmArtImporter.getAlbumArt();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        //albumArtThread.setUncaughtExceptionHandler(albumArtUncaughtExceptionHandler);
        albumArtThread.start();
        //containerLayout.addView(albumReloadProgressDialog);
        return true;
    /*
     * Concerts
     */
    case 4:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        this.hideMainUI();
        this.mainUIContainer.setVisibility(View.GONE);
        //this.hideHelpUI();
        this.showEventUI();

        /*
         * Concert Radius Thing 
         */
        // TODO: need a metric
        //         SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
        RockOnPreferenceManager prefs = new RockOnPreferenceManager(FILEX_PREFERENCES_PATH);
        concertRadius = prefs.getLong("ConcertRadius", (long) (this.CONCERT_RADIUS_DEFAULT));
        this.eventListRadius.setText(String.valueOf(Math.round((float) concertRadius / 1000)));

        /*
         * Show a dialog to give some nice feedback to the user
         */
        concertAnalysisProgressDialog = new ProgressDialog(this);
        concertAnalysisProgressDialog.setIcon(android.R.drawable.ic_menu_today);
        concertAnalysisProgressDialog.setTitle("Analysing concert information");
        concertAnalysisProgressDialog.setMessage("Waiting for Last.FM connection");
        concertAnalysisProgressDialog.show();

        /*
         * Analyze concert info
         */
        lastFmEventImporter = new LastFmEventImporter(context);
        new Thread() {
            public void run() {
                try {
                    lastFmEventImporter.getArtistEvents();
                } catch (SAXException e) {
                    e.printStackTrace();
                } catch (ParserConfigurationException e) {
                    e.printStackTrace();
                }
            }
        }.start();
        return true;
    /*
     * Playlists
     */
    case 6:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        /*
         * Get the views and make them visible
         */
        String sortOrder = MediaStore.Audio.Playlists.NAME + " ASC";
        Cursor playlistAllCursor = contentResolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                this.PLAYLIST_COLS, null, null, sortOrder);

        /*
         * Create Array with custom playlist + system playlists
         */
        Playlist playlistTemp;
        ArrayList<Playlist> playlistArray = new ArrayList<Playlist>();
        /* ALL Playlist*/
        playlistTemp = new Playlist();
        playlistTemp.id = constants.PLAYLIST_ALL;
        playlistTemp.name = "All songs";
        playlistArray.add(playlistTemp);
        /* Recently Added */
        playlistTemp = new Playlist();
        playlistTemp.id = constants.PLAYLIST_RECENT;
        playlistTemp.name = "Recently Added";
        playlistArray.add(playlistTemp);
        /* ... other system playlists ... */

        /* add every playlist in the media store */
        while (playlistAllCursor.moveToNext()) {
            playlistTemp = new Playlist();
            playlistTemp.id = playlistAllCursor
                    .getLong(playlistAllCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists._ID));
            playlistTemp.name = playlistAllCursor
                    .getString(playlistAllCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.NAME));
            playlistArray.add(playlistTemp);
            Log.i("PLAYLIST MENU", playlistTemp.id + " " + playlistTemp.name);
        }

        //           String[] fieldsFrom = new String[1];
        //          int[]   fieldsTo = new int[1];
        //           fieldsFrom[0] = MediaStore.Audio.Playlists.NAME;
        //          fieldsTo[0] = R.id.playlist_name;
        //           PlaylistCursorAdapter playlistAllAdapter = new PlaylistCursorAdapter(this.getApplicationContext(),
        //                                                                 R.layout.playlist_item, 
        //                                                                 playlistAllCursor, 
        //                                                                 fieldsFrom, 
        //                                                                 fieldsTo);
        PlaylistArrayAdapter playlistAllAdapter = new PlaylistArrayAdapter(getApplicationContext(),
                R.layout.playlist_item, playlistArray);

        /*
         * Create Dialog
         */
        AlertDialog.Builder aD = new AlertDialog.Builder(context);
        aD.create();
        aD.setTitle("Select Playlist");
        aD.setAdapter(playlistAllAdapter, playlistDialogClickListener);
        aD.show();

        //           playlistView.setAdapter(playlistAllAdapter);
        //           
        //           playlistView.setOnItemClickListener(playlistItemClickListener);

        //           /*
        //            * Animate scroll up of the listview
        //            */
        //           TranslateAnimation slideUp = new TranslateAnimation(0,0,display.getHeight(),0);
        //           slideUp.setFillAfter(true);
        //           slideUp.setDuration(250);
        //           playlistContainer.startAnimation(slideUp);
        //           
        //this.mainUIContainer.addView(playlistAllSpinner);
        return true;
    /*
     * Preferences
     */
    case 7:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        Intent i = new Intent();
        i.setClass(getApplicationContext(), RockOnSettings.class);
        //              this.recentPlaylistPeriod = getSharedPreferences(PREFS_NAME, 0)
        (new RockOnPreferenceManager(FILEX_PREFERENCES_PATH)).getInt(new Constants().PREF_KEY_RECENT_PERIOD,
                new Constants().RECENT_PERIOD_DEFAULT_IN_DAYS);
        startActivityForResult(i, new Constants().PREFERENCES_REQUEST);
        return true;
    /*
     * Help
     */
    case 8:
        this.hideMainUI();
        //this.mainUIContainer.setVisibility(View.GONE);
        this.showHelpUI();
        return true;
    /*
     * Exit
     */
    case 2:
        try {
            this.playerServiceIface.destroy();
            this.finish();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
    return false;
}