Skip to content
This repository was archived by the owner on Jul 18, 2026. It is now read-only.

Commit e8051cd

Browse files
authored
Merge pull request #99 from misaka10032w/develop
[Fix] 修复竖屏视频全屏方向错误的问题
2 parents b036f27 + aeeefd9 commit e8051cd

7 files changed

Lines changed: 75 additions & 7 deletions

File tree

app/src/main/java/com/yenaly/han1meviewer/ui/popup/HTimePickerPopup.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.yenaly.han1meviewer.ui.popup
33
import android.content.Context
44
import android.util.AttributeSet
55
import android.view.View
6+
import android.view.animation.AnimationUtils
67
import android.widget.ViewFlipper
78
import androidx.recyclerview.widget.LinearLayoutManager
89
import androidx.recyclerview.widget.RecyclerView
@@ -67,15 +68,27 @@ class HTimePickerPopup(
6768
tabLayout.removeAllTabs()
6869
tabLayout.addTab(tabLayout.newTab().setText(context.getString(R.string.specific_y_m)))
6970
tabLayout.addTab(tabLayout.newTab().setText(context.getString(R.string.approximate_range)))
71+
var lastSelectedTab = 0
7072

7173
tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
7274
override fun onTabSelected(tab: TabLayout.Tab) {
73-
viewFlipper.displayedChild = tab.position
75+
val newPosition = tab.position
76+
if (newPosition > lastSelectedTab) {
77+
viewFlipper.inAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_in_right)
78+
viewFlipper.outAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_out_left)
79+
} else {
80+
viewFlipper.inAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_in_left)
81+
viewFlipper.outAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_out_right)
82+
}
83+
viewFlipper.displayedChild = newPosition
84+
lastSelectedTab = newPosition
85+
btnSwitch.visibility = if (newPosition == 0) VISIBLE else GONE
7486
}
7587
override fun onTabUnselected(tab: TabLayout.Tab) {}
7688
override fun onTabReselected(tab: TabLayout.Tab) {}
7789
})
7890
viewFlipper.displayedChild = 0
91+
btnSwitch.visibility = VISIBLE
7992
}
8093

8194
override fun setMode(mode: Mode): TimePickerPopup {

app/src/main/java/com/yenaly/han1meviewer/ui/view/video/HJzvdStd.kt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import android.view.MotionEvent
1616
import android.view.View
1717
import android.view.View.OnLongClickListener
1818
import android.view.ViewGroup
19+
import android.view.animation.DecelerateInterpolator
1920
import android.widget.FrameLayout
2021
import android.widget.ImageView
2122
import android.widget.PopupWindow
@@ -692,8 +693,8 @@ class HJzvdStd @JvmOverloads constructor(
692693
var layoutParams = blockLayoutParams
693694
if (originalContainer is ConstraintLayout) {
694695
layoutParams = savedConstraintLayoutParams ?: ConstraintLayout.LayoutParams(
695-
ViewGroup.LayoutParams.MATCH_PARENT,
696-
ViewGroup.LayoutParams.WRAP_CONTENT
696+
LayoutParams.MATCH_PARENT,
697+
LayoutParams.WRAP_CONTENT
697698
)
698699
} else if (originalContainer is FrameLayout) {
699700
layoutParams = LayoutParams(blockLayoutParams)
@@ -733,14 +734,37 @@ class HJzvdStd @JvmOverloads constructor(
733734
CONTAINER_LIST.add(vg)
734735
val decorView = (JZUtils.scanForActivity(jzvdContext)).window.decorView as ViewGroup
735736
val fullLayout = LayoutParams(
736-
ViewGroup.LayoutParams.MATCH_PARENT,
737-
ViewGroup.LayoutParams.MATCH_PARENT
737+
LayoutParams.MATCH_PARENT,
738+
LayoutParams.MATCH_PARENT
738739
)
740+
val mediaKernel = CURRENT_JZVD?.mediaInterface as? ExoMediaKernel
741+
val videoWidth = mediaKernel?.videoRealWidth?:0
742+
val videoHeight = mediaKernel?.videoRealHeight?:0
743+
val isPortraitVideo = videoWidth > 0 && videoHeight > 0 && videoWidth < videoHeight
744+
if (isPortraitVideo) {
745+
pivotY = 0f
746+
scaleY = 0.5f
747+
}
739748
decorView.addView(this, fullLayout)
749+
if (isPortraitVideo) {
750+
animate()
751+
.scaleY(1f)
752+
.setDuration(300)
753+
.setInterpolator(DecelerateInterpolator())
754+
.start()
755+
}
740756
setScreenFullscreen()
741757
JZUtils.hideStatusBar(jzvdContext)
742-
if (activity != null) {
743-
manager.lockOrientation(activity,OrientationManager.ScreenOrientation.LANDSCAPE)
758+
val targetOrientation = if (videoWidth > 0 && videoHeight > 0) {
759+
if (isPortraitVideo)
760+
OrientationManager.ScreenOrientation.PORTRAIT
761+
else
762+
OrientationManager.ScreenOrientation.LANDSCAPE
763+
} else {
764+
OrientationManager.ScreenOrientation.LANDSCAPE
765+
}
766+
activity?.let {
767+
manager.lockOrientation(it, targetOrientation)
744768
}
745769
JZUtils.hideSystemUI(jzvdContext)
746770
}

app/src/main/java/com/yenaly/han1meviewer/ui/view/video/HMediaKernel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class ExoMediaKernel(jzvd: Jzvd) : JZMediaInterface(jzvd), Player.Listener, HMed
9494
private var callback: Runnable? = null
9595
private var prevSeek = 0L
9696

97+
var videoRealWidth: Int = 0
98+
private set
99+
var videoRealHeight: Int = 0
100+
private set
97101
@OptIn(UnstableApi::class)
98102
override fun prepare() {
99103
if (_exoPlayer != null) {
@@ -178,6 +182,9 @@ class ExoMediaKernel(jzvd: Jzvd) : JZMediaInterface(jzvd), Player.Listener, HMed
178182
override fun onVideoSizeChanged(videoSize: VideoSize) {
179183
val realWidth = videoSize.width * videoSize.pixelWidthHeightRatio
180184
val realHeight = videoSize.height
185+
videoRealWidth = realWidth.toInt()
186+
videoRealHeight = realHeight
187+
Log.i("JZVD-onVideoSizeChanged","realWidth:$realWidth,realHeight:$realHeight")
181188
handler.post {
182189
jzvd.onVideoSizeChanged(realWidth.toInt(), realHeight)
183190
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="300"
4+
android:fromXDelta="-100%"
5+
android:toXDelta="0%"
6+
android:interpolator="@android:interpolator/accelerate_decelerate"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="300"
4+
android:fromXDelta="100%"
5+
android:toXDelta="0%"
6+
android:interpolator="@android:interpolator/accelerate_decelerate"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="300"
4+
android:fromXDelta="0%"
5+
android:toXDelta="-100%"
6+
android:interpolator="@android:interpolator/accelerate_decelerate"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="300"
4+
android:fromXDelta="0%"
5+
android:toXDelta="100%"
6+
android:interpolator="@android:interpolator/accelerate_decelerate"/>

0 commit comments

Comments
 (0)