mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +01:00
add the image rotating functions
This commit is contained in:
parent
83a47e9b8c
commit
964ffe360a
2 changed files with 28 additions and 7 deletions
|
@ -21,6 +21,7 @@ import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
|||
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
||||
import com.simplemobiletools.gallery.dialogs.RenameFileDialog
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||
import com.simplemobiletools.gallery.helpers.MEDIUM
|
||||
import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE
|
||||
|
@ -39,6 +40,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private var mIsFullScreen = false
|
||||
private var mPos = -1
|
||||
private var mShowAll = false
|
||||
private var mRotationDegrees = 0f
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -125,9 +127,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
R.id.menu_edit -> openEditor(getCurrentFile())
|
||||
R.id.menu_properties -> showProperties()
|
||||
R.id.show_on_map -> showOnMap()
|
||||
R.id.rotate_right -> {}
|
||||
R.id.rotate_left -> {}
|
||||
R.id.rotate_one_eighty -> {}
|
||||
R.id.rotate_right -> rotateImageRight()
|
||||
R.id.rotate_left -> rotateImageLeft()
|
||||
R.id.rotate_one_eighty -> rotateImageOneEighty()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
|
@ -161,6 +163,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
})
|
||||
}
|
||||
|
||||
private fun rotateImageRight() {
|
||||
mRotationDegrees += 90
|
||||
getCurrentFragment().rotateImageViewBy(mRotationDegrees)
|
||||
}
|
||||
|
||||
private fun rotateImageLeft() {
|
||||
mRotationDegrees -= 90
|
||||
getCurrentFragment().rotateImageViewBy(mRotationDegrees)
|
||||
}
|
||||
|
||||
private fun rotateImageOneEighty() {
|
||||
mRotationDegrees += 180
|
||||
getCurrentFragment().rotateImageViewBy(mRotationDegrees)
|
||||
}
|
||||
|
||||
private fun getCurrentFragment() = ((view_pager.adapter as MyPagerAdapter).getCurrentFragment(view_pager.currentItem) as PhotoFragment)
|
||||
|
||||
private fun showProperties() {
|
||||
if (getCurrentMedium() != null)
|
||||
PropertiesDialog(this, getCurrentMedium()!!.path, false)
|
||||
|
|
|
@ -144,17 +144,19 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
}
|
||||
|
||||
override fun onResourceReady(bitmap: Bitmap?, model: String?, target: Target<Bitmap>?, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean {
|
||||
if (degrees == 0f)
|
||||
if (degrees == 0f) {
|
||||
addZoomableView()
|
||||
} else {
|
||||
photo_view.beVisible()
|
||||
subsampling_view.beGone()
|
||||
}
|
||||
return false
|
||||
}
|
||||
}).into(glideView)
|
||||
}
|
||||
|
||||
fun rotateImageViewBy(degrees: Float) {
|
||||
loadBitmap(degrees)
|
||||
photo_view.beVisible()
|
||||
subsampling_view.beGone()
|
||||
loadBitmap(degrees % 360)
|
||||
}
|
||||
|
||||
private fun addZoomableView() {
|
||||
|
|
Loading…
Reference in a new issue