imToken v2.9.3版本的 MD5 值为:42af1a08a3f01f69d2f3782d81007b3c
以下内容为反编译后的 ArticleWebView.java 源代码,内容仅作参考
package com.helpscout.beacon.internal.presentation.ui.article;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.facebook.react.uimanager.ViewProps;
import com.helpscout.beacon.a.d.a.a;
import com.helpscout.beacon.internal.core.model.ArticleDetailsApi;
import com.helpscout.beacon.ui.R;
import kotlin.Lazy;
import kotlin.LazyKt;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Lambda;
import kotlin.jvm.internal.Reflection;
import org.koin.core.Koin;
import org.koin.core.component.KoinComponent;
import org.koin.core.component.KoinScopeComponent;
import org.koin.core.qualifier.Qualifier;
import org.koin.mp.KoinPlatformTools;
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0080\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\r\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0000\u0018\u00002\u00020\u00012\u00020\u0002:\u00010B\u001b\u0012\u0006\u0010C\u001a\u00020B\u0012\n\b\u0002\u0010E\u001a\u0004\u0018\u00010D¢\u0006\u0004\bF\u0010GJ\u000f\u0010\u0004\u001a\u00020\u0003H\u0002¢\u0006\u0004\b\u0004\u0010\u0005J\u001f\u0010\u0004\u001a\u00020\u00032\u0006\u0010\u0007\u001a\u00020\u00062\u0006\u0010\t\u001a\u00020\bH\u0002¢\u0006\u0004\b\u0004\u0010\nJ\u0017\u0010\r\u001a\u00020\u00032\u0006\u0010\f\u001a\u00020\u000bH\u0016¢\u0006\u0004\b\r\u0010\u000eJ\u000f\u0010\u000f\u001a\u00020\u0003H\u0016¢\u0006\u0004\b\u000f\u0010\u0005J\u0017\u0010\u0013\u001a\u00020\u00122\u0006\u0010\u0011\u001a\u00020\u0010H\u0016¢\u0006\u0004\b\u0013\u0010\u0014J\u0017\u0010\u0017\u001a\u00020\u00032\u0006\u0010\u0016\u001a\u00020\u0015H\u0007¢\u0006\u0004\b\u0017\u0010\u0018J=\u0010\u0004\u001a\u00020\u00032\u0006\u0010\u001a\u001a\u00020\u00192\u0012\u0010\u001d\u001a\u000e\u0012\u0004\u0012\u00020\u001c\u0012\u0004\u0012\u00020\u00030\u001b2\u0012\u0010\u001e\u001a\u000e\u0012\u0004\u0012\u00020\u0012\u0012\u0004\u0012\u00020\u00030\u001b¢\u0006\u0004\b\u0004\u0010\u001fR\u0018\u0010#\u001a\u0004\u0018\u00010 8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b!\u0010\"R\u0016\u0010'\u001a\u00020$8\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b%\u0010&R\"\u0010*\u001a\u000e\u0012\u0004\u0012\u00020\u0012\u0012\u0004\u0012\u00020\u00030\u001b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b(\u0010)R\u001d\u0010/\u001a\u00020+8B@\u0002X\u0082\u0084\u0002¢\u0006\f\n\u0004\b\u0004\u0010,\u001a\u0004\b-\u0010.R\u0016\u00102\u001a\u00020\u001c8\u0002@\u0002X\u0082D¢\u0006\u0006\n\u0004\b0\u00101R\"\u0010\u001d\u001a\u000e\u0012\u0004\u0012\u00020\u001c\u0012\u0004\u0012\u00020\u00030\u001b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b3\u0010)R\u0018\u0010\f\u001a\u0004\u0018\u00010\u000b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b4\u00105R\u0016\u00108\u001a\u00020\u00128\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b6\u00107R\u001d\u0010=\u001a\u0002098B@\u0002X\u0082\u0084\u0002¢\u0006\f\n\u0004\b:\u0010,\u001a\u0004\b;\u0010<R\u0018\u0010?\u001a\u0004\u0018\u00010\u001c8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b>\u00101R\u0016\u0010A\u001a\u00020\u00128\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b@\u00107¨\u0006H"}, d2 = {"Lcom/helpscout/beacon/internal/presentation/ui/article/ArticleWebView;", "Landroid/webkit/WebView;", "Lcom/helpscout/beacon/a/d/a/a;", "", "a", "()V", "Landroid/content/res/Resources;", "resources", "Landroid/webkit/WebSettings;", "settings", "(Landroid/content/res/Resources;Landroid/webkit/WebSettings;)V", "Landroid/graphics/Canvas;", "canvas", "onDraw", "(Landroid/graphics/Canvas;)V", "destroy", "Landroid/view/MotionEvent;", "ev", "", "onTouchEvent", "(Landroid/view/MotionEvent;)Z", "Landroid/webkit/WebViewClient;", "client", "setupWebSettings", "(Landroid/webkit/WebViewClient;)V", "Lcom/helpscout/beacon/internal/core/model/ArticleDetailsApi;", "articleApi", "Lkotlin/Function1;", "", "linkClick", "loadingCallback", "(Lcom/helpscout/beacon/internal/core/model/ArticleDetailsApi;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V", "Landroid/graphics/Bitmap;", "d", "Landroid/graphics/Bitmap;", "bitmap", "Ljava/lang/Runnable;", "j", "Ljava/lang/Runnable;", "mNotifyPageRenderedInHardwareLayer", "i", "Lkotlin/jvm/functions/Function1;", "loading", "Lcom/helpscout/beacon/internal/presentation/common/d;", "Lkotlin/Lazy;", "getBeaconStringResolver", "()Lcom/helpscout/beacon/internal/presentation/common/d;", "beaconStringResolver", "c", "Ljava/lang/String;", "baseUrlForCookieCompliance", "h", "e", "Landroid/graphics/Canvas;", "k", "Z", ViewProps.VISIBLE, "Lcom/helpscout/beacon/internal/presentation/ui/article/e;", "b", "getArticleBuilder", "()Lcom/helpscout/beacon/internal/presentation/ui/article/e;", "articleBuilder", "g", "currentUrl", "f", "useSoftwareLayer", "Landroid/content/Context;", "context", "Landroid/util/AttributeSet;", "attrs", "<init>", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "beacon_release"}, k = 1, mv = {1, 4, 2})
public final class ArticleWebView extends WebView implements com.helpscout.beacon.a.d.a.a {
private final Lazy beaconStringResolver;
private final Lazy articleBuilder;
private final String baseUrlForCookieCompliance;
private Bitmap bitmap;
private Canvas canvas;
private boolean useSoftwareLayer;
private String currentUrl;
private Function1<? super String, Unit> linkClick;
private Function1<? super Boolean, Unit> loading;
private final Runnable mNotifyPageRenderedInHardwareLayer;
private boolean visible;
public static final class a extends Lambda implements Function0<com.helpscout.beacon.internal.presentation.common.d> {
final KoinComponent f1128a;
final Qualifier b;
final Function0 c;
public a(KoinComponent koinComponent, Qualifier qualifier, Function0 function0) {
super(0);
this.f1128a = koinComponent;
this.b = qualifier;
this.c = function0;
}
@Override
public final com.helpscout.beacon.internal.presentation.common.d invoke() {
KoinComponent koinComponent = this.f1128a;
return (koinComponent instanceof KoinScopeComponent ? ((KoinScopeComponent) koinComponent).getScope() : koinComponent.getKoin().getScopeRegistry().getRootScope()).get(Reflection.getOrCreateKotlinClass(com.helpscout.beacon.internal.presentation.common.d.class), this.b, this.c);
}
}
public static final class b extends Lambda implements Function0<com.helpscout.beacon.internal.presentation.ui.article.e> {
final KoinComponent f1129a;
final Qualifier b;
final Function0 c;
public b(KoinComponent koinComponent, Qualifier qualifier, Function0 function0) {
super(0);
this.f1129a = koinComponent;
this.b = qualifier;
this.c = function0;
}
@Override
public final com.helpscout.beacon.internal.presentation.ui.article.e invoke() {
KoinComponent koinComponent = this.f1129a;
return (koinComponent instanceof KoinScopeComponent ? ((KoinScopeComponent) koinComponent).getScope() : koinComponent.getKoin().getScopeRegistry().getRootScope()).get(Reflection.getOrCreateKotlinClass(com.helpscout.beacon.internal.presentation.ui.article.e.class), this.b, this.c);
}
}
public final class c extends WebViewClient {
public c() {
}
@Override
public void onPageFinished(WebView view, String url) {
Intrinsics.checkNotNullParameter(view, "view");
Intrinsics.checkNotNullParameter(url, "url");
ArticleWebView.this.loading.invoke(Boolean.FALSE);
super.onPageFinished(view, url);
}
@Override
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
ArticleWebView.this.loading.invoke(Boolean.TRUE);
super.onPageStarted(webView, str, bitmap);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
Uri url;
return Intrinsics.areEqual((webResourceRequest == null || (url = webResourceRequest.getUrl()) == null) ? null : url.getLastPathSegment(), "favicon.ico") ? new WebResourceResponse("image/png", null, null) : super.shouldInterceptRequest(webView, webResourceRequest);
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
Uri url;
String uri;
if (webResourceRequest == null || (url = webResourceRequest.getUrl()) == null || (uri = url.toString()) == null) {
return true;
}
return true;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intrinsics.checkNotNullParameter(view, "view");
Intrinsics.checkNotNullParameter(url, "url");
ArticleWebView.this.linkClick.invoke(url);
return true;
}
}
static final class d extends Lambda implements Function1<String, Unit> {
public static final d f1131a = new d();
d() {
super(1);
}
public final void a(String it) {
Intrinsics.checkNotNullParameter(it, "it");
}
@Override
public Unit invoke(String str) {
a(str);
return Unit.INSTANCE;
}
}
static final class e extends Lambda implements Function1<Boolean, Unit> {
public static final e f1132a = new e();
e() {
super(1);
}
public final void a(boolean z) {
}
@Override
public Unit invoke(Boolean bool) {
a(bool.booleanValue());
return Unit.INSTANCE;
}
}
static final class f implements Runnable {
f() {
}
@Override
public final void run() {
ArticleWebView.this.useSoftwareLayer = false;
ArticleWebView.this.a();
ArticleWebView.this.invalidate();
}
}
public ArticleWebView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
Intrinsics.checkNotNullParameter(context, "context");
this.beaconStringResolver = LazyKt.lazy(KoinPlatformTools.INSTANCE.defaultLazyMode(), (Function0) new a(this, null, null));
this.articleBuilder = LazyKt.lazy(KoinPlatformTools.INSTANCE.defaultLazyMode(), (Function0) new b(this, null, null));
this.baseUrlForCookieCompliance = "https://docs.helpscout.net";
this.linkClick = d.f1131a;
this.loading = e.f1132a;
this.mNotifyPageRenderedInHardwareLayer = new f();
setupWebSettings(new c());
}
public ArticleWebView(Context context, AttributeSet attributeSet, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(context, (i & 2) != 0 ? null : attributeSet);
}
public final void a() {
if (this.bitmap != null) {
this.bitmap = null;
this.canvas = null;
}
}
private final void a(Resources resources, WebSettings settings) {
float f2 = resources.getConfiguration().fontScale;
int integer = resources.getInteger(R.integer.hs_beacon_conversation_desired_font_size_px);
settings.setTextZoom((int) (((settings.getTextZoom() * integer) / resources.getInteger(R.integer.hs_beacon_conversation_unstyled_font_size_px)) * f2));
}
private final com.helpscout.beacon.internal.presentation.ui.article.e getArticleBuilder() {
return (com.helpscout.beacon.internal.presentation.ui.article.e) this.articleBuilder.getValue();
}
private final com.helpscout.beacon.internal.presentation.common.d getBeaconStringResolver() {
return (com.helpscout.beacon.internal.presentation.common.d) this.beaconStringResolver.getValue();
}
public final void a(ArticleDetailsApi articleApi, Function1<? super String, Unit> linkClick, Function1<? super Boolean, Unit> loadingCallback) {
Intrinsics.checkNotNullParameter(articleApi, "articleApi");
Intrinsics.checkNotNullParameter(linkClick, "linkClick");
Intrinsics.checkNotNullParameter(loadingCallback, "loadingCallback");
if (Intrinsics.areEqual(this.currentUrl, articleApi.getUrl())) {
loadingCallback.invoke(Boolean.FALSE);
return;
}
this.currentUrl = articleApi.getUrl();
this.linkClick = linkClick;
this.loading = loadingCallback;
loadDataWithBaseURL(this.baseUrlForCookieCompliance, getArticleBuilder().a(articleApi, getBeaconStringResolver().S0()), "text/html", "utf-8", null);
}
@Override
public void destroy() {
a();
removeCallbacks(this.mNotifyPageRenderedInHardwareLayer);
super.destroy();
}
@Override
public Koin getKoin() {
return a.C0124a.a(this);
}
@Override
public void onDraw(Canvas canvas) {
Intrinsics.checkNotNullParameter(canvas, "canvas");
super.onDraw(canvas);
if (!this.useSoftwareLayer || !this.visible || getWidth() <= 0 || getHeight() <= 0) {
return;
}
if (this.bitmap == null) {
try {
this.bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.RGB_565);
Bitmap bitmap = this.bitmap;
Intrinsics.checkNotNull(bitmap);
this.canvas = new Canvas(bitmap);
} catch (OutOfMemoryError unused) {
this.bitmap = null;
this.canvas = null;
this.useSoftwareLayer = false;
}
}
if (this.bitmap != null) {
int scrollX = getScrollX();
int scrollY = getScrollY();
Canvas canvas2 = this.canvas;
Intrinsics.checkNotNull(canvas2);
canvas2.save();
Canvas canvas3 = this.canvas;
Intrinsics.checkNotNull(canvas3);
canvas3.translate(-scrollX, -scrollY);
super.onDraw(this.canvas);
Canvas canvas4 = this.canvas;
Intrinsics.checkNotNull(canvas4);
canvas4.restore();
Bitmap bitmap2 = this.bitmap;
Intrinsics.checkNotNull(bitmap2);
canvas.drawBitmap(bitmap2, scrollX, scrollY, (Paint) null);
}
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
Intrinsics.checkNotNullParameter(ev, "ev");
if (ev.getActionMasked() == 5) {
requestDisallowInterceptTouchEvent(true);
}
return super.onTouchEvent(ev);
}
public final void setupWebSettings(WebViewClient client) {
int i;
Intrinsics.checkNotNullParameter(client, "client");
WebSettings settings = getSettings();
settings.setAppCacheEnabled(true);
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(false);
settings.setAllowFileAccess(false);
settings.setJavaScriptCanOpenWindowsAutomatically(false);
settings.setBlockNetworkImage(false);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
int i2 = Build.VERSION.SDK_INT;
if (i2 < 21 || i2 >= 23) {
i = i2 >= 23 ? 2 : 0;
Intrinsics.checkNotNullExpressionValue(settings, "settings.apply {\n …E\n }\n }");
Resources resources = getResources();
Intrinsics.checkNotNullExpressionValue(resources, "resources");
a(resources, settings);
setWebViewClient(client);
}
settings.setMixedContentMode(i);
Intrinsics.checkNotNullExpressionValue(settings, "settings.apply {\n …E\n }\n }");
Resources resources2 = getResources();
Intrinsics.checkNotNullExpressionValue(resources2, "resources");
a(resources2, settings);
setWebViewClient(client);
}
}