#Region Project Attributes
#ApplicationLabel: Test Pinch-Zoom
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim zoom As Float = 1.0
Private bmp As Bitmap
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private img As ImageView
Private gd As GestureDetector
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Lets draw a nice little smiley face for our sample
Dim cnv As Canvas
bmp.InitializeMutable(32dip,32dip)
cnv.Initialize2(bmp)
cnv.DrawColor(Colors.Red)
cnv.DrawCircle(16dip,16dip,16dip,Colors.Yellow,True,1dip)
cnv.DrawCircle(8dip,8dip,2dip,Colors.Black,True,1dip)
cnv.DrawCircle(24dip,8dip,2dip,Colors.Black,True,1dip)
Dim path1 As Path
path1.Initialize(0,16dip)
path1.LineTo(0,32dip)
path1.LineTo(32dip,32dip)
path1.LineTo(32dip,16dip)
path1.LineTo(0,16dip)
cnv.ClipPath(path1)
cnv.DrawCircle(16dip,16dip,12dip,Colors.Black,True,1)
'now we will create an image view and place it on the activity centered
img.Initialize("")
img.Gravity = Gravity.FILL
img.SetBackgroundImage(bmp)
Activity.AddView(img,(Activity.Width-bmp.Width)/2,(Activity.Height-bmp.Height)/2,bmp.Width,bmp.Height)
'now add the GestureDetector
gd.SetOnGestureListener(Activity,"gd")
gd.EnableLongPress(False)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'Here we recieve Pinchopen events. Try opening a little bit, then lift your fingers and replace on the screen a bit
' further apart. The image jumps as though you moved your fingers on the screen instead of just lifting them
Sub gd_onPinchOpen(NewDistance As Float, PreviousDistance As Float, MotionEvent As Object)
'We will find the ratio between the NewDistance and Previous Distance and resize the image view accordingly
zoom = zoom * (NewDistance/PreviousDistance)
img.Width = bmp.Width*zoom
img.Height = bmp.Height*zoom
img.Top = (Activity.Height-img.Height)/2
img.left = (Activity.Width - img.Width)/2
End Sub
'here we recieve PinchClose events. Same problem as above. any repositioning of the fingers are read as movement across
' the screen. PinchOpen/PinchClose should be reset when fingers are lifted from the screen.
Sub gd_onPinchClose(NewDistance As Float, PreviousDistance As Float, MotionEvent As Object)
zoom = zoom *(NewDistance/PreviousDistance)
img.Width = bmp.Width*zoom
img.Height = bmp.Height*zoom
img.Top = (Activity.Height-img.Height)/2
img.left = (Activity.Width - img.Width)/2
End Sub