package com.frewen.ttplayer; importjava.util.ArrayList; importjava.util.LinkedList; importjava.util.List; importandroid.app.Activity; importandroid.app.Application; importandroid.content.Context; importandroid.graphics.Bitmap; importandroid.graphics.BitmapFactory; importandroid.media.MediaPlayer; importandroid.util.Log; import com.frewen.ttplayer.entry.Music; import com.frewen.ttplayer.entry.impl.Musicdata; import com.frewen.ttplayer.util.MusicPreference; public classMyApplication extends Application { public static MediaPlayer mediaPlayer; public static MusicPreferencemusicPreference; public static ArrayList<Music> musics= new ArrayList<Music>(); public static boolean isStart = false; public List<Activity> activityList =new LinkedList<Activity>(); public static Bitmap bitmap_l; public static Bitmap bitmap_s; public static MyApplication instance; public ArrayList<Music> getMusics() { return musics; } public static Context context; @Override public void onCreate() { super.onCreate(); context = getApplicationContext(); new Thread(new Runnable() { @Override public void run() { setMusics(Musicdata.getMultiDatas(context)); bitmap_l = BitmapFactory.decodeResource(context.getResources(), R.drawable.default_bg_l); bitmap_s =BitmapFactory.decodeResource(context.getResources(), R.drawable.default_bg_s); } }).start(); mediaPlayer = new MediaPlayer(); musicPreference = new MusicPreference(context); } public void setMusics(ArrayList<Music>ms) { musics.clear(); musics = ms; Log.i("test", "列表长度" + this.musics.size()); } public MyApplication() { } // 单例模式中获取唯一的MyApplication实例 public static MyApplication getInstance() { if (null == instance) { instance = new MyApplication(); } return instance; } // 添加Activity到容器中 public void addActivity(Activity activity) { activityList.add(activity); } // 遍历所有Activity并finish public void exit() { for (Activity activity : activityList) { activity.finish(); } System.exit(0); } /** * 向musics集合中追加一组miusic信息 * *@param musics */ public void append(ArrayList<Music>musics) { if (musics != null) { this.musics.addAll(musics); } } public void append(Music music) { if (music != null) { this.musics.add(music); } } } |