adding a couple new things to VideoPlayerActivity

This commit is contained in:
tibbi 2019-01-02 16:26:28 +01:00
parent 780c326bd2
commit 5b14e0dd08
3 changed files with 112 additions and 49 deletions

View File

@ -1,33 +1,30 @@
package com.simplemobiletools.gallery.pro.activities
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import android.widget.SeekBar
import com.simplemobiletools.commons.extensions.beInvisibleIf
import com.simplemobiletools.commons.extensions.getFilenameFromUri
import com.simplemobiletools.commons.extensions.getParentPath
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.isPiePlus
import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.extensions.*
import com.simplemobiletools.gallery.pro.fragments.VideoFragment
import com.simplemobiletools.gallery.pro.fragments.ViewPagerFragment
import com.simplemobiletools.gallery.pro.helpers.MEDIUM
import com.simplemobiletools.gallery.pro.helpers.TYPE_VIDEOS
import com.simplemobiletools.gallery.pro.models.Medium
import kotlinx.android.synthetic.main.activity_video_player.*
import java.io.File
import kotlinx.android.synthetic.main.bottom_video_time_holder.*
open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentListener {
private var mMedium: Medium? = null
private var mIsFullScreen = false
private var mFragment: ViewPagerFragment? = null
open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
private var mIsFullscreen = false
private var mUri: Uri? = null
public override fun onCreate(savedInstanceState: Bundle?) {
@ -36,7 +33,7 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
checkIntent(savedInstanceState)
initPlayer()
} else {
toast(R.string.no_storage_permissions)
finish()
@ -50,11 +47,16 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
window.statusBarColor = Color.TRANSPARENT
window.navigationBarColor = Color.TRANSPARENT
if (config.blackBackground) {
video_player_holder.background = ColorDrawable(Color.BLACK)
}
initTimeHolder()
updateTextColors(video_player_holder)
}
private fun checkIntent(savedInstanceState: Bundle? = null) {
private fun initPlayer() {
mUri = intent.data ?: return
val filename = getFilenameFromUri(mUri!!)
supportActionBar?.title = getFilenameFromUri(mUri!!)
if (isPiePlus()) {
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
@ -62,28 +64,16 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis
}
showSystemUI(true)
val bundle = Bundle()
val file = File(mUri.toString())
val type = TYPE_VIDEOS
mMedium = Medium(null, filename, mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, 0, false, 0L)
supportActionBar?.title = mMedium!!.name
bundle.putSerializable(MEDIUM, mMedium)
if (savedInstanceState == null) {
mFragment = VideoFragment()
mFragment!!.listener = this
mFragment!!.arguments = bundle
supportFragmentManager.beginTransaction().replace(R.id.fragment_placeholder, mFragment!!).commit()
}
if (config.blackBackground) {
fragment_holder.background = ColorDrawable(Color.BLACK)
}
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
val isFullscreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
mFragment?.fullscreenToggled(isFullscreen)
fullscreenToggled(isFullscreen)
}
video_curr_time.setOnClickListener { skip(false) }
video_duration.setOnClickListener { skip(true) }
video_seekbar.setOnClickListener { }
video_player_holder.setOnClickListener {
fullscreenToggled(!mIsFullscreen)
}
}
@ -93,7 +83,7 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (mMedium == null || mUri == null) {
if (mUri == null) {
return true
}
@ -112,21 +102,61 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis
}
}
override fun fragmentClicked() {
mIsFullScreen = !mIsFullScreen
if (mIsFullScreen) {
private fun fullscreenToggled(isFullScreen: Boolean) {
mIsFullscreen = isFullScreen
if (isFullScreen) {
hideSystemUI(true)
} else {
showSystemUI(true)
}
val newAlpha = if (mIsFullScreen) 0f else 1f
val newAlpha = if (isFullScreen) 0f else 1f
top_shadow.animate().alpha(newAlpha).start()
video_time_holder.animate().alpha(newAlpha).start()
}
override fun videoEnded() = false
private fun initTimeHolder() {
val left = 0
val top = 0
var right = 0
var bottom = 0
override fun goToPrevItem() {}
if (hasNavBar()) {
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
bottom += navigationBarHeight
} else {
right += navigationBarWidth
bottom += navigationBarHeight
}
}
override fun goToNextItem() {}
video_time_holder.setPadding(left, top, right, bottom)
video_seekbar.setOnSeekBarChangeListener(this)
video_time_holder.beInvisibleIf(mIsFullscreen)
}
private fun hasNavBar(): Boolean {
val display = windowManager.defaultDisplay
val realDisplayMetrics = DisplayMetrics()
display.getRealMetrics(realDisplayMetrics)
val displayMetrics = DisplayMetrics()
display.getMetrics(displayMetrics)
return (realDisplayMetrics.widthPixels - displayMetrics.widthPixels > 0) || (realDisplayMetrics.heightPixels - displayMetrics.heightPixels > 0)
}
private fun skip(forward: Boolean) {
}
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {
}
override fun onStopTrackingTouch(seekBar: SeekBar?) {
}
}

View File

@ -1,19 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_holder"
android:id="@+id/video_player_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/top_shadow"
android:layout_width="match_parent"
android:layout_height="@dimen/default_status_action_height"
android:background="@drawable/gradient_background_flipped"/>
<TextureView
android:id="@+id/video_surface"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<com.simplemobiletools.gallery.pro.views.MediaSideScroll
android:id="@+id/video_volume_controller"
android:layout_width="@dimen/media_side_slider_width"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
<com.simplemobiletools.gallery.pro.views.MediaSideScroll
android:id="@+id/video_brightness_controller"
android:layout_width="@dimen/media_side_slider_width"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/slide_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="120dp"
android:alpha="0"
android:background="@drawable/black_rounded_background"
android:gravity="center"
android:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingBottom="@dimen/medium_margin"
android:textColor="@android:color/white"
android:textSize="@dimen/extra_big_text_size"/>
<include layout="@layout/bottom_video_time_holder"/>
</RelativeLayout>

View File

@ -5,7 +5,8 @@
android:id="@+id/video_time_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
android:layout_alignParentBottom="true"
android:background="@drawable/gradient_background">
<TextView
android:id="@+id/video_curr_time"