mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-31 12:16:44 +01:00
close PanoramaActivity if something goes wrong
This commit is contained in:
parent
08ec62b3e1
commit
448cf2d604
1 changed files with 21 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.simplemobiletools.gallery.activities
|
package com.simplemobiletools.gallery.activities
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -9,6 +10,7 @@ import android.widget.RelativeLayout
|
||||||
import com.google.vr.sdk.widgets.pano.VrPanoramaEventListener
|
import com.google.vr.sdk.widgets.pano.VrPanoramaEventListener
|
||||||
import com.google.vr.sdk.widgets.pano.VrPanoramaView
|
import com.google.vr.sdk.widgets.pano.VrPanoramaView
|
||||||
import com.simplemobiletools.commons.extensions.beVisible
|
import com.simplemobiletools.commons.extensions.beVisible
|
||||||
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
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.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
|
@ -24,6 +26,7 @@ open class PanoramaActivity : SimpleActivity() {
|
||||||
|
|
||||||
private var isFullScreen = false
|
private var isFullScreen = false
|
||||||
private var isExploreEnabled = true
|
private var isExploreEnabled = true
|
||||||
|
private var isRendering = false
|
||||||
|
|
||||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
useDynamicTheme = false
|
useDynamicTheme = false
|
||||||
|
@ -56,27 +59,37 @@ open class PanoramaActivity : SimpleActivity() {
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
panorama_view.resumeRendering()
|
panorama_view.resumeRendering()
|
||||||
|
isRendering = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
panorama_view.pauseRendering()
|
panorama_view.pauseRendering()
|
||||||
|
isRendering = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
if (isRendering) {
|
||||||
panorama_view.shutdown()
|
panorama_view.shutdown()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkIntent() {
|
private fun checkIntent() {
|
||||||
val path = intent.getStringExtra(PATH)
|
val path = intent.getStringExtra(PATH)
|
||||||
|
if (path != null) {
|
||||||
|
toast(R.string.invalid_image_path)
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
intent.removeExtra(PATH)
|
intent.removeExtra(PATH)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val options = VrPanoramaView.Options()
|
val options = VrPanoramaView.Options()
|
||||||
options.inputType = VrPanoramaView.Options.TYPE_MONO
|
options.inputType = VrPanoramaView.Options.TYPE_MONO
|
||||||
Thread {
|
Thread {
|
||||||
val bitmap = BitmapFactory.decodeFile(path)
|
val bitmap = getBitmapToLoad(path)
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
panorama_view.apply {
|
panorama_view.apply {
|
||||||
beVisible()
|
beVisible()
|
||||||
|
@ -102,7 +115,7 @@ open class PanoramaActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
showErrorToast(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||||
|
@ -116,6 +129,11 @@ open class PanoramaActivity : SimpleActivity() {
|
||||||
setupButtonMargins()
|
setupButtonMargins()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getBitmapToLoad(path: String): Bitmap {
|
||||||
|
val bitmap = BitmapFactory.decodeFile(path)
|
||||||
|
return bitmap
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupButtonMargins() {
|
private fun setupButtonMargins() {
|
||||||
(cardboard.layoutParams as RelativeLayout.LayoutParams).apply {
|
(cardboard.layoutParams as RelativeLayout.LayoutParams).apply {
|
||||||
bottomMargin = navigationBarHeight
|
bottomMargin = navigationBarHeight
|
||||||
|
|
Loading…
Reference in a new issue