Zahid-Ali-Shah SignatureView Not Working anymore?

1.2k views Asked by At

I have been using zahid-ali-shah/SignatureView's SignatureView for a few years now and today implementing it on a new project I am unable to draw the signature and have tested it on both emulator and physical device.

This has been convenient in speeding up the process to capture user signatures as bitmaps, and hope it is just a simple fix. Also am curious if anyone else is having the same issue.

Wouldnt be a good question without some code, here is my view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"
    app:title="@string/SIGNATURE_TOOLBAR_TITLE" />

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/signature_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.kyanogen.signatureview.SignatureView
        xmlns:sign="http://schemas.android.com/apk/res-auto"
        android:id="@+id/signature_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        sign:penSize="5dp"
        sign:backgroundColor="#ffffff"
        sign:penColor="#000000"
        sign:enableSignature="false"/>

    <Button
        android:id="@+id/submit"
        style="@style/ButtonStyle"
        android:layout_width="161dp"
        android:layout_height="47dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="Submit Signature"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <Button
        android:id="@+id/clear"
        style="@style/ButtonStyle"
        android:layout_width="142dp"
        android:layout_height="43dp"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="8dp"
        android:text="Clear"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

The Signature View is a Fragment "SignatureFragment" I am using Binding on the view and the "signature_view" is accessible using _binding

OnViewCreated:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    //Load UI Listeners
    attachListeners()
}

attachListeners():

   private fun attachListeners() {
    //Signature Pad Setup
    _binding?.signatureView?.penColor = Color.BLACK

    //Load all of the listeners here for organization
    _binding?.submit?.setOnClickListener(){
        val signatureSubmitAction =
            SignatureFragmentDirections.actionSignatureFragmentToRatingFragment()
        findNavController().navigate(signatureSubmitAction)
    }

    _binding?.clear?.setOnClickListener {
        confirmClearOfSignatureView()
    }
}

confirmClearSignature():

    private fun confirmClearOfSignatureView() {
    //Create Alert Builder and Control Clear
    val clearSignatureDialog = AlertDialog.Builder(context)
    clearSignatureDialog.setTitle("Clear Signature?")
    clearSignatureDialog.setMessage("Are you sure you want to clear your current signature? This operation is final.")

    clearSignatureDialog.setPositiveButton("Yes, Clear") { dialog, which ->
        _binding?.signatureView?.clearCanvas()
    }

    clearSignatureDialog.setNegativeButton("Don't Clear") { dialog, which ->
        //Default Action is Dismiss
    }

    clearSignatureDialog.show()
}

From what I see in the documentation and my past experience, I should with the above be able to at least see the strokes on the screen. I am not able to see anything.

Any suggestions on what might be going on or how to resolve this? I would love to still use this Repo if possible.

1

There are 1 answers

1
Keeano On BEST ANSWER

I was unable to resolve this with the above library and switched to a better supported one:

implementation 'com.github.gcacace:signature-pad:1.3.1'

Updated Signature Pad