Multi Touch / Pinch zoom

maxply45

New Member
I’m new to Android development, but have successfully implemented a couple of apps on my phone.

I am now looking at using the multitouch /pinch zoom feature on a new app, but i'm not sure if it will work.

Most of the pinch zoom apps i've seen have been for images and maps.

I’m wanting to use the pinch zoom on a “form” type app which contains mostly input fields and buttons.

Is this possible ?

Any advice would be greatly appreciated.
Thanks
 

Dominex

Active Member
Licensed User
Longtime User
Perhaps it may come in handy this code that I wrote with the library Gesture.

B4X:
Sub Globals
   Dim imv As ImageView
   Dim G As Gestures
   Dim TouchMap As Map   
   Dim Ipotenusa,Prodotto As Int
   Dim Zoom,ZoomStart As Float
   Dim ZoomMin,ZoomMax As Float
   ZoomMin = 0.5 '50%
   ZoomMax = 3 '300%
   Dim lbl As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim bmp As Bitmap
   bmp = LoadBitmap(File.DirAssets,"icon.png")
   imv.Initialize("")
   imv.Bitmap = bmp
   imv.Gravity = Gravity.FILL
   Activity.AddView(imv,50%x-(bmp.Width/2),50%y-(bmp.Height/2),bmp.Width,bmp.Height)
   Zoom = imv.Width '100%
   ZoomMin = Zoom*ZoomMin
   ZoomMax = Zoom*ZoomMax
   G.SetOnTouchListener(imv, "PinchZoom")
   TouchMap.Initialize
   '-----------------------
   lbl.Initialize("")
   Activity.AddView(lbl,0,0,100%x,100%y)
End Sub

Sub PinchZoom(View As Object, PointerID As Int, Action As Int, X As Float, Y As Float) As Boolean
   Dim point As Int
   Select Action
      Case G.ACTION_DOWN, G.ACTION_POINTER_DOWN
         point = PointerID
         TouchMap.Put(PointerID, point)
      Case G.ACTION_POINTER_UP
         TouchMap.Remove(PointerID)
         Ipotenusa = 0
         Zoom = Zoom+Prodotto
         Zoom = Min(Zoom,ZoomMax)
         Zoom = Max(Zoom,ZoomMin)
      Case G.ACTION_UP
         TouchMap.Clear
   End Select
   If (TouchMap.Size-1) = 1 Then
      If ZoomStart=0 Then ZoomStart=Zoom
      Dim xTemp,yTemp,Ipo,newZoom As Int
      xTemp = Abs(G.GetX(0)-G.GetX(1))
      yTemp = Abs(G.GetY(0)-G.GetY(1))
      Ipo = Sqrt(Power(xTemp,2)+Power(yTemp,2))/Density
      If Ipotenusa = 0 Then Ipotenusa = Ipo
      Prodotto = (Ipo-Ipotenusa)*2 'speed factor
      newZoom = Zoom+Prodotto
      lbl.Text = "%"&(100/ZoomStart*(newZoom)) 'label%
      newZoom = Min(newZoom,ZoomMax)
      newZoom = Max(newZoom,ZoomMin)
      Dim vWidth,vHeight As Float
      vWidth = newZoom
      vHeight = vWidth*(imv.Height/imv.Width)
      imv.SetLayout(50%x-(newZoom/2),50%y-(newZoom/2),vWidth,vHeight)
   End If
   Return True
End Sub
 

Attachments

  • PinchZoom.zip
    5.9 KB · Views: 886
Last edited:
Upvote 0
Top