i want to handle scale and scroll by two finger,how can do this
Best Answer
O
Olivier @MyScript
said
almost 2 years ago
Dear Heyb,
currently, I am not sure to understand the difficulties you are facing. What do you mean by it doesn't work when changing the mode? Which error do you have?
On my side, I updated the InputController.java, which you can find attached.
Playing with it, I was able to zoom in with 2 fingers.
Please note this is a quick sample, and of course shall be reworked. But it can provide with guidelines how to start.
You can also refer to the Demo sample we provide, in particular the zoomIn and zoomOut functions of the PartEditor.kt fun zoomIn() { editor?.renderer?.zoom(110.0f / 100.0f) }
fun zoomOut() { editor?.renderer?.zoom(100.0f / 110.0f) }
Regarding the scroll, you can refer to the onScroll function of the iink\examples\android\UIReferenceImplementation\src\main\java\com\myscript\iink\uireferenceimplementation\InputController.java file
@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (editor.isScrollAllowed()) { Point oldOffset = editor.getRenderer().getViewOffset(); Point newOffset = new Point(oldOffset.x + distanceX, oldOffset.y + distanceY); editor.clampViewOffset(newOffset); editor.getRenderer().setViewOffset(Math.round(newOffset.x), Math.round(newOffset.y)); renderTarget.invalidate(editor.getRenderer(), EnumSet.allOf(IRenderTarget.LayerType.class)); if(_viewListener != null) { _viewListener.showScrollbars(); } return true; } return false; }
Let us know if this helps.
Best regards,
Olivier
H
Heyb6
said
almost 2 years ago
hi,Olivier
thanks to reply my issue, I should elaborate on the requirements I am developing now. When I press two fingers, the mode switches to touch mode. When I withdraw one finger, it is still touch mode. When I only have one finger to press, it is pen mode. Now, the mode cannot be switched, so I cannot zoom and scroll. is there good way to implement this function. by the way,zoom function,i have done.
Best regards,
Heyb
O
Olivier @MyScript
said
almost 2 years ago
Dear Heyb,
I am not sure to completely understand: did you try using the getPointerCount function of the MotionEvent class?
For example, when 2 fingers are touching the screen in touch mode, you use the scalefactor to zoom? And when only 1 finger in touchmode, you scroll?
Or I may have missed something?
Best regards,
Olivier
H
Heyb6
said
almost 2 years ago
Hi,Olivier
when i set in the touch mode, These functions can be realized. But, i can't change the mode by two fingers ,like pen mode or touch mode .When i getPointerCount in OnTouch function ,and change the mode, it isn't work.even appear error.
O
Olivier @MyScript
said
almost 2 years ago
Answer
Dear Heyb,
currently, I am not sure to understand the difficulties you are facing. What do you mean by it doesn't work when changing the mode? Which error do you have?
On my side, I updated the InputController.java, which you can find attached.
Playing with it, I was able to zoom in with 2 fingers.
Please note this is a quick sample, and of course shall be reworked. But it can provide with guidelines how to start.
in facture,i want to know how to switch between touch and pen modes by detecting the state of double finger pressing. Your attach may be give me a good idea of development.
by the way,this attach can't be view about InputController. Can you handle it.
Heyb6
i want to handle scale and scroll by two finger,how can do this
Dear Heyb,
currently, I am not sure to understand the difficulties you are facing. What do you mean by it doesn't work when changing the mode? Which error do you have?
On my side, I updated the InputController.java, which you can find attached.
Playing with it, I was able to zoom in with 2 fingers.
Please note this is a quick sample, and of course shall be reworked. But it can provide with guidelines how to start.
Let me know if this helps.
Best regards,
Olivier
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstOlivier @MyScript
Dear Heyb6,
Thank you for contacting us and your question.
If I understand well, you would like to be able to pinch with 2 fingers, to zoom in and zoom out?
You would also like to be able to scroll a page?
In order to detect pinch gestures, you could use the ScaleGestureDetector.
In particular, you could override the onScale function, and use the scaleFactor to zoomin or zoomout.
Once you have this factor, you can use the "zoom" function of the renderer: https://developer.myscript.com/refguides/interactive-ink/android/2.0/com/myscript/iink/Renderer.html#zoom(float)
You can also refer to the Demo sample we provide, in particular the zoomIn and zoomOut functions of the PartEditor.kt
fun zoomIn() {
editor?.renderer?.zoom(110.0f / 100.0f)
}
fun zoomOut() {
editor?.renderer?.zoom(100.0f / 110.0f)
}
Regarding the scroll, you can refer to the onScroll function of the iink\examples\android\UIReferenceImplementation\src\main\java\com\myscript\iink\uireferenceimplementation\InputController.java file
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
if (editor.isScrollAllowed())
{
Point oldOffset = editor.getRenderer().getViewOffset();
Point newOffset = new Point(oldOffset.x + distanceX, oldOffset.y + distanceY);
editor.clampViewOffset(newOffset);
editor.getRenderer().setViewOffset(Math.round(newOffset.x), Math.round(newOffset.y));
renderTarget.invalidate(editor.getRenderer(), EnumSet.allOf(IRenderTarget.LayerType.class));
if(_viewListener != null)
{
_viewListener.showScrollbars();
}
return true;
}
return false;
}
Let us know if this helps.
Best regards,
Olivier
Heyb6
hi,Olivier
thanks to reply my issue, I should elaborate on the requirements I am developing now. When I press two fingers, the mode switches to touch mode. When I withdraw one finger, it is still touch mode. When I only have one finger to press, it is pen mode. Now, the mode cannot be switched, so I cannot zoom and scroll. is there good way to implement this function. by the way,zoom function,i have done.
Best regards,
Heyb
Olivier @MyScript
Dear Heyb,
I am not sure to completely understand: did you try using the getPointerCount function of the MotionEvent class?
For example, when 2 fingers are touching the screen in touch mode, you use the scalefactor to zoom? And when only 1 finger in touchmode, you scroll?
Or I may have missed something?
Best regards,
Olivier
Heyb6
Hi,Olivier
when i set in the touch mode, These functions can be realized. But, i can't change the mode by two fingers ,like pen mode or touch mode .When i getPointerCount in OnTouch function ,and change the mode, it isn't work.even appear error.
Olivier @MyScript
Dear Heyb,
currently, I am not sure to understand the difficulties you are facing. What do you mean by it doesn't work when changing the mode? Which error do you have?
On my side, I updated the InputController.java, which you can find attached.
Playing with it, I was able to zoom in with 2 fingers.
Please note this is a quick sample, and of course shall be reworked. But it can provide with guidelines how to start.
Let me know if this helps.
Best regards,
Olivier
Heyb6
Dear Olivier,
Thanks for your replay,
in facture,i want to know how to switch between touch and pen modes by detecting the state of double finger pressing. Your attach may be give me a good idea of development.
by the way,this attach can't be view about InputController. Can you handle it.
Best regards
Olivier @MyScript
Dear Heyb,
please find the InputController.java file at the following link: https://myscript.filecamp.com/s/7e8p7dDVXKgbtbIc/d
Let me know if it helps.
Best regards,
Olivier