Skip to content

Commit d8a0d5f

Browse files
authored
Merge pull request #354 from keinerVonIhnen/device_orientation
Device orientation
2 parents ebc1808 + ef433e2 commit d8a0d5f

File tree

3 files changed

+64
-47
lines changed

3 files changed

+64
-47
lines changed

app/src/main/java/com/panoramagl/sample/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class MainActivity : AppCompatActivity(), HotSpotListener {
3030

3131
plManager = PLManager(this).apply {
3232
setContentView(binding.contentView)
33+
3334
onCreate()
3435
isAccelerometerEnabled = false
3536
isInertiaEnabled = false
@@ -118,6 +119,7 @@ class MainActivity : AppCompatActivity(), HotSpotListener {
118119
}
119120
plManager.panorama = panorama
120121
currentIndex = index
122+
plManager.startSensorialRotation()
121123
}
122124

123125
override fun onHotspotClick(identifier: Long) {

library/src/main/java/com/panoramagl/PLManager.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.hardware.SensorEvent
77
import android.hardware.SensorEventListener
88
import android.hardware.SensorManager
99
import android.opengl.GLSurfaceView
10+
import android.os.Build
1011
import android.os.Handler
1112
import android.os.Looper
1213
import android.util.DisplayMetrics
@@ -38,6 +39,7 @@ import com.panoramagl.transitions.PLTransitionListener
3839
import timber.log.Timber
3940
import javax.microedition.khronos.opengles.GL10
4041

42+
4143
@Suppress("unused")
4244
open class PLManager(private val context: Context) : PLIView, SensorEventListener, OnDoubleTapListener {
4345
private var isValidForCameraAnimation: Boolean = false
@@ -131,6 +133,20 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene
131133
SensorManager.SENSOR_DELAY_FASTEST
132134
else
133135
SensorManager.SENSOR_DELAY_GAME
136+
137+
val rotation = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
138+
context.display?.rotation
139+
} else {
140+
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.orientation
141+
}
142+
143+
mCurrentDeviceOrientation = when (rotation) {
144+
Surface.ROTATION_0 -> UIDeviceOrientation.UIDeviceOrientationPortrait
145+
Surface.ROTATION_90 -> UIDeviceOrientation.UIDeviceOrientationLandscapeLeft
146+
Surface.ROTATION_180 -> UIDeviceOrientation.UIDeviceOrientationPortraitUpsideDown
147+
Surface.ROTATION_270 -> UIDeviceOrientation.UIDeviceOrientationLandscapeRight
148+
else -> UIDeviceOrientation.UIDeviceOrientationPortrait
149+
}
134150
}
135151

136152
fun onCreate() {
@@ -195,7 +211,6 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene
195211
mShakeThreshold = PLConstants.kShakeThreshold.toFloat()
196212
mIsValidForTransition = false
197213
mTouchStatus = PLTouchStatus.PLTouchStatusNone
198-
mCurrentDeviceOrientation = UIDeviceOrientation.UIDeviceOrientationPortrait
199214
mFileDownloaderManager = PLFileDownloaderManager()
200215
mIsZoomEnabled = true
201216
this.reset()

library/src/main/java/com/panoramagl/PLViewListener.kt

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,80 +13,80 @@ import com.panoramagl.transitions.PLITransition
1313

1414
@Suppress("UNUSED_PARAMETER")
1515
abstract class PLViewListener {
16-
fun onTouchesBegan(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
17-
fun onTouchesMoved(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
18-
fun onTouchesEnded(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
19-
fun onShouldBeginTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?): Boolean {
16+
open fun onTouchesBegan(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
17+
open fun onTouchesMoved(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
18+
open fun onTouchesEnded(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
19+
open fun onShouldBeginTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?): Boolean {
2020
return true
2121
}
2222

23-
fun onDidBeginTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
24-
fun onShouldMoveTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?): Boolean {
23+
open fun onDidBeginTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
24+
open fun onShouldMoveTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?): Boolean {
2525
return true
2626
}
2727

28-
fun onDidMoveTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
29-
fun onShouldEndTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?): Boolean {
28+
open fun onDidMoveTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
29+
open fun onShouldEndTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?): Boolean {
3030
return true
3131
}
3232

33-
fun onDidEndTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
34-
fun onShouldAccelerate(view: PLIView?, acceleration: UIAcceleration?, event: SensorEvent?): Boolean {
33+
open fun onDidEndTouching(view: PLIView?, touches: List<UITouch?>?, event: MotionEvent?) {}
34+
open fun onShouldAccelerate(view: PLIView?, acceleration: UIAcceleration?, event: SensorEvent?): Boolean {
3535
return true
3636
}
3737

38-
fun onDidAccelerate(view: PLIView?, acceleration: UIAcceleration?, event: SensorEvent?) {}
39-
fun onShouldBeginInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?): Boolean {
38+
open fun onDidAccelerate(view: PLIView?, acceleration: UIAcceleration?, event: SensorEvent?) {}
39+
open fun onShouldBeginInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?): Boolean {
4040
return true
4141
}
4242

43-
fun onDidBeginInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
44-
fun onShouldRunInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?): Boolean {
43+
open fun onDidBeginInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
44+
open fun onShouldRunInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?): Boolean {
4545
return true
4646
}
4747

48-
fun onDidRunInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
49-
fun onDidEndInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
50-
fun onShouldBeingScrolling(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?): Boolean {
48+
open fun onDidRunInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
49+
open fun onDidEndInertia(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
50+
open fun onShouldBeingScrolling(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?): Boolean {
5151
return true
5252
}
5353

54-
fun onDidBeginScrolling(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
55-
fun onDidEndScrolling(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
56-
fun onShouldBeginZooming(view: PLIView?): Boolean {
54+
open fun onDidBeginScrolling(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
55+
open fun onDidEndScrolling(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
56+
open fun onShouldBeginZooming(view: PLIView?): Boolean {
5757
return true
5858
}
5959

60-
fun onDidBeginZooming(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
61-
fun onShouldRunZooming(view: PLIView?, distance: Float, isZoomIn: Boolean, isZoomOut: Boolean): Boolean {
60+
open fun onDidBeginZooming(view: PLIView?, startPoint: CGPoint?, endPoint: CGPoint?) {}
61+
open fun onShouldRunZooming(view: PLIView?, distance: Float, isZoomIn: Boolean, isZoomOut: Boolean): Boolean {
6262
return true
6363
}
6464

65-
fun onDidRunZooming(view: PLIView?, distance: Float, isZoomIn: Boolean, isZoomOut: Boolean) {}
66-
fun onDidEndZooming(view: PLIView?) {}
67-
fun onShouldReset(view: PLIView?): Boolean {
65+
open fun onDidRunZooming(view: PLIView?, distance: Float, isZoomIn: Boolean, isZoomOut: Boolean) {}
66+
open fun onDidEndZooming(view: PLIView?) {}
67+
open fun onShouldReset(view: PLIView?): Boolean {
6868
return true
6969
}
7070

71-
fun onDidReset(view: PLIView?) {}
72-
fun onDidBeginCameraAnimation(view: PLIView?, sender: Any?, camera: PLICamera?, type: PLCameraAnimationType?) {}
73-
fun onDidEndCameraAnimation(view: PLIView?, sender: Any?, camera: PLICamera?, type: PLCameraAnimationType?) {}
74-
fun onDidResetCamera(view: PLIView?, sender: Any?, camera: PLICamera?) {}
75-
fun onDidLookAtCamera(view: PLIView?, sender: Any?, camera: PLICamera?, pitch: Float, yaw: Float, animated: Boolean) {}
76-
fun onDidRotateCamera(view: PLIView?, sender: Any?, camera: PLICamera?, pitch: Float, yaw: Float, roll: Float) {}
77-
fun onDidFovCamera(view: PLIView?, sender: Any?, camera: PLICamera?, fov: Float, animated: Boolean) {}
78-
fun onDidOverElement(view: PLIView?, element: PLISceneElement?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
79-
fun onDidClickElement(view: PLIView?, element: PLISceneElement?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
80-
fun onDidOutElement(view: PLIView?, element: PLISceneElement?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
81-
fun onDidOverHotspot(view: PLIView?, hotspot: PLIHotspot?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
82-
fun onDidClickHotspot(view: PLIView?, hotspot: PLIHotspot?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
83-
fun onDidOutHotspot(view: PLIView?, hotspot: PLIHotspot?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
84-
fun onDidBeginTransition(view: PLIView?, transition: PLITransition?) {}
85-
fun onDidProcessTransition(view: PLIView?, transition: PLITransition?, progressPercentage: Int) {}
86-
fun onDidStopTransition(view: PLIView?, transition: PLITransition?, progressPercentage: Int) {}
87-
fun onDidEndTransition(view: PLIView?, transition: PLITransition?) {}
88-
fun onDidBeginLoader(view: PLIView?, loader: PLILoader?) {}
89-
fun onDidCompleteLoader(view: PLIView?, loader: PLILoader?) {}
90-
fun onDidStopLoader(view: PLIView?, loader: PLILoader?) {}
91-
fun onDidErrorLoader(view: PLIView?, loader: PLILoader?, error: String?) {}
71+
open fun onDidReset(view: PLIView?) {}
72+
open fun onDidBeginCameraAnimation(view: PLIView?, sender: Any?, camera: PLICamera?, type: PLCameraAnimationType?) {}
73+
open fun onDidEndCameraAnimation(view: PLIView?, sender: Any?, camera: PLICamera?, type: PLCameraAnimationType?) {}
74+
open fun onDidResetCamera(view: PLIView?, sender: Any?, camera: PLICamera?) {}
75+
open fun onDidLookAtCamera(view: PLIView?, sender: Any?, camera: PLICamera?, pitch: Float, yaw: Float, animated: Boolean) {}
76+
open fun onDidRotateCamera(view: PLIView?, sender: Any?, camera: PLICamera?, pitch: Float, yaw: Float, roll: Float) {}
77+
open fun onDidFovCamera(view: PLIView?, sender: Any?, camera: PLICamera?, fov: Float, animated: Boolean) {}
78+
open fun onDidOverElement(view: PLIView?, element: PLISceneElement?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
79+
open fun onDidClickElement(view: PLIView?, element: PLISceneElement?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
80+
open fun onDidOutElement(view: PLIView?, element: PLISceneElement?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
81+
open fun onDidOverHotspot(view: PLIView?, hotspot: PLIHotspot?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
82+
open fun onDidClickHotspot(view: PLIView?, hotspot: PLIHotspot?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
83+
open fun onDidOutHotspot(view: PLIView?, hotspot: PLIHotspot?, screenPoint: CGPoint?, scene3DPoint: PLPosition?) {}
84+
open fun onDidBeginTransition(view: PLIView?, transition: PLITransition?) {}
85+
open fun onDidProcessTransition(view: PLIView?, transition: PLITransition?, progressPercentage: Int) {}
86+
open fun onDidStopTransition(view: PLIView?, transition: PLITransition?, progressPercentage: Int) {}
87+
open fun onDidEndTransition(view: PLIView?, transition: PLITransition?) {}
88+
open fun onDidBeginLoader(view: PLIView?, loader: PLILoader?) {}
89+
open fun onDidCompleteLoader(view: PLIView?, loader: PLILoader?) {}
90+
open fun onDidStopLoader(view: PLIView?, loader: PLILoader?) {}
91+
open fun onDidErrorLoader(view: PLIView?, loader: PLILoader?, error: String?) {}
9292
}

0 commit comments

Comments
 (0)