ZoomHelper will make any view to be zoomable just like Instagram pinch-to-zoom

Related tags

Kotlin ZoomHelper
Overview

ZoomHelper

ZoomHelper

ZoomHelper will make any view to be zoomable just like the Instagram pinch-to-zoom. 😉

ZoomHelper (RecyclerViewSample)

Installation

ZoomHelper is available in the JCenter, so you just need to add it as a dependency (Module gradle)

Gradle

implementation 'com.aghajari.zoomhelper:ZoomHelper:1.0.2'

Maven

<dependency>
	<groupId>com.aghajari.zoomhelper</groupId>
	<artifactId>ZoomHelper</artifactId>
	<version>1.0.2</version>
	<type>pom</type>
</dependency>

Usage (Kotlin)

just override dispatchTouchEvent in your Activity and pass all touch events to ZoomHelper!

override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
    return ZoomHelper.getInstance().dispatchTouchEvent(ev!!,this) || super.dispatchTouchEvent(ev)
}
            

And set View to be zoomable :

ZoomHelper.addZoomableView(view)
//ZoomHelper.addZoomableView(view,tag)

Or make a zoomable View by using xml layout :

<ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <tag android:id="@+id/zoomable" android:value="ZoomableViewTag" />
</ImageView>

Note: <tag> is only used in API level 21 and higher

And we are Done! 😃

Usage (Java)

Installation: you have to add kotlin as a dependency! (Module gradle)

implementation 'com.aghajari.zoomhelper:ZoomHelper:1.0.1'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion' //1.4.0-rc

and just override dispatchTouchEvent in your Activity and pass all touch events to ZoomHelper!

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
	return ZoomHelper.Companion.getInstance().dispatchTouchEvent(ev,this) || super.dispatchTouchEvent(ev);
}
            

And set View to be zoomable :

ZoomHelper.Companion.addZoomableView(view);
//ZoomHelper.Companion.addZoomableView(view,tag);

Or make a zoomable View by using xml layout :

<ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <tag android:id="@+id/zoomable" android:value="ZoomableViewTag" />
</ImageView>

Note: <tag> is only used in API level 21 and higher

And we are Done! 😃

Customization

Kotlin:

ZoomHelper.getInstance().minScale = 1f
ZoomHelper.getInstance().maxScale = Float.MAX_VALUE
ZoomHelper.getInstance().shadowColor = Color.BLACK
ZoomHelper.getInstance().maxShadowAlpha = 0.6f
ZoomHelper.getInstance().shadowAlphaFactory = 4
ZoomHelper.getInstance().dismissDuration = 200
ZoomHelper.getInstance().layoutTheme = android.R.style.Theme_Translucent_NoTitleBar_Fullscreen
ZoomHelper.getInstance().isEnabled = true

Java:

ZoomHelper zoomHelper = ZoomHelper.Companion.getInstance();
zoomHelper.setMinScale(1f);
zoomHelper.setMaxScale(Float.MAX_VALUE);
zoomHelper.setShadowColor(Color.BLACK);
zoomHelper.setMaxShadowAlpha(0.6f);
zoomHelper.setShadowAlphaFactory(4);
zoomHelper.setDismissDuration(200);
zoomHelper.setLayoutTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
zoomHelper.setEnabled(true);

ZoomHelper (Simple) ZoomHelper (Custom)

you can disable a zoomable view by using this code :

ZoomHelper.removeZoomableView(view)

Or skip a View or a ViewGroup and all its children :

ZoomHelper.skipLayout(view,true)

And also you can disable ZoomHelper by using this code :

ZoomHelper.getInstance().isEnabled = false

Check the layout is zooming currently :

if (ZoomHelper.getInstance().isZooming) 

Listeners :

You can add callbacks to listen for specific events.

ZoomHelper.getInstance().addOnZoomStateChangedListener(object : ZoomHelper.OnZoomStateChangedListener{
    override fun onZoomStateChanged(zoomHelper: ZoomHelper, zoomableView: View, isZooming: Boolean) {
       Toast.makeText(zoomableView.context,if (isZooming) "Zooming started" else "Zooming ended", Toast.LENGTH_SHORT).show()
       // you can also get zoomableView Tag
       val tag = ZoomHelper.getZoomableViewTag(zoomableView) 
    }
})

ZoomHelper.getInstance().addOnZoomScaleChangedListener(object : ZoomHelper.OnZoomScaleChangedListener{
    override fun onZoomScaleChanged(zoomHelper: ZoomHelper, zoomableView: View, scale: Float, event: MotionEvent?) {
       // called when zoom scale changed
    }
})

ZoomHelper.getInstance().addOnZoomLayoutCreatorListener(object : ZoomHelper.OnZoomLayoutCreatorListener{
    override fun onZoomLayoutCreated(zoomHelper: ZoomHelper, zoomableView: View, zoomLayout: FrameLayout) {
       // called when zoomlayout created (zoom started)
    }
})

Also the default view listeners (onClick,onLongClick,onTouch) will work as well!

Author

Amir Hossein Aghajari

Inspired by ImageZoom library.

License

Copyright 2020 Amir Hossein Aghajari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.



LCoders | AmirHosseinAghajari
Amir Hossein Aghajari • EmailGitHub
Comments
  • ZoomHelper shows old view

    ZoomHelper shows old view

    First of all , Thank you for this awesome library (helps me a lot meeting my requirement in project) , But having one road block explained below -

    I am having two RecylerViews in Two Different Fragments inside a same Activity .

    Activity -> Fragment1 -> RecyclerView1 -> add ZoomHelper to recyclerview1's item .

    Click on bottom Tab and navigate to other fragment (fragment2 is over fragment1).

    Activity -> Fragment2 -> Recyclerview2 -> add ZoomHelper to recyclerview2 item

    now when zooming recyclerview2's item , i am getting preview of (recyclerview1's item) , if older view is just below new item .

    can you please help me with this .

    its a requirement .

    let me know if you need any further information .

    opened by androidiapp 6
  • ZoomHelper with multiple fragment

    ZoomHelper with multiple fragment

    When using zoom helper in activity with multiple fragment , when navigating to new fragment to same activity , it holds instance of previous fragments view , ZooomHelper.release() not working

    opened by gauravbansod-retailogy 5
  • Incident collected through crashlytics

    Incident collected through crashlytics

    Hi! First of all, thank you very much for this library. I attach the report of a crash produced by this library, I think it can be useful for me and more people.

    Android 9 Redmi 5 Plus

    Fatal Exception: java.lang.NullPointerException at com.aghajari.zoomhelper.ZoomHelper$dismissDialogAndViews$1.run(ZoomHelper.kt:351) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6810) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

    If you could help me to solve this I would appreciate it, thanks

    opened by adrianddpp 4
  • getting crash on zoomhelper class.

    getting crash on zoomhelper class.

    in ZoomHelper class -> line number 205 and 351 I am getting crashes.

    I am using this on recyclerview and adding and removing it at view attach and detach.

    on both the lines -> onPostDelay() is used and the View may have already been destroyed and there is no null check for view inside the postdelay function.

    Can you please check the issue.

    opened by kiran-shrestha-retailogy 4
  • Fatal Exception: java.lang.NullPointerException in ZoomHelper

    Fatal Exception: java.lang.NullPointerException in ZoomHelper

    Fatal Exception: java.lang.NullPointerException at com.aghajari.zoomhelper.ZoomHelper$load$1.run(ZoomHelper.java:205) at -$$LambdaGroup$js$xzCUdXiP0Q4TFHhL_Vv-FNKpLyA.run(-.java:3) at android.os.Handler.handleCallback(Handler.java:907) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7625) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

    opened by PankajSavaliya 3
  • Layout flickering while using contraintlayout

    Layout flickering while using contraintlayout

    In your RecyclerViewActivity, rv_item is designed with LinearLayout, if you convert them into constraint then pinch to zoom getting flickering even also not working in nested scroll view with constraint layout parent that means this zooming not working with parent constraint.

    <androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/avatar"
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginHorizontal="16dp"
                android:layout_marginVertical="12dp" />
    
            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textColor="@android:color/black"
                android:textSize="18dp"
                android:textStyle="bold" />
    
        </LinearLayout>
    
        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout2" />
    
        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/image" />
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    Solution have to cover with another layout, but this solution is not a prominent solution.

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/avatar"
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginHorizontal="16dp"
                android:layout_marginVertical="12dp" />
    
            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textColor="@android:color/black"
                android:textSize="18dp"
                android:textStyle="bold" />
    
        </LinearLayout>
    
        <!--    Cover with another layout to work as expected-->
        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout2">
    
            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    
        <!--    End-->
        
        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/content" />
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    opened by PankajSavaliya 1
  •  cant find the file

    cant find the file

    when i used my AS i get problem that cant find the file and the location is build.gradle artifact.load(new FileInputStream("deploy.settings"))

    opened by 1v1luxueqi 1
  • holding a reference to `zoomableViewParent` leads to memory leaks

    holding a reference to `zoomableViewParent` leads to memory leaks

    In ZoomHelper.kt the zoomableView reference is cleared in onDismissDialog, however the zoomableViewParent reference is never cleared, so it still exists after the Fragment is destroyed. This field should be set to null after the placeholder is swapped out with the original view.

    opened by mateot1 0
  • Can't add dispatchTouchEvent in Adapter.

    Can't add dispatchTouchEvent in Adapter.

    Hello, I am trying to add in my Adapter the following code:

    @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            return ZoomHelper.Companion.getInstance().dispatchTouchEvent(ev,this) || super.dispatchTouchEvent(ev);
        }
    

    But the problem is that it shows up this problem: Capture How can I solve the problem and also add @NonNull ViewHolder holder as it is in the onBindViewHolder of my adapter?

    opened by Achisyg 0
  • fragment issue

    fragment issue

    hello aghajari

    I have a question I'm using five "fragments" for one "activity" in my app. One "fragment" is again using two "fragments". This "fragment" has two "fragments" doing "show/hide", not "attach" depending on the button.

    In issue #4

    return supportFragmentManager.findFragmentById(R.id.container)?.view?.let {
                 ZoomHelper.getInstance().dispatchTouchEvent(ev!!, it)
               }!! || super.dispatchTouchEvent(ev)
    

    You advised this code, it works very well when "fragment" is attached or detached However, after attaching another fragment from the existing "fragment", if you detach the fragment and show "fragment", the displayed "fragment" does not zoom.

    What should I do in this case?

    opened by shoesboy 1
  • Is there any way to use this library on androidx dialog fragment

    Is there any way to use this library on androidx dialog fragment

    I was trying to use the library on Androidx dialog fragment to pinch and zoom images from the view pager, recycler view, but it is not working with it.

    opened by manegirish 0
  • i need a single tab to back not  when i release my hand

    i need a single tab to back not when i release my hand

    thanks for you lib, now i meet a new question, our app need a scale mode than relases hands, the dialog should be scale in the window, i get it, but when i hands touch down, the view move a little just like a shake, the experience is not kind, so,if you can give me some support

    if you are chinese

    你好,这个库能否实现松开后当前屏幕再次操作双指缩放,单手指移动,我修改了您的库,也实现了上面的功能,但是手指再次放下去的时候 ,图片会移动,这样不太友好,能否给我提供一下帮助

    opened by puyaCheer 1
Releases(v1.1.0)
Owner
AmirHosseinAghajari
AmirHosseinAghajari
A simple and easy adapter for RecyclerView. You don't have to make adapters and view holders anymore. Slush will help you.

한국어 No more boilerplate adapters and view holders. Slush will make using RecyclerView easy and fast. The goal of this project is to make RecyclerView,

SeungHyun 26 Sep 13, 2022
DI can be simple. Forget about modules and components. Just use it!

PopKorn - Kotlin Multiplatform DI PopKorn is a simple, powerful and lightweight Kotlin Multiplatform Dependency Injector. It doesn't need any modules

Pau Corbella 145 Dec 25, 2022
A smart colored time selector. Users can select just free time with a handy colorful range selector.

Colored Time Range Selector A smart colored time range selector. Users can select just free time with a handy colorful range selector. Screen Shots Fe

Ehsan Mehranvari 154 Oct 3, 2022
Just an app with lame dad jokes content to fill up your day.

Just an app with lame dad jokes content to fill up your day. MVP This MVP version features: Feed walks you through the latest dad jokes, Browse back s

null 240 Dec 20, 2022
Minecraft Server Software specially designed for Thicc SMP. Here on GitHub without the private patches, just a normal hybrid JettPack-Pufferfish-Empirecraft fork

AlynaaMC A private, custom server software for Thicc SMP and a fork of Pufferfish. Here on GitHub with patches from JettPack, Airplane and Pufferfish

ThiccMC 14 Dec 31, 2021
Solves every bug, ever, for any Paper server.

NoServer Solves every bug, ever, for any Paper server. How does it work? By employing the use of advanced philosophical-programmatic thinking, we have

Brian 7 Dec 29, 2021
Android app to fetch closed pull request of any public repo

Pullr Android app to fetch closed pull request of any public repo ?? Features Co

Sonu Sourav 0 Dec 26, 2021
Solves the audit needs for any JVM based application

Auditor-v1 Solves the audit needs for any JVM based application.

Lowe's 12 Dec 15, 2022
Android Library to make SharedPreferences usage easier.

KotlinPreferences Kotlin Android Library, that makes preference usage simple and fun. KotlinPreferences now have a brother. With KotlinPreferences, yo

Marcin Moskała 50 Nov 6, 2022
Make a cool intro for your Android app.

AppIntro AppIntro is an Android Library that helps you build a cool carousel intro for your App. AppIntro has support for requesting permissions and h

AppIntro Team 10.3k Jan 2, 2023
A collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android.

requireKTX requireKTX is a collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android, using the sam

Márton Braun 82 Oct 1, 2022
A small DSL to make building a conversation in Bukkit easy.

Konversation Konversation provides a simple builder to construct chains of prompts to be used in the conversation API present in Bukkit. Bukkit only p

Tim Hagemann 2 Dec 4, 2022
Kstr is a set of helpful methods library for Kotlin intended for make the developer life easier.

Kstr is a set of helpful methods library for Kotlin intended for make the developer life easier. Kstr uses the powerful feature of extension func

Rafael Acioly 0 Nov 3, 2021
Elixir is a library designed to make minecraft login easier.

Elixir Elixir is a library designed to make minecraft login easier. Usage We have a maven repo for this project. repositories { maven { url = "htt

null 4 Aug 11, 2022
Make interesting books for your kids, usint text and images from simple.wikipedia.org

Baby Book Builder Baby Book Builder is an Android app and a website for creating books to help your growing child learn. Contributing Donations Baby B

Baby Apps 11 Nov 19, 2022
A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

common sense OSS 0 Jan 20, 2022
Joker-App - List application tha make requests to a Chuck Norris Api

Joker App About • Technologies • Features • Author • License ?? About the Projec

Miguel S. da Silva 1 Feb 4, 2022
Blinking-image-view - A variant of Android View that blinks only the source image (not the background)

Blinker View for Android What is this? Blinker View is an Android View that blinks a given drawable. Yes, it's that simple. Place it in your layout an

Milos Marinkovic 4 Jul 29, 2020