Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 16, 2025

This PR implements undo/erase functionality for the Android signature pad by tracking user strokes and providing the ability to remove the last stroke.

Implementation Details

Core Changes

SignatureSDK (signature-core)

  • Added strokeEndIndices to track stroke boundaries (complete DOWN→MOVE→UP sequences)
  • Implemented canUndo(): Boolean to check if undo operations are available
  • Implemented undo() to remove the last stroke and redraw the signature
  • Updated clear() and restoreEvents() to properly handle stroke tracking

SignaturePad (signature-view)

  • Exposed canUndo() and undo() methods that delegate to SignatureSDK
  • Maintains existing API compatibility

SignaturePadAdapter (signature-pad)

  • Added Compose-compatible canUndo() and undo() methods
  • Enables undo functionality in Jetpack Compose applications

Usage Example

// Check if undo is available
if (signaturePad.canUndo()) {
    // Remove the last stroke
    signaturePad.undo()
}

// In Compose
SignaturePadView(
    onReady = { adapter ->
        // Button state management
        undoButton.isEnabled = adapter.canUndo()
        
        // Undo last stroke
        undoButton.setOnClickListener {
            adapter.undo()
        }
    }
)

Technical Approach

The implementation leverages the existing event system for minimal invasive changes:

  1. Stroke Tracking: Records indices where strokes end (ACTION_UP events)
  2. Event Removal: Removes complete strokes from the event list during undo
  3. Efficient Redraw: Uses existing restoreEvents() method to redraw from remaining events
  4. State Management: Provides canUndo() for proper UI control states

Sample Integration

The sample app has been updated with an undo button demonstrating the functionality:

  • Button is enabled/disabled based on canUndo() state
  • Properly updates other UI elements after undo operations
  • Shows real-time undo capability alongside existing clear functionality

Validation

  • ✅ All modules build successfully with updated APIs
  • ✅ Stroke boundary logic validated with simulation testing
  • ✅ Event management and redraw functionality verified
  • ✅ Sample app demonstrates end-to-end undo capability
  • ✅ Backward compatibility maintained

Fixes #354.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repo.gradle.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx4096m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14.1-bin/baw1sv0jfoi8rxs14qo3h49cs/gradle-8.14.1/lib/gradle-daemon-main-8.14.1.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.14.1-bin/baw1sv0jfoi8rxs14qo3h49cs/gradle-8.14.1/lib/agents/gradle-instrumentation-agent-8.14.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.14.1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Support Undo / Erase Add undo/erase functionality with stroke tracking Jun 16, 2025
Copilot AI requested a review from warting June 16, 2025 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Undo / Erase

2 participants