Android Question [Solved] Strange Panel_Touch within a Class

Discussion in 'Android Questions' started by Star-Dust, Jun 9, 2017.

  1. Star-Dust

    Star-Dust Expert Licensed User

    Good evening at all,

    In one of my classes, I inserted the creation of a panel. When I try to intercept the Touch event with the Panel_Touch (Action As Int, X As Float, Y As Float) does not lift the event.
    Code:
    PanelFirma.Initialize("PanelFirma")
    Box.AddView(PanelFirma,
    20dip,50dip,Larghezza-40dip,180dip)
    I made this change
    Code:
    PanelFirma.Initialize("")
    Box.AddView(PanelFirma,
    20dip,50dip,Larghezza-40dip,180dip)

    Dim obj As Reflector
    obj.Target = PanelFirma
    obj.SetOnTouchListener(
    "PanelFirma_Touch")
    I modified the raised event with the same name ... and it works ... does anyone know why?
     
  2. stevel05

    stevel05 Expert Licensed User

    Did you set the sub name correctly?

    Code:
    Sub PanelFirma_Touch (Action As Int, X As Float, Y As Float)

    End Sub
     
    Star-Dust likes this.
  3. Star-Dust

    Star-Dust Expert Licensed User

    Sure, and now i change to :
    Code:
    Sub PanelFirma_Touch (viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean
      
    Return True
    End Sub
     
  4. stevel05

    stevel05 Expert Licensed User

    I'd need to see the original code in full to be able to give any other suggestions.
     
    Star-Dust likes this.
  5. Star-Dust

    Star-Dust Expert Licensed User

    The class is very long and complex .. I see if I can extrapolate a piece .. But now it works, it was curiosity if there was any reason for this behavior. It only works on panels and not on buttons.
     
  6. Star-Dust

    Star-Dust Expert Licensed User

    I cut a piece of code, but the affected part is all there
    Code:
    #Event: Response(Response as int, Signature as bitmap)
    #RaisesSynchronousEvents: BMsgBox3_Click

    Sub Class_Globals
        
    Public Response As Int = 100
        
    Public Sign As Bitmap
        
    Public ColoreStyle As Int = Colors.RGB(121,179,228)

        
    Private IsInitialized As Boolean = False
        
    Private My As Activity
        
    Private Pan As Panel
        
    Private Box As Panel
        
    Private CallBack As Object
        
    Private Event As String

        
    Private PanelFirma AsPanel
        
    Private Firma AsCanvas
        
    Private px,py As Int
    End Sub

    Public Sub Initialize(MyActivity As Activity, Me_CallBack As Object,EventName As String)
        My=MyActivity
        CallBack=Me_CallBack
        
    Event=EventName
        IsInitialized=
    True
        Sign=
    Null
    End Sub

    private Sub PanelMsgBox3_Touch (Action As Int, X As Float, Y As Float)
        
    Dim P As Phone
        P.HideKeyboard(My)
    End Sub

    #Region Box
    '-100 Error not initialized
    Sub Show(Title As String, Positive As String, Negative As String)
        
    Dim Larghezza As Int = 300dip
        
    Dim LBu3 As Int = (Larghezza-40dip)/3

        
    If IsInitialized Then
            Pan.Initialize(
    "PanelMsgBox3")
            Pan.Color=
    Colors.ARGB(210,10,10,10)
            My.AddView(Pan,
    0dip,0dip,100%x,100%y)
        
            Box.Initialize(
    "Box")
            Box.Tag=
    ""
            
    'Box.Color=Colors.White
            Box.Background=Corner(Colors.White)
            Pan.AddView(Box,
    50%x-Larghezza/2,50%y-150dip,Larghezza,300dip)
        
            
    Dim L As Label
            L.Initialize(
    "")
            L.SetBackgroundImage(Underline(
    Colors.White,Colors.DarkGray,True))
            L.Textcolor=
    Colors.Black
            L.Gravity=
    Gravity.CENTER
            L.TextSize=
    18
            L.Typeface=
    Typeface.DEFAULT_BOLD
            L.Text=Title
            Box.AddView(L,
    20dip,0dip,Larghezza-40dip,50dip)
        
            PanelFirma.Initialize(
    "")
            Box.AddView(PanelFirma,
    20dip,50dip,Larghezza-40dip,180dip)
            Firma.Initialize(PanelFirma)
            Firma.DrawColor(
    Colors.White)
            
    Dim obj As Reflector
            obj.Target = PanelFirma
            obj.SetOnTouchListener(
    "PanelFirma_Touch")

            
    Dim ResPanel As Panel
            ResPanel.Initialize(
    "")
            ResPanel.SetBackgroundImage(Underline(
    Colors.White,Colors.DarkGray,False))
            Box.AddView(ResPanel,
    20dip,240dip,Larghezza-40dip,60dip)
        
            
    Dim BPositive, BCancel, BNegative As Button
            
    If Positive.Trim<>"" Then
                BPositive.Initialize(
    "BMsgBox3")
                BPositive.Text=Positive
                BPositive.Gravity=
    Gravity.CENTER
                BPositive.TextColor=
    Colors.Black
                BPositive.Typeface=
    Typeface.DEFAULT_BOLD
                
    'BPositive.Background=Corner(ColoreStyle)
                BPositive.Color=Colors.Transparent
                BPositive.Tag=
    DialogResponse.POSITIVE
                Box.AddView(BPositive,
    10dip,240dip,LBu3,60dip)
            
    End If

            
    If Negative.Trim<>"" Then
                BNegative.Initialize(
    "BMsgBox3")
                BNegative.Text=Negative
                BNegative.Gravity=
    Gravity.CENTER
                BNegative.TextColor=
    Colors.Black
                BNegative.Typeface=
    Typeface.DEFAULT_BOLD
                
    'BNegative.Background=Corner(ColoreStyle)
                BNegative.Color=Colors.Transparent
                BNegative.Tag=
    DialogResponse.NEGATIVE
                Box.AddView(BNegative,Larghezza-LBu3-
    10dip,240dip,LBu3,60dip)
            
    End If

            BCancel.Initialize(
    "BMsgBox3")
            BCancel.Text=
    "RESET"
            BCancel.Gravity=
    Gravity.CENTER
            BCancel.TextColor=
    Colors.Black
            BCancel.Typeface=
    Typeface.DEFAULT_BOLD
            
    'BCancel.Background=Corner(ColoreStyle)
            BCancel.Color=Colors.Transparent
            BCancel.Tag=
    DialogResponse.CANCEL
            Box.AddView(BCancel,
    20dip+LBu3,240dip,LBu3,60dip)
        
            
    Image.Initialize("")
            
    Image.RemoveView
            
    Image.TextColor=Colors.Black
            
    Image.Gravity=Gravity.CENTER
            
    Image.TextSize=16
            Box.AddView(
    Image,Box.Width-45dip,5dip,40dip,40dip)
        
    Else
            
    ToastMessageShow("MessageBox not initialized",False)
        
    End If

    End Sub

    Private Sub PanelFirma_Touch (viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean
        
    If action = 0 Then 'mouse down constant
            px = x
            py = y
        
    Else
            Firma.DrawLine(px, py, x, y, 
    Colors.Black, 3dip)
            PanelFirma.Invalidate
            px = x
            py = y
        
    End If
        
    Return True
    End Sub

    #End Region
     
    Last edited: Jun 9, 2017
  7. stevel05

    stevel05 Expert Licensed User

    Where is PanelFirma defined?
     
  8. stevel05

    stevel05 Expert Licensed User

    This works here:

    Code:
    #Event: Response(Response as int, Signature as bitmap)
    #RaisesSynchronousEvents: BMsgBox3_Click

    Sub Class_Globals
        
    Public Response As Int = 100
        
    Public Sign As Bitmap
        
    Public ColoreStyle As Int = Colors.RGB(121,179,228)

        
    Private IsInitialized As Boolean = False
        
    Private My As Activity
        
    Private Pan As Panel
        
    Private Box As Panel
        
    Private CallBack As Object
        
    Private Event As String

        
    Private PanelFirma As Panel
        
    Private Firma As Canvas
        
    Private Image As ImageView
        
    Private px,py As Int
    End Sub

    Public Sub Initialize(MyActivity As Activity, Me_CallBack As Object,EventName As String)
        My=MyActivity
        CallBack=Me_CallBack
        
    Event=EventName
        IsInitialized=
    True
        Sign=
    Null
    End Sub

    private Sub PanelMsgBox3_Touch (Action As Int, X As Float, Y As Float)
        
    Dim P As Phone
        P.HideKeyboard(My)
    End Sub

    #Region Box
    '-100 Error not initialized
    Sub Show(Title As String, Positive As String, Negative As String)
        
    Dim Larghezza As Int = 300dip
        
    Dim LBu3 As Int = (Larghezza-40dip)/3

        
    If IsInitialized Then
            Pan.Initialize(
    "PanelMsgBox3")
            Pan.Color=
    Colors.ARGB(210,10,10,10)
            My.AddView(Pan,
    0dip,0dip,100%x,100%y)
       
            Box.Initialize(
    "Box")
            Box.Tag=
    ""
            
    'Box.Color=Colors.White
    '        Box.Background=Corner(Colors.White)
            Pan.AddView(Box,50%x-Larghezza/2,50%y-150dip,Larghezza,300dip)
       
            
    Dim L As Label
            L.Initialize(
    "")
    '        L.SetBackgroundImage(Underline(Colors.White,Colors.DarkGray,True))
            L.Textcolor=Colors.Black
            L.Gravity=
    Gravity.CENTER
            L.TextSize=
    18
            L.Typeface=
    Typeface.DEFAULT_BOLD
            L.Text=Title
            Box.AddView(L,
    20dip,0dip,Larghezza-40dip,50dip)
       
            PanelFirma.Initialize(
    "PanelFirma")
            Box.AddView(PanelFirma,
    20dip,50dip,Larghezza-40dip,180dip)
            Firma.Initialize(PanelFirma)
            Firma.DrawColor(
    Colors.White)
    '        Dim obj As Reflector
    '        obj.Target = PanelFirma
    '        obj.SetOnTouchListener("PanelFirma_Touch")

            
    Dim ResPanel As Panel
            ResPanel.Initialize(
    "")
    '        ResPanel.SetBackgroundImage(Underline(Colors.White,Colors.DarkGray,False))
            Box.AddView(ResPanel,20dip,240dip,Larghezza-40dip,60dip)
       
            
    Dim BPositive, BCancel, BNegative As Button
            
    If Positive.Trim<>"" Then
                BPositive.Initialize(
    "BMsgBox3")
                BPositive.Text=Positive
                BPositive.Gravity=
    Gravity.CENTER
                BPositive.TextColor=
    Colors.Black
                BPositive.Typeface=
    Typeface.DEFAULT_BOLD
                
    'BPositive.Background=Corner(ColoreStyle)
                BPositive.Color=Colors.Transparent
                BPositive.Tag=
    DialogResponse.POSITIVE
                Box.AddView(BPositive,
    10dip,240dip,LBu3,60dip)
            
    End If

            
    If Negative.Trim<>"" Then
                BNegative.Initialize(
    "BMsgBox3")
                BNegative.Text=Negative
                BNegative.Gravity=
    Gravity.CENTER
                BNegative.TextColor=
    Colors.Black
                BNegative.Typeface=
    Typeface.DEFAULT_BOLD
                
    'BNegative.Background=Corner(ColoreStyle)
                BNegative.Color=Colors.Transparent
                BNegative.Tag=
    DialogResponse.NEGATIVE
                Box.AddView(BNegative,Larghezza-LBu3-
    10dip,240dip,LBu3,60dip)
            
    End If

            BCancel.Initialize(
    "BMsgBox3")
            BCancel.Text=
    "RESET"
            BCancel.Gravity=
    Gravity.CENTER
            BCancel.TextColor=
    Colors.Black
            BCancel.Typeface=
    Typeface.DEFAULT_BOLD
            
    'BCancel.Background=Corner(ColoreStyle)
            BCancel.Color=Colors.Transparent
            BCancel.Tag=
    DialogResponse.CANCEL
            Box.AddView(BCancel,
    20dip+LBu3,240dip,LBu3,60dip)
       
    '        Image.Initialize("")
    '        Image.RemoveView
    '        Image.TextColor=Colors.Black
    '        Image.Gravity=Gravity.CENTER
    '        Image.TextSize=16
    '        Box.AddView(Image,Box.Width-45dip,5dip,40dip,40dip)
        Else
            
    ToastMessageShow("MessageBox not initialized",False)
        
    End If

    End Sub

    'Private Sub PanelFirma_Touch (viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean
    Private Sub PanelFirma_Touch (Action As Int, X As Float, Y As Float)
        
    Log("Touch")
        
    If Action = 0 Then 'mouse down constant
            px = x
            py = y
        
    Else
            Firma.DrawLine(px, py, x, y, 
    Colors.Black, 3dip)
            PanelFirma.Invalidate
            px = x
            py = y
        
    End If
        
    Return True
    End Sub

    #End Region
     
    Star-Dust likes this.
  9. Star-Dust

    Star-Dust Expert Licensed User

    Strange stuff, obviously you've taken the pictures and backgrounds that are based on function that I did not post ... for the rest is the same .. I do not know exactly.

    I uploaded the entire class .. I wanted to wait for it to be complete to publish it .. anyway I want to take this doubt away

    use it so
    Code:
    Dim Sd As SignatureDialog
    Sd.Initialize(
    Activity,Me,"Sd")
    Sd.Show(
    "Your Signature","Ok","Cancel")
     

    Attached Files:

    Last edited: Jun 9, 2017
  10. stevel05

    stevel05 Expert Licensed User

    This works too, I just changed the sub back, added the eventname and took out the reflection code.
     

    Attached Files:

    • Sig.zip
      File size:
      9.2 KB
      Views:
      80
    Star-Dust likes this.
  11. Star-Dust

    Star-Dust Expert Licensed User

    Even more strange, the same class as you are in your example works, as I insert it along with my project with the other classes, it does not work.:confused::confused::confused::confused:
     
  12. stevel05

    stevel05 Expert Licensed User

    I can see a potential problem if you call show twice, as there will be two of each view added to the activity. That could definitely cause it not to work.
     
    Star-Dust likes this.
  13. Star-Dust

    Star-Dust Expert Licensed User

    Yes, I'll add a check. Thank's
     
  14. stevel05

    stevel05 Expert Licensed User

    Are there any errors in the log when it fails?
     
    Star-Dust likes this.
  15. Star-Dust

    Star-Dust Expert Licensed User

    No. The event isn't eleved
     
  16. Star-Dust

    Star-Dust Expert Licensed User

    I give up. I go to sleep(datetime.TicksPerHour*8)
     
  17. Star-Dust

    Star-Dust Expert Licensed User

    @stevel05 Thanks for the help and the time you've lost, you deserve 5 like
     
  18. Star-Dust

    Star-Dust Expert Licensed User

    I still had the same problem on another library. I understand the reason.

    The bibreria contains several squares. Two of these (at least two) have dimensioned within objects of the same name. This is a mess and the Touch is not properly intercepted in the second class.

    Solution: Changing names to objects in the class A classes is only possible with the panels
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice