adding some PanoramaVideo implementation
This commit is contained in:
parent
9a4e9ad318
commit
cb4d86461e
7 changed files with 203 additions and 9 deletions
|
@ -56,6 +56,7 @@ dependencies {
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
|
||||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.9.0'
|
implementation 'com.google.android.exoplayer:exoplayer-core:2.9.0'
|
||||||
implementation 'com.google.vr:sdk-panowidget:1.170.0'
|
implementation 'com.google.vr:sdk-panowidget:1.170.0'
|
||||||
|
implementation 'com.google.vr:sdk-videowidget:1.170.0'
|
||||||
implementation 'org.apache.sanselan:sanselan:0.97-incubator'
|
implementation 'org.apache.sanselan:sanselan:0.97-incubator'
|
||||||
implementation 'info.androidhive:imagefilters:1.0.7'
|
implementation 'info.androidhive:imagefilters:1.0.7'
|
||||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||||
|
|
|
@ -127,6 +127,11 @@
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
android:theme="@style/FullScreenTheme"/>
|
android:theme="@style/FullScreenTheme"/>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activities.PanoramaVideoActivity"
|
||||||
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
|
android:theme="@style/FullScreenTheme"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.IncludedFoldersActivity"
|
android:name=".activities.IncludedFoldersActivity"
|
||||||
android:label="@string/include_folders"
|
android:label="@string/include_folders"
|
||||||
|
|
|
@ -19,7 +19,7 @@ import com.simplemobiletools.commons.helpers.isPiePlus
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
import com.simplemobiletools.gallery.helpers.PATH
|
import com.simplemobiletools.gallery.helpers.PATH
|
||||||
import kotlinx.android.synthetic.main.activity_panorama.*
|
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
|
||||||
|
@ -32,7 +32,7 @@ open class PanoramaPhotoActivity : SimpleActivity() {
|
||||||
useDynamicTheme = false
|
useDynamicTheme = false
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_panorama)
|
setContentView(R.layout.activity_panorama_photo)
|
||||||
supportActionBar?.hide()
|
supportActionBar?.hide()
|
||||||
|
|
||||||
if (isPiePlus()) {
|
if (isPiePlus()) {
|
||||||
|
@ -107,11 +107,6 @@ open class PanoramaPhotoActivity : SimpleActivity() {
|
||||||
loadImageFromBitmap(bitmap, options)
|
loadImageFromBitmap(bitmap, options)
|
||||||
setFlingingEnabled(true)
|
setFlingingEnabled(true)
|
||||||
setPureTouchTracking(true)
|
setPureTouchTracking(true)
|
||||||
setEventListener(object : VrPanoramaEventListener() {
|
|
||||||
override fun onClick() {
|
|
||||||
handleClick()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// add custom buttons so we can position them and toggle visibility as desired
|
// add custom buttons so we can position them and toggle visibility as desired
|
||||||
setFullscreenButtonEnabled(false)
|
setFullscreenButtonEnabled(false)
|
||||||
|
@ -122,6 +117,12 @@ open class PanoramaPhotoActivity : SimpleActivity() {
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
handleClick()
|
handleClick()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setEventListener(object : VrPanoramaEventListener() {
|
||||||
|
override fun onClick() {
|
||||||
|
handleClick()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
package com.simplemobiletools.gallery.activities
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.view.Window
|
||||||
|
import android.view.WindowManager
|
||||||
|
import android.widget.RelativeLayout
|
||||||
|
import com.google.vr.sdk.widgets.video.VrVideoEventListener
|
||||||
|
import com.google.vr.sdk.widgets.video.VrVideoView
|
||||||
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
|
import com.simplemobiletools.commons.helpers.isPiePlus
|
||||||
|
import com.simplemobiletools.gallery.R
|
||||||
|
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.PATH
|
||||||
|
import kotlinx.android.synthetic.main.activity_panorama_video.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
open class PanoramaVideoActivity : SimpleActivity() {
|
||||||
|
private var isFullScreen = false
|
||||||
|
private var isExploreEnabled = true
|
||||||
|
private var isRendering = false
|
||||||
|
|
||||||
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
useDynamicTheme = false
|
||||||
|
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_panorama_video)
|
||||||
|
supportActionBar?.hide()
|
||||||
|
|
||||||
|
if (isPiePlus()) {
|
||||||
|
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||||
|
}
|
||||||
|
|
||||||
|
setupButtonMargins()
|
||||||
|
|
||||||
|
explore.setOnClickListener {
|
||||||
|
isExploreEnabled = !isExploreEnabled
|
||||||
|
vr_video_view.setPureTouchTracking(isExploreEnabled)
|
||||||
|
explore.setImageResource(if (isExploreEnabled) R.drawable.ic_explore else R.drawable.ic_explore_off)
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||||
|
if (it) {
|
||||||
|
checkIntent()
|
||||||
|
} else {
|
||||||
|
toast(R.string.no_storage_permissions)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
vr_video_view.resumeRendering()
|
||||||
|
isRendering = true
|
||||||
|
if (config.blackBackground) {
|
||||||
|
updateStatusbarColor(Color.BLACK)
|
||||||
|
}
|
||||||
|
|
||||||
|
window.statusBarColor = resources.getColor(R.color.circle_black_background)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
vr_video_view.pauseRendering()
|
||||||
|
isRendering = false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
if (isRendering) {
|
||||||
|
vr_video_view.shutdown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkIntent() {
|
||||||
|
val path = intent.getStringExtra(PATH)
|
||||||
|
if (path == null) {
|
||||||
|
toast(R.string.invalid_image_path)
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
intent.removeExtra(PATH)
|
||||||
|
|
||||||
|
try {
|
||||||
|
val options = VrVideoView.Options()
|
||||||
|
options.inputType = VrVideoView.Options.TYPE_MONO
|
||||||
|
|
||||||
|
vr_video_view.apply {
|
||||||
|
loadVideo(Uri.fromFile(File(path)), options)
|
||||||
|
setFlingingEnabled(true)
|
||||||
|
setPureTouchTracking(true)
|
||||||
|
|
||||||
|
// add custom buttons so we can position them and toggle visibility as desired
|
||||||
|
setFullscreenButtonEnabled(false)
|
||||||
|
setInfoButtonEnabled(false)
|
||||||
|
setTransitionViewEnabled(false)
|
||||||
|
setStereoModeButtonEnabled(false)
|
||||||
|
|
||||||
|
setOnClickListener {
|
||||||
|
handleClick()
|
||||||
|
}
|
||||||
|
|
||||||
|
setEventListener(object : VrVideoEventListener() {
|
||||||
|
override fun onClick() {
|
||||||
|
handleClick()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
showErrorToast(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||||
|
isFullScreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
|
||||||
|
toggleButtonVisibility()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration?) {
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
setupButtonMargins()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupButtonMargins() {
|
||||||
|
(explore.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navigationBarHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toggleButtonVisibility() {
|
||||||
|
explore.animate().alpha(if (isFullScreen) 0f else 1f)
|
||||||
|
explore.isClickable = !isFullScreen
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleClick() {
|
||||||
|
isFullScreen = !isFullScreen
|
||||||
|
toggleButtonVisibility()
|
||||||
|
if (isFullScreen) {
|
||||||
|
hideSystemUI(false)
|
||||||
|
} else {
|
||||||
|
showSystemUI(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.simplemobiletools.gallery.fragments
|
package com.simplemobiletools.gallery.fragments
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Point
|
import android.graphics.Point
|
||||||
import android.graphics.SurfaceTexture
|
import android.graphics.SurfaceTexture
|
||||||
|
@ -26,10 +27,12 @@ import com.google.android.exoplayer2.upstream.FileDataSource
|
||||||
import com.google.android.exoplayer2.video.VideoListener
|
import com.google.android.exoplayer2.video.VideoListener
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
|
import com.simplemobiletools.gallery.activities.PanoramaVideoActivity
|
||||||
import com.simplemobiletools.gallery.activities.VideoActivity
|
import com.simplemobiletools.gallery.activities.VideoActivity
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
import com.simplemobiletools.gallery.helpers.MEDIUM
|
import com.simplemobiletools.gallery.helpers.MEDIUM
|
||||||
import com.simplemobiletools.gallery.helpers.MediaSideScroll
|
import com.simplemobiletools.gallery.helpers.MediaSideScroll
|
||||||
|
import com.simplemobiletools.gallery.helpers.PATH
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.pager_video_item.view.*
|
import kotlinx.android.synthetic.main.pager_video_item.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -77,6 +80,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
video_curr_time.setOnClickListener { skip(false) }
|
video_curr_time.setOnClickListener { skip(false) }
|
||||||
video_duration.setOnClickListener { skip(true) }
|
video_duration.setOnClickListener { skip(true) }
|
||||||
video_holder.setOnClickListener { toggleFullscreen() }
|
video_holder.setOnClickListener { toggleFullscreen() }
|
||||||
|
panorama_outline.setOnClickListener { openPanorama() }
|
||||||
|
|
||||||
// adding an empty click listener just to avoid ripple animation at toggling fullscreen
|
// adding an empty click listener just to avoid ripple animation at toggling fullscreen
|
||||||
video_seekbar.setOnClickListener { }
|
video_seekbar.setOnClickListener { }
|
||||||
|
@ -611,6 +615,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
mIsDragged = false
|
mIsDragged = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun openPanorama() {
|
||||||
|
Intent(context, PanoramaVideoActivity::class.java).apply {
|
||||||
|
putExtra(PATH, medium.path)
|
||||||
|
startActivity(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun fullscreenToggled(isFullscreen: Boolean) {
|
override fun fullscreenToggled(isFullscreen: Boolean) {
|
||||||
mIsFullscreen = isFullscreen
|
mIsFullscreen = isFullscreen
|
||||||
checkFullscreen()
|
checkFullscreen()
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
android:id="@+id/cardboard"
|
android:id="@+id/cardboard"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
android:padding="@dimen/activity_margin"
|
android:padding="@dimen/activity_margin"
|
||||||
android:src="@drawable/ic_cardboard"/>
|
android:src="@drawable/ic_cardboard"/>
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@
|
||||||
android:id="@+id/explore"
|
android:id="@+id/explore"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
android:padding="@dimen/activity_margin"
|
android:padding="@dimen/activity_margin"
|
||||||
android:src="@drawable/ic_explore"/>
|
android:src="@drawable/ic_explore"/>
|
||||||
|
|
23
app/src/main/res/layout/activity_panorama_video.xml
Normal file
23
app/src/main/res/layout/activity_panorama_video.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/vr_video_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="#FF000000">
|
||||||
|
|
||||||
|
<com.google.vr.sdk.widgets.video.VrVideoView
|
||||||
|
android:id="@+id/vr_video_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/explore"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:padding="@dimen/activity_margin"
|
||||||
|
android:src="@drawable/ic_explore"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
Loading…
Reference in a new issue