Skip to content

Commit

Permalink
add setup CurrentDeviceOrientation depending on the DeviceOrientation
Browse files Browse the repository at this point in the history
was setup to portrait despite of being used in all rendering and gyroscope calculations
  • Loading branch information
Fabian Fromm committed Oct 10, 2024
1 parent 324018b commit ef433e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/main/java/com/panoramagl/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MainActivity : AppCompatActivity(), HotSpotListener {

plManager = PLManager(this).apply {
setContentView(binding.contentView)

onCreate()
isAccelerometerEnabled = false
isInertiaEnabled = false
Expand Down Expand Up @@ -118,6 +119,7 @@ class MainActivity : AppCompatActivity(), HotSpotListener {
}
plManager.panorama = panorama
currentIndex = index
plManager.startSensorialRotation()
}

override fun onHotspotClick(identifier: Long) {
Expand Down
17 changes: 16 additions & 1 deletion library/src/main/java/com/panoramagl/PLManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ef433e2

Please sign in to comment.