allow changing grid column count by pinching

This commit is contained in:
tibbi 2016-12-11 21:22:07 +01:00
parent a077e36831
commit b9d5c004e0
3 changed files with 78 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.util.Log
import android.view.Menu
import android.view.MenuItem
@ -20,6 +21,7 @@ import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
import com.simplemobiletools.gallery.extensions.getHumanizedFilename
import com.simplemobiletools.gallery.helpers.*
import com.simplemobiletools.gallery.models.Medium
import com.simplemobiletools.gallery.views.MyScalableRecyclerView
import kotlinx.android.synthetic.main.activity_media.*
import java.io.File
import java.io.IOException
@ -54,6 +56,23 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mShowAll = mConfig.showAll
if (mShowAll)
supportActionBar?.setDisplayHomeAsUpEnabled(false)
val layoutManager = media_grid.layoutManager as GridLayoutManager
MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.ZoomListener {
override fun zoomIn() {
if (layoutManager.spanCount > 1) {
layoutManager.spanCount--
MediaAdapter.actMode?.finish()
}
}
override fun zoomOut() {
if (layoutManager.spanCount < 10) {
layoutManager.spanCount++
MediaAdapter.actMode?.finish()
}
}
}
}
override fun onResume() {

View File

@ -0,0 +1,58 @@
package com.simplemobiletools.gallery.views
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.ScaleGestureDetector
class MyScalableRecyclerView : RecyclerView {
var mScaleDetector: ScaleGestureDetector
companion object {
var mListener: ZoomListener? = null
var mCurrScaleFactor = 1.0f
}
constructor(context: Context) : super(context) {
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
}
init {
mScaleDetector = ScaleGestureDetector(context, GestureListener())
}
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
super.dispatchTouchEvent(ev)
if (ev.action == MotionEvent.ACTION_UP) {
mCurrScaleFactor = 1.0f
}
return mScaleDetector.onTouchEvent(ev)
}
class GestureListener : ScaleGestureDetector.SimpleOnScaleGestureListener() {
val ZOOM_IN_THRESHOLD = -0.7f
val ZOOM_OUT_THRESHOLD = 0.3f
override fun onScale(detector: ScaleGestureDetector): Boolean {
val diff = mCurrScaleFactor - detector.scaleFactor
if (diff < ZOOM_IN_THRESHOLD && mCurrScaleFactor == 1.0f) {
mListener?.zoomIn()
mCurrScaleFactor = detector.scaleFactor
} else if (diff > ZOOM_OUT_THRESHOLD && mCurrScaleFactor == 1.0f) {
mListener?.zoomOut()
mCurrScaleFactor = detector.scaleFactor
}
return false
}
}
interface ZoomListener {
fun zoomOut()
fun zoomIn()
}
}

View File

@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
<com.simplemobiletools.gallery.views.MyScalableRecyclerView
android:id="@+id/media_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"