正在查看: AdaModal v1.4.0 应用的 TWebActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: AdaModal v1.4.0 应用的 TWebActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.common.fine.activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.net.MailTo;
import androidx.databinding.DataBindingUtil;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.StringUtils;
import com.common.fine.R;
import com.common.fine.databinding.ActivitySonicWebBinding;
import com.common.fine.utils.ExpUtils;
import com.common.fine.utils.jsbridge.FileChooserAdapter;
import com.common.fine.utils.twebview.OneWayFuncRegister;
import com.common.fine.utils.twebview.TWebViewClient;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class TWebActivity extends AppCompatActivity {
private ActivitySonicWebBinding binding;
private FileChooserAdapter mFileChooserAdapter;
private String mHomeUrl;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
ActivitySonicWebBinding activitySonicWebBinding = (ActivitySonicWebBinding) DataBindingUtil.setContentView(this, R.layout.activity_sonic_web);
this.binding = activitySonicWebBinding;
activitySonicWebBinding.statusLayout.setRetryListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
TWebActivity.this.lambda$onCreate$0(view);
}
});
setupToolbar();
String stringExtra = getIntent().getStringExtra("url");
this.mHomeUrl = stringExtra;
if (!StringUtils.isTrimEmpty(stringExtra)) {
initWebView(this.mHomeUrl);
}
EventBus.getDefault().register(this);
}
public void lambda$onCreate$0(View view) {
reloadWebView();
}
private void setupToolbar() {
try {
this.binding.webToolbar.setVisibility(0);
setSupportActionBar(this.binding.webToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} catch (Exception e) {
ExpUtils.show(e);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == 16908332) {
finish();
return true;
}
return super.onOptionsItemSelected(menuItem);
}
private void initWebView(String str) {
getWindow().addFlags(16777216);
this.mFileChooserAdapter = new FileChooserAdapter(this);
this.binding.webViewWeb.setWebChromeClient(getChromeClient());
this.binding.webViewWeb.setWebViewClient(getWebViewClient());
this.binding.webViewWeb.setDownloadListener(getDownloadListener());
registerJavaHandlers();
if (!StringUtils.isTrimEmpty(str)) {
if (NetworkUtils.isConnected()) {
this.binding.statusLayout.showContent();
} else {
this.binding.statusLayout.showNoNetwork();
}
this.binding.webViewWeb.loadUrl(str);
return;
}
this.binding.statusLayout.showError();
}
public void reloadWebView() {
if (this.binding.webViewWeb != null) {
if (NetworkUtils.isConnected()) {
this.binding.webViewWeb.reload();
this.binding.statusLayout.setStatus(1);
} else {
this.binding.statusLayout.setStatus(2);
}
}
}
@Override
public void onBackPressed() {
if (this.binding.webViewWeb.canGoBack()) {
this.binding.webViewWeb.goBack();
} else {
super.onBackPressed();
}
}
private void registerJavaHandlers() {
OneWayFuncRegister.registerOneWayHandlers(this.binding.webViewWeb, this);
}
@Override
@Subscribe(threadMode = ThreadMode.MAIN)
protected void onActivityResult(int i, int i2, Intent intent) {
super.onActivityResult(i, i2, intent);
this.mFileChooserAdapter.onActivityResult(i, i2, intent);
}
private WebChromeClient getChromeClient() {
return new WebChromeClient() {
@Override
public void onProgressChanged(WebView webView, int i) {
super.onProgressChanged(webView, i);
if (i > 0 && i < 100) {
TWebActivity.this.binding.webViewProgress.setProgress(i);
TWebActivity.this.binding.webViewProgress.setVisibility(0);
} else {
TWebActivity.this.binding.webViewProgress.setVisibility(8);
}
}
@Override
public void onReceivedTitle(WebView webView, String str) {
super.onReceivedTitle(webView, str);
}
public void openFileChooser(ValueCallback<Uri> valueCallback, String str, String str2) {
TWebActivity.this.mFileChooserAdapter.openFileChooser(valueCallback, str, str2);
}
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
return TWebActivity.this.mFileChooserAdapter.onShowFileChooser(webView, valueCallback, fileChooserParams);
}
};
}
private DownloadListener getDownloadListener() {
return new DownloadListener() {
@Override
public final void onDownloadStart(String str, String str2, String str3, String str4, long j) {
TWebActivity.this.lambda$getDownloadListener$1(str, str2, str3, str4, j);
}
};
}
public void lambda$getDownloadListener$1(String str, String str2, String str3, String str4, long j) {
startBrowseAction(str);
}
public void startBrowseAction(String str) {
try {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
intent.setData(Uri.parse(str));
startActivity(intent);
} catch (Exception e) {
ExpUtils.show(e);
}
}
private WebViewClient getWebViewClient() {
return new TWebViewClient() {
@Override
public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
if (webResourceRequest.isForMainFrame()) {
TWebActivity.this.binding.statusLayout.showError();
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
if (str != null && (str.startsWith(MailTo.MAILTO_SCHEME) || str.startsWith("tel:"))) {
TWebActivity.this.startBrowseAction(str);
return true;
}
return super.shouldOverrideUrlLoading(webView, str);
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
try {
return shouldOverrideUrlLoading(webView, webResourceRequest.getUrl().toString());
} catch (Exception e) {
ExpUtils.show(e);
return super.shouldOverrideUrlLoading(webView, webResourceRequest);
}
}
};
}
@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}
}