Android Question Rotate Code does not function

herryj

Member
Licensed User
Longtime User
Hi, masters, I have 2 modify codes here I've get through this forum as well.

First one is code in rotating image

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bp As BitmapPlus
    Dim bmp, bmpPressed As Bitmap
    Dim ivRotatKnob As ImageView

    Dim MinAngle As Int
    MinAngle = -360
    Dim MaxAngle As Int
    MaxAngle = 360

    Dim Angle, OldAngle As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Activity.Color = Colors.Blue

    bmp = LoadBitmap(File.DirAssets, "cat.png")
    bmpPressed = LoadBitmap(File.DirAssets, "cat.png")

    ivRotatKnob.Initialize("")
    ivRotatKnob.Gravity = Gravity.NO_GRAVITY
    Activity.AddView(ivRotatKnob, 60dip, 34dip, bmp.Width * Density, bmp.Height * Density)
    Dim r As Reflector
    r.Target = ivRotatKnob
    r.SetOnTouchListener("Knob_Touch")

    'Angle = MinAngle
    ivRotatKnob.SetBackgroundImage(bp.Rotate(bmp, bmp.Width, bmp.Height, Angle, True))

End Sub

Private Sub getAngle(X As Float, Y As Float) As Float
    Dim dx, dy As Float
   dx = (ivRotatKnob.Width / 2) - X
   dy = Y - (ivRotatKnob.Height / 2)
    Return ATan2(-dx, -dy) / cPI * 180
End Sub

Sub CalcAngle(X As Float, Y As Float)
    Dim NewAngle As Float
    NewAngle = getAngle(X, Y)
    Dim Delta, Delta1, Delta2, Delta3 As Float
    Delta1 = NewAngle - OldAngle
    Delta2 = NewAngle - OldAngle + 360
    Delta3 = NewAngle - OldAngle - 360
    ' What's the shortest distance between the old and new angles ?
    If Abs(Delta1) < Abs(Delta2) AND Abs(Delta1) < Abs(Delta3) Then
        Delta = Delta1
    Else If Abs(Delta2) < Abs(Delta3) Then
        Delta = Delta2
    Else
        Delta = Delta3
    End If
    Angle = Max(MinAngle, Min(Angle + Delta, MaxAngle))
    OldAngle = NewAngle
End Sub

Sub Knob_Touch(ViewTag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Select Action
        Case 0 ' DOWN
            OldAngle = getAngle(X, Y)
                ivRotatKnob.SetBackgroundImage(bp.Rotate(bmpPressed, bmpPressed.Width, bmpPressed.Height, Angle, True))
        Case 1 ' UP
                ivRotatKnob.SetBackgroundImage(bp.Rotate(bmpPressed,bmpPressed.Width, bmpPressed.Height, Angle, True))
        Case 2 ' MOVE
            CalcAngle(X, Y)
                ivRotatKnob.SetBackgroundImage(bp.Rotate(bmpPressed, bmpPressed.Width, bmpPressed.Height, Angle, True))
    End Select
    Return True
End Sub

The second one is dragging the image


B4X:
Sub Panel11_Touch(ViewTag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Select Action
        Case 0
           
            StartX = X
            StartY = Y
            MoveInProgress = False
        Case 1
            If MoveInProgress Then
                If Sender Is EditText Then CallSubDelayed(Me, "HideKeyboard")
                MoveInProgress = False
            End If
        Case 2
           
            If Abs(X - StartX) > 15 OR Abs(Y - StartY) > 15 OR MoveInProgress Then
           
                Panel11.Left = Max(MarginStillVisible -Panel11.Width, _
                                        Min(Panel11.Left + X - StartX, 100%x - MarginStillVisible))
                Panel11.Top = Max(MarginStillVisible - Panel11.Height, _
                                        Min(Panel11.Top + Y - StartY, 100%y - MarginStillVisible))
                Activity.Invalidate
                If Sender <> Panel11 Then
                    Dim r As Reflector
                    r.Target = Sender
                   r.runmethod2("setPressed","False","java.lang.boolean")
                End If
                MoveInProgress = True
                Return True
            End If
    End Select
    If Sender = Panel11 Then Return True
End Sub


And my problem is, when I combine this two codes the rotating image, doesn't now function.

Guys, I really need your help to figure out the problem.

Your help is high appreciated.

Thanks in advance.

-herryj
 

DonManfred

Expert
Licensed User
Longtime User
I cannot see your project attached (ide->file->export as zip).
Without seeing what you have done and how it is NOT possible to give advices!
You also missed to post the ERRORmessage from the LOG

Just saying "does not function" is the wrong attempt to get help.
Read this thread (not only the first post).
 
Upvote 0

herryj

Member
Licensed User
Longtime User
@DonManfred My apology sir.
What I meant on the title is when I combine the rotate and drag function, the code on the rotate functions doesn't work. And know as I test it again. the codes of each functions does not work both.

Here is an attachment.
 

Attachments

  • testing.zip
    142.4 KB · Views: 120
Upvote 0
Top