Search in sources :

Example 1 with SDCardInfo

use of com.youku.service.download.SDCardManager.SDCardInfo in project SimplifyReader by chentao0707.

the class FileCreateThread method run.

@Override
public void run() {
    for (DownloadInfo info : download_temp_infos) {
        if (download.existsDownloadInfo(info.videoid)) {
            if (download.isDownloadFinished(info.videoid)) {
                // 已下载完成
                PlayerUtil.showTips(R.string.download_exist_finished);
            } else {
                PlayerUtil.showTips(R.string.download_exist_not_finished);
            }
            continue;
        }
        long time = System.currentTimeMillis();
        info.createTime = time;
        // 用时间戳做ID
        info.taskId = String.valueOf(time).substring(5);
        if (init(info)) {
            Logger.d("DownloadFlow", "init() success");
            download.addDownloadingInfo(info);
            switch(info.format) {
                case DownloadInfo.FORMAT_HD2:
                    break;
                case DownloadInfo.FORMAT_MP4:
                    break;
                default:
                    break;
            }
            successCount++;
            YoukuPlayerApplication.context.sendBroadcast(new Intent(IDownload.ACTION_CREATE_DOWNLOAD_ONE_READY));
        } else {
            Logger.d("DownloadFlow", "init() fail");
            failCount++;
            YoukuPlayerApplication.context.sendBroadcast(new Intent(IDownload.ACTION_CREATE_DOWNLOAD_ONE_FAILED));
            if (info.getExceptionId() == DownloadInfo.EXCEPTION_NO_SPACE) {
                // 没有空间,提示切换空间
                failCount = download_temp_infos.size() - successCount;
                ArrayList<SDCardInfo> card = SDCardManager.getExternalStorageDirectory();
                if (card != null && card.size() > 1) {
                    hasMaryPaths = true;
                    HandlerThread ht = new HandlerThread("handler_thread1");
                    ht.start();
                    new Handler(ht.getLooper()) {

                        public void handleMessage(Message msg) {
                            /*								YoukuPlayerApplication.context
										.startActivity(new Intent(
												YoukuPlayerApplication.context,
												EmptyActivity.class)
												.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));*/
                            Toast.makeText(YoukuPlayerApplication.context, "存储空间不足", Toast.LENGTH_SHORT).show();
                        }

                        ;
                    }.sendEmptyMessageDelayed(0, 500L);
                }
                break;
            }
            continue;
        }
    }
    for (DownloadInfo info : download_temp_infos) {
        tempCreateData.remove(info.videoid);
    }
    showTips();
    over();
    HandlerThread ht = new HandlerThread("handler_thread2");
    ht.start();
    new Handler(ht.getLooper()) {

        public void handleMessage(Message msg) {
            Logger.d("DownloadFlow", "FileCreateThread: create task to download");
            download.startNewTask();
        }

        ;
    }.sendEmptyMessageDelayed(0, 1000L);
    super.run();
}
Also used : HandlerThread(android.os.HandlerThread) Message(android.os.Message) Handler(android.os.Handler) Intent(android.content.Intent) SDCardInfo(com.youku.service.download.SDCardManager.SDCardInfo)

Aggregations

Intent (android.content.Intent)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 Message (android.os.Message)1 SDCardInfo (com.youku.service.download.SDCardManager.SDCardInfo)1