adding a panorama video button for toggling cardboard mode

This commit is contained in:
tibbi 2018-10-21 21:23:28 +02:00
parent 3ee3887754
commit 33880f7c1b
3 changed files with 41 additions and 15 deletions

View file

@ -24,7 +24,7 @@ import kotlinx.android.synthetic.main.activity_panorama_photo.*
open class PanoramaPhotoActivity : SimpleActivity() { open class PanoramaPhotoActivity : SimpleActivity() {
private val CARDBOARD_DISPLAY_MODE = 3 private val CARDBOARD_DISPLAY_MODE = 3
private var isFullScreen = false private var isFullscreen = false
private var isExploreEnabled = true private var isExploreEnabled = true
private var isRendering = false private var isRendering = false
@ -131,7 +131,7 @@ open class PanoramaPhotoActivity : SimpleActivity() {
} }
window.decorView.setOnSystemUiVisibilityChangeListener { visibility -> window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
isFullScreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0 isFullscreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
toggleButtonVisibility() toggleButtonVisibility()
} }
} }
@ -159,8 +159,9 @@ open class PanoramaPhotoActivity : SimpleActivity() {
} }
private fun setupButtonMargins() { private fun setupButtonMargins() {
val navBarHeight = navigationBarHeight
(cardboard.layoutParams as RelativeLayout.LayoutParams).apply { (cardboard.layoutParams as RelativeLayout.LayoutParams).apply {
bottomMargin = navigationBarHeight bottomMargin = navBarHeight
rightMargin = navigationBarWidth rightMargin = navigationBarWidth
} }
@ -168,17 +169,17 @@ open class PanoramaPhotoActivity : SimpleActivity() {
} }
private fun toggleButtonVisibility() { private fun toggleButtonVisibility() {
cardboard.animate().alpha(if (isFullScreen) 0f else 1f) cardboard.animate().alpha(if (isFullscreen) 0f else 1f)
cardboard.isClickable = !isFullScreen cardboard.isClickable = !isFullscreen
explore.animate().alpha(if (isFullScreen) 0f else 1f) explore.animate().alpha(if (isFullscreen) 0f else 1f)
explore.isClickable = !isFullScreen explore.isClickable = !isFullscreen
} }
private fun handleClick() { private fun handleClick() {
isFullScreen = !isFullScreen isFullscreen = !isFullscreen
toggleButtonVisibility() toggleButtonVisibility()
if (isFullScreen) { if (isFullscreen) {
hideSystemUI(false) hideSystemUI(false)
} else { } else {
showSystemUI(false) showSystemUI(false)

View file

@ -20,10 +20,7 @@ import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.isPiePlus import com.simplemobiletools.commons.helpers.isPiePlus
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.*
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.HIDE_PLAY_PAUSE_DELAY
import com.simplemobiletools.gallery.helpers.MIN_SKIP_LENGTH import com.simplemobiletools.gallery.helpers.MIN_SKIP_LENGTH
import com.simplemobiletools.gallery.helpers.PATH import com.simplemobiletools.gallery.helpers.PATH
@ -33,6 +30,8 @@ import kotlinx.android.synthetic.main.bottom_video_time_holder.*
import java.io.File import java.io.File
open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener { open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
private val CARDBOARD_DISPLAY_MODE = 3
private var mIsFullscreen = false private var mIsFullscreen = false
private var mIsExploreEnabled = true private var mIsExploreEnabled = true
private var mIsRendering = false private var mIsRendering = false
@ -59,6 +58,10 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
setupButtonMargins() setupButtonMargins()
cardboard.setOnClickListener {
vr_video_view.displayMode = CARDBOARD_DISPLAY_MODE
}
explore.setOnClickListener { explore.setOnClickListener {
mIsExploreEnabled = !mIsExploreEnabled mIsExploreEnabled = !mIsExploreEnabled
vr_video_view.setPureTouchTracking(mIsExploreEnabled) vr_video_view.setPureTouchTracking(mIsExploreEnabled)
@ -254,14 +257,27 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
} }
private fun setupButtonMargins() { private fun setupButtonMargins() {
(video_time_holder.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navigationBarHeight val navBarHeight = navigationBarHeight
video_time_holder.apply {
(layoutParams as RelativeLayout.LayoutParams).bottomMargin = navBarHeight
setPadding(paddingLeft, paddingTop, navigationBarWidth, paddingBottom)
}
video_time_holder.onGlobalLayout { video_time_holder.onGlobalLayout {
(explore.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navigationBarHeight + video_time_holder.height (explore.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navBarHeight + video_time_holder.height
(cardboard.layoutParams as RelativeLayout.LayoutParams).apply {
bottomMargin = navBarHeight + video_time_holder.height
rightMargin = navigationBarWidth
}
explore.requestLayout() explore.requestLayout()
} }
} }
private fun toggleButtonVisibility() { private fun toggleButtonVisibility() {
cardboard.animate().alpha(if (mIsFullscreen) 0f else 1f)
cardboard.isClickable = !mIsFullscreen
explore.animate().alpha(if (mIsFullscreen) 0f else 1f) explore.animate().alpha(if (mIsFullscreen) 0f else 1f)
explore.isClickable = !mIsFullscreen explore.isClickable = !mIsFullscreen

View file

@ -20,6 +20,15 @@
android:padding="@dimen/activity_margin" android:padding="@dimen/activity_margin"
android:src="@drawable/ic_explore"/> android:src="@drawable/ic_explore"/>
<ImageView
android:id="@+id/cardboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:padding="@dimen/activity_margin"
android:src="@drawable/ic_cardboard"/>
<ImageView <ImageView
android:id="@+id/video_play_outline" android:id="@+id/video_play_outline"
android:layout_width="@dimen/play_outline_size_big" android:layout_width="@dimen/play_outline_size_big"