Skip to content

nos-digital/imagin

Repository files navigation

Imagin

Imagin is an Android library, written in Kotlin. It attaches to an ImageView and allows you to add 'pinch to zoom', 'swipe to close', 'double tap to zoom' and dragging functionality. Because it attaches to a regular ImageView, it allows you to use all existing functionality of the ImageView or extend the ImageView to add extra functionality. Keep in mind that Imagin sets an OnTouchListener on the ImageView.

This library is currently supported on Android 5.1 Lollipop (22) and higher.

Usage

  1. Add the Imagin library to your build.gradle file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.nos-digital:imagin:${imagin.version}'
}
  1. Usage in your project:

    Load an image into an ImageView like usual.

Imagin.with(imageWrapper, imageView)
    // enable double tap to zoom functionality
    .enableDoubleTapToZoom()
    // enable pinch to zoom functionality
    .enablePinchToZoom()
    // add an event listener when the user does a single tap
    .enableSingleTap(object : SingleTapHandler.OnSingleTapListener {
        override fun onSingleTap() {
            Toast.makeText(imageView.context, picture.name, Toast.LENGTH_SHORT).show()
        }
    })
    // this allows us to do an action when the user swipes the ImageView vertically and/or horizontally
    .enableScroll(
        allowScrollOutOfBoundsHorizontally = false,
        allowScrollOutOfBoundsVertically = true,
        scrollDistanceToCloseInPx = distanceToClose
    ) {
        onSwipedToCloseListener?.onSwipeToClose()
    }

Licence

Imagin is available under the MIT license.

About

An attachable image zooming library for the Android ImageView.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages