diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaVideoActivity.kt index 5a9ebee26..9380531b4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaVideoActivity.kt @@ -4,6 +4,7 @@ import android.content.res.Configuration import android.graphics.Color import android.net.Uri import android.os.Bundle +import android.os.Handler import android.view.View import android.view.Window import android.view.WindowManager @@ -19,7 +20,9 @@ import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.hideSystemUI import com.simplemobiletools.gallery.extensions.navigationBarHeight import com.simplemobiletools.gallery.extensions.showSystemUI +import com.simplemobiletools.gallery.helpers.HIDE_PLAY_PAUSE_DELAY import com.simplemobiletools.gallery.helpers.PATH +import com.simplemobiletools.gallery.helpers.PLAY_PAUSE_VISIBLE_ALPHA import kotlinx.android.synthetic.main.activity_panorama_video.* import java.io.File @@ -27,6 +30,9 @@ open class PanoramaVideoActivity : SimpleActivity() { private var isFullScreen = false private var isExploreEnabled = true private var isRendering = false + private var isPlaying = true + + private var mHidePlayPauseHandler = Handler() public override fun onCreate(savedInstanceState: Bundle?) { useDynamicTheme = false @@ -80,6 +86,10 @@ open class PanoramaVideoActivity : SimpleActivity() { if (isRendering) { vr_video_view.shutdown() } + + if (!isChangingConfigurations) { + mHidePlayPauseHandler.removeCallbacksAndMessages(null) + } } private fun checkIntent() { @@ -98,6 +108,7 @@ open class PanoramaVideoActivity : SimpleActivity() { vr_video_view.apply { loadVideo(Uri.fromFile(File(path)), options) + schedulePlayPauseFadeOut() setFlingingEnabled(true) setPureTouchTracking(true) @@ -117,6 +128,10 @@ open class PanoramaVideoActivity : SimpleActivity() { } }) } + + video_play_outline.setOnClickListener { + togglePlayPause() + } } catch (e: Exception) { showErrorToast(e) } @@ -132,6 +147,37 @@ open class PanoramaVideoActivity : SimpleActivity() { setupButtonMargins() } + private fun togglePlayPause() { + isPlaying = !isPlaying + mHidePlayPauseHandler.removeCallbacksAndMessages(null) + video_play_outline.alpha = PLAY_PAUSE_VISIBLE_ALPHA + schedulePlayPauseFadeOut() + if (isPlaying) { + playVideo() + } else { + pauseVideo() + } + } + + private fun playVideo() { + vr_video_view.playVideo() + video_play_outline.setImageResource(R.drawable.ic_pause) + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + + private fun pauseVideo() { + vr_video_view.pauseVideo() + video_play_outline.setImageResource(R.drawable.ic_play) + window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + + private fun schedulePlayPauseFadeOut() { + mHidePlayPauseHandler.removeCallbacksAndMessages(null) + mHidePlayPauseHandler.postDelayed({ + video_play_outline.animate().alpha(0f).start() + }, HIDE_PLAY_PAUSE_DELAY) + } + private fun setupButtonMargins() { (explore.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navigationBarHeight } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index ef35bc1fe..c1976644b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -32,6 +32,7 @@ import com.simplemobiletools.gallery.activities.VideoActivity import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium +import kotlinx.android.synthetic.main.activity_panorama_video.* import kotlinx.android.synthetic.main.pager_video_item.view.* import java.io.File @@ -415,6 +416,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S mIsPlaying = true mExoPlayer?.playWhenReady = true mView!!.video_play_outline.setImageResource(R.drawable.ic_pause) + video_play_outline.alpha = PLAY_PAUSE_VISIBLE_ALPHA activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) schedulePlayPauseFadeOut() } diff --git a/app/src/main/res/layout/activity_panorama_video.xml b/app/src/main/res/layout/activity_panorama_video.xml index 7708f6412..e5c970568 100644 --- a/app/src/main/res/layout/activity_panorama_video.xml +++ b/app/src/main/res/layout/activity_panorama_video.xml @@ -20,4 +20,13 @@ android:padding="@dimen/activity_margin" android:src="@drawable/ic_explore"/> + +