Dear Frens,
I am trying to learn GestureDetector Library in which i am going to implement OnDoubleTap Gesture to smooth zoom the screen.I have code on Java writtern by my fren but unable to convert it to B4A so if anyone can help me i will be grateful.
Here is the code what i have tried so far :
Original Code on Java :
i have no idea how to use this TimerTask and UIthread.
Please help me to Learn.
Thank u.
I am trying to learn GestureDetector Library in which i am going to implement OnDoubleTap Gesture to smooth zoom the screen.I have code on Java writtern by my fren but unable to convert it to B4A so if anyone can help me i will be grateful.
Here is the code what i have tried so far :
B4X:
Sub Gesture_onDoubleTap(X As Float, Y As Float, MotionEvent As Object)
' Log(" onDoubleTap x = " & X & ", y = " & Y & ", ev = " & MotionEvent)
' ToastMessageShow("Double-Tap", False)
Dim initial As Double : initial = zoom
Dim f As Double : f = 1.5 * zoom
Dim ctr As Vector2D
Dim increment As Double
Dim finalzoom As Double
If f> 3000 Then f=2999
finalzoom = f
increment = (finalzoom - initial)/10
ctr.Initialize(0,0)
ctr.Xx = x
ctr.Yy =y
Dim v As Double : v= zoom + increment
If v> finalzoom Then
Else
centeredZoom(ctr,zoom+increment)
End If
End Sub
B4X:
@override
public boolean onDoubleTap(MotionEvent e)
{
//Smooth zoom animation: zoom 1.5X in 200ms
final float initial = zoom;
float f = 1.5f * zoom;
if (f > 3000) f = 2999;
final float finalzoom = f;
final float increment = (finalzoom - initial) / 10;
final Vector2D ctr = new Vector2D(e.getX(), e.getY());
final Timer rTimer = new Timer();
TimerTask rTask = new TimerTask()
{
@override
public void run()
{
((Activity) ctx).runOnUiThread(new Runnable()
{
@override
public void run()
{
float v = zoom + increment;
if (v > finalzoom)
{
rTimer.cancel();
} else
{
centeredZoom(ctr, zoom + increment);
}
}
});
}
};
rTimer.schedule(rTask, 0, 20);
return false;
}
i have no idea how to use this TimerTask and UIthread.
Please help me to Learn.
Thank u.