From ef433e2dc6cb5583cac2d810d2d104c257a25d91 Mon Sep 17 00:00:00 2001 From: Fabian Fromm Date: Thu, 10 Oct 2024 15:26:49 +0200 Subject: [PATCH] add setup CurrentDeviceOrientation depending on the DeviceOrientation was setup to portrait despite of being used in all rendering and gyroscope calculations --- .../java/com/panoramagl/sample/MainActivity.kt | 2 ++ .../src/main/java/com/panoramagl/PLManager.kt | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/panoramagl/sample/MainActivity.kt b/app/src/main/java/com/panoramagl/sample/MainActivity.kt index a4a0023..224d948 100644 --- a/app/src/main/java/com/panoramagl/sample/MainActivity.kt +++ b/app/src/main/java/com/panoramagl/sample/MainActivity.kt @@ -30,6 +30,7 @@ class MainActivity : AppCompatActivity(), HotSpotListener { plManager = PLManager(this).apply { setContentView(binding.contentView) + onCreate() isAccelerometerEnabled = false isInertiaEnabled = false @@ -118,6 +119,7 @@ class MainActivity : AppCompatActivity(), HotSpotListener { } plManager.panorama = panorama currentIndex = index + plManager.startSensorialRotation() } override fun onHotspotClick(identifier: Long) { diff --git a/library/src/main/java/com/panoramagl/PLManager.kt b/library/src/main/java/com/panoramagl/PLManager.kt index 4db46ce..aaf9a72 100755 --- a/library/src/main/java/com/panoramagl/PLManager.kt +++ b/library/src/main/java/com/panoramagl/PLManager.kt @@ -7,6 +7,7 @@ import android.hardware.SensorEvent import android.hardware.SensorEventListener import android.hardware.SensorManager import android.opengl.GLSurfaceView +import android.os.Build import android.os.Handler import android.os.Looper import android.util.DisplayMetrics @@ -38,6 +39,7 @@ import com.panoramagl.transitions.PLTransitionListener import timber.log.Timber import javax.microedition.khronos.opengles.GL10 + @Suppress("unused") open class PLManager(private val context: Context) : PLIView, SensorEventListener, OnDoubleTapListener { private var isValidForCameraAnimation: Boolean = false @@ -131,6 +133,20 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene SensorManager.SENSOR_DELAY_FASTEST else SensorManager.SENSOR_DELAY_GAME + + val rotation = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + context.display?.rotation + } else { + (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.orientation + } + + mCurrentDeviceOrientation = when (rotation) { + Surface.ROTATION_0 -> UIDeviceOrientation.UIDeviceOrientationPortrait + Surface.ROTATION_90 -> UIDeviceOrientation.UIDeviceOrientationLandscapeLeft + Surface.ROTATION_180 -> UIDeviceOrientation.UIDeviceOrientationPortraitUpsideDown + Surface.ROTATION_270 -> UIDeviceOrientation.UIDeviceOrientationLandscapeRight + else -> UIDeviceOrientation.UIDeviceOrientationPortrait + } } fun onCreate() { @@ -195,7 +211,6 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene mShakeThreshold = PLConstants.kShakeThreshold.toFloat() mIsValidForTransition = false mTouchStatus = PLTouchStatus.PLTouchStatusNone - mCurrentDeviceOrientation = UIDeviceOrientation.UIDeviceOrientationPortrait mFileDownloaderManager = PLFileDownloaderManager() mIsZoomEnabled = true this.reset()