package com.mihoyo.sdk.payplatform.cashier; import android.annotation.SuppressLint; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.http.SslError; import android.os.Build; import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.ViewGroup; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; import android.webkit.CookieManager; import android.webkit.SslErrorHandler; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ImageView; import android.widget.RelativeLayout; import com.huawei.hms.framework.common.ContainerUtils; import ho.c; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Map; import jo.b; import org.json.JSONObject; @SuppressLint({"ViewConstructor"}) public class ContentWebView extends RelativeLayout { /* renamed from: a reason: collision with root package name */ public WebView f39725a; /* renamed from: b reason: collision with root package name */ public ImageView f39726b; /* renamed from: c reason: collision with root package name */ public RelativeLayout f39727c; /* renamed from: d reason: collision with root package name */ public Activity f39728d; /* renamed from: e reason: collision with root package name */ public final String f39729e = "mihoyo_pay_cashier_loading.png"; public class a extends WebViewClient { /* renamed from: a reason: collision with root package name */ public boolean f39730a; public a() { } public void onPageFinished(WebView webView, String str) { super.onPageFinished(webView, str); b.a("onPageFinished:" + str); ContentWebView.this.f39726b.clearAnimation(); ContentWebView contentWebView = ContentWebView.this; contentWebView.removeView(contentWebView.f39727c); } public void onPageStarted(WebView webView, String str, Bitmap bitmap) { b.a("onPageStarted:" + str); super.onPageStarted(webView, str, bitmap); } public void onReceivedError(WebView webView, int i10, String str, String str2) { super.onReceivedError(webView, i10, str, str2); } public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) { super.onReceivedSslError(webView, sslErrorHandler, sslError); } @Override // android.webkit.WebViewClient public boolean shouldOverrideUrlLoading(WebView webView, String str) { if (!TextUtils.isEmpty(str)) { b.a("shouldOverrideUrlLoading:" + str); if (!str.startsWith("http") && !str.startsWith("https")) { return true; } } return super.shouldOverrideUrlLoading(webView, str); } } @SuppressLint({"ResourceAsColor", "AddJavascriptInterface"}) public ContentWebView(Activity activity, c cVar, Map<String, String> map) { super(activity); this.f39728d = activity; setLayoutParams(new ViewGroup.LayoutParams(-1, -1)); ColorDrawable colorDrawable = new ColorDrawable(0); setBackground(colorDrawable); e(activity); this.f39725a.setBackgroundColor(0); this.f39725a.setBackground(colorDrawable); this.f39725a.getBackground().setAlpha(0); this.f39725a.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1)); this.f39725a.setWebViewClient(getWebViewClient()); WebView webView = this.f39725a; webView.addJavascriptInterface(new ho.a(webView, activity, cVar), "MiHoYoSDKInvoke"); addView(this.f39725a); d(); StringBuilder sb2 = new StringBuilder(TextUtils.isEmpty(map.get("url")) ? "https://webstatic.mihoyo.com/payment/payment-shell/index.html" : map.get("url")); sb2.append("?"); sb2.append("app_id"); sb2.append(ContainerUtils.KEY_VALUE_DELIMITER); sb2.append(map.get("app_id")); sb2.append("&"); try { String encode = URLEncoder.encode(map.get("order_info"), "UTF-8"); sb2.append("order"); sb2.append(ContainerUtils.KEY_VALUE_DELIMITER); sb2.append(encode); } catch (UnsupportedEncodingException e10) { e10.printStackTrace(); } b.a("finalUrl:" + ((Object) sb2)); this.f39725a.loadUrl(sb2.toString()); } private WebViewClient getWebViewClient() { return new a(); } public void c() { try { JSONObject jSONObject = new JSONObject(); jSONObject.put("retcode", 0); jSONObject.put("message", "调用返回"); b.a("callBackPress result content:" + jSONObject.toString()); if (Build.VERSION.SDK_INT >= 19) { WebView webView = this.f39725a; webView.evaluateJavascript("MiHoYoBackPress(" + jSONObject + ")", null); return; } WebView webView2 = this.f39725a; webView2.loadUrl("javascript:MiHoYoBackPress('" + jSONObject + "')"); } catch (Exception e10) { b.a("callback login result error:" + e10.getMessage()); } } public final void d() { Drawable drawable = null; try { drawable = Drawable.createFromResourceStream(getContext().getResources(), null, getContext().getAssets().open("mihoyo_pay_cashier_loading.png"), "mihoyo_pay_cashier_loading.png"); } catch (Exception e10) { b.a("initLoadingImage error:" + e10.getMessage()); } if (drawable != null) { DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); int min = (int) (((float) Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels)) * 0.16666667f); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(min, min); layoutParams.addRule(13); RelativeLayout relativeLayout = new RelativeLayout(getContext()); this.f39727c = relativeLayout; relativeLayout.setBackgroundColor(Color.parseColor("#FF000000")); this.f39727c.setLayoutParams(layoutParams); ImageView imageView = new ImageView(getContext()); this.f39726b = imageView; imageView.setImageDrawable(drawable); RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-2, -2); layoutParams2.addRule(13); this.f39726b.setLayoutParams(layoutParams2); RotateAnimation rotateAnimation = new RotateAnimation(0.0f, 360.0f, 1, 0.5f, 1, 0.5f); rotateAnimation.setRepeatCount(-1); rotateAnimation.setDuration(1000); rotateAnimation.setInterpolator(new LinearInterpolator()); this.f39726b.setAnimation(rotateAnimation); this.f39727c.addView(this.f39726b); addView(this.f39727c); } } @SuppressLint({"SetJavaScriptEnabled"}) public final void e(Activity activity) { WebView webView = new WebView(activity); this.f39725a = webView; webView.setOverScrollMode(2); WebSettings settings = this.f39725a.getSettings(); settings.setJavaScriptEnabled(true); settings.setBlockNetworkImage(false); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setSaveFormData(true); settings.setSavePassword(true); CookieManager.getInstance().setAcceptCookie(true); settings.setSupportMultipleWindows(true); settings.setAppCacheEnabled(true); settings.setDatabaseEnabled(true); settings.setGeolocationEnabled(true); settings.setAllowFileAccess(true); settings.setDomStorageEnabled(true); settings.setPluginState(WebSettings.PluginState.ON_DEMAND); settings.setCacheMode(-1); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setAllowFileAccessFromFileURLs(true); settings.setAllowUniversalAccessFromFileURLs(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setTextZoom(100); int i10 = Build.VERSION.SDK_INT; if (i10 >= 17) { settings.setMediaPlaybackRequiresUserGesture(false); } if (i10 >= 21) { settings.setMixedContentMode(0); } } }