improving rotation handling

This commit is contained in:
tibbi 2019-02-07 11:26:13 +01:00
parent 60da404865
commit 77b4a65ac3
2 changed files with 14 additions and 11 deletions

View File

@ -75,7 +75,7 @@ dependencies {
implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.caverock:androidsvg-aar:1.3' implementation 'com.caverock:androidsvg-aar:1.3'
implementation 'com.github.tibbi:gestureviews:985ba285fb' implementation 'com.github.tibbi:gestureviews:985ba285fb'
implementation 'com.github.tibbi:subsampling-scale-image-view:40dc6ee2b1' implementation 'com.github.tibbi:subsampling-scale-image-view:51cb8f922c'
kapt 'com.github.bumptech.glide:compiler:4.8.0' // keep it here too, not just in Commons, else loading SVGs wont work kapt 'com.github.bumptech.glide:compiler:4.8.0' // keep it here too, not just in Commons, else loading SVGs wont work
kapt 'androidx.room:room-compiler:2.0.0' kapt 'androidx.room:room-compiler:2.0.0'

View File

@ -444,6 +444,11 @@ class PhotoFragment : ViewPagerFragment() {
override fun make() = PicassoRegionDecoder() override fun make() = PicassoRegionDecoder()
} }
var newOrientation = (rotation + mCurrentRotationDegrees) % 360
if (newOrientation < 0) {
newOrientation += 360
}
val config = context!!.config val config = context!!.config
mView.subsampling_view.apply { mView.subsampling_view.apply {
setMaxTileSize(if (config.showHighestQuality) Integer.MAX_VALUE else 4096) setMaxTileSize(if (config.showHighestQuality) Integer.MAX_VALUE else 4096)
@ -454,7 +459,7 @@ class PhotoFragment : ViewPagerFragment() {
maxScale = 10f maxScale = 10f
beVisible() beVisible()
isOneToOneZoomEnabled = config.allowOneToOneZoom isOneToOneZoomEnabled = config.allowOneToOneZoom
orientation = (rotation + mCurrentRotationDegrees) % 360 orientation = newOrientation
setImage(path) setImage(path)
onImageEventListener = object : SubsamplingScaleImageView.OnImageEventListener { onImageEventListener = object : SubsamplingScaleImageView.OnImageEventListener {
override fun onReady() { override fun onReady() {
@ -472,15 +477,13 @@ class PhotoFragment : ViewPagerFragment() {
} }
override fun onImageRotation(degrees: Int) { override fun onImageRotation(degrees: Int) {
if (mCurrentRotationDegrees != degrees) { val fullRotation = (rotation + degrees) % 360
val fullRotation = (rotation + degrees) % 360 val useWidth = if (fullRotation == 90 || fullRotation == 270) sHeight else sWidth
val useWidth = if (fullRotation == 90 || fullRotation == 270) sHeight else sWidth val useHeight = if (fullRotation == 90 || fullRotation == 270) sWidth else sHeight
val useHeight = if (fullRotation == 90 || fullRotation == 270) sWidth else sHeight doubleTapZoomScale = getDoubleTapZoomScale(useWidth, useHeight)
doubleTapZoomScale = getDoubleTapZoomScale(useWidth, useHeight) mCurrentRotationDegrees = (mCurrentRotationDegrees + degrees) % 360
loadBitmap(degrees, false) loadBitmap(mCurrentRotationDegrees, false)
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
}
mCurrentRotationDegrees = degrees
} }
} }
} }