Android Question [Solved] Strange Panel_Touch within a Class

Star-Dust

Expert
Licensed User
Longtime 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.
B4X:
PanelFirma.Initialize("PanelFirma")
Box.AddView(PanelFirma,20dip,50dip,Larghezza-40dip,180dip)
I made this change
B4X:
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?
 

stevel05

Expert
Licensed User
Longtime User
Did you set the sub name correctly?

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

End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Did you set the sub name correctly?

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

End Sub
Sure, and now i change to :
B4X:
Sub PanelFirma_Touch (viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean
  Return True
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I'd need to see the original code in full to be able to give any other suggestions.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I'd need to see the original code in full to be able to give any other suggestions.
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.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I cut a piece of code, but the affected part is all there
B4X:
#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:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Where is PanelFirma defined?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
This works here:

B4X:
#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
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime 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
B4X:
Dim Sd As SignatureDialog
Sd.Initialize(Activity,Me,"Sd")
Sd.Show("Your Signature","Ok","Cancel")
 

Attachments

  • SignatureDialog.bas
    7.3 KB · Views: 296
Last edited:
Upvote 0

stevel05

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

Attachments

  • Sig.zip
    9.2 KB · Views: 315
Upvote 0

Star-Dust

Expert
Licensed User
Longtime 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:
 
Upvote 0

stevel05

Expert
Licensed User
Longtime 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.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Yes, I'll add a check. Thank's
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Are there any errors in the log when it fails?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
No. The event isn't eleved
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I give up. I go to sleep(datetime.TicksPerHour*8)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
@stevel05 Thanks for the help and the time you've lost, you deserve 5 like
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I still had the same problem on another library. I understand the reason.

The library contains several class. 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
 
Last edited:
Upvote 0
Top