Coder Social home page Coder Social logo

okaybroda / imagezoom Goto Github PK

View Code? Open in Web Editor NEW
120.0 6.0 25.0 29.86 MB

An Android library that makes any view to be zoomable.

License: GNU General Public License v3.0

Java 100.00%
zoomable image-zoom recyclerview android-library view zoom

imagezoom's Introduction

ImageZoom

An Android library that makes any view to be zoomable. It was created to mimick the Instagram Zoom feature.

View Preview

Installation

Add Jitpack

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Then add ImageZoom library

dependencies {
  compile 'com.github.okaybroda:ImageZoom:1.1.0'
}

Usage

Create an ImageZoomHelper instance in the OnCreate function of your Activity

ImageZoomHelper imageZoomHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // ... your code ...
    imageZoomHelper = new ImageZoomHelper(this);
}

Override dispatchTouchEvent in your Activity and pass all touch events to the ImageZoomHelper instance:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    return imageZoomHelper.onDispatchTouchEvent(ev) || super.dispatchTouchEvent(ev);
}

Set the R.id.zoomable tag to the Views that you would like to be zoomable.

ImageZoomHelper.setViewZoomable(findViewById(R.id.imgLogo));

To enable/disable zoom for certain Views (e.g. Recycler View refreshing)

ImageZoomHelper.setZoom(recyclerView, false)

Advanced Usage

For a smoother zoom transition, set the layout to be fullscreen. This only works on API 16 and above.

Place this code in the OnCreate function of your Activity. Preferably before the setContentView line.

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    decorView.setSystemUiVisibility(uiOptions);
}

The above code makes your Activity layout go behind the status bar which brings the status bar on top of the layout. To fix that, put this line in your root layout XML.

android:fitsSystemWindows="true"

Known Issues

RecyclerView

When using RecyclerView and setting it's child to be zoomable, RecyclerView crashes.

ImageView imageView = new ImageView(RecyclerViewActivity.this);
imageView.setImageResource(R.mipmap.ic_launcher);
ImageZoomHelper.setViewZoomable(imageView);
return new RecyclerView.ViewHolder(frameLayout) {};

Workaround is to wrap the zoomable View with a parent ViewGroup.

// Wrap ImageView with FrameLayout to avoid RecyclerView issue
FrameLayout frameLayout = new FrameLayout(parent.getContext());
frameLayout.addView(imageView);
return new RecyclerView.ViewHolder(frameLayout) {};

imagezoom's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

imagezoom's Issues

Only zoom not move

i want only zoom on pinch not move any where on screen. how can i achieve it

Zooming inside a fixed height width

I have one recyclerview which needs to be zoomed, i wrapped it with frame layout and gave id 'zoomable'. There are other view also, in my case recyclerview should be zoomed within its bound only.
Issue is : recyclerview is poped out of its place and is zooming all over the screen.

Null pointer exception on animation update

Hello, I found this issue on various devices, it mostly happens in Samsung devices, any idea how to fix it?

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setScaleX(float)' on a null object reference at com.viven.imagezoom.ImageZoomHelper$2.onAnimationUpdate(ImageZoomHelper.java:213) at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1463) at android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1384) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1427) at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:759) at android.animation.ValueAnimator$AnimationHandler$1.run(ValueAnimator.java:801) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) at android.view.Choreographer.doCallbacks(Choreographer.java:686) at android.view.Choreographer.doFrame(Choreographer.java:619) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7325) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Seems likes when we reach the onAnimationUpdate in ImageZoomHelper(line 162) the zoomableView is null, any idea why this happends?

If we add a this.zoomableView != null in that method do you think it will be fixed?

Any help I'll be grateful.

I have an issue when render a bigger image.

Your library is really good but It s crash when render a bigger image.

AppCompatImageView not displayed because it is too large to fit into a software layer (or drawing cache), needs 10765440 bytes, only 8294400 available

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.graphics.Bitmap.createBitmap(Bitmap.java:773)
at com.viven.imagezoom.ImageZoomHelper.onDispatchTouchEvent(ImageZoomHelper.java:106)

original

Elapsed time of video

How to get time of video ? Means when a button clicked on which second or minute my video was ?

Image goes invisible when zooming in recyclerview

I am facing one issue when using ImageZoom inside recyclerview. The issue is that, whole image or some part of image becomes invisible at the time of zooming.
(I have wrapped ImageView in FrameLayout as mention in library use case description )
Please refer following screenshots for more details of issues.
Before zooming:
screenshot_2018-08-04-12-06-39-760_com enthuons fchat

After zooming:
screenshot_2018-08-04-12-03-42-630_com enthuons fchat

As you can seen in second screenshot after zooming first image multiple time first image goes invisible and after zooming second image multiple times , some part of image goes invisible...

Usage in fragment

How I can override this method in fragment?
@Override public boolean dispatchTouchEvent(MotionEvent ev) { return imageZoomHelper.onDispatchTouchEvent(ev) || super.dispatchTouchEvent(ev); }

java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams

11-23 16:40:50.623 17535-17535/compro.a99vr E/AndroidRuntime: FATAL EXCEPTION: main
Process: compro.a99vr, PID: 17535
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17562)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17562)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17562)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:17562)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17562)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
at android.view.View.measure(View.java:17562)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17562)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2871)
at android.view.View.measure(View.java:17562)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2015)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1173)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1379)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5891)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5294)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

Set ImageZoom on RecyclerView Adapter

Hi I'm really proud and apprciate it about this library help me on Activity, can you give me knowledge how to setup in RecyclerView Adapter event we have create adapter on Class? Because I didn't know how to setup ImageZoomHelper imageZoomHelper; and imageZoomHelper = new ImageZoomHelper(this); also for dispatchTouchEvent.

Thanks and Regards
Edi Kurniawan

Great work, however there is a HUGE bug

When you initially grab the image, there is a huge flicker! I found this even on your sample app, so I know it's not anything I did when integrating into my project.

zoom from touch coordinates not from center

Hello,
This is not a issue but I am trying to achieve the functionality like zooming image from its touch coordinates. can you help me through it ?
updateZoomableViewMargins(newCenter[0] - twoPointCenter[0] + originalXY[0], newCenter[1] - twoPointCenter[1] + originalXY[1]);
I tried a lot to tweaking above code segment but couldn't get success.

View flickering

When pinch start on image and end , image view flikers due to setting placeHolderView background

set minimum scale

how to set minimum scale so the zoom image can't be smaller than original imageview size?

ImageView flick in Zoom Out

When i do a zoom out, there is a little flick in the imageview.
The ImageView is inside a RecyclerView and its loaded with Glide.

After release one finger I have a graphic bug

Hi, some compliments for the lib, it is the most powerful pinch to zoom that exist ๐Ÿ‘
But I have a problem after release one finger: the view is moved down.

Here the xml: https://www.dropbox.com/s/qhy607wi45rb803/activity.xml?dl=0
Here the view before zoom: https://www.dropbox.com/s/mfe0ocijvrolggi/1.png?dl=0
Here the view after release one finger from zoom: https://www.dropbox.com/s/4am83s6tnonnqko/2.png?dl=0

I've colored view to know which is moved.

Can you help me?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.