正在查看: Online Loans v421.2.42 应用的 InAppWebViewDialog.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Online Loans v421.2.42 应用的 InAppWebViewDialog.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.infobip.mobile.messaging.interactive.inapp.view;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.PopupWindow;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import java.util.HashMap;
import java.util.Map;
import org.infobip.mobile.messaging.MobileMessagingCore;
import org.infobip.mobile.messaging.MobileMessagingProperty;
import org.infobip.mobile.messaging.R;
import org.infobip.mobile.messaging.api.support.util.ApiConstants;
import org.infobip.mobile.messaging.api.support.util.UserAgentUtil;
import org.infobip.mobile.messaging.app.ActivityLifecycleListener;
import org.infobip.mobile.messaging.app.ActivityLifecycleMonitor;
import org.infobip.mobile.messaging.interactive.NotificationAction;
import org.infobip.mobile.messaging.interactive.inapp.InAppWebViewMessage;
import org.infobip.mobile.messaging.interactive.inapp.view.InAppView;
import org.infobip.mobile.messaging.interactive.inapp.view.InAppWebViewDialog;
import org.infobip.mobile.messaging.logging.MobileMessagingLogger;
import org.infobip.mobile.messaging.platform.AndroidBroadcaster;
import org.infobip.mobile.messaging.platform.Time;
import org.infobip.mobile.messaging.util.PreferenceHelper;
import org.infobip.mobile.messaging.util.StringUtils;
import org.infobip.mobile.messaging.util.UserAgentAdditions;
public class InAppWebViewDialog implements InAppWebView, ActivityLifecycleListener {
public static final int ACTION_TYPE_CLOSE = 0;
public static final int ACTION_TYPE_OPEN = 1;
public static final String BANNER_CLICKED = "banner";
public static final String PRIMARY_BUTTON_CLICKED = "primary_button";
public static final double SCREEN_COVER_PERCENTAGE = 0.85d;
public static final int SCREEN_MARGINS = 16;
public static final String SET_START_ATTEMPTS = "0";
public static final int VERTICAL_SCROLLBAR_SIZE = 30;
public static final int WIDTH_PADDING = 16;
public static int l;
public final InAppView.Callback a;
public AndroidBroadcaster b;
public NotificationAction[] c;
public final DisplayMetrics d;
public PopupWindow e;
public WebView f;
public final ActivityWrapper g;
public InAppWebViewMessage h;
public ConnectionTimeoutHandler i = null;
public View j;
public CardView k;
@SuppressLint({"StaticFieldLeak"})
public class ConnectionTimeoutHandler extends AsyncTask<Void, Void, String> {
public Boolean b = Boolean.FALSE;
public final long a = Time.now();
public ConnectionTimeoutHandler() {
int unused = InAppWebViewDialog.l = 0;
}
@Override
public String doInBackground(Void... voidArr) {
while (!this.b.booleanValue()) {
if (InAppWebViewDialog.l != 100 && Time.now() - this.a > 20000) {
return "CONNECTION_TIMEOUT";
}
if (InAppWebViewDialog.l == 100) {
this.b = Boolean.TRUE;
}
}
return "PAGE_LOADED";
}
@Override
public void onPostExecute(String str) {
if ("CONNECTION_TIMEOUT".equalsIgnoreCase(str)) {
InAppWebViewDialog.F(-8);
InAppWebViewDialog.this.u();
}
}
}
public static class InAppWebChromeClient extends WebChromeClient {
@Override
public void onProgressChanged(WebView webView, int i) {
int unused = InAppWebViewDialog.l = i;
MobileMessagingLogger.d("[InAppWebViewDialog]", "Page progress [" + InAppWebViewDialog.l + "%]");
super.onProgressChanged(webView, i);
}
}
public class InAppWebViewInterface {
public InAppWebViewInterface() {
}
public final void b(int i) {
if (InAppWebViewDialog.this.z()) {
InAppWebViewDialog.this.b.notificationTapped(InAppWebViewDialog.this.h);
InAppView.Callback callback = InAppWebViewDialog.this.a;
InAppWebViewDialog inAppWebViewDialog = InAppWebViewDialog.this;
callback.notificationPressedFor(inAppWebViewDialog, inAppWebViewDialog.h, InAppWebViewDialog.this.c[i], InAppWebViewDialog.this.x());
d(InAppWebViewDialog.BANNER_CLICKED);
} else {
InAppView.Callback callback2 = InAppWebViewDialog.this.a;
InAppWebViewDialog inAppWebViewDialog2 = InAppWebViewDialog.this;
callback2.actionButtonPressedFor(inAppWebViewDialog2, inAppWebViewDialog2.h, null, InAppWebViewDialog.this.c[i]);
}
if (i == 1 && InAppWebViewDialog.this.e.isShowing()) {
d(InAppWebViewDialog.PRIMARY_BUTTON_CLICKED);
}
}
public final void c() {
b(0);
InAppWebViewDialog.this.e.dismiss();
InAppWebViewDialog.this.a.dismissed(InAppWebViewDialog.this);
InAppWebViewDialog.this.G(null);
InAppWebViewDialog.this.f.destroy();
}
@JavascriptInterface
public void close(String str) {
MobileMessagingLogger.d("[InAppWebViewDialog]", "close()");
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public final void run() {
InAppWebViewDialog.InAppWebViewInterface.this.c();
}
});
}
public final void d(String str) {
String userAgent = new UserAgentUtil().getUserAgent(UserAgentAdditions.getLibVersion(), UserAgentAdditions.getAdditions(InAppWebViewDialog.this.g.getActivity()));
if (StringUtils.isNotBlank(InAppWebViewDialog.this.h.clickUrl)) {
MobileMessagingCore.getInstance((Context) InAppWebViewDialog.this.x()).reportInAppClick(StringUtils.concat(StringUtils.concat(StringUtils.concat(InAppWebViewDialog.this.h.clickUrl, str, StringUtils.COMMA_WITH_SPACE), userAgent, StringUtils.COMMA_WITH_SPACE), "0", StringUtils.COMMA_WITH_SPACE));
}
}
@JavascriptInterface
public void heightRequested(float f) {
MobileMessagingLogger.d("[InAppWebViewDialog]", "onHeightChanged: " + f);
InAppWebViewDialog.this.M(f);
}
@JavascriptInterface
public void openAppPage(String str) {
MobileMessagingLogger.d("[InAppWebViewDialog]", "openAppPage: " + str);
InAppWebViewDialog.this.h.setDeeplink(str);
b(1);
InAppWebViewDialog.this.u();
}
@JavascriptInterface
public void openBrowser(String str) {
MobileMessagingLogger.d("[InAppWebViewDialog]", "openBrowser: " + str);
InAppWebViewDialog.this.h.setBrowserUrl(str);
b(1);
InAppWebViewDialog.this.u();
}
@JavascriptInterface
public void openWebView(String str) {
MobileMessagingLogger.d("[InAppWebViewDialog]", "openWebView: " + str);
InAppWebViewDialog.this.h.setWebViewUrl(str);
b(1);
InAppWebViewDialog.this.u();
}
}
public class a extends WebViewClient {
public final CardView a;
public a(CardView cardView) {
this.a = cardView;
}
@Override
public void onLoadResource(WebView webView, String str) {
super.onLoadResource(webView, str);
}
@Override
public void onPageCommitVisible(WebView webView, String str) {
MobileMessagingLogger.d("[InAppWebViewDialog]", "onPageCommitVisible()");
if (InAppWebViewDialog.this.h.type == InAppWebViewMessage.InAppWebViewType.BANNER) {
InAppWebViewDialog.this.f.loadUrl("javascript:window.InfobipMobileMessaging.readBodyHeight()");
}
if (InAppWebViewDialog.this.z()) {
InAppWebViewDialog.this.setDialogTimeout(6000);
}
InAppWebViewDialog inAppWebViewDialog = InAppWebViewDialog.this;
inAppWebViewDialog.L(this.a, inAppWebViewDialog.h.position, InAppWebViewDialog.this.h.type);
}
@Override
public void onPageFinished(WebView webView, String str) {
super.onPageFinished(webView, str);
ConnectionTimeoutHandler connectionTimeoutHandler = InAppWebViewDialog.this.i;
if (connectionTimeoutHandler != null) {
connectionTimeoutHandler.cancel(true);
InAppWebViewDialog.this.i = null;
}
}
@Override
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
InAppWebViewDialog.this.i = InAppWebViewDialog.this.new ConnectionTimeoutHandler();
InAppWebViewDialog.this.i.execute(new Void[0]);
super.onPageStarted(webView, str, bitmap);
}
@Override
public void onReceivedError(WebView webView, int i, String str, String str2) {
InAppWebViewDialog.F(i);
InAppWebViewDialog.this.u();
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
return false;
}
}
public static class b {
public static final int[] a;
static {
int[] iArr = new int[InAppWebViewMessage.InAppWebViewType.values().length];
a = iArr;
try {
iArr[InAppWebViewMessage.InAppWebViewType.BANNER.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
a[InAppWebViewMessage.InAppWebViewType.FULLSCREEN.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
public InAppWebViewDialog(InAppView.Callback callback, ActivityWrapper activityWrapper) {
this.a = callback;
this.g = activityWrapper;
DisplayMetrics displayMetrics = new DisplayMetrics();
this.d = displayMetrics;
x().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
w();
}
public static void F(int i) {
String str;
String str2;
String str3;
switch (i) {
case -15:
str = "Too many requests during this load";
str2 = "Too Many Requests";
break;
case -14:
str3 = "File not found";
str = str3;
str2 = "File";
break;
case -13:
str3 = "Generic file error";
str = str3;
str2 = "File";
break;
case -12:
str = "Check entered URL..";
str2 = "Malformed URL";
break;
case -11:
str = "Failed to perform SSL handshake";
str2 = "SSL Handshake Failed";
break;
case -10:
str = "Unsupported URI scheme";
str2 = "URI Scheme Error";
break;
case -9:
str = "Too many redirects";
str2 = "Redirect Loop Error";
break;
case -8:
str = "The server is taking too much time to communicate. Try again later.";
str2 = "Connection Timeout";
break;
case -7:
str = "The server failed to communicate. Try again later.";
str2 = "IO Error";
break;
case -6:
str = "Failed to connect to the server";
str2 = "Connection";
break;
case -5:
str = "User authentication failed on proxy";
str2 = "Proxy Auth Error";
break;
case -4:
str = "User authentication failed on server";
str2 = "Auth Error";
break;
case -3:
str = "Unsupported authentication scheme (not basic or digest)";
str2 = "Auth Scheme Error";
break;
case -2:
str = "Server or proxy hostname lookup failed";
str2 = "Host Lookup Error";
break;
case -1:
str = "Generic error";
str2 = "Unknown Error";
break;
default:
str = null;
str2 = null;
break;
}
if (str != null) {
MobileMessagingLogger.e("[InAppWebViewDialog]", str2 + ": " + str);
}
}
public static int v(float f, Context context) {
return Math.round(f * (context.getResources().getDisplayMetrics().densityDpi / 160.0f));
}
public final void A() {
if (this.f != null) {
this.a.dismissed(this);
this.f.clearHistory();
this.f.clearCache(true);
this.f.clearFormData();
this.f.clearMatches();
this.f.destroy();
this.f.setVisibility(8);
if (this.e.isShowing()) {
this.e.dismiss();
}
}
MobileMessagingLogger.d("[InAppWebViewDialog]", "Deleted local history");
}
public final void B() {
if (this.e.isShowing()) {
this.e.dismiss();
this.a.dismissed(this);
}
}
public final void D(InAppWebViewMessage inAppWebViewMessage) {
View inflate = x().getLayoutInflater().inflate(R.layout.ib_inapp_webview, (ViewGroup) null, false);
this.j = inflate;
this.k = inflate.findViewById(R.id.webview_dialog_card);
if (inAppWebViewMessage.type == InAppWebViewMessage.InAppWebViewType.FULLSCREEN) {
H(0.0f, false, 0.0f);
this.k.getLayoutParams().height = -1;
this.e = new PopupWindow(this.j, -1, -1, false);
} else {
H(25.0f, true, 2.0f);
this.k.getLayoutParams().height = -2;
this.e = new PopupWindow(this.j, this.d.widthPixels - 16, -2, false);
}
int rotation = ((WindowManager) x().getSystemService("window")).getDefaultDisplay().getRotation();
if (rotation == 1 || rotation == 3) {
this.k.getLayoutParams().width = this.d.heightPixels - 16;
}
this.e.setContentView(this.j);
if (inAppWebViewMessage.type == InAppWebViewMessage.InAppWebViewType.BANNER) {
I(inAppWebViewMessage.position);
this.e.setOutsideTouchable(false);
} else {
this.e.setAnimationStyle(android.R.style.Animation);
this.e.setOutsideTouchable(true);
}
K(this.k);
Map<String, String> y = y();
if (y.isEmpty()) {
this.f.loadUrl(inAppWebViewMessage.url);
} else {
this.f.loadUrl(inAppWebViewMessage.url, y);
}
}
public final void E(int i) {
int dimensionPixelSize = x().getResources().getDimensionPixelSize(R.dimen.dialog_banner_min_height);
int dimensionPixelSize2 = x().getResources().getDimensionPixelSize(R.dimen.dialog_banner_max_height);
ViewGroup.LayoutParams layoutParams = this.f.getLayoutParams();
if (this.h.type == InAppWebViewMessage.InAppWebViewType.BANNER) {
layoutParams.height = Math.min(dimensionPixelSize2, Math.max(dimensionPixelSize, i));
}
if (this.h.type == InAppWebViewMessage.InAppWebViewType.POPUP) {
int i2 = (int) ((this.d.heightPixels * 0.85d) - 16.0d);
if (Math.min(i2, Math.max(dimensionPixelSize, i)) == i2) {
layoutParams.height = i2;
} else if (Math.min(i2, Math.max(dimensionPixelSize, i)) == dimensionPixelSize) {
layoutParams.height = dimensionPixelSize;
}
}
this.f.setLayoutParams(layoutParams);
}
public final void G(ActivityLifecycleListener activityLifecycleListener) {
ActivityLifecycleMonitor activityLifecycleMonitor = MobileMessagingCore.getInstance((Context) x()).getActivityLifecycleMonitor();
if (x() == null || activityLifecycleMonitor == null) {
return;
}
activityLifecycleMonitor.activityListener = activityLifecycleListener;
}
public final void H(float f, boolean z, float f2) {
this.k.setRadius(f);
this.k.setUseCompatPadding(z);
this.k.setElevation(f2);
}
public final void I(InAppWebViewMessage.InAppWebViewPosition inAppWebViewPosition) {
MobileMessagingLogger.d("[InAppWebViewDialog]", "setDialogAnimations()");
if (inAppWebViewPosition == InAppWebViewMessage.InAppWebViewPosition.TOP) {
this.e.setAnimationStyle(R.style.BannerAnimationTop);
} else if (inAppWebViewPosition == InAppWebViewMessage.InAppWebViewPosition.BOTTOM) {
this.e.setAnimationStyle(R.style.BannerAnimationBottom);
}
}
public final void J() {
if (this.e.isShowing()) {
MobileMessagingCore.getInstance((Context) x()).setMessagesSeen(this.h.getMessageId());
}
}
public final void K(CardView cardView) {
WebView webView = (WebView) cardView.findViewById(R.id.ib_webview);
this.f = webView;
if (this.h.type == InAppWebViewMessage.InAppWebViewType.FULLSCREEN) {
webView.getLayoutParams().height = -1;
} else {
webView.getLayoutParams().height = -2;
}
this.f.setWebViewClient(new a(cardView));
this.f.setWebChromeClient(new InAppWebChromeClient());
this.f.getSettings().setJavaScriptEnabled(true);
this.f.getSettings().setDisplayZoomControls(false);
this.f.getSettings().setBuiltInZoomControls(false);
this.f.getSettings().setSupportZoom(false);
this.f.getSettings().setLoadWithOverviewMode(true);
this.f.setVerticalScrollBarEnabled(false);
this.f.setHorizontalScrollBarEnabled(false);
this.f.addJavascriptInterface(new InAppWebViewInterface(), "InAppWebViewInterface");
}
public final void L(View view, InAppWebViewMessage.InAppWebViewPosition inAppWebViewPosition, InAppWebViewMessage.InAppWebViewType inAppWebViewType) {
int i = b.a[inAppWebViewType.ordinal()];
if (i != 1) {
if (i != 2) {
this.e.showAtLocation(view, 17, 0, 0);
} else {
this.e.setHeight(-1);
this.e.showAtLocation(view, 17, 0, 0);
}
} else if (inAppWebViewPosition == InAppWebViewMessage.InAppWebViewPosition.TOP) {
this.e.showAtLocation(view, 49, 0, 0);
} else {
this.e.showAtLocation(view, 81, 0, 0);
}
J();
}
public void M(float f) {
x().getWindow().getDecorView().getWindowVisibleDisplayFrame(new Rect());
final int v = v(f, x());
if (this.h.type == InAppWebViewMessage.InAppWebViewType.FULLSCREEN && v > this.d.heightPixels) {
setVerticalScrollBar(30);
}
try {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public final void run() {
InAppWebViewDialog.this.E(v);
}
});
} catch (Exception e) {
MobileMessagingLogger.e("[InAppWebViewDialog]", "Failed due to " + e.getMessage());
}
}
@Override
public void onActivityStopped(Activity activity) {
PopupWindow popupWindow = this.e;
if (popupWindow != null) {
popupWindow.dismiss();
G(null);
}
}
public void setDialogTimeout(int i) {
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public final void run() {
InAppWebViewDialog.this.B();
}
};
this.e.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public final void onDismiss() {
handler.removeCallbacks(runnable);
}
});
handler.postDelayed(runnable, i);
}
public void setVerticalScrollBar(int i) {
this.f.setVerticalScrollBarEnabled(true);
this.f.setScrollBarSize(i);
}
@Override
public void show(@NonNull final InAppWebViewMessage inAppWebViewMessage, @NonNull NotificationAction... notificationActionArr) {
this.h = inAppWebViewMessage;
this.c = notificationActionArr;
G(this);
if (!PreferenceHelper.findBoolean(x(), MobileMessagingProperty.FULL_FEATURE_IN_APPS_ENABLED)) {
MobileMessagingLogger.e("[InAppWebViewDialog]", "InApp WebView dialog cannot be displayed because Full-featured In-Apps not enabled!");
return;
}
try {
x().runOnUiThread(new Runnable() {
@Override
public final void run() {
InAppWebViewDialog.this.D(inAppWebViewMessage);
}
});
} catch (Exception e) {
MobileMessagingLogger.e("[InAppWebViewDialog]", "Failed to display webview for message with ID " + inAppWebViewMessage.getMessageId() + " due to: " + e.getMessage());
}
}
public final void u() {
try {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public final void run() {
InAppWebViewDialog.this.A();
}
});
} catch (Exception e) {
MobileMessagingLogger.e("[InAppWebViewDialog]", "Failed to delete local history due to " + e.getMessage());
}
}
public final synchronized void w() {
if (this.b == null) {
this.b = new AndroidBroadcaster(x());
}
}
public final Activity x() {
return this.g.getActivity();
}
public final Map y() {
String applicationCode = MobileMessagingCore.getApplicationCode(this.g.getActivity());
String pushRegistrationId = MobileMessagingCore.getInstance((Context) x()).getPushRegistrationId();
UserAgentUtil userAgentUtil = new UserAgentUtil();
HashMap hashMap = new HashMap();
if (applicationCode != null) {
hashMap.put(ApiConstants.AUTHORIZATION, "App " + applicationCode);
hashMap.put(ApiConstants.USER_AGENT, userAgentUtil.getUserAgent(UserAgentAdditions.getLibVersion(), UserAgentAdditions.getAdditions(this.g.getActivity())));
hashMap.put(ApiConstants.PUSH_REGISTRATION_ID, pushRegistrationId);
}
return hashMap;
}
public final boolean z() {
return this.h.type == InAppWebViewMessage.InAppWebViewType.BANNER;
}
}