optimized playing screen
This commit is contained in:
@@ -21,6 +21,8 @@ import android.widget.ScrollView
|
|||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import android.widget.Switch
|
import android.widget.Switch
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import cn.learningpad.oraltrainer.sample.Module
|
import cn.learningpad.oraltrainer.sample.Module
|
||||||
import cn.learningpad.oraltrainer.sample.PROGRESS_MAX
|
import cn.learningpad.oraltrainer.sample.PROGRESS_MAX
|
||||||
import cn.learningpad.oraltrainer.sample.R
|
import cn.learningpad.oraltrainer.sample.R
|
||||||
@@ -104,18 +106,66 @@ internal class PlayerChrome(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createLandscapeContentView(): View =
|
fun createLandscapeContentView(): View =
|
||||||
FrameLayout(activity).apply {
|
LinearLayout(activity).apply {
|
||||||
|
orientation = LinearLayout.VERTICAL
|
||||||
setBackgroundColor(Color.BLACK)
|
setBackgroundColor(Color.BLACK)
|
||||||
addView(createPlayerView())
|
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
|
||||||
|
val bars = insets.getInsets(
|
||||||
|
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout(),
|
||||||
|
)
|
||||||
|
val gestures = insets.getInsets(WindowInsetsCompat.Type.mandatorySystemGestures())
|
||||||
|
view.setPadding(
|
||||||
|
bars.left,
|
||||||
|
bars.top,
|
||||||
|
bars.right,
|
||||||
|
maxOf(bars.bottom, gestures.bottom, 24.dp),
|
||||||
|
)
|
||||||
|
WindowInsetsCompat.CONSUMED
|
||||||
|
}
|
||||||
addView(
|
addView(
|
||||||
createPlayerOverlay().apply {
|
createPlayerOverlay(compact = true).apply {
|
||||||
layoutParams = FrameLayout.LayoutParams(
|
layoutParams = LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
Gravity.TOP,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
addView(
|
||||||
|
FrameLayout(activity).apply {
|
||||||
|
layoutParams = LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
0,
|
||||||
|
1f,
|
||||||
|
)
|
||||||
|
addView(
|
||||||
|
object : FrameLayout(activity) {
|
||||||
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
|
val maxWidth = MeasureSpec.getSize(widthMeasureSpec)
|
||||||
|
val maxHeight = MeasureSpec.getSize(heightMeasureSpec)
|
||||||
|
val heightFromWidth = if (maxWidth > 0) (maxWidth * 9) / 16 else 0
|
||||||
|
val width: Int
|
||||||
|
val height: Int
|
||||||
|
if (heightFromWidth <= maxHeight) {
|
||||||
|
width = maxWidth
|
||||||
|
height = heightFromWidth
|
||||||
|
} else {
|
||||||
|
height = maxHeight
|
||||||
|
width = (maxHeight * 16) / 9
|
||||||
|
}
|
||||||
|
super.onMeasure(
|
||||||
|
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
||||||
|
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}.apply {
|
||||||
|
layoutParams = FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
Gravity.TOP or Gravity.CENTER_HORIZONTAL,
|
||||||
|
)
|
||||||
|
addView(createPlayerView())
|
||||||
|
},
|
||||||
|
)
|
||||||
val subtitleContainer = LinearLayout(activity).apply {
|
val subtitleContainer = LinearLayout(activity).apply {
|
||||||
orientation = LinearLayout.VERTICAL
|
orientation = LinearLayout.VERTICAL
|
||||||
layoutParams = FrameLayout.LayoutParams(
|
layoutParams = FrameLayout.LayoutParams(
|
||||||
@@ -135,6 +185,8 @@ internal class PlayerChrome(
|
|||||||
addView(subtitleContainer)
|
addView(subtitleContainer)
|
||||||
applyLandscapeSubtitleState(subtitleContainer, animate = false)
|
applyLandscapeSubtitleState(subtitleContainer, animate = false)
|
||||||
installLandscapeSwipeGesture(subtitleContainer)
|
installLandscapeSwipeGesture(subtitleContainer)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSentenceContent(translucent: Boolean): LinearLayout {
|
fun createSentenceContent(translucent: Boolean): LinearLayout {
|
||||||
@@ -279,12 +331,16 @@ internal class PlayerChrome(
|
|||||||
)
|
)
|
||||||
}.also { bindings.playerView = it }
|
}.also { bindings.playerView = it }
|
||||||
|
|
||||||
private fun createPlayerOverlay(): View {
|
private fun createPlayerOverlay(compact: Boolean = false): View {
|
||||||
val overlay = LinearLayout(activity).apply {
|
val overlay = LinearLayout(activity).apply {
|
||||||
orientation = LinearLayout.HORIZONTAL
|
orientation = LinearLayout.HORIZONTAL
|
||||||
gravity = Gravity.CENTER_VERTICAL
|
gravity = Gravity.CENTER_VERTICAL
|
||||||
|
if (compact) {
|
||||||
|
setPadding(12.dp, 4.dp, 12.dp, 0)
|
||||||
|
} else {
|
||||||
setPadding(12.dp, 10.dp, 12.dp, 8.dp)
|
setPadding(12.dp, 10.dp, 12.dp, 8.dp)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bindings.timeText = widgets.overlayPill("--:-- / --:--").apply {
|
bindings.timeText = widgets.overlayPill("--:-- / --:--").apply {
|
||||||
layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)
|
layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user