Math

Answered

How to scale and scroll by two fingers

i want to handle scale and scroll by two finger,how can do this 


Best 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.


Let me know if this helps.


Best regards,


Olivier

java

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

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


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.


Let me know if this helps.


Best regards,


Olivier

java

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.

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

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

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

Login or Signup to post a comment