Skip to content

Commit

Permalink
fix(android): remove onSystemUiVisibilityChange listener
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Jun 17, 2024
1 parent c6b8b0f commit 76d53d9
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 64 deletions.
3 changes: 3 additions & 0 deletions docs/development/android-3.0-upgrade-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
}
```

7. HippyDeviceAdapter中reviseDimensionIfNeed接口参数调整 <br>
由于HippyRootView不再监听onSystemUiVisibilityChange消息,移除shouldUseScreenDisplay和systemUiVisibilityChanged两个无效参数。

</br>

# 新增特性
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -122,44 +121,29 @@ 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);
}
}
}

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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 76d53d9

Please sign in to comment.