1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("是否需要下载离线地图?"); builder.setMessage(f.getAbsolutePath() + " 没有找到离线地图文件"); builder.setCancelable(true); final ProgressDialog dialog22 = new ProgressDialog(this); dialog22.setTitle("正在下载离线地图"); dialog22.setCancelable(false); builder.setPositiveButton("下载(文件>500M)", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { FileDownloader.getImpl().create(Config.KJMAPDOWNLOAD) .setAutoRetryTimes(100) .setPath(f.getAbsolutePath(),true) .setListener(new FileDownloadLargeFileListener() { @Override protected void pending(BaseDownloadTask task, long soFarBytes, long totalBytes) { dialog22.show(); } @Override protected void progress(BaseDownloadTask task, long soFarBytes, long totalBytes) { dialog22.setMessage( "重试"+task.getRetryingTimes()+"次,下载速度:" + task.getSpeed() + "kb/s,百分比:" + soFarBytes / 1048576 + "/" + totalBytes / 1048576 + "M"); } @Override protected void completed(BaseDownloadTask task) { Toast.makeText(LineActivity.this, "下载成功,请重新打开该页面", Toast.LENGTH_LONG).show(); String oldFileUrl=task.getPath()+"/"+task.getFilename(); Log.i("oldFileUrl",oldFileUrl); File oldName=new File(oldFileUrl); File newName=new File(f.getAbsolutePath()+"/"+Config.KJMAPDOWNLOADFILENAME); if (oldName.renameTo(newName)){ Log.i("LineActivity","重命名成功"); }else { Log.e("LineActivity","重命名失败"); } dialog22.dismiss(); } @Override protected void paused(BaseDownloadTask task, long soFarBytes, long totalBytes) { } @Override protected void error(BaseDownloadTask task, Throwable e) { Toast.makeText(LineActivity.this, "下载失败", Toast.LENGTH_LONG).show(); dialog22.dismiss(); } @Override protected void warn(BaseDownloadTask task) { } }).start(); dialog.dismiss(); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show();
|