fix orientation-change can not work normally (#16774)

* fix orientation-change can not work normally
This commit is contained in:
bofeng-song
2024-03-22 09:27:54 +08:00
committed by GitHub
parent 559bfc9467
commit 5da2f9b63a
9 changed files with 167 additions and 30 deletions
@@ -24,6 +24,7 @@
package com.cocos.lib;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.media.AudioManager;
@@ -45,6 +46,7 @@ import java.util.List;
public class CocosActivity extends GameActivity {
private static final String TAG = "CocosActivity";
private static final int INITIAL_ROTATION = -1;
private CocosWebViewHelper mWebViewHelper = null;
private CocosVideoHelper mVideoHelper = null;
@@ -52,6 +54,8 @@ public class CocosActivity extends GameActivity {
private List<CocosSurfaceView> mSurfaceViewArray;
private FrameLayout mRootLayout;
private int mRotation = INITIAL_ROTATION;
private native void onCreateNative();
@@ -172,6 +176,18 @@ public class CocosActivity extends GameActivity {
surfaceView.setVisibility(View.VISIBLE);
}
}
if (mRotation == INITIAL_ROTATION
&& getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
//onConfigurationChange can be triggered at the mode of 'sensor or fullSensor'. Here only handles the sensorLandscape mode.
mRotation = CocosHelper.getDeviceRotation();
mSurfaceView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
int rotation = CocosHelper.getDeviceRotation();
if (mRotation != rotation) {
mRotation = rotation;
this.onConfigurationChangedNative(this.getGameActivityNativeHandle());
}
});
}
}
@Override