diff --git a/build.gradle b/build.gradle index d4801ab9..d93b4267 100644 --- a/build.gradle +++ b/build.gradle @@ -35,9 +35,10 @@ buildscript { ], 'androidx' : [ - 'appcompat' : 'androidx.appcompat:appcompat:1.0.0', - 'fragment' : 'androidx.fragment:fragment:1.0.0', - 'recyclerview': 'androidx.recyclerview:recyclerview:1.0.0', + 'appcompat' : 'androidx.appcompat:appcompat:1.3.1', + 'fragment' : 'androidx.fragment:fragment:1.3.1', + 'recyclerview' : 'androidx.recyclerview:recyclerview:1.2.1', + "swiperefreshlayout": "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0", ], 'growingio': [ diff --git a/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridBridgeLoader.java b/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridBridgeLoader.java index 542d955e..3be324a7 100644 --- a/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridBridgeLoader.java +++ b/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridBridgeLoader.java @@ -22,6 +22,7 @@ import com.growingio.android.sdk.track.modelloader.ModelLoader; import com.growingio.android.sdk.track.modelloader.ModelLoaderFactory; import com.growingio.android.sdk.track.modelloader.data.HybridBridge; +import com.growingio.android.sdk.track.utils.ClassExistHelper; /** *

@@ -57,9 +58,9 @@ public HybridDataFetcher(HybridBridge eventData) { public Boolean executeData() { if (bridge.getView() instanceof WebView) { HybridBridgeProvider.get().bridgeForWebView(SuperWebView.make((WebView) bridge.getView())); - } else if (bridge.getView() instanceof com.tencent.smtt.sdk.WebView) { + } else if (ClassExistHelper.instanceOfX5WebView(bridge.getView())) { HybridBridgeProvider.get().bridgeForWebView(SuperWebView.makeX5((com.tencent.smtt.sdk.WebView) bridge.getView())); - } else if (bridge.getView() instanceof com.uc.webview.export.WebView) { + } else if (ClassExistHelper.instanceOfUcWebView(bridge.getView())) { HybridBridgeProvider.get().bridgeForWebView(SuperWebView.makeUC((com.uc.webview.export.WebView) bridge.getView())); } else { return false; diff --git a/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridBridgeProvider.java b/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridBridgeProvider.java index f787d5dc..d0e86a0b 100644 --- a/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridBridgeProvider.java +++ b/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridBridgeProvider.java @@ -88,12 +88,9 @@ public Disposable getWebViewDomTree(SuperWebView webView, final Callback { + Logger.e(TAG, "getWebViewDomTree timeout"); + callback.onFailed(); }, EVALUATE_JAVASCRIPT_TIMEOUT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { @@ -126,8 +123,8 @@ public void onReceiveValue(String value) { Logger.e(TAG, "You need use after Android 4.4 to getWebViewDomTree"); if (!disposable.isDisposed()) { disposable.dispose(); - callback.onFailed(); } + callback.onFailed(); } return disposable; } diff --git a/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridDomLoader.java b/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridDomLoader.java index 209969b0..3e7692d8 100644 --- a/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridDomLoader.java +++ b/growingio-hybrid/src/main/java/com/growingio/android/hybrid/HybridDomLoader.java @@ -25,6 +25,7 @@ import com.growingio.android.sdk.track.modelloader.ModelLoaderFactory; import com.growingio.android.sdk.track.modelloader.data.HybridDom; import com.growingio.android.sdk.track.modelloader.data.HybridJson; +import com.growingio.android.sdk.track.utils.ClassExistHelper; import org.json.JSONObject; @@ -67,6 +68,7 @@ public HybridDataFetcher(HybridDom eventData) { public void loadData(DataCallback callback) { if (dom.getView() == null) { callback.onLoadFailed(new NullPointerException("webview is null")); + return; } SuperWebView superWebView = getSuperWebView(); if (superWebView == null) { @@ -89,9 +91,9 @@ public void onFailed() { public SuperWebView getSuperWebView() { if (dom.getView() instanceof WebView) { return SuperWebView.make((WebView) dom.getView()); - } else if (dom.getView() instanceof com.tencent.smtt.sdk.WebView) { + } else if (ClassExistHelper.instanceOfX5WebView(dom.getView())) { return SuperWebView.makeX5((com.tencent.smtt.sdk.WebView) dom.getView()); - } else if (dom.getView() instanceof com.uc.webview.export.WebView) { + } else if (ClassExistHelper.instanceOfUcWebView(dom.getView())) { return SuperWebView.makeUC((com.uc.webview.export.WebView) dom.getView()); } else { return null; diff --git a/growingio-tracker-core/build.gradle b/growingio-tracker-core/build.gradle index 7e4a0001..12514543 100644 --- a/growingio-tracker-core/build.gradle +++ b/growingio-tracker-core/build.gradle @@ -73,6 +73,7 @@ dependencies { compileOnly libraries.androidx.appcompat compileOnly libraries.androidx.recyclerview + compileOnly libraries.androidx.swiperefreshlayout compileOnly libraries.android.appcompat compileOnly libraries.android.recyclerview //compileOnly libraries.others.x5_webview diff --git a/growingio-webservice/circler/src/main/java/com/growingio/android/circler/screenshot/CircleScreenshot.java b/growingio-webservice/circler/src/main/java/com/growingio/android/circler/screenshot/CircleScreenshot.java index 86857b03..913cebb8 100644 --- a/growingio-webservice/circler/src/main/java/com/growingio/android/circler/screenshot/CircleScreenshot.java +++ b/growingio-webservice/circler/src/main/java/com/growingio/android/circler/screenshot/CircleScreenshot.java @@ -28,8 +28,6 @@ import com.growingio.android.sdk.autotrack.view.ViewNode; import com.growingio.android.sdk.autotrack.view.ViewUtil; import com.growingio.android.sdk.track.async.Callback; -import com.growingio.android.sdk.track.async.Disposable; -import com.growingio.android.sdk.track.async.UnsubscribedDisposable; import com.growingio.android.sdk.track.modelloader.LoadDataFetcher; import com.growingio.android.sdk.track.modelloader.ModelLoader; import com.growingio.android.sdk.track.modelloader.data.HybridDom; @@ -109,10 +107,9 @@ public static final class Builder { private long mSnapshotKey; private final List mViewElements = new ArrayList<>(); private final List mPages = new ArrayList<>(); - private final AtomicInteger mWebViewCount = new AtomicInteger(0); + private final AtomicInteger mScreenLock = new AtomicInteger(0); private int mViewCount = 0; private Callback mScreenshotResultCallback; - private Disposable mBuildDisposable; public Builder setScale(float scale) { mScale = scale; @@ -129,19 +126,21 @@ public Builder setSnapshotKey(long snapshotKey) { return this; } - public Disposable build(Callback callback) { - if (callback == null) { - return Disposable.EMPTY_DISPOSABLE; - } + public void build(Callback callback) { List decorViews = WindowHelper.get().getTopActivityViews(); - return build(decorViews, callback); + build(decorViews, callback); } - public Disposable build(List decorViews, Callback callback) { + public void build(List decorViews, Callback callback) { if (callback == null) { - return Disposable.EMPTY_DISPOSABLE; + return; + } + + if (decorViews == null || decorViews.isEmpty()) { + callResultOnFailed(); + return; } - mBuildDisposable = new UnsubscribedDisposable(); + mScreenshotResultCallback = callback; DisplayMetrics displayMetrics = DeviceUtil.getDisplayMetrics(TrackerContext.get().getApplicationContext()); @@ -152,31 +151,16 @@ public Disposable build(List decorViews, Callback c if (decorView.getView() instanceof TipView) { continue; } - checkView2PageElement(decorView.getView()); - checkView2ViewElement(decorView.getView()); - } - if (mWebViewCount.get() == 0) { - callResultOnSuccess(); - } - return mBuildDisposable; - } - private void callResultOnSuccess() { - if (!mBuildDisposable.isDisposed()) { - mBuildDisposable.dispose(); - if (mScreenshotResultCallback != null) { - mScreenshotResultCallback.onSuccess(new CircleScreenshot(this)); + if (isViewInvisible(decorView.getView())) { + continue; } - } - } - private void callResultOnFailed() { - if (!mBuildDisposable.isDisposed()) { - mBuildDisposable.dispose(); - if (mScreenshotResultCallback != null) { - mScreenshotResultCallback.onFailed(); - } + mScreenLock.incrementAndGet(); + checkView2PageElement(decorView.getView()); + checkView2ViewElement(decorView.getView()); } + callResultOnSuccess(); } private ViewElement.Builder createViewElementBuilder(ViewNode viewNode) { @@ -199,14 +183,11 @@ private ViewElement.Builder createViewElementBuilder(ViewNode viewNode) { private void checkView2ViewElement(View view) { ViewNode topViewNode = ViewHelper.getTopViewNode(view, null); - if (disposeWebView(topViewNode)) { - return; - } - traverseViewNode(topViewNode); } private void traverseViewNode(ViewNode viewNode) { + if (isViewInvisible(viewNode.getView())) return; if (!disposeWebView(viewNode) && ViewUtil.canCircle(viewNode.getView())) { mViewElements.add(createViewElementBuilder(viewNode).build()); } @@ -225,21 +206,19 @@ private boolean disposeWebView(ViewNode viewNode) { if (ClassExistHelper.isWebView(viewNode.getView())) { ModelLoader modelLoader = ScreenshotProvider.get().getHybridModelLoader(); if (modelLoader == null) return false; - mWebViewCount.incrementAndGet(); + mScreenLock.incrementAndGet(); LoadDataFetcher loadDataFetcher = (LoadDataFetcher) modelLoader.buildLoadData(new HybridDom(viewNode.getView())).fetcher; loadDataFetcher.loadData(new LoadDataFetcher.DataCallback() { @Override public void onDataReady(HybridJson data) { ViewElement.Builder elementBuilder = createViewElementBuilder(viewNode); mViewElements.add(elementBuilder.setWebView(data.getJsonObject()).build()); - if (mWebViewCount.decrementAndGet() == 0) { - callResultOnSuccess(); - } + callResultOnSuccess(); } @Override public void onLoadFailed(Exception e) { - callResultOnFailed(); + callResultOnSuccess(); } }); return true; @@ -247,6 +226,20 @@ public void onLoadFailed(Exception e) { return false; } + private void callResultOnSuccess() { + if (mScreenLock.decrementAndGet() <= 0) { + if (mScreenshotResultCallback != null) { + mScreenshotResultCallback.onSuccess(new CircleScreenshot(this)); + } + } + } + + private void callResultOnFailed() { + if (mScreenshotResultCallback != null) { + mScreenshotResultCallback.onFailed(); + } + } + private void checkView2PageElement(View view) { Page viewPage = ViewAttributeUtil.getViewPage(view); if (viewPage != null) { @@ -273,5 +266,9 @@ private void checkView2PageElement(View view) { } } } + + private boolean isViewInvisible(View view) { + return view.getVisibility() == View.GONE || view.getWidth() <= 0 || view.getHeight() <= 0; + } } } diff --git a/growingio-webservice/circler/src/main/java/com/growingio/android/circler/screenshot/ScreenshotProvider.java b/growingio-webservice/circler/src/main/java/com/growingio/android/circler/screenshot/ScreenshotProvider.java index 636e4427..651c0e2c 100644 --- a/growingio-webservice/circler/src/main/java/com/growingio/android/circler/screenshot/ScreenshotProvider.java +++ b/growingio-webservice/circler/src/main/java/com/growingio/android/circler/screenshot/ScreenshotProvider.java @@ -140,29 +140,25 @@ public interface OnScreenshotRefreshedListener { } private long mSnapshotKey = 0; - private Disposable mCircleScreenshotDisposable; public void sendScreenshotRefreshed(String screenshotBase64, float scale) { - if (mCircleScreenshotDisposable != null) { - mCircleScreenshotDisposable.dispose(); - } - - mCircleScreenshotDisposable = new CircleScreenshot.Builder() + CircleScreenshot.Builder builder = new CircleScreenshot.Builder() .setScale(scale) .setScreenshot(screenshotBase64) - .setSnapshotKey(mSnapshotKey++) - .build(new Callback() { - @Override - public void onSuccess(CircleScreenshot result) { - Logger.d(TAG, "Create circle screenshot successfully"); - sendScreenshot(result); - } - - @Override - public void onFailed() { - Logger.e(TAG, "Create circle screenshot failed"); - } - }); + .setSnapshotKey(mSnapshotKey++); + + builder.build(new Callback() { + @Override + public void onSuccess(CircleScreenshot result) { + Logger.d(TAG, "Create circle screenshot successfully"); + sendScreenshot(result); + } + + @Override + public void onFailed() { + Logger.e(TAG, "Create circle screenshot failed"); + } + }); } public void sendScreenshot(CircleScreenshot result) {