mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
fix orientation-change can not work normally (#16774)
* fix orientation-change can not work normally
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user