android-signaturepad icon indicating copy to clipboard operation
android-signaturepad copied to clipboard

Algorithm doesn't render dots

Open gcacace opened this issue 8 years ago • 12 comments

Tapping on the SignaturePad to draw dots doesn't render the zero length line.

gcacace avatar Feb 26 '16 11:02 gcacace

hi, is there any solution for this bug?

robinrev avatar Apr 28 '16 04:04 robinrev

Is there any workaround ? or temporary solution ?

iballan avatar May 30 '16 11:05 iballan

i added this snippet in addPoint function

            if(mPoints.get(0).x == mPoints.get(1).x && mPoints.get(0).y == mPoints.get(1).y &&
                    mPoints.get(0).x == mPoints.get(2).x && mPoints.get(0).y == mPoints.get(2).y &&
                    mPoints.get(1).x == mPoints.get(2).x && mPoints.get(1).y == mPoints.get(2).y) {
                mPoints.get(1).x = mPoints.get(1).x + mMinWidth;
                mPoints.get(1).y = mPoints.get(1).y + mMaxWidth;
                mPoints.get(2).x = mPoints.get(2).x + mMinWidth;
                mPoints.get(2).y = mPoints.get(2).y + mMaxWidth;
            }

just to make sure, I fill 3 mpoints with min and max width so if you put dot in there, it will make a litle line on that pad

this is the full addpoint function

`private void addPoint(TimedPoint newPoint) { mPoints.add(newPoint);

    int pointsCount = mPoints.size();
    if (pointsCount > 3) {

        // check if the line from point 0 to poin 1 is in the same spot, means dot
        if(mPoints.get(0).x == mPoints.get(1).x && mPoints.get(0).y == mPoints.get(1).y &&
                mPoints.get(0).x == mPoints.get(2).x && mPoints.get(0).y == mPoints.get(2).y &&
                mPoints.get(1).x == mPoints.get(2).x && mPoints.get(1).y == mPoints.get(2).y) {
            mPoints.get(1).x = mPoints.get(1).x + mMinWidth;
            mPoints.get(1).y = mPoints.get(1).y + mMaxWidth;
            mPoints.get(2).x = mPoints.get(2).x + mMinWidth;
            mPoints.get(2).y = mPoints.get(2).y + mMaxWidth;
        }

        ControlTimedPoints tmp = calculateCurveControlPoints(mPoints.get(0), mPoints.get(1), mPoints.get(2));
        TimedPoint c2 = tmp.c2;
        recyclePoint(tmp.c1);

        tmp = calculateCurveControlPoints(mPoints.get(1), mPoints.get(2), mPoints.get(3));
        TimedPoint c3 = tmp.c1;
        recyclePoint(tmp.c2);

        Bezier curve = mBezierCached.set(mPoints.get(1), c2, c3, mPoints.get(2));

        TimedPoint startPoint = curve.startPoint;
        TimedPoint endPoint = curve.endPoint;

        float velocity = endPoint.velocityFrom(startPoint);
        velocity = Float.isNaN(velocity) ? 0.0f : velocity;

        velocity = mVelocityFilterWeight * velocity
                + (1 - mVelocityFilterWeight) * mLastVelocity;

        // The new width is a function of the velocity. Higher velocities
        // correspond to thinner strokes.
        float newWidth = strokeWidth(velocity);

        // The Bezier's width starts out as last curve's final width, and
        // gradually changes to the stroke width just calculated. The new
        // width calculation is based on the velocity between the Bezier's
        // start and end mPoints.
        addBezier(curve, mLastWidth, newWidth);

        mLastVelocity = velocity;
        mLastWidth = newWidth;

        // Remove the first element from the list,
        // so that we always have no more than 4 mPoints in mPoints array.
        recyclePoint(mPoints.remove(0));

        recyclePoint(c2);
        recyclePoint(c3);

    } else if (pointsCount == 1) {
        // To reduce the initial lag make it work with 3 mPoints
        // by duplicating the first point
        TimedPoint firstPoint = mPoints.get(0);
        mPoints.add(getNewPoint(firstPoint.x, firstPoint.y));
    }
}`

hope it helped

robinrev avatar May 31 '16 02:05 robinrev

@robinrev How do i put this into the library?

AndreyNazarchuk avatar Aug 05 '16 22:08 AndreyNazarchuk

@AndreyNazarchuk please read: https://help.github.com/articles/using-pull-requests/

gcacace avatar Aug 06 '16 10:08 gcacace

Any solution so far for this bug?

AnixPasBesoin avatar Dec 19 '16 13:12 AnixPasBesoin

This works fine for me now, has it been resolved already?

tplive avatar Jan 22 '18 12:01 tplive

There is still an issue in the latest build. A single tap on the screen with no motion doesn't create a dot. A small amount of motion is required to get a dot.

vit001 avatar Feb 11 '18 07:02 vit001

When we tap any finger on signature box area, sometimes it does not produce any dot/image but it still saves the empty signature image in the form of bitmap. I have one action to perform in my app which should meet all the requirements including the signatures. Since, there are no signatures drawn in front of the user and it still produces the signature image internally and it allows the user to perform an action by taking the empty signature ahead. Please try to resolve the problem as soon as possible.

Thanks Varun Goyal

varun-springrole avatar Feb 11 '18 07:02 varun-springrole

@gcacace Please suggest me a solution for the above problem. I would be grateful to you.

varun-springrole avatar Feb 13 '18 07:02 varun-springrole

@gcacace Library is perfect but please consider this bug as high priority. @robinrev It's not working for me. :( Android 7.1.1

Aks-4125 avatar Feb 21 '18 05:02 Aks-4125

I have implemented a function in my code that will check to see that the signature covers at least 60% of the height of the signature area, to make sure that I get a good signature as it is used in further processing. I never actually saw the problem where a dot is not shown but added as a bitmap.

tplive avatar Feb 21 '18 07:02 tplive