iink SDK on Device

Answered

How to erase stroke and How to erase by point in Android?

How to erase stroke and How to erase by point in Android?



Best Answer

Hello Fenglong Wu,


Thank you for your question.


To answer it, it depends if you simply want to erase doing a gesture, of if you want a rubber:
-In the first case, doing an erasure or scratch out, it will erase the stroke. ( see https://developer.myscript.com/docs/concepts/editing-gestures/#ink-gestures)
-In the second case, your shall ensure the "iinkPointerType" to set the iinkPointerType to "PointerType.ERASER".

If you are using our GetStarted or Demo example with our UIReferenceImplementaton, this can be done with the following updates:


In the UIReferenceImplementation/src/main/java/com/myscript/iink/uireferenceimplementation/InputController.java

add the input mode eraser INPUT_MODE_ERASER = 3 :


  public static final int INPUT_MODE_NONE = -1;
  public static final int INPUT_MODE_FORCE_PEN = 0;
  public static final int INPUT_MODE_FORCE_TOUCH = 1;
  public static final int INPUT_MODE_AUTO = 2;
  public static final int INPUT_MODE_ERASER = 3;



Then in the handleOnTouchForPointer method, add the handling of this input mode, by replacing the block from line 78 to 101 by the following block:

    if (inputMode == INPUT_MODE_FORCE_PEN)
    {
      iinkPointerType = PointerType.PEN;
    }
    else if (inputMode == INPUT_MODE_FORCE_TOUCH)
    {
      iinkPointerType = PointerType.TOUCH;
    }
     else if (inputMode == INPUT_MODE_ERASER)
       {
             iinkPointerType = PointerType.ERASER;
      }
    else
    {
      switch (pointerType)
      {
        case MotionEvent.TOOL_TYPE_STYLUS:
          iinkPointerType = PointerType.PEN;
          break;
        case MotionEvent.TOOL_TYPE_FINGER:
        case MotionEvent.TOOL_TYPE_MOUSE:
          iinkPointerType = PointerType.TOUCH;
          break;
        case MotionEvent.TOOL_TYPE_ERASER:
          iinkPointerType = PointerType.ERASER;
          break;
        default:
          // unsupported event type
          return false;
      }
    }



Then you will be able to add a new rubber button in your application, and when clicking on the rubber, you will have to switch the pointer type to the eraser mode, with the following update:


 setInputMode(InputController.INPUT_MODE_ERASER);


By default, for Drawing and Raw Content, the eraser removes ink portions within its trajectory. But its configuration can be modified so that it removes the stroke it touches.

For Text and Math, the eraser removes characters, not strokes, and this cannot be changed.


Best regards,


Gwenaëlle


1 Comment

Answer

Hello Fenglong Wu,


Thank you for your question.


To answer it, it depends if you simply want to erase doing a gesture, of if you want a rubber:
-In the first case, doing an erasure or scratch out, it will erase the stroke. ( see https://developer.myscript.com/docs/concepts/editing-gestures/#ink-gestures)
-In the second case, your shall ensure the "iinkPointerType" to set the iinkPointerType to "PointerType.ERASER".

If you are using our GetStarted or Demo example with our UIReferenceImplementaton, this can be done with the following updates:


In the UIReferenceImplementation/src/main/java/com/myscript/iink/uireferenceimplementation/InputController.java

add the input mode eraser INPUT_MODE_ERASER = 3 :


  public static final int INPUT_MODE_NONE = -1;
  public static final int INPUT_MODE_FORCE_PEN = 0;
  public static final int INPUT_MODE_FORCE_TOUCH = 1;
  public static final int INPUT_MODE_AUTO = 2;
  public static final int INPUT_MODE_ERASER = 3;



Then in the handleOnTouchForPointer method, add the handling of this input mode, by replacing the block from line 78 to 101 by the following block:

    if (inputMode == INPUT_MODE_FORCE_PEN)
    {
      iinkPointerType = PointerType.PEN;
    }
    else if (inputMode == INPUT_MODE_FORCE_TOUCH)
    {
      iinkPointerType = PointerType.TOUCH;
    }
     else if (inputMode == INPUT_MODE_ERASER)
       {
             iinkPointerType = PointerType.ERASER;
      }
    else
    {
      switch (pointerType)
      {
        case MotionEvent.TOOL_TYPE_STYLUS:
          iinkPointerType = PointerType.PEN;
          break;
        case MotionEvent.TOOL_TYPE_FINGER:
        case MotionEvent.TOOL_TYPE_MOUSE:
          iinkPointerType = PointerType.TOUCH;
          break;
        case MotionEvent.TOOL_TYPE_ERASER:
          iinkPointerType = PointerType.ERASER;
          break;
        default:
          // unsupported event type
          return false;
      }
    }



Then you will be able to add a new rubber button in your application, and when clicking on the rubber, you will have to switch the pointer type to the eraser mode, with the following update:


 setInputMode(InputController.INPUT_MODE_ERASER);


By default, for Drawing and Raw Content, the eraser removes ink portions within its trajectory. But its configuration can be modified so that it removes the stroke it touches.

For Text and Math, the eraser removes characters, not strokes, and this cannot be changed.


Best regards,


Gwenaëlle