aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt42
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt10
3 files changed, 46 insertions, 12 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
index e37c38e9..b347d6a0 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -5,6 +5,7 @@ import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
+import android.content.res.Configuration
import android.graphics.PointF
import android.graphics.drawable.ColorDrawable
import android.net.Uri
@@ -495,4 +496,9 @@ class MainActivity : BaseActivity(),
L.d("Video view released")
videoViewer = null
}
+
+ override fun onConfigurationChanged(newConfig: Configuration) {
+ super.onConfigurationChanged(newConfig)
+ videoViewer?.updateLocation()
+ }
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
index 9932abae..c5508a4d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
@@ -68,23 +68,42 @@ class FrostVideoView @JvmOverloads constructor(
}
} else {
hideControls()
- val scale = Math.min(height / 4f / videoDimensions.y, width / 2.3f / videoDimensions.x)
- val desiredHeight = scale * videoDimensions.y
- val desiredWidth = scale * videoDimensions.x
- val padding = containerContract.lowerVideoPadding
- val offsetX = width - MINIMIZED_PADDING - desiredWidth
- val offsetY = height - MINIMIZED_PADDING - desiredHeight
- val translationX = offsetX / 2 - padding.x
- val translationY = offsetY / 2 - padding.y
- videoBounds.set(offsetX, offsetY, width.toFloat(), height.toFloat())
- videoBounds.offset(padding.x, padding.y)
- animate().scaleXY(scale).translationX(translationX).translationY(translationY).setDuration(ANIMATION_DURATION).withStartAction {
+ val (scale, tX, tY) = mapBounds()
+ animate().scaleXY(scale).translationX(tX).translationY(tY).setDuration(ANIMATION_DURATION).withStartAction {
backgroundView?.animate()?.alpha(0f)?.setDuration(ANIMATION_DURATION)
viewerContract.onFade(0f, ANIMATION_DURATION)
}
}
}
+ /**
+ * Store the boundaries of the minimized video,
+ * and return the necessary transitions to get there
+ */
+ private fun mapBounds(): Triple<Float, Float, Float> {
+ val portrait = height > width
+ val scale = Math.min(height / (if (portrait) 4f else 2.3f) / videoDimensions.y, width / (if (portrait) 2.3f else 4f) / videoDimensions.x)
+ val desiredHeight = scale * videoDimensions.y
+ val desiredWidth = scale * videoDimensions.x
+ val padding = containerContract.lowerVideoPadding
+ val offsetX = width - MINIMIZED_PADDING - desiredWidth
+ val offsetY = height - MINIMIZED_PADDING - desiredHeight
+ val tX = offsetX / 2 - padding.x
+ val tY = offsetY / 2 - padding.y
+ videoBounds.set(offsetX, offsetY, width.toFloat(), height.toFloat())
+ videoBounds.offset(padding.x, padding.y)
+ L.v("Video bounds: fullwidth $width, fullheight $height, scale $scale, tX $tX, tY $tY")
+ return Triple(scale, tX, tY)
+ }
+
+ fun updateLocation() {
+ L.d("Update video location")
+ val (scale, tX, tY) = if (isExpanded) Triple(1f, 0f, 0f) else mapBounds()
+ scaleXY = scale
+ translationX = tX
+ translationY = tY
+ }
+
init {
setOnPreparedListener {
start()
@@ -103,7 +122,6 @@ class FrostVideoView @JvmOverloads constructor(
fun jumpToStart() {
pause()
- videoControls?.hide()
v.seekTo(0)
videoControls?.finishLoading()
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
index 7ba49d3c..bf4df8fe 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
@@ -9,6 +9,7 @@ import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
+import android.view.ViewTreeObserver
import android.widget.FrameLayout
import android.widget.ImageView
import ca.allanwang.kau.utils.*
@@ -124,6 +125,15 @@ class FrostVideoViewer @JvmOverloads constructor(
restarter.fadeIn()
}
+ fun updateLocation() {
+ viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
+ override fun onGlobalLayout() {
+ video.updateLocation()
+ viewTreeObserver.removeOnGlobalLayoutListener(this)
+ }
+ })
+ }
+
}
interface FrostVideoViewerContract {