正在查看: St.John's v1.0.9 应用的 EvaluationReportCardActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: St.John's v1.0.9 应用的 EvaluationReportCardActivity.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.Uri;
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 EvaluationReportCardActivity extends AppCompatActivity implements View.OnClickListener {
private static final String TAG = "com.mcb.stjohnsemschool.activity.EvaluationReportCardActivity";
static String base64String = "";
public static AppCompatActivity myActivity;
Context context;
ImageView mDownload;
ImageView mEmail;
private ProgressDialog mProgress;
WebView mreportCardView;
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);
setUpIds();
}
private void setUpIds() {
SharedPreferences sharedPreferences = this.context.getSharedPreferences("", 0);
this.studentGuid = sharedPreferences.getString("StudentGUID", "");
this.reportCardUrl = getString(R.string.payonline_url) + "/EvaluationReportCard";
this.mProgress = ProgressDialog.show(this, "", "Please wait for a moment...");
Bundle extras = getIntent().getExtras();
int i = extras.getInt("TermId", 0);
String string = extras.getString("EvaluationId", "0");
int i2 = extras.getInt("AcademicYearId", 0);
getSupportActionBar().setTitle(extras.getString("TermName", "Evaluation Report Card"));
getSupportActionBar().setSubtitle(extras.getString("Evaluation", ""));
Integer.parseInt(sharedPreferences.getString("BranchSectionIDKey", "0"));
Integer.parseInt(sharedPreferences.getString("studentEnrollmentIdKey", "0"));
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);
WebView webView = (WebView) findViewById(2131364517);
this.mreportCardView = webView;
WebSettings settings = webView.getSettings();
settings.setLoadsImagesAutomatically(true);
settings.setJavaScriptEnabled(true);
settings.getAllowContentAccess();
settings.setDomStorageEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
settings.setAllowFileAccess(false);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
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 onPageFinished(WebView webView2, String str) {
}
@Override
public void onPageStarted(WebView webView2, String str, Bitmap bitmap) {
super.onPageStarted(webView2, str, bitmap);
}
});
this.mreportCardView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i3, KeyEvent keyEvent) {
if (i3 != 4 || !EvaluationReportCardActivity.this.mreportCardView.canGoBack()) {
return false;
}
EvaluationReportCardActivity.this.mreportCardView.goBack();
return true;
}
});
this.mreportCardView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView webView2, String str, String str2, JsResult jsResult) {
return super.onJsAlert(webView2, str, str2, jsResult);
}
});
this.mreportCardView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String str, String str2, String str3, String str4, long j) {
EvaluationReportCardActivity.this.mDownload.setVisibility(0);
if (EvaluationReportCardActivity.this.mProgress != null && EvaluationReportCardActivity.this.mProgress.isShowing()) {
EvaluationReportCardActivity.this.mProgress.dismiss();
}
EvaluationReportCardActivity.this.mreportCardView.loadUrl(JavaScriptInterface.getBase64StringFromBlobUrl(str));
}
});
this.mreportCardView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i3, KeyEvent keyEvent) {
if (i3 != 4 || !EvaluationReportCardActivity.this.mreportCardView.canGoBack()) {
return false;
}
EvaluationReportCardActivity.this.mreportCardView.goBack();
return true;
}
});
this.mreportCardView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView webView2, String str, String str2, JsResult jsResult) {
return super.onJsAlert(webView2, str, str2, jsResult);
}
});
String str = this.reportCardUrl + "/" + this.studentGuid + "/" + i2 + "/" + i + "/" + string;
this.reportCardUrl = str;
this.mreportCardView.loadUrl(str);
}
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == 16908332) {
super.onBackPressed();
return true;
}
return super.onOptionsItemSelected(menuItem);
}
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_EVALUATION_REPORT_CARD", bundle);
}
@Override
public void onClick(View view) {
if (view == this.mDownload) {
try {
convertBase64StringToPdfAndStoreIt();
} catch (IOException e) {
e.printStackTrace();
}
}
}
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 static class JavaScriptInterface {
@JavascriptInterface
public void getBase64FromBlobData(String str) throws IOException {
EvaluationReportCardActivity.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');";
}
}
public void onBackPressed() {
if (this.mreportCardView.canGoBack()) {
this.mreportCardView.goBack();
} else {
super.onBackPressed();
}
}
}