新疆交投路损赔补偿系统 v1.0.2版本的 MD5 值为:5e336668c8c96e65d739f00d1fa2a3b9

以下内容为反编译后的 App.java 源代码,内容仅作参考


package com.example.XjjtpmsApp;

import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.Toast;
import com.itextpdf.text.Annotation;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.io.PagedChannelRandomAccessSource;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfObject;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.cordova.CordovaActivity;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class App {
    File file_pdf;
    private WebView mAppView;
    private CordovaActivity mGap;
    ProgressDialog pd = null;
    String UPDATE_SERVERAPK = "XjjtpmsApp.apk";
    String ServerUrl = "http://gzzjyk.com/xjjtcs/framework/App/";
    String http_url = PdfObject.NOTHING;
    String download_flag = "0";
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            App.this.pd.cancel();
            App.this.update();
        }
    };
    Handler handler_pdf = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            App.this.pd.cancel();
            App.this.openpdfbyapplication();
        }
    };

    public App(CordovaActivity gap, WebView view) {
        this.mAppView = view;
        this.mGap = gap;
    }

    @JavascriptInterface
    public void loadUrl(String url) {
        openExternal(url);
    }

    public String openExternal(String url) {
        Intent intent;
        try {
            intent = new Intent("android.intent.action.VIEW");
        } catch (ActivityNotFoundException e) {
            e = e;
        }
        try {
            Uri uri = Uri.parse(url);
            if (!Annotation.FILE.equals(uri.getScheme())) {
                intent.setData(uri);
            }
            intent.putExtra("com.android.browser.application_id", this.mGap.getActivity().getPackageName());
            this.mGap.getActivity().startActivity(intent);
            return PdfObject.NOTHING;
        } catch (ActivityNotFoundException e2) {
            e = e2;
            return e.toString();
        }
    }

    public Intent getHtmlFileIntent(String param) {
        Uri uri = Uri.parse(param).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme(Annotation.CONTENT).encodedPath(param).build();
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setDataAndType(uri, "text/html");
        return intent;
    }

    @JavascriptInterface
    public void doNewVersionUpdate(String istest) {
        if (istest == "1") {
            this.ServerUrl = "http://gzzjyk.com/xjjtcs/framework/App/";
        }
        this.download_flag = "0";
        this.pd = new ProgressDialog(this.mAppView.getContext());
        this.pd.setTitle("正在下载");
        this.pd.setMessage("请稍后。。。");
        this.pd.setCanceledOnTouchOutside(false);
        this.pd.setProgressStyle(0);
        this.pd.setIndeterminate(false);
        this.pd.setProgressStyle(1);
        downFile(this.ServerUrl.concat("XjjtpmsApp.apk"));
    }

    @JavascriptInterface
    public void doPdfPlus() {
        this.download_flag = "1";
        this.pd = new ProgressDialog(this.mAppView.getContext());
        this.pd.setTitle("正在下载PDF插件");
        this.pd.setMessage("请稍后。。。");
        this.pd.setCanceledOnTouchOutside(false);
        this.pd.setProgressStyle(0);
        this.pd.setIndeterminate(false);
        this.pd.setProgressStyle(1);
        downFile(this.ServerUrl.concat("AdobeAcrobat.apk"));
    }

    @JavascriptInterface
    public void openPdf(String url) {
        this.http_url = url;
        this.pd = new ProgressDialog(this.mAppView.getContext());
        this.pd.setTitle("正在生成文书");
        this.pd.setMessage("请稍后。。。");
        this.pd.setCanceledOnTouchOutside(false);
        this.pd.setProgressStyle(0);
        downFile_Pdf(url);
    }

    @JavascriptInterface
    public void showtoast(String text) {
        Toast toast = Toast.makeText(this.mAppView.getContext(), text, 0);
        toast.show();
    }

    public static String getUrlName(String fileUrl) {
        try {
            String[] fileRoot = fileUrl.split("/");
            String fileName = fileRoot[fileRoot.length - 1];
            return fileName;
        } catch (Exception e) {
            e.printStackTrace();
            return PdfObject.NOTHING;
        }
    }

    public void downFile_Pdf(String url) {
        this.pd.show();
        new Thread() {
            @Override
            public void run() {
                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet(App.this.http_url);
                App.this.mGap.getActivity().getApplicationContext();
                try {
                    HttpResponse response = client.execute(get);
                    HttpEntity entity = response.getEntity();
                    entity.getContentLength();
                    InputStream is = entity.getContent();
                    FileOutputStream fileOutputStream = null;
                    if (is != null) {
                        File file = new File(Environment.getExternalStorageDirectory(), App.getUrlName(App.this.http_url));
                        App.this.file_pdf = file;
                        fileOutputStream = new FileOutputStream(file);
                        byte[] b = new byte[1024];
                        int count = 0;
                        while (true) {
                            int charb = is.read(b);
                            if (charb == -1) {
                                break;
                            }
                            fileOutputStream.write(b, 0, charb);
                            count += charb;
                        }
                    }
                    fileOutputStream.flush();
                    if (fileOutputStream != null) {
                        fileOutputStream.close();
                    }
                    App.this.down_pdf();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    public void downFile(final String url) {
        this.pd.show();
        new Thread() {
            @Override
            public void run() {
                String name;
                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet(url);
                try {
                    HttpResponse response = client.execute(get);
                    HttpEntity entity = response.getEntity();
                    long length = entity.getContentLength();
                    App.this.pd.setMax((int) length);
                    InputStream is = entity.getContent();
                    FileOutputStream fileOutputStream = null;
                    if (is != null) {
                        String str = App.this.UPDATE_SERVERAPK;
                        if (App.this.download_flag == "0") {
                            name = App.this.UPDATE_SERVERAPK;
                        } else {
                            name = "AdobeAcrobat.apk";
                        }
                        File file = new File(Environment.getExternalStorageDirectory(), name);
                        fileOutputStream = new FileOutputStream(file);
                        byte[] b = new byte[1024];
                        int count = 0;
                        while (true) {
                            int charb = is.read(b);
                            if (charb == -1) {
                                break;
                            }
                            fileOutputStream.write(b, 0, charb);
                            count += charb;
                            App.this.pd.setProgress(count);
                        }
                    }
                    fileOutputStream.flush();
                    if (fileOutputStream != null) {
                        fileOutputStream.close();
                    }
                    App.this.pd.setProgress(100);
                    App.this.down();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    public void down() {
        new Thread() {
            @Override
            public void run() {
                Message message = App.this.handler.obtainMessage();
                App.this.handler.sendMessage(message);
            }
        }.start();
    }

    public void update() {
        String name;
        Intent intent = new Intent("android.intent.action.VIEW");
        if (this.download_flag == "0") {
            name = this.UPDATE_SERVERAPK;
        } else {
            name = "AdobeAcrobat.apk";
        }
        intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory(), name)), "application/vnd.android.package-archive");
        this.mGap.startActivity(intent);
    }

    public void openpdfbyapplication() {
        this.mGap.getActivity().getApplicationContext();
        Uri path = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), getUrlName(this.http_url)));
        Intent pdfIntent = new Intent("android.intent.action.VIEW");
        pdfIntent.setDataAndType(path, "application/pdf");
        pdfIntent.setFlags(PagedChannelRandomAccessSource.DEFAULT_TOTAL_BUFSIZE);
        this.mGap.startActivity(pdfIntent);
    }

    public void down_pdf() {
        new Thread() {
            @Override
            public void run() {
                Message message = App.this.handler_pdf.obtainMessage();
                App.this.handler_pdf.sendMessage(message);
            }
        }.start();
    }

    @JavascriptInterface
    public Intent doPrinter(String args) {
        try {
            JSONArray jsonArray = new JSONArray(args);
            generateAll(jsonArray);
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public void generateAll(JSONArray jsonArray) throws JSONException {
        String[] pdfs = new String[jsonArray.length()];
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObj = jsonArray.getJSONObject(i);
            pdfs[i] = generateOne(jsonObj, i);
        }
        if (pdfs.length > 0) {
            String filePath = pdfs[0].substring(0, pdfs[0].lastIndexOf("/"));
            String savepath = String.valueOf(filePath) + "/all.pdf";
            morePdfTopdf(pdfs, savepath);
            openPdf_local(savepath);
        }
    }

    public String generateOne(JSONObject jsonObj, int index) throws JSONException {
        new ByteArrayOutputStream();
        InputStream mouldFilePath = getClass().getResourceAsStream("/assets/www/FileMould/" + jsonObj.getString("pdf_report_name") + ".pdf");
        String fileSavePath = Environment.getExternalStorageDirectory() + "/交投文书/" + index + ".pdf";
        File file = new File(Environment.getExternalStorageDirectory() + "/交投文书");
        if (!file.exists()) {
            file.mkdir();
        }
        try {
            PdfReader reader = new PdfReader(mouldFilePath);
            FileOutputStream fos = new FileOutputStream(fileSavePath);
            PdfStamper stamper = new PdfStamper(reader, fos);
            stamper.getUnderContent(1);
            BaseFont bf = BaseFont.createFont("/assets/www/font/simsun.ttc,0", BaseFont.IDENTITY_H, false);
            AcroFields form = stamper.getAcroFields();
            form.addSubstitutionFont(bf);
            form.setFieldProperty("companyOfSender", "textfont", bf, (int[]) null);
            Iterator it = jsonObj.keys();
            new ArrayList();
            while (it.hasNext()) {
                String key = it.next();
                String value = jsonObj.getString(key);
                form.setField(key, value);
            }
            stamper.setFormFlattening(true);
            stamper.close();
            reader.close();
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        return fileSavePath;
    }

    public static void morePdfTopdf(String[] files, String savepath) {
        Document document;
        Document document2 = null;
        try {
            try {
                document = new Document(new PdfReader(files[0]).getPageSize(1));
            } catch (Throwable th) {
                th = th;
            }
        } catch (DocumentException e) {
            e = e;
        } catch (IOException e2) {
            e = e2;
        }
        try {
            PdfCopy copy = new PdfCopy(document, new FileOutputStream(savepath));
            document.open();
            for (String str : files) {
                PdfReader reader = new PdfReader(str);
                int n = reader.getNumberOfPages();
                for (int j = 1; j <= n; j++) {
                    document.newPage();
                    PdfImportedPage page = copy.getImportedPage(reader, j);
                    copy.addPage(page);
                }
            }
            if (document != null) {
                document.close();
            }
            document2 = document;
        } catch (DocumentException e3) {
            e = e3;
            document2 = document;
            e.printStackTrace();
            if (document2 != null) {
                document2.close();
            }
        } catch (IOException e4) {
            e = e4;
            document2 = document;
            e.printStackTrace();
            if (document2 != null) {
                document2.close();
            }
        } catch (Throwable th2) {
            th = th2;
            document2 = document;
            if (document2 != null) {
                document2.close();
            }
            throw th;
        }
    }

    public void openPdf_local(String filePath) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/pdf");
        this.mGap.getActivity().startActivity(intent);
    }
}