安卓点歌代码
  f7L79lyjPkIX 2023年11月02日 47 0

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;
}

}

安卓点歌代码_安卓点歌代码、java点歌

安卓点歌代码_json_02

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  lh6O4DgR0ZQ8   2023年11月02日   55   0   0 javaListjson
f7L79lyjPkIX
作者其他文章 更多