Example usage for android.database Cursor getColumnIndexOrThrow

List of usage examples for android.database Cursor getColumnIndexOrThrow

Introduction

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

Prototype

int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;

Source Link

Document

Returns the zero-based index for the given column name, or throws IllegalArgumentException if the column doesn't exist.

Usage

From source file:com.cyanogenmod.eleven.MusicPlaybackService.java

/**
 * Returns the genre name of song/*from   w w w  .  j av a2  s .c  o  m*/
 *
 * @return The current song genre name
 */
public String getGenreName() {
    synchronized (this) {
        if (mCursor == null || mPlayPos < 0 || mPlayPos >= mPlaylist.size()) {
            return null;
        }
        String[] genreProjection = { MediaStore.Audio.Genres.NAME };
        Uri genreUri = MediaStore.Audio.Genres.getContentUriForAudioId("external",
                (int) mPlaylist.get(mPlayPos).mId);
        Cursor genreCursor = getContentResolver().query(genreUri, genreProjection, null, null, null);
        if (genreCursor != null) {
            try {
                if (genreCursor.moveToFirst()) {
                    return genreCursor
                            .getString(genreCursor.getColumnIndexOrThrow(MediaStore.Audio.Genres.NAME));
                }
            } finally {
                genreCursor.close();
            }
        }
        return null;
    }
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
    if (resultCode == RESULT_CANCELED)
        return;//from  ww  w  .ja  v  a 2s  .c o m

    //After running Media Gallery Program
    if (requestCode == ACTIVITY_SELECT_IMAGE) {
        Uri_image = data.getData();

        Intent i = new Intent(HomeScreen.this, SingleImageView.class);
        startActivity(i);

        return;
    }

    if (requestCode == ACTIVITY_SELECT_VIDEO) {
        Uri_image = data.getData();

        Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
        intent.setDataAndType(Uri_image, "video/mpeg");
        startActivity(intent);
        return;
    }

    //after running audio program
    if (requestCode == REQUEST_CODE_RECORD) {
        //move file into GT/s directory
        Uri savedUri = data.getData();
        Cursor cursor = getContentResolver().query(savedUri, null, null, null, null);
        if (cursor.moveToFirst()) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);//Instead of "MediaStore.Images.Media.DATA" can be used "_data"
            Uri filePathUri = Uri.parse(cursor.getString(column_index));
            String file_path = filePathUri.getPath();

            //rename the file
            String path = GTConstants.sendfileFolder + Utility.createFileName() + ".3ga";

            //put the file name into the global
            file_name = path;

            File file_to = new File(path);
            File file_from = new File(file_path);
            file_from.renameTo(file_to);

            //Toast.makeText(HomeScreen.this, file_name, Toast.LENGTH_LONG).show();
        }
    }

    //after running camera, audio or video program
    if (requestCode == REQUEST_CODE_RECORD || requestCode == CAMERA_PIC_REQUEST
            || requestCode == ACTION_TAKE_VIDEO) {

        //this section was pulled from the "Cancel" option of the the tagging code - it replaces tagging (i.e. as if cancel is always being selected

        try {
            //copy file to /GT/r directory so that local user can view the image
            File file = new File(file_name);
            copyFile(GTConstants.sendfileFolder, file.getName(), GTConstants.receivefileFolder);

            //this needs to be sent to clear the deleted image from the gallery memory - otherwise would have to wait for reboot of phone
            //sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri .parse("file://" + Environment.getExternalStorageDirectory())));
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                    Uri.parse("file://" + Environment.getExternalStorageDirectory())));

            //new Upload_FTP().execute(file_name);
            Utility.setUploadAvailable();
        } catch (Exception e) {
            Toast.makeText(HomeScreen.this, "File copy Error: " + e, Toast.LENGTH_LONG).show();
        }

        //create filename info for dar
        String darFile[] = null;
        String newFile;
        try {
            darFile = file_name.split("_");
            newFile = GTConstants.LICENSE_ID.substring(7) + "_" + darFile[1] + "_" + darFile[2];
            //Toast.makeText(HomeScreen.this, "File: " + newFile, Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            Toast.makeText(HomeScreen.this, "File Naming Error: " + e, Toast.LENGTH_LONG).show();
            newFile = "unknown";
        }

        //email option
        if (requestCode == REQUEST_CODE_RECORD) {
            //add event to dar and srp
            if (GTConstants.sendData) {
                Utility.write_to_file(HomeScreen.this,
                        GTConstants.dardestinationFolder + GTConstants.darfileName, "Voice;" + newFile + ".3ga"
                                + ";" + Utility.getLocalTime() + ";" + Utility.getLocalDate() + "\r\n",
                        true);

                if (GTConstants.srpfileName.length() > 1)
                    Utility.write_to_file(HomeScreen.this,
                            GTConstants.dardestinationFolder + GTConstants.srpfileName,
                            "Voice;" + newFile + ".3ga" + ";" + Utility.getLocalTime() + ";"
                                    + Utility.getLocalDate() + "\r\n",
                            true);

            }
            send_media_via_email("audio");
        }

        if (requestCode == CAMERA_PIC_REQUEST) {
            //add event to dar and srp
            if (GTConstants.sendData) {
                Utility.write_to_file(HomeScreen.this,
                        GTConstants.dardestinationFolder + GTConstants.darfileName, "Photo;" + newFile + ".jpg"
                                + ";" + Utility.getLocalTime() + ";" + Utility.getLocalDate() + "\r\n",
                        true);

                if (GTConstants.srpfileName.length() > 1)
                    Utility.write_to_file(HomeScreen.this,
                            GTConstants.dardestinationFolder + GTConstants.srpfileName,
                            "Photo;" + newFile + ".jpg" + ";" + Utility.getLocalTime() + ";"
                                    + Utility.getLocalDate() + "\r\n",
                            true);

            }
            send_media_via_email("photo");
        }

        if (requestCode == ACTION_TAKE_VIDEO) {
            //add event to dar
            if (GTConstants.sendData) {
                Utility.write_to_file(HomeScreen.this,
                        GTConstants.dardestinationFolder + GTConstants.darfileName, "Video;" + newFile + ".mpeg"
                                + ";" + Utility.getLocalTime() + ";" + Utility.getLocalDate() + "\r\n",
                        true);

                if (GTConstants.srpfileName.length() > 1)
                    Utility.write_to_file(HomeScreen.this,
                            GTConstants.dardestinationFolder + GTConstants.srpfileName,
                            "Video;" + newFile + ".mpeg" + ";" + Utility.getLocalTime() + ";"
                                    + Utility.getLocalDate() + "\r\n",
                            true);

            }
            send_media_via_email("video");
        }

        //end cancel section

        /*  Allowing fore tagging of media files removed 7/1/14 - B. Hall
        //after taking audio, camera or video this routine fires.  file_name is a common variable file name that is assigned when an audio, camera or video is taken
        AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
        dialog.setTitle("Tag");
        dialog.setMessage("Add a tag?");
        final EditText input = new EditText(this);
        dialog.setView(input);
                
        dialog.setPositiveButton("OK",new DialogInterface.OnClickListener() 
        {
           @Override
           public void onClick(DialogInterface dialog,int which) 
           {
              String tagText = input.getText().toString().trim();
                      
              //rename the file
              File currentFile = new File(file_name);
              String path = GTConstants.sendfileFolder;
                      
              String oldFile = currentFile.getName();
              String newFile = oldFile.substring(0, oldFile.lastIndexOf('.')) + "_" + tagText + "_";
                      
              if (requestCode == CAMERA_PIC_REQUEST) 
                 { 
                 //rename the file to include tag
                 newFile = newFile + ".jpg";
                 file_name = path + newFile;
                         
                 File from = new File(path,oldFile);
                 File to = new File(path,newFile);
                 from.renameTo(to);
                         
                 //now upload the file to the ftp server
          //new Upload_FTP().execute(file_name);
          Utility.setUploadAvailable();
                  
          //email option
          send_media_via_email("photo");
                  
          //this needs to be sent to clear the deleted image from the gallery memory - otherwise would have to wait for reboot of phone
         sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri .parse("file://" + Environment.getExternalStorageDirectory())));
                 
          //Toast.makeText(HomeScreen.this, "Picture saved", Toast.LENGTH_LONG).show();
                 }  
                         
                 if (requestCode == ACTION_TAKE_VIDEO) 
                 {
          newFile = newFile + ".mpeg";
                 file_name = path + newFile;
                         
                 File from = new File(path,oldFile);
                 File to = new File(path,newFile);
                 from.renameTo(to);
          //new Upload_FTP().execute(file_name);
                         
                 Utility.setUploadAvailable();
                  
          //email option
          send_media_via_email("video");
                  
          //this needs to be sent to clear the deleted image from the gallery memory - otherwise would have to wait for reboot of phone
         sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
                 
          //Toast.makeText(HomeScreen.this, "Video saved", Toast.LENGTH_LONG).show();
                 }
                         
                 if (requestCode == REQUEST_CODE_RECORD) 
                 {
          newFile = newFile + ".3ga";
                 file_name = path + newFile;
                         
                 File from = new File(path,oldFile);
                 File to = new File(path,newFile);
                 from.renameTo(to);
          //new Upload_FTP().execute(file_name);
                 Utility.setUploadAvailable();
                  
          //email option
          send_media_via_email("audio");
                  
          //Toast.makeText(HomeScreen.this, "Audio saved", Toast.LENGTH_LONG).show();
                 }
                         
               //copy file to /GT/r directory so that local user can view the image
             copyFile(GTConstants.sendfileFolder, newFile, GTConstants.receivefileFolder);
                     
             //this needs to be sent to clear the deleted image from the gallery memory - otherwise would have to wait for reboot of phone
             sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri .parse("file://" + Environment.getExternalStorageDirectory())));
           }
        });
                
        //if no tag is added then leave the filename alone, it was set during initial save (although issue still exists with audio filename!!!).
        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() 
        {
             public void onClick(DialogInterface dialog, int which) 
             {
                //copy file to /GT/r directory so that local user can view the image
                File file = new File(file_name);
              copyFile(GTConstants.sendfileFolder, file.getName(), GTConstants.receivefileFolder);
                      
              //this needs to be sent to clear the deleted image from the gallery memory - otherwise would have to wait for reboot of phone
              sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri .parse("file://" + Environment.getExternalStorageDirectory())));
                      
                //new Upload_FTP().execute(file_name);
              Utility.setUploadAvailable();
                        
                //email option
                if (requestCode == REQUEST_CODE_RECORD)send_media_via_email("audio");
                if (requestCode == CAMERA_PIC_REQUEST) send_media_via_email("photo");
                if (requestCode == ACTION_TAKE_VIDEO)  send_media_via_email("video"); 
             } 
         });
        dialog.show();
        */
    }

}

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

public void initializeAlbumCursor() {
    try {/*from ww w  .jav a2s . com*/
        Log.i("DBG", "Initializing Album Cursor - playlist - " + playlist);
        //      playlist = this.getSharedPreferences(this.PREFS_NAME, 0).getLong(constants.PREF_KEY_PLAYLIST, constants.PLAYLIST_ALL);
        if (playlist == constants.PLAYLIST_ALL) {
            String sortClause = MediaStore.Audio.Albums.ARTIST + " ASC";
            albumCursor = contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, ALBUM_COLS, // we should minimize the number of columns
                    null, // all albums 
                    null, // parameters to the previous parameter - which is null also 
                    sortClause // sort order, SQLite-like
            );
        } else if (playlist == constants.PLAYLIST_RECENT) {
            RockOnPreferenceManager prefs = new RockOnPreferenceManager(FILEX_PREFERENCES_PATH);
            //          double period = getSharedPreferences(PREFS_NAME, 0)
            double period = prefs.getInt(constants.PREF_KEY_RECENT_PERIOD,
                    constants.RECENT_PERIOD_DEFAULT_IN_DAYS) * 24 * 60 * 60;
            String whereClause = MediaStore.Audio.Media.DATE_ADDED + ">"
                    + (System.currentTimeMillis() / 1000 - period);
            String sortOrder = MediaStore.Audio.Albums.ALBUM + " ASC";
            Cursor songCursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, SONG_COLS,
                    whereClause, null, sortOrder);
            whereClause = "";
            String lastAlbumKey = "";
            while (songCursor.moveToNext()) {
                if (songCursor.getString(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_KEY))
                        .equals(lastAlbumKey)) {
                    lastAlbumKey = songCursor
                            .getString(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_KEY));
                    //Log.i("DBG", "Album Repeated - "+songCursor.getString(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_KEY)));
                    //Log.i("DBG", "Album Repeated - "+songCursor.getString(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)));
                    continue;
                }
                if (whereClause != "")
                    whereClause += " OR ";
                whereClause += MediaStore.Audio.Albums.ALBUM_KEY + "=\""
                        + songCursor
                                .getString(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_KEY))
                                .replaceAll("\"", "\"\"")
                        + "\"";

                lastAlbumKey = songCursor
                        .getString(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_KEY));
                //Log.i("PLAYLIST_RECENT", songCursor.getDouble(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATE_ADDED))+" > "+ (System.currentTimeMillis()/1000 - period));
            }
            sortOrder = MediaStore.Audio.Albums.ARTIST + " ASC";
            albumCursor = contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, ALBUM_COLS, // we should minimize the number of columns
                    whereClause, // all albums 
                    null, // parameters to the previous parameter - which is null also 
                    sortOrder // sort order, SQLite-like
            );
            Log.i("DBG", "query length = " + albumCursor.getCount());

            // more pre defined playlists
        } else {
            /*
             * A previously chosen playlist
             */
            String sortClause = MediaStore.Audio.Playlists.Members.ALBUM + " ASC";
            Cursor playlistCursor = contentResolver.query(
                    MediaStore.Audio.Playlists.Members.getContentUri("external", playlist), PLAYLIST_SONG_COLS, // we should minimize the number of columns
                    null, // all albums 
                    null, // parameters to the previous parameter - which is null also 
                    sortClause // sort order, SQLite-like
            );
            String whereClause = "";
            String lastAlbumKey = "";
            while (playlistCursor.moveToNext()) {
                if (playlistCursor
                        .getString(playlistCursor
                                .getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY))
                        .equals(lastAlbumKey)) {
                    lastAlbumKey = playlistCursor.getString(
                            playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY));
                    Log.i("DBG", "Album Repeated - " + playlistCursor.getString(playlistCursor
                            .getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY)));
                    Log.i("DBG", "Album Repeated - " + playlistCursor.getString(
                            playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM)));
                    continue;
                }
                if (whereClause != "")
                    whereClause += " OR ";
                whereClause += MediaStore.Audio.Albums.ALBUM_KEY + "=\""
                        + playlistCursor
                                .getString(playlistCursor
                                        .getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY))
                                .replaceAll("\"", "\"\"")
                        + "\"";

                lastAlbumKey = playlistCursor.getString(
                        playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY));

                Log.i("DBG", "Album - " + playlistCursor.getString(
                        playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY)));

            }

            Log.i("DBG", whereClause);
            sortClause = MediaStore.Audio.Albums.ARTIST + " ASC";
            albumCursor = contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, ALBUM_COLS, // we should minimize the number of columns
                    whereClause, // all albums 
                    null, // parameters to the previous parameter - which is null also 
                    sortClause // sort order, SQLite-like
            );
            Log.i("DBG", "query length = " + albumCursor.getCount());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    //       /*************DBG********************************/
    //       initializeAlbumCursorFromPlaylist();
}

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

public Cursor initializeSongCursor(String albumName) {
    //       //playlist=1;
    //       if(albumName == null){
    //          songCursor = 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
    //               );
    //       } else {
    try {//from  w  w  w .  j a  va  2 s.c  o m
        String whereClause = null;
        if (playlist == constants.PLAYLIST_ALL) {
            if (albumName != null)
                whereClause = MediaStore.Audio.Media.ALBUM + "=\"" + albumName.replaceAll("\"", "\"\"") + "\"";
            String sortClause = MediaStore.Audio.Media.TRACK + " ASC";
            Log.i("SONGSEARCH", "" + whereClause);
            return contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, SONG_COLS, // we should minimize the number of columns
                    whereClause, // all songs from a certain album
                    null, // parameters to the previous parameter - which is null also 
                    sortClause // sort order, SQLite-like
            );
        } else if (playlist == constants.PLAYLIST_RECENT) {
            if (albumName != null)
                whereClause = MediaStore.Audio.Media.ALBUM + "=\"" + albumName.replaceAll("\"", "\"\"") + "\"";
            String sortClause = MediaStore.Audio.Media.TRACK + " ASC";
            Log.i("SONGSEARCH", "" + whereClause);
            return contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, SONG_COLS, // we should minimize the number of columns
                    whereClause, // all songs from a certain album
                    null, // parameters to the previous parameter - which is null also 
                    sortClause // sort order, SQLite-like
            );
            //another dynamic playlist
        } else {
            /*
              * A previously chosen playlist
              */
            if (albumName != null)
                whereClause = MediaStore.Audio.Playlists.Members.ALBUM + "=\""
                        + albumName.replaceAll("\"", "\"\"") + "\"";
            Cursor playlistCursor = contentResolver.query(
                    MediaStore.Audio.Playlists.Members.getContentUri("external", playlist), PLAYLIST_SONG_COLS, // we should minimize the number of columns
                    whereClause, // all albums 
                    null, // parameters to the previous parameter - which is null also 
                    null // sort order, SQLite-like
            );
            whereClause = MediaStore.Audio.Media.ALBUM + "=\"" + albumName.replaceAll("\"", "\"\"") + "\"";
            //              String lastAlbumKey = "";
            while (playlistCursor.moveToNext()) {
                //                 if(playlistCursor.getString(playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY)).equals(lastAlbumKey)){
                //                    lastAlbumKey = playlistCursor.getString(playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY));
                //                    Log.i("DBG", "Album Repeated - "+playlistCursor.getString(playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY)));
                //                    Log.i("DBG", "Album Repeated - "+playlistCursor.getString(playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM)));
                //                    continue;
                //                 }
                if (whereClause != "")
                    whereClause += " OR ";
                whereClause += MediaStore.Audio.Media.TITLE_KEY + "=\""
                        + playlistCursor
                                .getString(playlistCursor
                                        .getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.TITLE_KEY))
                                .replaceAll("\"", "\"\"")
                        + "\"";

                //                 lastAlbumKey = playlistCursor.getString(playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.ALBUM_KEY));

                Log.i("DBG", "Album - " + playlistCursor.getString(
                        playlistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.TITLE_KEY)));
            }

            String sortClause = MediaStore.Audio.Media.TRACK + " ASC";
            //String sortClause = null;
            Log.i("SONGSEARCH", whereClause);
            return contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, SONG_COLS, // we should minimize the number of columns
                    whereClause, // all songs from a certain album
                    null, // parameters to the previous parameter - which is null also 
                    sortClause // sort order, SQLite-like
            );

        }
    } catch (Exception e) {
        e.printStackTrace();
        return songCursor;
    }
    //       }
}

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

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    /*/*from w ww  .  jav 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;
}

From source file:com.codename1.impl.android.AndroidImplementation.java

private static String convertImageUriToFilePath(Uri imageUri, Context activity) {
    Cursor cursor = null;
    String[] proj = { MediaStore.Images.Media.DATA };
    cursor = activity.getContentResolver().query(imageUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/* w  w  w .  j  a va  2  s  . c o m*/
    String path = cursor.getString(column_index);
    cursor.close();
    return path;
}