Fullscreen and Aspect

This commit is contained in:
Florian Märkl 2019-09-16 19:00:05 +02:00
commit 5b821f2f64
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
6 changed files with 84 additions and 24 deletions

View file

@ -20,7 +20,10 @@
</intent-filter>
</activity>
<activity android:name=".stream.StreamActivity" />
<activity
android:name=".stream.StreamActivity"
android:theme="@style/StreamTheme"
android:screenOrientation="userLandscape"/>
</application>
</manifest>

View file

@ -30,7 +30,7 @@ data class StreamStateCreateError(val error: SessionCreateError): StreamState()
data class StreamStateQuit(val reason: QuitReason, val reasonString: String?): StreamState()
data class StreamStateLoginPinRequest(val pinIncorrect: Boolean): StreamState()
class StreamSession(connectInfo: ConnectInfo)
class StreamSession(val connectInfo: ConnectInfo)
{
var session: Session? = null
private set(value) { field = value }
@ -88,7 +88,7 @@ class StreamSession(connectInfo: ConnectInfo)
return surfaceTexture == null
}
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {}
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) { }
override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {}
}

View file

@ -17,20 +17,15 @@
package com.metallic.chiaki.stream
import android.graphics.SurfaceTexture
import android.graphics.Matrix
import android.os.Bundle
import android.util.Log
import android.view.Surface
import android.view.SurfaceHolder
import android.view.TextureView
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import com.metallic.chiaki.R
import com.metallic.chiaki.lib.ConnectInfo
import com.metallic.chiaki.lib.Session
import com.metallic.chiaki.lib.SessionCreateError
import kotlinx.android.synthetic.main.activity_stream.*
class StreamActivity : AppCompatActivity()
@ -64,5 +59,63 @@ class StreamActivity : AppCompatActivity()
viewModel.session.state.observe(this, Observer {
stateTextView.text = "$it"
})
textureView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
adjustTextureViewAspect()
}
}
override fun onResume()
{
super.onResume()
hideSystemUI()
}
override fun onWindowFocusChanged(hasFocus: Boolean)
{
super.onWindowFocusChanged(hasFocus)
if(hasFocus)
hideSystemUI()
}
private fun hideSystemUI()
{
Log.i("StreamActivity", "HIDE!!!!!!!!!!")
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
private fun adjustTextureViewAspect()
{
val contentWidth = viewModel.session.connectInfo.videoProfile.width.toFloat()
val contentHeight = viewModel.session.connectInfo.videoProfile.height.toFloat()
val viewWidth = textureView.width.toFloat()
val viewHeight = textureView.height.toFloat()
val contentAspect = contentHeight / contentWidth
val width: Float
val height: Float
if(viewHeight > viewWidth * contentAspect)
{
width = viewWidth
height = viewWidth * contentAspect
}
else
{
width = viewHeight / contentAspect
height = viewHeight
}
Matrix().also {
textureView.getTransform(it)
it.setScale(width / viewWidth, height / viewHeight)
it.postTranslate((viewWidth - width) * 0.5f, (viewHeight - height) * 0.5f)
textureView.setTransform(it)
}
}
}

View file

@ -9,15 +9,12 @@
<TextureView
android:id="@+id/textureView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/stateTextView"
app:layout_constraintTop_toTopOf="parent"/>
android:layout_height="match_parent"/>
<TextView
android:id="@+id/stateTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/textureView"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="primary">#008577</color>
<color name="primary_dark">#00574B</color>
<color name="accent">#D81B60</color>
<color name="stream_text">@android:color/white</color>
<color name="stream_background">@android:color/black</color>
</resources>

View file

@ -1,11 +1,15 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
<style name="StreamTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:windowBackground">@color/stream_background</item>
<item name="android:textColor">@color/stream_text</item>
</style>
</resources>