From 76d53d937fe2d682cb93d44f7dc621b2662d3315 Mon Sep 17 00:00:00 2001 From: siguangli Date: Mon, 17 Jun 2024 21:08:07 +0800 Subject: [PATCH] fix(android): remove onSystemUiVisibilityChange listener --- .../android-3.0-upgrade-guidelines.md | 3 ++ .../mtt/hippy/HippyEngineManagerImpl.java | 8 ++-- .../adapter/device/DefaultDeviceAdapter.java | 4 +- .../adapter/device/HippyDeviceAdapter.java | 3 +- .../hippy/bridge/HippyBridgeManagerImpl.java | 5 +-- .../mtt/hippy/utils/DimensionsUtil.java | 21 +++------- .../com/tencent/mtt/hippy/HippyRootView.java | 42 ++++++------------- .../com/tencent/renderer/FrameworkProxy.java | 3 +- .../com/tencent/renderer/NativeRender.java | 3 +- .../com/tencent/renderer/NativeRenderer.java | 6 +-- 10 files changed, 34 insertions(+), 64 deletions(-) diff --git a/docs/development/android-3.0-upgrade-guidelines.md b/docs/development/android-3.0-upgrade-guidelines.md index facbc2a9077..e49e5892009 100644 --- a/docs/development/android-3.0-upgrade-guidelines.md +++ b/docs/development/android-3.0-upgrade-guidelines.md @@ -123,6 +123,9 @@ } ``` +7. HippyDeviceAdapter中reviseDimensionIfNeed接口参数调整
+ 由于HippyRootView不再监听onSystemUiVisibilityChange消息,移除shouldUseScreenDisplay和systemUiVisibilityChanged两个无效参数。 +
# 新增特性 diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java b/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java index 1e525025c06..f3a6db2a34f 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java @@ -269,14 +269,13 @@ public void onSizeChanged(int rootId, int w, int h, int ow, int oh) { } @Override - public void updateDimension(int width, int height, boolean shouldUseScreenDisplay, - boolean systemUiVisibilityChanged) { + public void updateDimension(int width, int height) { if (mEngineContext == null) { return; } Context context = mEngineContext.getGlobalConfigs().getContext(); HippyMap dimensionMap = DimensionsUtil - .getDimensions(width, height, context, shouldUseScreenDisplay); + .getDimensions(width, height, context); int dimensionW = 0; int dimensionH = 0; if (dimensionMap != null) { @@ -287,8 +286,7 @@ public void updateDimension(int width, int height, boolean shouldUseScreenDispla if (height < 0 || dimensionW == dimensionH) { HippyDeviceAdapter deviceAdapter = mEngineContext.getGlobalConfigs().getDeviceAdapter(); if (deviceAdapter != null) { - deviceAdapter.reviseDimensionIfNeed(context, dimensionMap, shouldUseScreenDisplay, - systemUiVisibilityChanged); + deviceAdapter.reviseDimensionIfNeed(context, dimensionMap); } } DimensionsUtil.convertDimensionsToDp(dimensionMap); diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/device/DefaultDeviceAdapter.java b/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/device/DefaultDeviceAdapter.java index e9368cf3715..50620b7fd90 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/device/DefaultDeviceAdapter.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/device/DefaultDeviceAdapter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.tencent.mtt.hippy.adapter.device; import android.content.Context; @@ -24,8 +25,7 @@ public class DefaultDeviceAdapter implements HippyDeviceAdapter { @SuppressWarnings("unused") @Override - public void reviseDimensionIfNeed(Context context, HippyMap dimensionMap, - boolean shouldUseScreenDisplay, boolean systemUiVisibilityChanged) { + public void reviseDimensionIfNeed(Context context, HippyMap dimensionMap) { // Default do nothing here } } diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/device/HippyDeviceAdapter.java b/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/device/HippyDeviceAdapter.java index a55b66e3267..2b174b8dc20 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/device/HippyDeviceAdapter.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/device/HippyDeviceAdapter.java @@ -23,6 +23,5 @@ public interface HippyDeviceAdapter { @SuppressWarnings({"EmptyMethod", "deprecation"}) - void reviseDimensionIfNeed(Context context, HippyMap dimensionMap, boolean shouldUseScreenDisplay, - boolean systemUiVisibilityChanged); + void reviseDimensionIfNeed(Context context, HippyMap dimensionMap); } diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyBridgeManagerImpl.java b/framework/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyBridgeManagerImpl.java index 72a0af5297d..ab830ac3b00 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyBridgeManagerImpl.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyBridgeManagerImpl.java @@ -506,13 +506,12 @@ String getGlobalConfigs() { assert (context != null); HippyMap globalParams = new HippyMap(); - HippyMap dimensionMap = DimensionsUtil.getDimensions(-1, -1, context, false); + HippyMap dimensionMap = DimensionsUtil.getDimensions(-1, -1, context); if (mContext.getGlobalConfigs() != null && mContext.getGlobalConfigs().getDeviceAdapter() != null) { mContext.getGlobalConfigs().getDeviceAdapter() - .reviseDimensionIfNeed(context, dimensionMap, false, - false); + .reviseDimensionIfNeed(context, dimensionMap); } DimensionsUtil.convertDimensionsToDp(dimensionMap); globalParams.pushMap("Dimensions", dimensionMap); diff --git a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/DimensionsUtil.java b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/DimensionsUtil.java index 22a6473dcd7..d2c60f438f2 100644 --- a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/DimensionsUtil.java +++ b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/DimensionsUtil.java @@ -169,8 +169,7 @@ public static int getStatusBarHeight() { return STATUS_BAR_HEIGHT; } - public static HippyMap getDimensions(int ww, int wh, Context context, - boolean shouldUseScreenDisplay) { + public static HippyMap getDimensions(int ww, int wh, Context context) { if (context == null) { return null; } @@ -191,19 +190,11 @@ public static HippyMap getDimensions(int ww, int wh, Context context, int navigationBarHeight = getNavigationBarHeight(context); HippyMap windowDisplayMetricsMap = new HippyMap(); - if (shouldUseScreenDisplay) { - windowDisplayMetricsMap.pushDouble("width", ww >= 0 ? ww : screenDisplayMetrics.widthPixels); - windowDisplayMetricsMap.pushDouble("height", wh >= 0 ? wh : screenDisplayMetrics.heightPixels); - windowDisplayMetricsMap.pushDouble("scale", screenDisplayMetrics.density); - windowDisplayMetricsMap.pushDouble("fontScale", screenDisplayMetrics.scaledDensity); - windowDisplayMetricsMap.pushDouble("densityDpi", screenDisplayMetrics.densityDpi); - } else { - windowDisplayMetricsMap.pushDouble("width", ww >= 0 ? ww : windowDisplayMetrics.widthPixels); - windowDisplayMetricsMap.pushDouble("height", wh >= 0 ? wh : windowDisplayMetrics.heightPixels); - windowDisplayMetricsMap.pushDouble("scale", windowDisplayMetrics.density); - windowDisplayMetricsMap.pushDouble("fontScale", windowDisplayMetrics.scaledDensity); - windowDisplayMetricsMap.pushDouble("densityDpi", windowDisplayMetrics.densityDpi); - } + windowDisplayMetricsMap.pushDouble("width", ww >= 0 ? ww : windowDisplayMetrics.widthPixels); + windowDisplayMetricsMap.pushDouble("height", wh >= 0 ? wh : windowDisplayMetrics.heightPixels); + windowDisplayMetricsMap.pushDouble("scale", windowDisplayMetrics.density); + windowDisplayMetricsMap.pushDouble("fontScale", windowDisplayMetrics.scaledDensity); + windowDisplayMetricsMap.pushDouble("densityDpi", windowDisplayMetrics.densityDpi); windowDisplayMetricsMap.pushDouble("statusBarHeight", statusBarHeight); windowDisplayMetricsMap.pushDouble("navigationBarHeight", navigationBarHeight); dimensionMap.pushMap("windowPhysicalPixels", windowDisplayMetricsMap); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java index efa30b06893..23a1cb21eff 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java @@ -53,7 +53,6 @@ public HippyRootView(Context context, int instanceId, int rootId) { setTag(tagMap); if (rootId != SCREEN_SNAPSHOT_ROOT_ID) { getViewTreeObserver().addOnGlobalLayoutListener(getGlobalLayoutListener()); - setOnSystemUiVisibilityChangeListener(getGlobalLayoutListener()); } } @@ -89,7 +88,7 @@ protected void onSizeChanged(int w, int h, int ow, int oh) { super.onSizeChanged(w, h, ow, oh); NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext()); if ((w != ow || h != oh) && nativeRenderer != null) { - nativeRenderer.updateDimension(w, h, false, false); + nativeRenderer.updateDimension(w, h); nativeRenderer.onSizeChanged(getId(), w, h, ow, oh); } } @@ -122,29 +121,23 @@ private GlobalLayoutListener getGlobalLayoutListener() { return mGlobalLayoutListener; } - private class GlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener, - OnSystemUiVisibilityChangeListener { + private class GlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener { private int mOrientation = ORIENTATION_UNDEFINED; - @SuppressWarnings("RedundantIfStatement") - @Override - public void onSystemUiVisibilityChange(int visibility) { - if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { - checkUpdateDimension(false, true); - } else { - checkUpdateDimension(true, true); - } - } - @Override public void onGlobalLayout() { - if (getContext() != null) { - int orientation = getContext().getResources().getConfiguration().orientation; - if (orientation != mOrientation) { - mOrientation = orientation; - sendOrientationChangeEvent(mOrientation); - checkUpdateDimension(false, false); + Context context = getContext(); + if (context == null) { + return; + } + int orientation = context.getResources().getConfiguration().orientation; + if (orientation != mOrientation) { + mOrientation = orientation; + sendOrientationChangeEvent(mOrientation); + NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(context); + if (nativeRenderer != null) { + nativeRenderer.updateDimension(-1, -1); } } } @@ -152,14 +145,5 @@ public void onGlobalLayout() { private void sendOrientationChangeEvent(int orientation) { LogUtils.d(TAG, "sendOrientationChangeEvent: orientation=" + orientation); } - - private void checkUpdateDimension(boolean shouldUseScreenDisplay, - boolean systemUiVisibilityChanged) { - NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext()); - if (nativeRenderer != null) { - nativeRenderer.updateDimension(-1, -1, shouldUseScreenDisplay, - systemUiVisibilityChanged); - } - } } } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java b/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java index afb20bd984b..2093b63c536 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java @@ -59,8 +59,7 @@ public interface FrameworkProxy { void handleNativeException(Exception exception); - void updateDimension(int width, int height, boolean shouldUseScreenDisplay, - boolean systemUiVisibilityChanged); + void updateDimension(int width, int height); void onSizeChanged(int rootId, int w, int h, int ow, int oh); } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java index 86c8ecbfc02..0a3e18eeb4c 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java @@ -103,8 +103,7 @@ VirtualNode createVirtualNode(int rootId, int id, int pid, int index, @NonNull S void onSizeChanged(int rootId, int nodeId, int width, int height, boolean isSync); - void updateDimension(int width, int height, boolean shouldUseScreenDisplay, - boolean systemUiVisibilityChanged); + void updateDimension(int width, int height); void dispatchEvent(int rootId, int nodeId, @NonNull String eventName, @Nullable Object params, boolean useCapture, boolean useBubble, EventType eventType); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java index f241db49e0e..b78c119fca8 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java @@ -403,11 +403,9 @@ public void onSizeChanged(int rootId, int nodeId, int width, int height, boolean } @Override - public void updateDimension(int width, int height, boolean shouldUseScreenDisplay, - boolean systemUiVisibilityChanged) { + public void updateDimension(int width, int height) { if (mFrameworkProxy != null) { - mFrameworkProxy.updateDimension(width, height, shouldUseScreenDisplay, - systemUiVisibilityChanged); + mFrameworkProxy.updateDimension(width, height); } }