导航菜单

页面标题

页面副标题

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

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

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


package com.mcb.stjohnsemschool.activity;

import android.app.ProgressDialog;
import android.content.Context;
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.util.Base64;
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.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import com.google.android.gcm.GCMConstants;
import com.google.firebase.analytics.FirebaseAnalytics;
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;

public class ReportCardActivity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "com.mcb.stjohnsemschool.activity.ReportCardActivity";
    static String base64String = "";
    public static AppCompatActivity myActivity;
    private int branchSectionId;
    private ConnectivityManager conMgr;
    Context context;
    ImageView mDownload;
    private SharedPreferences.Editor mEditor;
    ImageView mEmail;
    private ProgressDialog mProgress;
    private SharedPreferences mSharedPref;
    WebView mreportCardView;
    private int studentEnrollmentId;
    private int term;
    private String termName;
    private String yearId;
    private String reportCardUrl = "";
    private String studentGuid = "";

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_fee_transaction_receipt);
        this.context = getApplicationContext();
        myActivity = this;
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        this.mProgress = ProgressDialog.show(myActivity, "", "Please wait for a moment...");
        if (Build.VERSION.SDK_INT >= 23) {
            getMultiplePermissions();
        }
        setUpIds();
    }

    private void setUpIds() {
        SharedPreferences sharedPreferences = this.context.getSharedPreferences("", 0);
        this.mSharedPref = sharedPreferences;
        this.mEditor = sharedPreferences.edit();
        Bundle extras = getIntent().getExtras();
        this.yearId = extras.getString("academicyearId");
        this.term = extras.getInt("TermId", 0);
        getSupportActionBar().setTitle(extras.getString("TermName", "Report Card"));
        this.branchSectionId = Integer.parseInt(this.mSharedPref.getString("BranchSectionIDKey", "0"));
        this.studentEnrollmentId = Integer.parseInt(this.mSharedPref.getString("studentEnrollmentIdKey", "0"));
        this.reportCardUrl = getString(R.string.payonline_url) + "/ReportCard";
        this.studentGuid = this.mSharedPref.getString("StudentGUID", "");
        this.mEmail = (ImageView) findViewById(R.id.img_email);
        this.mDownload = (ImageView) findViewById(R.id.img_download);
        this.mreportCardView = (WebView) findViewById(2131364517);
        this.mEmail.setVisibility(8);
        this.mDownload.setVisibility(8);
        this.mEmail.setOnClickListener(this);
        this.mDownload.setOnClickListener(this);
        WebSettings settings = this.mreportCardView.getSettings();
        settings.setLoadsImagesAutomatically(true);
        settings.setJavaScriptEnabled(true);
        settings.getAllowContentAccess();
        settings.setDomStorageEnabled(true);
        settings.setSupportMultipleWindows(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setAllowFileAccess(true);
        settings.setBuiltInZoomControls(true);
        settings.setDisplayZoomControls(false);
        settings.setLoadWithOverviewMode(true);
        settings.setUseWideViewPort(true);
        settings.setSupportZoom(true);
        settings.setDefaultTextEncodingName("utf-8");
        this.mreportCardView.addJavascriptInterface(new JavaScriptInterface(), GCMConstants.EXTRA_APPLICATION_PENDING_INTENT);
        this.mreportCardView.setScrollBarStyle(0);
        this.mreportCardView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
                super.onPageStarted(webView, str, bitmap);
            }

            @Override
            public void onPageFinished(WebView webView, String str) {
                if (ReportCardActivity.this.mProgress == null || !ReportCardActivity.this.mProgress.isShowing()) {
                    return;
                }
                ReportCardActivity.this.mProgress.dismiss();
            }
        });
        this.mreportCardView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int i, KeyEvent keyEvent) {
                if (i != 4 || !ReportCardActivity.this.mreportCardView.canGoBack()) {
                    return false;
                }
                ReportCardActivity.this.mreportCardView.goBack();
                return true;
            }
        });
        this.mreportCardView.setWebChromeClient(new WebChromeClient() {
            @Override
            public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
                return super.onJsAlert(webView, str, str2, jsResult);
            }
        });
        this.mreportCardView.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String str, String str2, String str3, String str4, long j) {
                ReportCardActivity.this.mDownload.setVisibility(0);
                ReportCardActivity.this.mreportCardView.loadUrl(JavaScriptInterface.getBase64StringFromBlobUrl(str));
                if (ReportCardActivity.this.mProgress.isShowing()) {
                    ReportCardActivity.this.mProgress.dismiss();
                }
            }
        });
        this.mreportCardView.loadUrl(this.reportCardUrl + "/" + this.studentGuid + "/" + String.valueOf(this.yearId) + "/" + String.valueOf(this.term));
    }

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

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

    public static class JavaScriptInterface {
        @JavascriptInterface
        public void getBase64FromBlobData(String str) throws IOException {
            ReportCardActivity.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 {
        if (base64String.length() != 0) {
            File file = new File(this.context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + "/" + DateFormat.getDateTimeInstance().format(new Date()) + ".pdf");
            byte[] decode = Base64.decode(base64String, 0);
            FileOutputStream fileOutputStream = new FileOutputStream(file, false);
            fileOutputStream.write(decode);
            fileOutputStream.flush();
            if (file.exists()) {
                showPdf(file.getAbsolutePath());
                return;
            }
            return;
        }
        Utility.showInfoDialog(myActivity, "Unable to download now!");
    }

    private 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(this.context, this.context.getPackageName() + ".fileprovider", file);
            this.context.grantUriPermission(this.context.getPackageName() + ".fileprovider", uriForFile, 3);
            intent.setFlags(268435457);
            intent.setDataAndType(uriForFile, mimeTypeFromExtension);
            try {
                this.context.startActivity(intent);
            } catch (Exception unused) {
                Utility.showInfoDialog(myActivity, "No handler for this type of file./ No file has found. Please download the docs supported App from Play store to view the file.");
            }
        } catch (Exception unused2) {
            Utility.showInfoDialog(myActivity, "Please download the Docs supported App from Play store to view the file./ No file has found");
        }
    }

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

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