导航菜单

页面标题

页面副标题

St.John's v1.0.9 - FeeTransactionReceiptActivity.java 源代码

正在查看: St.John's v1.0.9 应用的 FeeTransactionReceiptActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mcb.stjohnsemschool.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintManager;
import android.util.Base64;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.JavascriptInterface;
import android.webkit.JsResult;
import android.webkit.MimeTypeMap;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.FileProvider;
import com.google.android.gcm.GCMConstants;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.mcb.stjohnsemschool.services.ApiClient;
import com.mcb.stjohnsemschool.services.ApiInterface;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.Utility;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class FeeTransactionReceiptActivity extends BaseActivity implements View.OnClickListener {
    static String base64String = "";
    static Context mContext;
    public static ProgressDialog mProgress;
    public static Activity myActivity;
    ImageView mDownload;
    ImageView mEmail;
    private TransparentProgressDialog mProgressbar;
    private SharedPreferences mSharedPref;
    WebView webView;
    String url = "";
    String userId = "0";
    String studentEnrolmentId = "0";
    String orgId = "0";
    String transactionId = "";

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_fee_transaction_receipt);
        mContext = getApplicationContext();
        myActivity = this;
        this.mProgressbar = new TransparentProgressDialog(myActivity, R.drawable.spinner_loading_imag);
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("", 0);
        this.mSharedPref = sharedPreferences;
        this.userId = sharedPreferences.getString("UseridKey", this.userId);
        this.studentEnrolmentId = this.mSharedPref.getString("studentEnrollmentIdKey", this.studentEnrolmentId);
        this.orgId = this.mSharedPref.getString("orgnizationIdKey", this.orgId);
        if (Build.VERSION.SDK_INT >= 23) {
            getMultiplePermissions();
        }
        this.url = getIntent().getStringExtra("PaymentReceiptDownloadUrl");
        this.transactionId = getIntent().getStringExtra("TransactionId");
        getSupportActionBar().setTitle("Fee Receipt");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mProgress = ProgressDialog.show(myActivity, "", "Please wait for a moment...");
        this.webView = (WebView) findViewById(2131364517);
        this.mEmail = (ImageView) findViewById(R.id.img_email);
        this.mDownload = (ImageView) findViewById(R.id.img_download);
        this.mEmail.setVisibility(8);
        this.mDownload.setVisibility(8);
        this.mEmail.setOnClickListener(this);
        this.mDownload.setOnClickListener(this);
        this.webView.getSettings().setLoadsImagesAutomatically(true);
        this.webView.getSettings().setJavaScriptEnabled(true);
        this.webView.getSettings().getAllowContentAccess();
        this.webView.getSettings().setDomStorageEnabled(true);
        this.webView.getSettings().setSupportMultipleWindows(true);
        this.webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        this.webView.getSettings().setAllowFileAccess(true);
        this.webView.getSettings().setBuiltInZoomControls(true);
        this.webView.getSettings().setDisplayZoomControls(false);
        this.webView.getSettings().setLoadWithOverviewMode(true);
        this.webView.getSettings().setUseWideViewPort(true);
        this.webView.addJavascriptInterface(new JavaScriptInterface(), GCMConstants.EXTRA_APPLICATION_PENDING_INTENT);
        this.webView.setScrollBarStyle(0);
        this.webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
                return super.onJsAlert(webView, str, str2, jsResult);
            }
        });
        this.webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String str) {
                return false;
            }

            @Override
            public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
                super.onPageStarted(webView, str, bitmap);
            }

            @Override
            public void onPageFinished(WebView webView, String str) {
                super.onPageFinished(webView, str);
            }
        });
        this.webView.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String str, String str2, String str3, String str4, long j) {
                if (FeeTransactionReceiptActivity.mProgress.isShowing()) {
                    FeeTransactionReceiptActivity.mProgress.dismiss();
                }
                FeeTransactionReceiptActivity.this.mEmail.setVisibility(0);
                FeeTransactionReceiptActivity.this.mDownload.setVisibility(0);
                FeeTransactionReceiptActivity.this.webView.loadUrl(JavaScriptInterface.getBase64StringFromBlobUrl(str.replace("%3A", ":")));
            }
        });
        this.webView.loadUrl(this.url);
        this.webView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int i, KeyEvent keyEvent) {
                if (i != 4 || !FeeTransactionReceiptActivity.this.webView.canGoBack()) {
                    return false;
                }
                FeeTransactionReceiptActivity.this.webView.goBack();
                return true;
            }
        });
    }

    private void createWebPrintJob() {
        PrintManager printManager = (PrintManager) getSystemService("print");
        PrintDocumentAdapter createPrintDocumentAdapter = this.webView.createPrintDocumentAdapter();
        String str = getString(2131886124) + " Print";
        if (printManager != null) {
            printManager.print(str, createPrintDocumentAdapter, new PrintAttributes.Builder().build());
        }
    }

    @Override
    public void onClick(View view) {
        if (view == this.mDownload) {
            try {
                convertBase64StringToPdfAndStoreIt();
                return;
            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
        }
        if (view == this.mEmail) {
            emailFeeReceipt();
        }
    }

    public static class JavaScriptInterface {
        @JavascriptInterface
        public void getBase64FromBlobData(String str) throws IOException {
            FeeTransactionReceiptActivity.base64String = str.replaceFirst("^data:application/pdf;base64,", "");
        }

        public static String getBase64StringFromBlobUrl(String str) {
            if (str.startsWith("blob")) {
                return "javascript: var xhr = new XMLHttpRequest();xhr.open('GET', '" + str + "', true);xhr.setRequestHeader('Access-Control-Allow-Origin','*');xhr.setRequestHeader('Content-type','application/pdf');xhr.responseType = 'blob';xhr.onload = function(e) {    if (this.status == 200) {        var blobPdf = this.response;        var reader = new FileReader();        reader.readAsDataURL(blobPdf);        reader.onloadend = function() {            base64data = reader.result;            app.getBase64FromBlobData(base64data);        }    }};xhr.send();";
            }
            return "javascript: console.log('It is not a Blob URL');";
        }
    }

    private void convertBase64StringToPdfAndStoreIt() throws IOException {
        DateFormat.getDateTimeInstance().format(new Date());
        File file = new File(getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + "/" + this.transactionId + ".pdf");
        byte[] decode = Base64.decode(base64String, 0);
        FileOutputStream fileOutputStream = new FileOutputStream(file, false);
        fileOutputStream.write(decode);
        fileOutputStream.flush();
        if (file.exists()) {
            showPdf(file.getAbsolutePath());
        }
    }

    public static void showPdf(String str) {
        try {
            String lowerCase = str.substring(str.lastIndexOf(".") + 1).toLowerCase();
            File file = new File(str);
            MimeTypeMap singleton = MimeTypeMap.getSingleton();
            Intent intent = new Intent("android.intent.action.VIEW");
            String mimeTypeFromExtension = singleton.getMimeTypeFromExtension(lowerCase);
            Uri uriForFile = FileProvider.getUriForFile(mContext, mContext.getPackageName() + ".fileprovider", file);
            mContext.grantUriPermission(mContext.getPackageName() + ".fileprovider", uriForFile, 3);
            intent.setFlags(268435457);
            intent.setDataAndType(uriForFile, mimeTypeFromExtension);
            try {
                mContext.startActivity(intent);
            } catch (Exception unused) {
                Toast.makeText(mContext, "No handler for this type of file./ No file has found", 0).show();
                Toast.makeText(mContext, "Please download the Docs supported App from Play store to view the file", 0).show();
            }
        } catch (Exception unused2) {
            Toast.makeText(mContext, "Please download the Docs supported App from Play store to view the file./ No file has found", 0).show();
        }
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == 16908332) {
            super.onBackPressed();
            finish();
            return true;
        }
        return super.onOptionsItemSelected(menuItem);
    }

    public void onBackPressed() {
        if (this.webView.canGoBack()) {
            this.webView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    private void emailFeeReceipt() {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
        if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
            sendReceiptEmail();
        } else {
            Toast.makeText(mContext, "Check your Network Connection", 0).show();
        }
    }

    private void sendReceiptEmail() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        HashMap hashMap = new HashMap();
        hashMap.put("MCBTransactionID", this.transactionId);
        hashMap.put("FileName", this.transactionId + ".pdf");
        hashMap.put("FileBytes", base64String);
        hashMap.put("apikey", Utility.getSchoolApiKey(mContext));
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).SendReceiptEmail(hashMap).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                if (FeeTransactionReceiptActivity.this.mProgressbar != null && FeeTransactionReceiptActivity.this.mProgressbar.isShowing()) {
                    FeeTransactionReceiptActivity.this.mProgressbar.dismiss();
                }
                if (response != null && response.body() != null) {
                    String str = (String) response.body();
                    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(FeeTransactionReceiptActivity.myActivity, R.style.MyDialogTheme));
                    builder.setMessage(str).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                        }
                    }).setCancelable(false);
                    builder.create().show();
                    return;
                }
                Utility.showAlertDialog(FeeTransactionReceiptActivity.myActivity);
            }

            public void onFailure(Call<String> call, Throwable th) {
                if (FeeTransactionReceiptActivity.this.mProgressbar != null && FeeTransactionReceiptActivity.this.mProgressbar.isShowing()) {
                    FeeTransactionReceiptActivity.this.mProgressbar.dismiss();
                }
                Utility.showAlertDialog(FeeTransactionReceiptActivity.myActivity);
            }
        });
    }

    protected void onResume() {
        super.onResume();
        String string = this.mSharedPref.getString("usernamekey", "");
        Bundle bundle = new Bundle();
        bundle.putString("user_name", string);
        FirebaseAnalytics.getInstance(this).logEvent("PAGE_FEE_TRANSACTION_RECEIPT", bundle);
    }

    protected void onStop() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && transparentProgressDialog.isShowing()) {
            this.mProgressbar.dismiss();
        }
        super.onStop();
    }
}