B4A=true Group=Default Group ModulesStructureVersion=1 Type=Activity Version=7.01 @EndOfDesignText@ #Region Activity Attributes #FullScreen: True #IncludeTitle: False #End Region Sub Process_Globals Type Point(Id As Int, prevX As Int, prevY As Int) Dim ImageDir As String Dim ImageFileName As String End Sub Sub Globals Private PanelView As Panel Dim cv As Canvas Dim BackgroundColor As Int = Colors.Black Dim BackBmp As Bitmap Dim SrcRect As Rect Dim DestRect As Rect Dim LastX As Float, LastY As Float Dim ViewWidth As Int, ViewHeight As Int Dim CurrentX As Float, CurrentY As Float Dim BmpWidth As Int, BmpHeight As Int '----------- Dim GD As GestureDetector ' Dim G As Gestures ' Dim TouchMap As Map 'Dim MoreThan1 As Boolean Dim lenOld As Float Dim lenNew As Float Dim ImageScale As Double Dim MinScale As Double Dim MaxScale As Double = 3 Dim BtnCloseDra(2) As BitmapDrawable Dim ButtonCloseSLD As StateListDrawable Dim ButtonClose As Button End Sub Sub Activity_Create(FirstTime As Boolean) PanelView.Initialize("") Activity.AddView(PanelView,0,0,100%x,100%y) cv.Initialize(PanelView) '------------- GD.SetOnGestureListener(PanelView, "Gesture") GD.EnableLongPress(False) If File.Exists(ImageDir, ImageFileName) Then LoadFile(ImageDir, ImageFileName) Else Activity.Finish Return End If '-------- BtnCloseDra(0).Initialize(LoadBitmap(File.DirAssets,"close_image_up.png")) BtnCloseDra(1).Initialize(LoadBitmap(File.DirAssets,"close_image_down.png")) ButtonCloseSLD.Initialize ButtonClose.Initialize("ButtonClose") ButtonCloseSLD.AddState(ButtonCloseSLD.State_Pressed,BtnCloseDra(1)) ButtonCloseSLD.AddCatchAllState(BtnCloseDra(0)) ButtonClose.Background = ButtonCloseSLD Activity.AddView(ButtonClose, 100%x-40dip-4dip,4dip,40dip,40dip) End Sub Sub Activity_Resume End Sub Sub Activity_Pause (UserClosed As Boolean) End Sub '{ButtonClose Sub ButtonClose_Click Activity.Finish End Sub '} Sub LoadFile(FilePath As String, FileName As String) BackBmp = LoadBitmap(FilePath,FileName) BmpWidth = BackBmp.Width BmpHeight = BackBmp.Height ViewWidth = PanelView.Width ViewHeight = PanelView.Height If BmpWidth< ViewWidth And BmpHeight BmpHeight/ViewHeight Then ImageScale = ViewWidth/BmpWidth Else ImageScale = ViewHeight/BmpHeight End If End If MinScale = ImageScale '--------- DestRect.Initialize(0, 0, ViewWidth, ViewHeight) Dim CenterX As Int, CenterY As Int Dim HalfWidth As Int, HalfHeight As Int CenterX = BmpWidth/2 CenterY= BmpHeight/2 HalfWidth = (ViewWidth/ImageScale)/2 HalfHeight = (ViewHeight/ImageScale)/2 SrcRect.Initialize(CenterX-HalfWidth,CenterY-HalfHeight, CenterX+HalfWidth,CenterY+HalfHeight) cv.DrawColor(BackgroundColor) cv.DrawBitmap(BackBmp, SrcRect, DestRect) PanelView.Invalidate CurrentX = CenterX-HalfWidth CurrentY = CenterY-HalfHeight '} End Sub #Region GestureDetector Sub Gesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean If Action = GD.ACTION_UP Then lenOld = 0 End If Return True 'True = Handle this touch event, False = Ignore it End Sub Sub Gesture_onDown(X As Float, Y As Float, MotionEvent As Object) LastX = X LastY = Y End Sub Sub Gesture_onPinchOpen(NewDistance As Float, PreviousDistance As Float, MotionEvent As Object) ZoomImage(NewDistance) End Sub Sub Gesture_onPinchClose(NewDistance As Float, PreviousDistance As Float, MotionEvent As Object) ZoomImage(NewDistance) End Sub Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object) Dim X, Y As Int Try X = GD.getX(MotionEvent, 0) Y = GD.getY(MotionEvent, 0) If (LastX = X) And (LastY = Y) Then Return Dim newWidth As Int, NewHeight As Int newWidth = (ViewWidth/ImageScale) NewHeight = (ViewHeight/ImageScale) If newWidthBmpWidth Then CurrentX=BmpWidth-newWidth End If If NewHeightBmpHeight Then CurrentY=BmpHeight-NewHeight End If SrcRect.Initialize(CurrentX, CurrentY, CurrentX+newWidth, CurrentY+NewHeight) cv.DrawColor(BackgroundColor) cv.DrawBitmap(BackBmp,SrcRect, DestRect) PanelView.Invalidate LastX = X LastY = Y Catch Log(LastException) End Try End Sub Sub ZoomImage(NewDistance As Float) Try If lenOld = 0 Then lenOld = NewDistance Return End If lenNew = NewDistance '{ If (lenNew - lenOld) <> 0 Then Dim CenterX As Int, CenterY As Int Dim HalfWidth As Int, HalfHeight As Int CenterX = SrcRect.CenterX CenterY = SrcRect.CenterY '---------- ImageScale = ImageScale *(1 + (lenNew - lenOld)/lenOld) If ImageScale < MinScale Then ImageScale = MinScale If ImageScale > MaxScale Then ImageScale = MaxScale HalfWidth = (ViewWidth/ImageScale)/2 HalfHeight = (ViewHeight/ImageScale)/2 If CenterX-HalfWidth<0 Then CenterX = HalfWidth If CenterY-HalfHeight<0 Then CenterY = HalfHeight If CenterX+HalfWidth>BmpWidth Then CenterX = BmpWidth - HalfWidth If CenterY+HalfHeight>BmpHeight Then CenterY = BmpHeight-HalfHeight If HalfWidth*2>=BmpWidth Then CenterX = BmpWidth/2 If HalfHeight*2>=BmpHeight Then CenterY = BmpHeight/2 SrcRect.Initialize(CenterX-HalfWidth, CenterY-HalfHeight, CenterX+HalfWidth, CenterY+HalfHeight) cv.DrawColor(BackgroundColor) cv.DrawBitmap(BackBmp, SrcRect, DestRect) PanelView.Invalidate CurrentX = CenterX-HalfWidth CurrentY = CenterY-HalfHeight End If lenOld = NewDistance Catch Log(LastException) End Try End Sub #End Region