mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-19 03:29:58 +01:00
fixed video aspect ratio
This commit is contained in:
parent
35fdd3c395
commit
ec38659a41
@ -6,8 +6,8 @@ import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.commonsware.cwac.layouts.AspectLockedFrameLayout
|
||||
import kotlinx.android.synthetic.main.layout_media_viewer_browser_fragment.*
|
||||
import kotlinx.android.synthetic.main.layout_media_viewer_texture_video_view.*
|
||||
import org.mariotaku.mediaviewer.library.MediaViewerFragment
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.EXTRA_MEDIA
|
||||
@ -16,7 +16,7 @@ import org.mariotaku.twidere.model.ParcelableMedia
|
||||
class ExternalBrowserPageFragment : MediaViewerFragment() {
|
||||
|
||||
override fun onCreateMediaView(inflater: LayoutInflater, parent: ViewGroup,
|
||||
savedInstanceState: Bundle?): View {
|
||||
savedInstanceState: Bundle?): View {
|
||||
return inflater.inflate(R.layout.layout_media_viewer_browser_fragment, parent, false)
|
||||
}
|
||||
|
||||
@ -28,15 +28,7 @@ class ExternalBrowserPageFragment : MediaViewerFragment() {
|
||||
webSettings.loadsImagesAutomatically = true
|
||||
val media = arguments.getParcelable<ParcelableMedia>(EXTRA_MEDIA) ?: throw NullPointerException()
|
||||
webView.loadUrl(if (TextUtils.isEmpty(media.media_url)) media.url else media.media_url)
|
||||
webViewContainer.setAspectRatioSource(object : AspectLockedFrameLayout.AspectRatioSource {
|
||||
override fun getWidth(): Int {
|
||||
return media.width
|
||||
}
|
||||
|
||||
override fun getHeight(): Int {
|
||||
return media.height
|
||||
}
|
||||
})
|
||||
videoContainer.setAspectRatioSource(VideoPageFragment.MediaAspectRatioSource(media, this))
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -11,6 +11,7 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.support.v4.app.Fragment
|
||||
import android.util.Pair
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@ -57,21 +58,6 @@ class VideoPageFragment : CacheDownloadMediaViewerFragment(), IBaseFragment<Vide
|
||||
private var mediaDownloadEvent: MediaDownloadEvent? = null
|
||||
|
||||
|
||||
private var aspectRatioSource = object : AspectRatioSource {
|
||||
override fun getHeight(): Int {
|
||||
val height = media?.height ?: 0
|
||||
if (height <= 0) return view!!.measuredHeight
|
||||
return height
|
||||
}
|
||||
|
||||
override fun getWidth(): Int {
|
||||
val width = media?.width ?: 0
|
||||
if (width <= 0) return view!!.measuredWidth
|
||||
return width
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
@ -101,7 +87,7 @@ class VideoPageFragment : CacheDownloadMediaViewerFragment(), IBaseFragment<Vide
|
||||
playPauseButton.setOnClickListener(this)
|
||||
volumeButton.setOnClickListener(this)
|
||||
videoControl.visibility = View.GONE
|
||||
videoContainer.setAspectRatioSource(aspectRatioSource)
|
||||
videoContainer.setAspectRatioSource(MediaAspectRatioSource(media, this))
|
||||
if (isLoopEnabled) {
|
||||
videoViewProgress.thumb = ColorDrawable(Color.TRANSPARENT)
|
||||
videoViewProgress.isEnabled = false
|
||||
@ -416,6 +402,31 @@ class VideoPageFragment : CacheDownloadMediaViewerFragment(), IBaseFragment<Vide
|
||||
}
|
||||
}
|
||||
|
||||
class MediaAspectRatioSource(val media: ParcelableMedia?, val fragment: Fragment) : AspectRatioSource {
|
||||
override fun getHeight(): Int {
|
||||
var height = media?.height ?: 0
|
||||
if (height <= 0) {
|
||||
height = fragment.view!!.measuredHeight
|
||||
}
|
||||
if (height <= 0) {
|
||||
height = 100
|
||||
}
|
||||
return height
|
||||
}
|
||||
|
||||
override fun getWidth(): Int {
|
||||
var width = media?.width ?: 0
|
||||
if (width <= 0) {
|
||||
width = fragment.view!!.measuredWidth
|
||||
}
|
||||
if (width <= 0) {
|
||||
width = 100
|
||||
}
|
||||
return width
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val EXTRA_LOOP = "loop"
|
||||
|
Loading…
Reference in New Issue
Block a user