package com.chaoran.thread;

import java.io.File;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.util.DownloadManager;

public class DownApk implements Runnable{
	private ProgressDialog pd;
	private String url;
	private Context context;
	private Handler handler;

	public DownApk(ProgressDialog pd,String url, Context context,Handler handler) {
		this.pd = pd;
		this.url= url;
		this.context = context;
		this.handler=handler;
	}

	@Override
	public void run() {
		try {
			File file = DownloadManager.getFileFromServer(
					url, pd, context);
			Thread.currentThread().sleep(3000);
			pd.dismiss();
			Message msg = new Message();
			msg.what=2;
			msg.obj = file;
			handler.sendMessage(msg);
		} catch (Exception e) {
			Message msg = new Message();
			msg.what =-5;
			handler.sendMessage(msg);
			e.printStackTrace();
		}
	}
}
