Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Need zoom feature and Download vector graphics from server feature #45

Open
anishkumar11 opened this issue Mar 5, 2019 · 22 comments
Open

Comments

@anishkumar11
Copy link

Hi Tarek,

I like your library. I have very useful and powerful. But two features are missing in your library.

  1. Zoom feature. It will help to fill the path tiny places.
  2. If we have put graphic xml file on the server or in the sdcard. then it should be load by your library.
@tarek360
Copy link
Owner

tarek360 commented Mar 5, 2019 via email

@anishkumar11
Copy link
Author

Hi Tarek. I happy you replied about my query.

@anishkumar11
Copy link
Author

I have created the pull requests

@AmineLAHRIM
Copy link

please how about the zoom ?

@anishkumar11
Copy link
Author

anishkumar11 commented Jan 29, 2020 via email

@tarek360
Copy link
Owner

Hi,
@anishkumar11 where is that pull request?

@AmineLAHRIM could you explain more about your use case?
do you need to zoom at the level of the path or the view?

@anishkumar11
Copy link
Author

anishkumar11 commented Jan 30, 2020 via email

@AmineLAHRIM
Copy link

AmineLAHRIM commented Jan 30, 2020

just in view i try with TouchImageView.java and extends from RichPathView the Zoom not working but if the class extends from the SVGImageView that from the library of AndroidSVG it works but the problem that i need to work on your library because of having some great functionality and thank you so much Tarek. for your reply

TouchImageView.java =>
https://gist.github.com/Antarix/65cfc180c05524ce616f

the right problem is in RichPathDrawale because if i make set imageDrawable(A_SIMPLE_DRAWABLE) the zoom work but if I make imageDrawable(richPathDrawable) the zoom didn't work because of extendes methods like draw() ononBoundsChange() ...

but finally we need that richPathDrawable because is part of the library.

@anishkumar11
Copy link
Author

anishkumar11 commented Jan 30, 2020 via email

@anishkumar11
Copy link
Author

anishkumar11 commented Jan 30, 2020 via email

@tarek360
Copy link
Owner

@AmineLAHRIM cool, you have figured where the problem with a zoom view, are you able to fix that in RichPathDrawabl? What exactly is going wrong in RichPathDrawabl?

@AmineLAHRIM
Copy link

@tarek360 we cloud not fix it i try so hard about everyday with no result could you please help us

@tarek360
Copy link
Owner

tarek360 commented Feb 1, 2020

@AmineLAHRIM I checked it and I found that TouchImageView.java is an ImageView but in your case, you need a ViewGroup, you need a layout to wrap the RichPathView to be able to zoom.

There are many many samples on the internet for zoom layout, I found one of them here

here is an example I tested and the zoom works:

<com.shopgun.android.zoomlayout.ZoomLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/touchImageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.richpath.RichPathView
        android:id="@+id/ic_command"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        app:vector="@drawable/ic_command" />

</com.shopgun.android.zoomlayout.ZoomLayout>

zoom

@AmineLAHRIM
Copy link

AmineLAHRIM commented Feb 1, 2020 via email

@AmineLAHRIM
Copy link

but there is a single problem when you zoom you can't apply any click listener effect in RichPathView:
ic_command.setOnPathClickListener(new RichPath.OnPathClickListener() {
@OverRide
public void onClick(RichPath richPath) {
Log.d("TAG", "getFillColor: " + richPath.getFillColor());

                final int random = new Random().nextInt((max - min) + 1) + min;
                RichPathAnimator.animate(richPath)
                        .fillColor(random)
                        .start();
        }
    });

@AmineLAHRIM
Copy link

AmineLAHRIM commented Feb 1, 2020

i hight recommend to download the zoomlayout source code and edit it like the following instructions:
1/ declare a public richpathview image in ZoomLayout class
2/ relate the richpathview that you have in MainActivity to it like that
zoomLayout.richpathview = richpathview;
3/ edit onTouchEvent
public RichPathView richpathview;
private PointF firstPointerDown = new PointF();
private boolean isImageMoved = false;

@Override
public boolean onTouchEvent(MotionEvent ev) {

    mArray[0] = ev.getX();
    mArray[1] = ev.getY(); 
    PointF curr = new PointF(ev.getX(), ev.getY());

    final int action = ev.getAction() & MotionEvent.ACTION_MASK;
    //final int pointerCount = ev.getPointerCount();

    float deltaXBeforePointerUp;
    float deltaYBeforePointerUp;

    dispatchOnTouch(action, ev);

    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_POINTER_DOWN:
            Log.d(TAG, "onTouchEvent: ACTION_POINTER_DOWN DISPATCH");

            break;
        case MotionEvent.ACTION_DOWN:
            Log.d(TAG, "onTouchEvent: ACTION_DOWN DISPATCH");
            firstPointerDown.set(curr);
            Log.d(TAG, "onTouchEvent2: " + curr.x + "  ___ " + firstPointerDown.x);

            break;
        case MotionEvent.ACTION_UP:

            deltaXBeforePointerUp = curr.x - firstPointerDown.x;
            deltaYBeforePointerUp = curr.y - firstPointerDown.y;
            if (Math.abs(deltaXBeforePointerUp) > 0 || Math.abs(deltaYBeforePointerUp) > 0) {
                Log.d(TAG, "onTouchEvent: ACTION_UP NO_DISPATCH");
            } else {
                Log.d(TAG, "onTouchEvent: ACTION_UP DISPATCH");
                if (!isImageMoved) {
                    dispatchEventToRichPathView(ev);
                }
            }

            //init
            isImageMoved=false;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            break;
        case MotionEvent.ACTION_MOVE:
            deltaXBeforePointerUp = curr.x - firstPointerDown.x;
            deltaYBeforePointerUp = curr.y - firstPointerDown.y;
            if (Math.abs(deltaXBeforePointerUp) > 0 || Math.abs(deltaYBeforePointerUp) > 0) {
                Log.d(TAG, "onTouchEvent: ACTION_MOVE NO_DISPATCH");
                isImageMoved=true;
            }
            break;
    }

    scaledPointsToScreenPoints(mArray);
    ev.setLocation(mArray[0], mArray[1]);

    if (!mAllowZoom) {
        return false;
    }


    boolean consumed = mScaleDetector.onTouchEvent(ev);
    consumed = mGestureDetector.onTouchEvent(ev) || consumed;
    if (action == MotionEvent.ACTION_UP) {
        // manually call up
        consumed = mGestureListener.onUp(ev) || consumed;
    }
    return consumed;
}

private void dispatchEventToRichPathView(MotionEvent ev) {
    if (this.richpathview != null) {
        richpathview.dispatchTouchEvent(ev);
    }
}

@tarek360
Copy link
Owner

tarek360 commented Feb 1, 2020

So it works now?

@AmineLAHRIM
Copy link

Yeap with two-finger zoom and one finger drag and one-click coloring.

@AmineLAHRIM
Copy link

special thanks to you tarek.

@tarek360
Copy link
Owner

tarek360 commented Feb 1, 2020

Are you doing a coloring book app?

@AmineLAHRIM
Copy link

AmineLAHRIM commented Feb 1, 2020 via email

@ManuelCoral1998
Copy link

Remembering what @tarek360 said about the ZoomLayout, I found that this ZoomLayout works fine and allows images to still have their click listener in the RichPathView as long as it has hasClickableChildren set to true.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants