Fix some rotation issue
This commit is contained in:
parent
3abf6c3554
commit
cfffa2e418
@ -38,6 +38,8 @@ import fr.mobdev.peertubelive.R
|
||||
import fr.mobdev.peertubelive.databinding.StreamBinding
|
||||
import fr.mobdev.peertubelive.manager.InstanceManager.EXTRA_DATA
|
||||
import fr.mobdev.peertubelive.objects.StreamData
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class StreamActivity : AppCompatActivity() {
|
||||
|
||||
@ -50,11 +52,12 @@ class StreamActivity : AppCompatActivity() {
|
||||
private var surfaceInit: Boolean = false
|
||||
private var permissionGiven: Boolean = false
|
||||
private var streamIsActive: Boolean = false
|
||||
private var screenOrientation: Int = 0
|
||||
private var screenOrientation: Int = -1
|
||||
private var lastScreenOrientation: Int = 0
|
||||
private var orientationCounter: Int = 0
|
||||
private var rotationIsEnabled: Boolean = true
|
||||
|
||||
private var orientationTimer: Timer = Timer()
|
||||
|
||||
companion object {
|
||||
const val BACKGROUND :Int = 1
|
||||
const val LOCK :Int = 2
|
||||
@ -69,48 +72,11 @@ class StreamActivity : AppCompatActivity() {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.stream)
|
||||
|
||||
|
||||
|
||||
orientationEventListener = object: OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){
|
||||
override fun onOrientationChanged(orientation: Int) {
|
||||
if(orientation < 0 || !rotationIsEnabled) {
|
||||
return
|
||||
}
|
||||
var localOrientation: Int
|
||||
localOrientation = when (orientation) {
|
||||
in 45..135 -> {
|
||||
90
|
||||
}
|
||||
in 135..225 -> {
|
||||
180
|
||||
}
|
||||
in 225..315 -> {
|
||||
270
|
||||
}
|
||||
else -> {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
if(localOrientation != lastScreenOrientation) {
|
||||
lastScreenOrientation = localOrientation
|
||||
orientationCounter = 0
|
||||
} else {
|
||||
orientationCounter++
|
||||
}
|
||||
|
||||
if (lastScreenOrientation != screenOrientation && orientationCounter > 30) {
|
||||
screenOrientation = lastScreenOrientation
|
||||
rtmpCamera2.glInterface.setStreamRotation(screenOrientation)
|
||||
|
||||
if (screenOrientation == 90) {
|
||||
localOrientation = 270
|
||||
} else if(screenOrientation == 270) {
|
||||
localOrientation = 90
|
||||
}
|
||||
binding.flash.rotation = localOrientation.toFloat()
|
||||
binding.muteMicro.rotation = localOrientation.toFloat()
|
||||
binding.switchCamera.rotation = localOrientation.toFloat()
|
||||
binding.rotation.rotation = localOrientation.toFloat()
|
||||
}
|
||||
handlerOrientation(orientation)
|
||||
}
|
||||
}
|
||||
orientationEventListener.enable()
|
||||
@ -146,14 +112,11 @@ class StreamActivity : AppCompatActivity() {
|
||||
binding.flash.visibility = View.GONE
|
||||
|
||||
binding.rotation.setOnClickListener {
|
||||
if (rotationIsEnabled) {
|
||||
rotationIsEnabled = !rotationIsEnabled
|
||||
if (rotationIsEnabled)
|
||||
binding.rotation.setImageResource(R.drawable.baseline_screen_lock_rotation_24)
|
||||
}
|
||||
else {
|
||||
rotationIsEnabled = !rotationIsEnabled
|
||||
else
|
||||
binding.rotation.setImageResource(R.drawable.baseline_screen_rotation_24)
|
||||
}
|
||||
rotationIsEnabled = !rotationIsEnabled
|
||||
}
|
||||
binding.rotation.visibility = View.GONE
|
||||
binding.surfaceView.holder.addCallback(object: SurfaceHolder.Callback {
|
||||
@ -262,6 +225,52 @@ class StreamActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun handlerOrientation(orientation: Int) {
|
||||
if(orientation < 0 || !rotationIsEnabled) {
|
||||
return
|
||||
}
|
||||
var localOrientation: Int
|
||||
localOrientation = when (orientation) {
|
||||
in 45..135 -> {
|
||||
90
|
||||
}
|
||||
in 135..225 -> {
|
||||
180
|
||||
}
|
||||
in 225..315 -> {
|
||||
270
|
||||
}
|
||||
else -> {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
if(localOrientation != lastScreenOrientation) {
|
||||
lastScreenOrientation = localOrientation
|
||||
orientationTimer.cancel()
|
||||
orientationTimer.purge()
|
||||
orientationTimer = Timer()
|
||||
orientationTimer.schedule(object : TimerTask() {
|
||||
override fun run() {
|
||||
if (lastScreenOrientation != screenOrientation) {
|
||||
screenOrientation = lastScreenOrientation
|
||||
rtmpCamera2.glInterface.setStreamRotation(screenOrientation)
|
||||
|
||||
if (screenOrientation == 90) {
|
||||
localOrientation = 270
|
||||
} else if(screenOrientation == 270) {
|
||||
localOrientation = 90
|
||||
}
|
||||
binding.flash.rotation = localOrientation.toFloat()
|
||||
binding.muteMicro.rotation = localOrientation.toFloat()
|
||||
binding.switchCamera.rotation = localOrientation.toFloat()
|
||||
binding.rotation.rotation = localOrientation.toFloat()
|
||||
}
|
||||
}
|
||||
},3000)
|
||||
}
|
||||
}
|
||||
|
||||
private fun startStream() {
|
||||
streamIsActive = true
|
||||
binding.permissionInfo.visibility = View.GONE
|
||||
|
Loading…
x
Reference in New Issue
Block a user