|
|
@@ -51,7 +51,7 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
private final int OBATIN_PDF_PATH = 100;
|
|
|
|
|
|
private PDFView mPDFView;
|
|
|
- private TextView mStateTextView, mRemainTextView, mReloadTextView, mExitTextView, mPauseTextView;
|
|
|
+ private TextView mStateTextView, mRemainTextView, mRedownloadTextView, mExitTextView, mPauseTextView, mLoadTextView;
|
|
|
private ProgressBar mDownloadProgressBar;
|
|
|
private RelativeLayout mDownloadRelativeLayout;
|
|
|
private LinearLayout mErrorLinearLayout;
|
|
|
@@ -63,6 +63,7 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
private long contentLength;
|
|
|
private long totalBytes;
|
|
|
private String replace;
|
|
|
+ private int mRetryTimes = 0;
|
|
|
|
|
|
private Handler mHandler = new Handler() {
|
|
|
@Override
|
|
|
@@ -72,7 +73,7 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
try {
|
|
|
int progress = (int) msg.obj;
|
|
|
Log.d("progress", progress + ":" + contentLength);
|
|
|
- mStateTextView.setText(R.string.str_loading);
|
|
|
+ mStateTextView.setText(R.string.str_downloading);
|
|
|
mDownloadProgressBar.setProgress(progress);
|
|
|
mRemainTextView.setText((100 - (((progress * 1024 * 100) / contentLength))) + "");
|
|
|
} catch (Exception e) {
|
|
|
@@ -82,14 +83,7 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
case Constants.CONSTANT.DOWNLOAD_SUCCESS:
|
|
|
mPauseTextView.setVisibility(View.GONE);
|
|
|
mStateTextView.setText("报表文件下载成功!\n正在加载....");
|
|
|
-// mDownloadProgressBar.setProgress(100);
|
|
|
mRemainTextView.setText("0");
|
|
|
- /*mDownloadRelativeLayout.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mDownloadRelativeLayout.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- }, 1000);*/
|
|
|
displayFromFile(new File(PDF_FILE_PATH, PDF_FILE_NAME));
|
|
|
break;
|
|
|
case Constants.CONSTANT.PDF_OVERLOAD:
|
|
|
@@ -116,9 +110,9 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
break;
|
|
|
case com.core.app.Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
result = msg.getData().getString("response");
|
|
|
- String exception = "";
|
|
|
+ String exception = "系统错误";
|
|
|
if (JSONUtil.validate(result)) {
|
|
|
- if (JSON.parse(result) instanceof JSONObject) {
|
|
|
+ if (JSON.parse(result) instanceof com.alibaba.fastjson.JSONObject) {
|
|
|
exception = JSON.parseObject(result).getString("exceptionInfo");
|
|
|
}
|
|
|
}
|
|
|
@@ -218,11 +212,17 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
.spacing(10)
|
|
|
.load();
|
|
|
} catch (Exception e) {
|
|
|
- mPauseTextView.setVisibility(View.GONE);
|
|
|
- mErrorLinearLayout.setVisibility(View.VISIBLE);
|
|
|
- mStateTextView.setText("报表文件加载失败!");
|
|
|
- mDownloadProgressBar.setProgress(0);
|
|
|
- mRemainTextView.setText(100 + "");
|
|
|
+ if (mRetryTimes <= 2) {
|
|
|
+ mRetryTimes++;
|
|
|
+ displayFromFile(new File(PDF_FILE_PATH, PDF_FILE_NAME));
|
|
|
+ } else {
|
|
|
+ mPauseTextView.setVisibility(View.GONE);
|
|
|
+ mErrorLinearLayout.setVisibility(View.VISIBLE);
|
|
|
+ mLoadTextView.setVisibility(View.VISIBLE);
|
|
|
+ mStateTextView.setText("报表文件加载失败!");
|
|
|
+ mDownloadProgressBar.setProgress(0);
|
|
|
+ mRemainTextView.setText(100 + "");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -237,6 +237,10 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
}
|
|
|
|
|
|
private void obtainPdfPath() {
|
|
|
+ mStateTextView.setText(R.string.obtain_pdf_path);
|
|
|
+ mDownloadProgressBar.setProgress(0);
|
|
|
+ mRemainTextView.setText(100 + "");
|
|
|
+
|
|
|
String url = replace + "report/pdf/path";
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("u", CommonUtil.getSharedPreferences(ct, "erp_master"));
|
|
|
@@ -279,17 +283,19 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
mRemainTextView = (TextView) findViewById(R.id.pdf_download_remain_tv);
|
|
|
mDownloadProgressBar = (ProgressBar) findViewById(R.id.pdf_download_progress_pb);
|
|
|
mDownloadRelativeLayout = (RelativeLayout) findViewById(R.id.pdf_download_progress_rl);
|
|
|
- mReloadTextView = (TextView) findViewById(R.id.pdf_download_reload_tv);
|
|
|
+ mRedownloadTextView = (TextView) findViewById(R.id.pdf_download_redownload_tv);
|
|
|
mExitTextView = (TextView) findViewById(R.id.pdf_download_exit_tv);
|
|
|
mErrorLinearLayout = (LinearLayout) findViewById(R.id.pdf_download_error_menu_ll);
|
|
|
mPauseTextView = (TextView) findViewById(R.id.pdf_download_pause_tv);
|
|
|
+ mLoadTextView = (TextView) findViewById(R.id.pdf_download_load_tv);
|
|
|
}
|
|
|
|
|
|
private void initEvents() {
|
|
|
mExitTextView.setOnClickListener(this);
|
|
|
- mReloadTextView.setOnClickListener(this);
|
|
|
+ mRedownloadTextView.setOnClickListener(this);
|
|
|
mDownloadRelativeLayout.setOnClickListener(this);
|
|
|
mPauseTextView.setOnClickListener(this);
|
|
|
+ mLoadTextView.setOnClickListener(this);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -298,9 +304,11 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
case R.id.pdf_download_exit_tv:
|
|
|
onBackPressed();
|
|
|
break;
|
|
|
- case R.id.pdf_download_reload_tv:
|
|
|
- mStateTextView.setText(R.string.str_loading);
|
|
|
+ case R.id.pdf_download_redownload_tv:
|
|
|
+ mStateTextView.setText(R.string.str_downloading);
|
|
|
mErrorLinearLayout.setVisibility(View.GONE);
|
|
|
+ mDownloadProgressBar.setProgress(0);
|
|
|
+ mRemainTextView.setText(100 + "");
|
|
|
// PDFUtils.downloadPDF(downloadUrl, mHandler);
|
|
|
if (TextUtils.isEmpty(downloadUrl)) {
|
|
|
obtainPdfPath();
|
|
|
@@ -311,16 +319,27 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
case R.id.pdf_download_pause_tv:
|
|
|
if (getString(R.string.pause_download).equals(mPauseTextView.getText().toString())) {
|
|
|
mPauseTextView.setText(R.string.continue_download);
|
|
|
+ mStateTextView.setText(R.string.download_paused);
|
|
|
mDownloader.pause();
|
|
|
ToastUtil.showToast(this, "下载暂停");
|
|
|
// 存储此时的totalBytes,即断点位置。
|
|
|
breakPoints = totalBytes;
|
|
|
} else if (getString(R.string.continue_download).equals(mPauseTextView.getText().toString())) {
|
|
|
mPauseTextView.setText(R.string.pause_download);
|
|
|
+ mStateTextView.setText(R.string.str_downloading);
|
|
|
ToastUtil.showToast(this, "下载继续");
|
|
|
mDownloader.download(breakPoints);
|
|
|
}
|
|
|
break;
|
|
|
+ case R.id.pdf_download_load_tv:
|
|
|
+ mRetryTimes = 0;
|
|
|
+ mErrorLinearLayout.setVisibility(View.GONE);
|
|
|
+ mLoadTextView.setVisibility(View.GONE);
|
|
|
+ mStateTextView.setText(R.string.str_reloading);
|
|
|
+ mDownloadProgressBar.setProgress((int) (contentLength / 1024));
|
|
|
+ mRemainTextView.setText(0 + "");
|
|
|
+ displayFromFile(new File(PDF_FILE_PATH, PDF_FILE_NAME));
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -352,12 +371,17 @@ public class PDFDownloadActivity extends BaseActivity implements View.OnClickLis
|
|
|
|
|
|
@Override
|
|
|
public void onError(Throwable t) {
|
|
|
- Log.e("pdfloaderror", t.getMessage() == null ? "" : t.getMessage());
|
|
|
- mPauseTextView.setVisibility(View.GONE);
|
|
|
- mErrorLinearLayout.setVisibility(View.VISIBLE);
|
|
|
- mStateTextView.setText("报表文件加载失败!");
|
|
|
- mDownloadProgressBar.setProgress(0);
|
|
|
- mRemainTextView.setText(100 + "");
|
|
|
+ if (mRetryTimes <= 2) {
|
|
|
+ mRetryTimes++;
|
|
|
+ displayFromFile(new File(PDF_FILE_PATH, PDF_FILE_NAME));
|
|
|
+ } else {
|
|
|
+ mPauseTextView.setVisibility(View.GONE);
|
|
|
+ mErrorLinearLayout.setVisibility(View.VISIBLE);
|
|
|
+ mLoadTextView.setVisibility(View.VISIBLE);
|
|
|
+ mStateTextView.setText("报表文件加载失败!");
|
|
|
+ mDownloadProgressBar.setProgress(0);
|
|
|
+ mRemainTextView.setText(100 + "");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|