From 683f1edba02eba088e8fb80562c1386f708f37b0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Jan 2019 21:49:25 +0100 Subject: [PATCH] adding a play/pause button at the bottom --- .../pro/activities/PanoramaVideoActivity.kt | 88 ++++++++----------- .../pro/activities/VideoPlayerActivity.kt | 21 ++--- .../gallery/pro/extensions/Activity.kt | 13 +++ .../res/layout/activity_panorama_video.xml | 18 +--- .../res/layout/bottom_video_time_holder.xml | 7 +- app/src/main/res/values/dimens.xml | 1 + 6 files changed, 60 insertions(+), 88 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PanoramaVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PanoramaVideoActivity.kt index 7518add3c..cbfaec7c8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PanoramaVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PanoramaVideoActivity.kt @@ -8,7 +8,6 @@ import android.os.Handler import android.view.View import android.view.Window import android.view.WindowManager -import android.view.animation.AnimationUtils import android.widget.RelativeLayout import android.widget.SeekBar import com.google.vr.sdk.widgets.video.VrVideoEventListener @@ -21,10 +20,8 @@ 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.helpers.HIDE_PLAY_PAUSE_DELAY import com.simplemobiletools.gallery.pro.helpers.MIN_SKIP_LENGTH import com.simplemobiletools.gallery.pro.helpers.PATH -import com.simplemobiletools.gallery.pro.helpers.PLAY_PAUSE_VISIBLE_ALPHA import kotlinx.android.synthetic.main.activity_panorama_video.* import kotlinx.android.synthetic.main.bottom_video_time_holder.* import java.io.File @@ -41,7 +38,6 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList private var mDuration = 0 private var mCurrTime = 0 - private var mHidePlayPauseHandler = Handler() private var mTimerHandler = Handler() public override fun onCreate(savedInstanceState: Bundle?) { @@ -56,18 +52,6 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) } - setupButtons() - - cardboard.setOnClickListener { - vr_video_view.displayMode = CARDBOARD_DISPLAY_MODE - } - - explore.setOnClickListener { - mIsExploreEnabled = !mIsExploreEnabled - vr_video_view.setPureTouchTracking(mIsExploreEnabled) - explore.setImageResource(if (mIsExploreEnabled) R.drawable.ic_explore else R.drawable.ic_explore_off) - } - handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { checkIntent() @@ -102,7 +86,6 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList } if (!isChangingConfigurations) { - mHidePlayPauseHandler.removeCallbacksAndMessages(null) mTimerHandler.removeCallbacksAndMessages(null) } } @@ -115,6 +98,7 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList return } + setupButtons() intent.removeExtra(PATH) video_curr_time.setOnClickListener { skip(false) } @@ -164,7 +148,7 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList }) } - video_play_outline.setOnClickListener { + video_toggle_play_pause.setOnClickListener { togglePlayPause() } } catch (e: Exception) { @@ -205,18 +189,15 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList private fun togglePlayPause() { mIsPlaying = !mIsPlaying - video_play_outline.alpha = PLAY_PAUSE_VISIBLE_ALPHA - mHidePlayPauseHandler.removeCallbacksAndMessages(null) if (mIsPlaying) { playVideo() } else { pauseVideo() } - schedulePlayPauseFadeOut() } private fun playVideo() { - video_play_outline.setImageResource(R.drawable.ic_pause) + video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline) if (mCurrTime == mDuration) { setVideoProgress(0) mPlayOnReady = true @@ -229,7 +210,7 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList private fun pauseVideo() { vr_video_view.pauseVideo() - video_play_outline.setImageResource(R.drawable.ic_play) + video_toggle_play_pause.setImageResource(R.drawable.ic_play_outline) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } @@ -246,55 +227,57 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList video_seekbar.progress = video_seekbar.max video_curr_time.text = mDuration.getFormattedDuration() pauseVideo() - video_play_outline.alpha = PLAY_PAUSE_VISIBLE_ALPHA - } - - private fun schedulePlayPauseFadeOut() { - mHidePlayPauseHandler.removeCallbacksAndMessages(null) - mHidePlayPauseHandler.postDelayed({ - video_play_outline.animate().alpha(0f).start() - }, HIDE_PLAY_PAUSE_DELAY) } private fun setupButtons() { - val navBarHeight = navigationBarHeight - video_time_holder.apply { - (layoutParams as RelativeLayout.LayoutParams).bottomMargin = navBarHeight - setPadding(paddingLeft, paddingTop, navigationBarWidth, paddingBottom) + var right = 0 + var bottom = 0 + + if (hasNavBar()) { + if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { + bottom += navigationBarHeight + } else { + right += navigationBarWidth + bottom += navigationBarHeight + } } + video_time_holder.setPadding(0, 0, right, bottom) video_time_holder.onGlobalLayout { - (explore.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navBarHeight + video_time_holder.height + val newBottomMargin = video_time_holder.height - resources.getDimension(R.dimen.video_player_play_pause_size).toInt() - resources.getDimension(R.dimen.activity_margin).toInt() + (explore.layoutParams as RelativeLayout.LayoutParams).bottomMargin = newBottomMargin (cardboard.layoutParams as RelativeLayout.LayoutParams).apply { - bottomMargin = navBarHeight + video_time_holder.height + bottomMargin = newBottomMargin rightMargin = navigationBarWidth } - vr_view_gradient_background.layoutParams.height = navBarHeight + video_time_holder.height + explore.height explore.requestLayout() } + video_toggle_play_pause.setImageResource(R.drawable.ic_play_outline) + + cardboard.setOnClickListener { + vr_video_view.displayMode = CARDBOARD_DISPLAY_MODE + } + + explore.setOnClickListener { + mIsExploreEnabled = !mIsExploreEnabled + vr_video_view.setPureTouchTracking(mIsExploreEnabled) + explore.setImageResource(if (mIsExploreEnabled) R.drawable.ic_explore else R.drawable.ic_explore_off) + } } private fun toggleButtonVisibility() { val newAlpha = if (mIsFullscreen) 0f else 1f - arrayOf(cardboard, explore, vr_view_gradient_background).forEach { + arrayOf(cardboard, explore).forEach { it.animate().alpha(newAlpha) + } + + arrayOf(cardboard, explore, video_toggle_play_pause, video_curr_time, video_duration).forEach { it.isClickable = !mIsFullscreen } - var anim = android.R.anim.fade_in - if (mIsFullscreen) { - anim = android.R.anim.fade_out - video_seekbar.setOnSeekBarChangeListener(null) - } else { - video_seekbar.setOnSeekBarChangeListener(this) - } - - AnimationUtils.loadAnimation(this, anim).apply { - duration = 150 - fillAfter = true - video_time_holder.startAnimation(this) - } + video_seekbar.setOnSeekBarChangeListener(if (mIsFullscreen) null else this) + video_time_holder.animate().alpha(newAlpha).start() } private fun handleClick() { @@ -338,6 +321,5 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList mIsPlaying = true playVideo() mIsDragged = false - schedulePlayPauseFadeOut() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt index 77bc90f02..bc33713f3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt @@ -68,7 +68,6 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) window.statusBarColor = Color.TRANSPARENT window.navigationBarColor = Color.TRANSPARENT - video_time_holder.background = resources.getDrawable(R.drawable.gradient_background) if (config.blackBackground) { video_player_holder.background = ColorDrawable(Color.BLACK) } @@ -247,6 +246,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen } private fun playVideo() { + video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline) if (mExoPlayer == null) { return } @@ -259,11 +259,11 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen mWasVideoStarted = true mIsPlaying = true mExoPlayer?.playWhenReady = true - video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } private fun pauseVideo() { + video_toggle_play_pause.setImageResource(R.drawable.ic_play_outline) if (mExoPlayer == null) { return } @@ -273,7 +273,6 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen mExoPlayer?.playWhenReady = false } - video_toggle_play_pause.setImageResource(R.drawable.ic_play_outline) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } @@ -380,6 +379,10 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen val newAlpha = if (isFullScreen) 0f else 1f top_shadow.animate().alpha(newAlpha).start() video_time_holder.animate().alpha(newAlpha).start() + video_seekbar.setOnSeekBarChangeListener(if (mIsFullscreen) null else this) + arrayOf(video_toggle_play_pause, video_curr_time, video_duration).forEach { + it.isClickable = !mIsFullscreen + } } private fun initTimeHolder() { @@ -417,18 +420,6 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen }) } - 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) { if (mExoPlayer == null) { return diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 663637b28..a8103b206 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.pro.extensions import android.app.Activity import android.content.Intent import android.provider.MediaStore +import android.util.DisplayMetrics import android.view.View import androidx.appcompat.app.AppCompatActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity @@ -292,3 +293,15 @@ fun BaseSimpleActivity.updateFavoritePaths(fileDirItems: ArrayList, } }.start() } + +fun Activity.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) +} diff --git a/app/src/main/res/layout/activity_panorama_video.xml b/app/src/main/res/layout/activity_panorama_video.xml index 7b7919887..343496d24 100644 --- a/app/src/main/res/layout/activity_panorama_video.xml +++ b/app/src/main/res/layout/activity_panorama_video.xml @@ -11,12 +11,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> - + - - - - diff --git a/app/src/main/res/layout/bottom_video_time_holder.xml b/app/src/main/res/layout/bottom_video_time_holder.xml index 7e0422f00..94f5b147e 100644 --- a/app/src/main/res/layout/bottom_video_time_holder.xml +++ b/app/src/main/res/layout/bottom_video_time_holder.xml @@ -5,12 +5,13 @@ 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"> 96dp 60dp 60dp + 60dp 50dp 72dp 64dp