安卓点歌系统

您所在的位置:网站首页 浙教版中考科学必考知识点 安卓点歌系统

安卓点歌系统

#安卓点歌系统| 来源: 网络整理| 查看: 265

public class Favor_Song {

    private static Favor_Song mfavor_song = null;      private Context mcontext= null;     private List mlist= new ArrayList();     private String sfile= null;     private final int ETF_Favor_MAX = 50;     private final int ETF_SAVE_Favor = 256;     private Handler mhandler;

    private Favor_Song()     {         mhandler = new Handler(){             public void handleMessage(Message message)             {                 switch(message.what){                 case ETF_SAVE_Favor:                     savefile();                     break;                 }             }         };     }

    public static Favor_Song getInstance()     {         if(mfavor_song == null)             mfavor_song = new Favor_Song();         return mfavor_song;     }

    private void loadfile()     {         try{             JSONArray jsonarray = new JSONArray(etfStatic.load_file(sfile));             int i = 0;             while(i < jsonarray.length()){                 Song b1 = Song.jsontosong(jsonarray.getJSONObject(i));                 if(b1 != null)                     add(b1);                 i++;             }             }catch(Exception ex){}     }

    private Song find(Song b1)     {         String s;         String s1;         int i;         s = b1.getmusic_id();         s1 = b1.getmusic_name();         i = 0;         Song b2 = null;         while(i < mlist.size()){             String s2;             String s3;             b2 = (Song)mlist.get(i);             s2 = b2.getmusic_id();             s3 = b2.getmusic_name();             if(s2.equals(s) && s3.equals(s1)) break;             i++;         }         return b2;     }

    private void savefile()     {         try         {             JSONArray jsonarray = new JSONArray();             Iterator iterator = mlist.iterator();             while(iterator.hasNext())             {                 jsonarray.put(((Song)iterator.next()).tojson());             };             etfStatic.save_file(sfile, jsonarray.toString());         }         catch(Exception exception)         {             exception.printStackTrace();         }     }

    public void init(Context context)     {         mcontext = context;         sfile = String.valueOf(mcontext.getCacheDir().getAbsolutePath())+"/music_favorite";         loadfile();     }

    public void add(Song b1)     {         if(find(b1) == null){             mlist.add(0, b1);             if(mlist.size() > ETF_Favor_MAX)                 mlist.remove(ETF_Favor_MAX);             if(mhandler != null)             {                 mhandler.removeMessages(ETF_SAVE_Favor);                 mhandler.sendEmptyMessageDelayed(ETF_SAVE_Favor, 5000L);             }         }      }

    public List getlist()     {         return mlist;     }

    public void remove(Song b1)     {         Song b2 = find(b1);         if(b2 != null)         {             mlist.remove(b2);             if(mhandler != null)             {                 mhandler.removeMessages(ETF_SAVE_Favor);                 mhandler.sendEmptyMessageDelayed(ETF_SAVE_Favor, 5000L);             }         }     }

    public boolean check(Song b1)     {         boolean flag;         if(find(b1) != null)             flag = true;         else             flag = false;         return flag;     } }

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3