|
|
@@ -1,207 +0,0 @@
|
|
|
-package com.xzjmyk.pm.activity.ui.erp.activity.datainquiry.activity;
|
|
|
-
|
|
|
-import android.content.Intent;
|
|
|
-import android.graphics.Canvas;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.os.Handler;
|
|
|
-import android.os.Message;
|
|
|
-import android.util.Log;
|
|
|
-import android.view.View;
|
|
|
-import android.widget.LinearLayout;
|
|
|
-import android.widget.ProgressBar;
|
|
|
-import android.widget.RelativeLayout;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.github.barteksc.pdfviewer.PDFView;
|
|
|
-import com.github.barteksc.pdfviewer.listener.OnDrawListener;
|
|
|
-import com.github.barteksc.pdfviewer.listener.OnErrorListener;
|
|
|
-import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
|
|
|
-import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
|
|
|
-import com.github.barteksc.pdfviewer.listener.OnPageScrollListener;
|
|
|
-import com.github.barteksc.pdfviewer.listener.OnRenderListener;
|
|
|
-import com.xzjmyk.pm.activity.R;
|
|
|
-import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.activity.datainquiry.Constants;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.activity.datainquiry.PDFUtils;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by RaoMeng on 2017/8/17.
|
|
|
- * 报表统计PDF文件下载并展示页面
|
|
|
- */
|
|
|
-public class PDFDownloadActivity extends BaseActivity implements View.OnClickListener, OnDrawListener, OnLoadCompleteListener, OnPageChangeListener, OnPageScrollListener, OnErrorListener, OnRenderListener {
|
|
|
- private PDFView mPDFView;
|
|
|
- private TextView mStateTextView, mRemainTextView, mReloadTextView, mExitTextView;
|
|
|
- private ProgressBar mDownloadProgressBar;
|
|
|
- private RelativeLayout mDownloadRelativeLayout;
|
|
|
- private LinearLayout mErrorLinearLayout;
|
|
|
- private String downloadUrl = "", mReportName = "";
|
|
|
- private String mCondition;
|
|
|
-
|
|
|
- private Handler mHandler = new Handler() {
|
|
|
- @Override
|
|
|
- public void handleMessage(Message msg) {
|
|
|
- switch (msg.what) {
|
|
|
- case Constants.CONSTANT.DOWNLOAD_PROGRESS:
|
|
|
- try {
|
|
|
- int progress = (int) msg.obj;
|
|
|
- Log.d("progress", progress + "");
|
|
|
- mStateTextView.setText(R.string.str_loading);
|
|
|
- mDownloadProgressBar.setProgress(progress);
|
|
|
- mRemainTextView.setText((100 - progress) + "");
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- break;
|
|
|
- case Constants.CONSTANT.DOWNLOAD_SUCCESS:
|
|
|
- mStateTextView.setText("报表文件下载成功!");
|
|
|
- mDownloadProgressBar.setProgress(100);
|
|
|
- mRemainTextView.setText("0");
|
|
|
- mDownloadRelativeLayout.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mDownloadRelativeLayout.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- }, 1000);
|
|
|
- displayFromFile(new File(Constants.CONSTANT.PDF_FILE_PATH, Constants.CONSTANT.PDF_FILE_NAME));
|
|
|
- break;
|
|
|
- case Constants.CONSTANT.PDF_OVERLOAD:
|
|
|
- mErrorLinearLayout.setVisibility(View.VISIBLE);
|
|
|
- mStateTextView.setText("数据量过载,报表文件获取失败!");
|
|
|
- mDownloadProgressBar.setProgress(0);
|
|
|
- mRemainTextView.setText(100 + "");
|
|
|
- break;
|
|
|
- case Constants.CONSTANT.DOWNLOAD_FAILED:
|
|
|
- mErrorLinearLayout.setVisibility(View.VISIBLE);
|
|
|
- String info = "";
|
|
|
- if (msg.obj != null) {
|
|
|
- info = "\n" + (String) msg.obj;
|
|
|
- }
|
|
|
- mStateTextView.setText("报表文件下载失败" + info);
|
|
|
- mDownloadProgressBar.setProgress(0);
|
|
|
- mRemainTextView.setText(100 + "");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- private void displayFromFile(File fileName) {
|
|
|
- mPDFView.fromFile(fileName)
|
|
|
-// .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
|
|
|
- .enableSwipe(true) // allows to block changing pages using swipe
|
|
|
- .swipeHorizontal(true)
|
|
|
- .enableDoubletap(true)
|
|
|
- .defaultPage(0)
|
|
|
- // allows to draw something on the current page, usually visible in the middle of the screen
|
|
|
- .onDraw(this)
|
|
|
- // allows to draw something on all pages, separately for every page. Called only for visible pages
|
|
|
- .onDrawAll(this)
|
|
|
- .onLoad(this) // called after document is loaded and starts to be rendered
|
|
|
- .onPageChange(this)
|
|
|
- .onPageScroll(this)
|
|
|
- .onError(this)
|
|
|
- .onRender(this) // called after document is rendered for the first time
|
|
|
- .enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
|
|
|
- .password(null)
|
|
|
- .scrollHandle(null)
|
|
|
- .enableAntialiasing(true) // improve rendering a little bit on low-res screens
|
|
|
- // spacing between pages in dp. To define spacing color, set view background
|
|
|
- .spacing(10)
|
|
|
- .load();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_pdf_download);
|
|
|
-
|
|
|
- initViews();
|
|
|
- initEvents();
|
|
|
- downloadPDF();
|
|
|
- }
|
|
|
-
|
|
|
- private void downloadPDF() {
|
|
|
- PDFUtils.downloadPDF(downloadUrl, mHandler);
|
|
|
- }
|
|
|
-
|
|
|
- private void initViews() {
|
|
|
- Intent intent = getIntent();
|
|
|
- if (intent != null) {
|
|
|
- mCondition = intent.getStringExtra("condition");
|
|
|
- mReportName = intent.getStringExtra("reportName");
|
|
|
- }
|
|
|
-
|
|
|
-// downloadUrl = com.xzjmyk.pm.activity.ui.erp.util.Constants.getAppBaseUrl(this)
|
|
|
-// + "report/pdf/data?u=" + CommonUtil.getSharedPreferences(ct, "erp_master")
|
|
|
-// + "&pf=phone&r=" + mReportName + "&w=" + mCondition;
|
|
|
-// downloadUrl = "http://192.168.253.60:8090/report/pdf/data?u=" + CommonUtil.getSharedPreferences(ct, "erp_master")
|
|
|
-// + "&pf=phone&r=" + mReportName + "&w=where " + mCondition;
|
|
|
- downloadUrl = "http://print.ubtob.com/report/pdf/data?u=" + CommonUtil.getSharedPreferences(ct, "erp_master")
|
|
|
- + "&pf=phone&r=" + mReportName + "&w=where " + mCondition;
|
|
|
-
|
|
|
- Log.d("downloadUrl", downloadUrl);
|
|
|
-
|
|
|
- mPDFView = (PDFView) findViewById(R.id.pdf_download_pdfview);
|
|
|
- mPDFView.useBestQuality(true);
|
|
|
-
|
|
|
- mStateTextView = (TextView) findViewById(R.id.pdf_download_state_tv);
|
|
|
- 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);
|
|
|
- mExitTextView = (TextView) findViewById(R.id.pdf_download_exit_tv);
|
|
|
- mErrorLinearLayout = (LinearLayout) findViewById(R.id.pdf_download_error_menu_ll);
|
|
|
- }
|
|
|
-
|
|
|
- private void initEvents() {
|
|
|
- mExitTextView.setOnClickListener(this);
|
|
|
- mReloadTextView.setOnClickListener(this);
|
|
|
- mDownloadRelativeLayout.setOnClickListener(this);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- switch (v.getId()) {
|
|
|
- case R.id.pdf_download_exit_tv:
|
|
|
- onBackPressed();
|
|
|
- break;
|
|
|
- case R.id.pdf_download_reload_tv:
|
|
|
- mStateTextView.setText(R.string.str_loading);
|
|
|
- mErrorLinearLayout.setVisibility(View.GONE);
|
|
|
- PDFUtils.downloadPDF(downloadUrl, mHandler);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void loadComplete(int nbPages) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onPageChanged(int page, int pageCount) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onPageScrolled(int page, float positionOffset) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(Throwable t) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onInitiallyRendered(int nbPages, float pageWidth, float pageHeight) {
|
|
|
- mPDFView.fitToWidth();
|
|
|
- }
|
|
|
-}
|