旋转屏幕,使用的是重力感应自旋转,但是一切手动切换了屏幕的旋转,那么重力旋转就无效了

This commit is contained in:
wujie
2022-11-02 09:32:52 +08:00
parent 6786cf2908
commit d63d7ecee3
3 changed files with 58 additions and 28 deletions

View File

@ -7,7 +7,9 @@ import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import java.net.Inet4Address;
@ -135,18 +137,25 @@ public class LocalAddressUtil {
@SuppressLint("JavascriptInterface")
@JavascriptInterface
public void rotateScreen(int type) {
// 使用的是view对象旋转出现的问题键盘并没有出现旋转
// view.setRotationX(type);
// view.setRotationY(type);
public void rotateScreen() {
int angle = ((WindowManager)activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
// activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
if (type == 0) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
switch (angle) {
case Surface.ROTATION_0:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
break;
case Surface.ROTATION_90:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
break;
case Surface.ROTATION_180:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case Surface.ROTATION_270:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
default:
break;
}
// System.out.println("MainActivity.rotate :: " + MainActivity.rotate);
}