|
@@ -9,6 +9,7 @@ import android.preference.DialogPreference;
|
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.annotation.RequiresApi;
|
|
import android.support.annotation.RequiresApi;
|
|
|
|
|
+import android.util.Log;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.webkit.WebChromeClient;
|
|
import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebResourceRequest;
|
|
import android.webkit.WebResourceRequest;
|
|
@@ -32,7 +33,6 @@ import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
import com.sheep.gamegroup.model.entity.TaskState;
|
|
import com.sheep.gamegroup.model.entity.TaskState;
|
|
|
import com.sheep.gamegroup.presenter.TaskDialogContract;
|
|
import com.sheep.gamegroup.presenter.TaskDialogContract;
|
|
|
import com.sheep.gamegroup.presenter.TaskDialogPresenter;
|
|
import com.sheep.gamegroup.presenter.TaskDialogPresenter;
|
|
|
-import com.sheep.gamegroup.util.DeviceUtil;
|
|
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.MyDbManager;
|
|
import com.sheep.gamegroup.util.MyDbManager;
|
|
|
import com.sheep.gamegroup.util.MyListview;
|
|
import com.sheep.gamegroup.util.MyListview;
|
|
@@ -50,6 +50,11 @@ import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
+import org.wlf.filedownloader.DownloadFileInfo;
|
|
|
|
|
+import org.wlf.filedownloader.FileDownloader;
|
|
|
|
|
+import org.wlf.filedownloader.listener.OnDetectBigUrlFileListener;
|
|
|
|
|
+import org.wlf.filedownloader.listener.OnDownloadFileChangeListener;
|
|
|
|
|
+import org.wlf.filedownloader.listener.OnFileDownloadStatusListener;
|
|
|
import org.xutils.ex.DbException;
|
|
import org.xutils.ex.DbException;
|
|
|
import org.xutils.x;
|
|
import org.xutils.x;
|
|
|
|
|
|
|
@@ -95,6 +100,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
private DownloadManager downloadManager;
|
|
private DownloadManager downloadManager;
|
|
|
DownloadInfo downloadInfo;
|
|
DownloadInfo downloadInfo;
|
|
|
private int type;//0,开始任务 1,开始试玩 2,开始下载
|
|
private int type;//0,开始任务 1,开始试玩 2,开始下载
|
|
|
|
|
+ private boolean isStartPause = false;//false:开始,true:暂停
|
|
|
private boolean isDownLoad = false;//是否下载
|
|
private boolean isDownLoad = false;//是否下载
|
|
|
private String buttonStr = "开始任务";//是否下载
|
|
private String buttonStr = "开始任务";//是否下载
|
|
|
private Activity activity;
|
|
private Activity activity;
|
|
@@ -137,6 +143,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
activity = this;
|
|
activity = this;
|
|
|
initViews();
|
|
initViews();
|
|
|
initDatas();
|
|
initDatas();
|
|
|
|
|
+ doFiler();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void initDatas() {
|
|
private void initDatas() {
|
|
@@ -151,7 +158,11 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
dialogItemSizeTv.setText( task_entity.getPackage_size() + "M");
|
|
dialogItemSizeTv.setText( task_entity.getPackage_size() + "M");
|
|
|
isDownLoad = PackageUtil.isAppInstalled(SheepApp.mContext, task_entity.getPackage_names());
|
|
isDownLoad = PackageUtil.isAppInstalled(SheepApp.mContext, task_entity.getPackage_names());
|
|
|
|
|
|
|
|
- isHaveLoad();
|
|
|
|
|
|
|
+// isHaveLoad();
|
|
|
|
|
+// downLoadApk();
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 下载
|
|
|
|
|
+ */
|
|
|
loadTvAdp = new DownLoadTvAdp(activity, infoList);
|
|
loadTvAdp = new DownLoadTvAdp(activity, infoList);
|
|
|
listview_down.setAdapter(loadTvAdp);
|
|
listview_down.setAdapter(loadTvAdp);
|
|
|
|
|
|
|
@@ -237,7 +248,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
switch (type){
|
|
switch (type){
|
|
|
case 0://开始任务
|
|
case 0://开始任务
|
|
|
JSONObject object = new JSONObject();
|
|
JSONObject object = new JSONObject();
|
|
|
- object.put("device_id", DeviceUtil.getDeviceId(DialogActivity.this));
|
|
|
|
|
|
|
+ object.put("device_id", new DeviceUtils(activity).getIMEI()+"");
|
|
|
object.put("release_task_id", Integer.valueOf(task_entity.getRelease_task_id()+""));
|
|
object.put("release_task_id", Integer.valueOf(task_entity.getRelease_task_id()+""));
|
|
|
preference.acceptedTask(object);
|
|
preference.acceptedTask(object);
|
|
|
break;
|
|
break;
|
|
@@ -245,7 +256,14 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
toTestPlay();
|
|
toTestPlay();
|
|
|
break;
|
|
break;
|
|
|
case 2://开始下载
|
|
case 2://开始下载
|
|
|
- downLoadApk();
|
|
|
|
|
|
|
+// downLoadApk();
|
|
|
|
|
+ if(!isStartPause){
|
|
|
|
|
+ startFiler();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ FileDownloader.pause(task_entity.getDownload_link());
|
|
|
|
|
+ }
|
|
|
|
|
+ isStartPause = !isStartPause;
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
@@ -323,7 +341,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
// start_task_tv.setText("继续下载");
|
|
// start_task_tv.setText("继续下载");
|
|
|
}
|
|
}
|
|
|
infoList.clear();
|
|
infoList.clear();
|
|
|
-
|
|
|
|
|
infoList.add(downloadInfo);
|
|
infoList.add(downloadInfo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -354,6 +371,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
start_task_tv.setText(buttonStr);
|
|
start_task_tv.setText(buttonStr);
|
|
|
|
|
+
|
|
|
loadTvAdp.setTaskState(type);
|
|
loadTvAdp.setTaskState(type);
|
|
|
loadTvAdp.addTaskPreference(preference);
|
|
loadTvAdp.addTaskPreference(preference);
|
|
|
loadTvAdp.addTaskEty(task_entity);
|
|
loadTvAdp.addTaskEty(task_entity);
|
|
@@ -409,11 +427,107 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
@Override
|
|
@Override
|
|
|
public void getStatefail(Object o) {
|
|
public void getStatefail(Object o) {
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
|
|
+ unFiler();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*----------------------------*/
|
|
|
|
|
+ OnFileDownloadStatusListener onFileDownloadStatusListener = new OnFileDownloadStatusListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFileDownloadStatusWaiting(DownloadFileInfo downloadFileInfo) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFileDownloadStatusPreparing(DownloadFileInfo downloadFileInfo) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFileDownloadStatusPrepared(DownloadFileInfo downloadFileInfo) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFileDownloadStatusDownloading(DownloadFileInfo downloadFileInfo, float downloadSpeed, long
|
|
|
|
|
+ remainingTime) {
|
|
|
|
|
+ // 正在下载,downloadSpeed为当前下载速度,单位KB/s,remainingTime为预估的剩余时间,单位秒
|
|
|
|
|
+ Log.e("tDownloadedSizeLong---",downloadFileInfo.getDownloadedSizeLong()+"");
|
|
|
|
|
+ Log.e("getFileSizeLong---",downloadFileInfo.getFileSizeLong()+"");
|
|
|
|
|
+ Log.e("getFileSizeLong---",(int)(downloadFileInfo.getDownloadedSizeLong()*100 /downloadFileInfo.getFileSizeLong()) + "%"+"");
|
|
|
|
|
+ start_task_tv.setText((int)(downloadFileInfo.getDownloadedSizeLong() * 100 /downloadFileInfo.getFileSizeLong() )+ "%");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFileDownloadStatusPaused(DownloadFileInfo downloadFileInfo) {
|
|
|
|
|
+ start_task_tv.setText("继续下载");
|
|
|
|
|
+ Log.e("DownloadStatusPaused---",downloadFileInfo.getDownloadedSizeLong()+","+downloadFileInfo.getFileSizeLong());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFileDownloadStatusCompleted(DownloadFileInfo downloadFileInfo) {
|
|
|
|
|
+
|
|
|
|
|
+ Log.e("Completed---",downloadFileInfo.getDownloadedSizeLong()+","+downloadFileInfo.getFileSizeLong());
|
|
|
|
|
+ if(PackageUtil.isAppInstalled(activity, task_entity.getPackage_names())){
|
|
|
|
|
+// PackageUtil.startApp(SheepApp.mContext, task_entity.getPackage_names());
|
|
|
|
|
+ start_task_tv.setText("开始试玩");
|
|
|
|
|
+ type = 1;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ PackageUtil.installApk(activity, task_entity.getPackage_names());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFileDownloadStatusFailed(String s, DownloadFileInfo downloadFileInfo, FileDownloadStatusFailReason fileDownloadStatusFailReason) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ private OnDownloadFileChangeListener mOnDownloadFileChangeListener = new OnDownloadFileChangeListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDownloadFileCreated(DownloadFileInfo downloadFileInfo) {
|
|
|
|
|
+ // 一个新下载文件被创建,也许你需要同步你自己的数据存储,比如在你的业务数据库中增加一条记录
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDownloadFileUpdated(DownloadFileInfo downloadFileInfo, Type type) {
|
|
|
|
|
+ // 一个下载文件被更新,也许你需要同步你自己的数据存储,比如在你的业务数据库中更新一条记录
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDownloadFileDeleted(DownloadFileInfo downloadFileInfo) {
|
|
|
|
|
+ // 一个下载文件被删除,也许你需要同步你自己的数据存储,比如在你的业务数据库中删除一条记录
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ private void doFiler(){
|
|
|
|
|
+ FileDownloader.registerDownloadStatusListener(onFileDownloadStatusListener);
|
|
|
|
|
+ FileDownloader.registerDownloadFileChangeListener(mOnDownloadFileChangeListener);
|
|
|
|
|
+ }
|
|
|
|
|
+ private void unFiler(){
|
|
|
|
|
+ FileDownloader.unregisterDownloadStatusListener(onFileDownloadStatusListener);
|
|
|
|
|
+ FileDownloader.unregisterDownloadFileChangeListener(mOnDownloadFileChangeListener);
|
|
|
|
|
+ }
|
|
|
|
|
+ private void startFiler(){
|
|
|
|
|
+ ClassFileHelper.getInstance().createSDDirection();
|
|
|
|
|
+// File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
|
|
+ FileDownloader.detect(task_entity.getDownload_link(), new OnDetectBigUrlFileListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDetectNewDownloadFile(String url, String fileName, String saveDir, long fileSize) {
|
|
|
|
|
+ // 如果有必要,可以改变文件名称fileName和下载保存的目录saveDir
|
|
|
|
|
+ FileDownloader.createAndStart(url, ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDetectUrlFileExist(String url) {
|
|
|
|
|
+ // 继续下载,自动会断点续传(如果服务器无法支持断点续传将从头开始下载)
|
|
|
|
|
+ FileDownloader.start(url);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDetectUrlFileFailed(String url, DetectBigUrlFileFailReason failReason) {
|
|
|
|
|
+ // 探测一个网络文件失败了,具体查看failReason
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|