creating a PanoramaActivity for handling panoramas

This commit is contained in:
tibbi 2018-07-03 21:15:03 +02:00
parent 727c42f7bd
commit 9614bd07c2
22 changed files with 198 additions and 13 deletions

View file

@ -55,6 +55,7 @@ dependencies {
implementation 'com.github.chrisbanes:PhotoView:2.1.3' implementation 'com.github.chrisbanes:PhotoView:2.1.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2' implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.android.exoplayer:exoplayer-core:2.8.2' implementation 'com.google.android.exoplayer:exoplayer-core:2.8.2'
implementation 'com.google.vr:sdk-panowidget:1.150.0'
implementation 'org.apache.sanselan:sanselan:0.97-incubator' implementation 'org.apache.sanselan:sanselan:0.97-incubator'
kapt "android.arch.persistence.room:compiler:1.1.1" kapt "android.arch.persistence.room:compiler:1.1.1"

View file

@ -1,12 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest <manifest
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.simplemobiletools.gallery" package="com.simplemobiletools.gallery"
android:installLocation="auto"> android:installLocation="auto">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.SET_WALLPAPER"/> <uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-sdk
tools:overrideLibrary="com.google.vr.widgets.common, com.google.vr.sdk.widgets.pano"/>
<application <application
android:name=".App" android:name=".App"
android:allowBackup="true" android:allowBackup="true"
@ -112,6 +116,11 @@
android:name=".activities.PhotoVideoActivity" android:name=".activities.PhotoVideoActivity"
android:configChanges="orientation|keyboardHidden|screenSize"/> android:configChanges="orientation|keyboardHidden|screenSize"/>
<activity
android:name=".activities.PanoramaActivity"
android:theme="@style/FullScreenTheme"
android:configChanges="orientation|keyboardHidden|screenSize"/>
<activity <activity
android:name=".activities.IncludedFoldersActivity" android:name=".activities.IncludedFoldersActivity"
android:label="@string/include_folders" android:label="@string/include_folders"

View file

@ -0,0 +1,112 @@
package com.simplemobiletools.gallery.activities
import android.graphics.BitmapFactory
import android.os.Bundle
import android.view.View
import android.view.Window
import android.widget.RelativeLayout
import com.google.vr.sdk.widgets.pano.VrPanoramaView
import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.gallery.R
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.*
open class PanoramaActivity : SimpleActivity() {
private var isFullScreen = true
public override fun onCreate(savedInstanceState: Bundle?) {
useDynamicTheme = false
requestWindowFeature(Window.FEATURE_NO_TITLE)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_panorama)
supportActionBar?.hide()
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN
(cardboard.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navigationBarHeight
(explore.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navigationBarHeight
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
checkIntent()
} else {
toast(R.string.no_storage_permissions)
finish()
}
}
}
override fun onResume() {
super.onResume()
panorama_view.resumeRendering()
}
override fun onPause() {
super.onPause()
panorama_view.pauseRendering()
}
override fun onDestroy() {
super.onDestroy()
panorama_view.shutdown()
}
private fun checkIntent() {
val path = intent.getStringExtra(PATH)
intent.removeExtra(PATH)
try {
val options = VrPanoramaView.Options()
options.inputType = VrPanoramaView.Options.TYPE_MONO
Thread {
val bitmap = BitmapFactory.decodeFile(path)
runOnUiThread {
panorama_view.apply {
beVisible()
loadImageFromBitmap(bitmap, 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()
}
}
}
}.start()
} catch (e: Exception) {
}
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
isFullScreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
toggleButtonVisibility()
}
}
private fun toggleButtonVisibility() {
cardboard.animate().alpha(if (isFullScreen) 0f else 1f)
cardboard.isClickable = !isFullScreen
explore.animate().alpha(if (isFullScreen) 0f else 1f)
explore.isClickable = !isFullScreen
}
private fun handleClick() {
isFullScreen = !isFullScreen
toggleButtonVisibility()
if (isFullScreen) {
hideSystemUI(false)
} else {
showSystemUI(false)
}
}
}

View file

@ -85,7 +85,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
} }
} }
showSystemUI() showSystemUI(true)
val bundle = Bundle() val bundle = Bundle()
val file = File(mUri.toString()) val file = File(mUri.toString())
val type = when { val type = when {
@ -201,9 +201,9 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
override fun fragmentClicked() { override fun fragmentClicked() {
mIsFullScreen = !mIsFullScreen mIsFullScreen = !mIsFullScreen
if (mIsFullScreen) { if (mIsFullScreen) {
hideSystemUI() hideSystemUI(true)
} else { } else {
showSystemUI() showSystemUI(true)
} }
if (!bottom_actions.isGone()) { if (!bottom_actions.isGone()) {

View file

@ -207,7 +207,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
config.isThirdPartyIntent = true config.isThirdPartyIntent = true
} }
showSystemUI() showSystemUI(true)
val isShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false) val isShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false)
val isShowingRecycleBin = intent.getBooleanExtra(SHOW_RECYCLE_BIN, false) val isShowingRecycleBin = intent.getBooleanExtra(SHOW_RECYCLE_BIN, false)
@ -379,7 +379,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (getMediaForSlideshow()) { if (getMediaForSlideshow()) {
view_pager.onGlobalLayout { view_pager.onGlobalLayout {
if (!isActivityDestroyed()) { if (!isActivityDestroyed()) {
hideSystemUI() hideSystemUI(true)
mSlideshowInterval = config.slideshowInterval mSlideshowInterval = config.slideshowInterval
mSlideshowMoveBackwards = config.slideshowMoveBackwards mSlideshowMoveBackwards = config.slideshowMoveBackwards
mIsSlideshowActive = true mIsSlideshowActive = true
@ -457,7 +457,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun stopSlideshow() { private fun stopSlideshow() {
if (mIsSlideshowActive) { if (mIsSlideshowActive) {
mIsSlideshowActive = false mIsSlideshowActive = false
showSystemUI() showSystemUI(true)
mSlideshowHandler.removeCallbacksAndMessages(null) mSlideshowHandler.removeCallbacksAndMessages(null)
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} }
@ -1072,10 +1072,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun checkSystemUI() { private fun checkSystemUI() {
if (mIsFullScreen) { if (mIsFullScreen) {
hideSystemUI() hideSystemUI(true)
} else { } else {
stopSlideshow() stopSlideshow()
showSystemUI() showSystemUI(true)
} }
} }

View file

@ -78,15 +78,21 @@ fun SimpleActivity.launchAbout() {
or LICENSE_SUBSAMPLING or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GIF_DRAWABLE or LICENSE_PHOTOVIEW or LICENSE_EXOPLAYER, BuildConfig.VERSION_NAME, faqItems) or LICENSE_SUBSAMPLING or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GIF_DRAWABLE or LICENSE_PHOTOVIEW or LICENSE_EXOPLAYER, BuildConfig.VERSION_NAME, faqItems)
} }
fun AppCompatActivity.showSystemUI() { fun AppCompatActivity.showSystemUI(toggleActionBarVisibility: Boolean) {
if (toggleActionBarVisibility) {
supportActionBar?.show() supportActionBar?.show()
}
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
} }
fun AppCompatActivity.hideSystemUI() { fun AppCompatActivity.hideSystemUI(toggleActionBarVisibility: Boolean) {
if (toggleActionBarVisibility) {
supportActionBar?.hide() supportActionBar?.hide()
}
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or

View file

@ -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.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
@ -26,12 +27,15 @@ import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.PanoramaActivity
import com.simplemobiletools.gallery.activities.PhotoActivity import com.simplemobiletools.gallery.activities.PhotoActivity
import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.activities.ViewPagerActivity
import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.helpers.GlideRotateTransformation import com.simplemobiletools.gallery.helpers.GlideRotateTransformation
import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.helpers.PATH
import com.simplemobiletools.gallery.helpers.ROTATE_BY_ASPECT_RATIO import com.simplemobiletools.gallery.helpers.ROTATE_BY_ASPECT_RATIO
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import it.sephiroth.android.library.exif2.ExifInterface import it.sephiroth.android.library.exif2.ExifInterface
@ -65,6 +69,7 @@ class PhotoFragment : ViewPagerFragment() {
photo_view.setOnClickListener { photoClicked() } photo_view.setOnClickListener { photoClicked() }
instant_prev_item.setOnClickListener { listener?.goToPrevItem() } instant_prev_item.setOnClickListener { listener?.goToPrevItem() }
instant_next_item.setOnClickListener { listener?.goToNextItem() } instant_next_item.setOnClickListener { listener?.goToNextItem() }
panorama_outline.setOnClickListener { openPanorama() }
instant_prev_item.parentView = container instant_prev_item.parentView = container
instant_next_item.parentView = container instant_next_item.parentView = container
@ -290,6 +295,13 @@ class PhotoFragment : ViewPagerFragment() {
} }
} }
private fun openPanorama() {
Intent(context, PanoramaActivity::class.java).apply {
putExtra(PATH, medium.path)
startActivity(this)
}
}
private fun addZoomableView() { private fun addZoomableView() {
if (!context!!.config.replaceZoomableImages && medium.isImage() && isFragmentVisible && view.subsampling_view.isGone()) { if (!context!!.config.replaceZoomableImages && medium.isImage() && isFragmentVisible && view.subsampling_view.isGone()) {
ViewPagerActivity.wasDecodedByGlide = false ViewPagerActivity.wasDecodedByGlide = false
@ -342,7 +354,7 @@ class PhotoFragment : ViewPagerFragment() {
false false
} }
view.panorama_outline.beVisibleIf(isPanorama) view.panorama_outline.beVisibleIf(isPanorama && isLollipopPlus())
} }
private fun getImageOrientation(): Int { private fun getImageOrientation(): Int {

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 670 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 996 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 979 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/panorama_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000">
<com.google.vr.sdk.widgets.pano.VrPanoramaView
android:id="@+id/panorama_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<ImageView
android:id="@+id/cardboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:padding="@dimen/activity_margin"
android:src="@drawable/ic_cardboard"/>
<ImageView
android:id="@+id/explore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:padding="@dimen/activity_margin"
android:src="@drawable/ic_explore"/>
</RelativeLayout>

View file

@ -0,0 +1,7 @@
<resources>
<style name="FullScreenTheme" parent="AppTheme.Base">
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>

View file

@ -2,4 +2,9 @@
<style name="AppTheme" parent="AppTheme.Base"/> <style name="AppTheme" parent="AppTheme.Base"/>
<style name="FullScreenTheme.Base" parent="AppTheme">
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="FullScreenTheme" parent="FullScreenTheme.Base"/>
</resources> </resources>