Android Open Source - hts-cycle Songs Manager






From Project

Back to project page hts-cycle.

License

The source code is released under:

GNU General Public License

If you think the Android project hts-cycle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package it.uniroma2.musicsharep2p;
/*  ww  w . j  a va2s.c  o m*/


import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class SongsManager {

  private SQLiteDatabase database;
  private DataBaseHelper myDbHelper;
  private Context ctx;
  //niente
  // SDCard Path
  //final String MEDIA_PATH = new String("/storage/emulated/0/Music");
  final String MEDIA_PATH = new String("/sdcard");
  private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();



  public void setContext(Context con){

    this.ctx=con;


  }


  // Constructor
  public SongsManager(){

  }



  // Constructor
  public SongsManager(Context con){

    this.ctx=con;

  }

  /**
   * Function to read all mp3 files from sdcard
   * and store the details in ArrayList
   * */
  public ArrayList<HashMap<String, String>> getPlayList(){

    myDbHelper = new DataBaseHelper(ctx);

    try {myDbHelper.createDataBase();} 
    catch (IOException ioe) 
    {throw new Error("Unable to create database");}

    try {myDbHelper.openDataBase();}
    catch(SQLException sqle){throw sqle;}

    


    
    database=myDbHelper.getReadableDatabase();
    
    Cursor cursor;
    cursor = database.rawQuery(("select * from dest"), null);
    cursor.moveToFirst();
    String Ric = new String();
    Ric=cursor.getString(cursor.getColumnIndex("dest"));
    

    File home = new File(Ric);
    if(home!=null)
    {
      FileExtensionFilter lf= new FileExtensionFilter();
      File[] f= home.listFiles(lf);
      if(f!=null)
    if (home.listFiles(new FileExtensionFilter()).length > 0) {
      for (File file : home.listFiles(new FileExtensionFilter())) {
        HashMap<String, String> song = new HashMap<String, String>();
        song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
        song.put("songPath", file.getPath());

        // Adding each song to SongList
        songsList.add(song);
      }
    }
    }
    // return songs list array
    return songsList;
  }
  

  /**
   * Class to filter files which are having .mp3 extension
   * */
  class FileExtensionFilter implements FilenameFilter {
    public boolean accept(File dir, String name) {
      return (name.endsWith(".mp3") || name.endsWith(".MP3"));
    }
  }
}




Java Source Code List

it.uniroma2.musicsharep2p.DataBaseHelper.java
it.uniroma2.musicsharep2p.DefaultValue.java
it.uniroma2.musicsharep2p.DownloadActivity.java
it.uniroma2.musicsharep2p.MainActivity.java
it.uniroma2.musicsharep2p.MessengerService.java
it.uniroma2.musicsharep2p.MusicSettingActivity.java
it.uniroma2.musicsharep2p.MusicShutReceiver.java
it.uniroma2.musicsharep2p.PlayListActivity.java
it.uniroma2.musicsharep2p.RemoteServiceConnection.java
it.uniroma2.musicsharep2p.SongsManager.java
it.uniroma2.musicsharep2p.Utilities.java
it.uniroma2.wifionoff.AlarmReceiver.java
it.uniroma2.wifionoff.AppActivity.java
it.uniroma2.wifionoff.AppHelper.java
it.uniroma2.wifionoff.DataBaseHelper.java
it.uniroma2.wifionoff.IpMaker.java
it.uniroma2.wifionoff.MainActivity.java
it.uniroma2.wifionoff.MessageMaker.java
it.uniroma2.wifionoff.MyListActivity.java
it.uniroma2.wifionoff.NameActivity.java
it.uniroma2.wifionoff.OnOffService.java
it.uniroma2.wifionoff.PacketHandler.java
it.uniroma2.wifionoff.ServiceCall.java
it.uniroma2.wifionoff.SettingActivity.java
it.uniroma2.wifionoff.Setting.java
it.uniroma2.wifionoff.ShutDownReceiver.java
it.uniroma2.wifionoff.WifiConfigurationNew.java
it.uniroma2.wifionoff.WifiHandler.java
it.uniroma2.wifionoff.WifiManagerNew.java
it.uniroma2.wifionoff.WifiOffReceiver.java
it.uniroma2.wifionoff.WifiReceiver.java