Android Question Can Sender be used with Panel_Touch

AlexOfOz

Active Member
Licensed User
I have successfully used Sender with Button_Click a number of times. But now I'm getting more adventurous and want to use Sender with Panel_Touch. I am moving things on the screen using Panel_Touch, but am trying to avoid using the same code for each object. So far it isn't working.
 

mangojack

Expert
Licensed User
Longtime User
It would help if you posted the code that does not work.

I have added 2 panels to a layout. I set both event names (designer property) to PanelX and set individual Tags.

B4X:
Sub PanelX_Touch (Action As Int, X As Float, Y As Float)    
    Dim p As Panel = Sender
    Log(p.Tag)
End Sub
 
Upvote 0

AlexOfOz

Active Member
Licensed User
Thanks mj.

This is the start of the routine, but it's enough as there is no action at all. It compiles OK, just doesn't do anything.

B4X:
Sub Panel_Touch (Action As Int, X As Float, Y As Float)
    
    Dim panl As Panel
    panl = Sender
    
    panltag = panl.Tag
    panltag = panltag - 1

    If inplace(panltag) <> "Yes" Then
        Select Action
            Case Activity.ACTION_DOWN
                X0 = X
                Y0 = Y
                X1 = tile(panltag).Left
                Y1 = tile(panltag).Top
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
What is inplace(panltag) Are you sure it does not equal "Yes" ?

a slightly better way
B4X:
Dim panl As Panel = Sender  
panltag = panl.Tag -1

ps: it might be better to past a small demo project and explain exactly what your trying to achieve.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
Yes, I know that the code works. What I've been doing is coding the activities for each object, then when it works properly, converting it to a SENDER routine. "inplace(panltag)" is simply saying that the tile of the jigsaw is in the correct place, is all. If it doesn't equal YES, it means to continue to move that object.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
mj, I will try making the adjustment you suggest. I will post the whole routine, but it won't show any further reason why it doesn't work. I am using a cut'n'paste from sample code provided on this site, but am simply trying to convert it from a button to a panel.

Keep in mind that I am a very amateur coder, learning so I have a retirement activity. I also am having so much fun I could just giggle. And as you read this code, please keep in mind that exactly this code works properly when applied to each individual panel object.
B4X:
Sub Panel_Touch (Action As Int, X As Float, Y As Float)
    
    Dim panl As Panel
    panl = Sender
    
    panltag = panl.Tag
    panltag = panltag - 1

    If inplace(panltag) <> "Yes" Then
        Select Action
            Case Activity.ACTION_DOWN
                X0 = X
                Y0 = Y
                X1 = tile(panltag).Left
                Y1 = tile(panltag).Top
    
            Case Activity.ACTION_MOVE
                dX = X - X0
                dY = Y - Y0
                tile(panltag).Left = X1 + dX
                tile(panltag).Top = Y1 + dY
                If tile(panltag).Left >= (tL(panltag) - 12) And tile(panltag).Left <= (tL(panltag) + 12)  Then
                    If tile(panltag).Top >= (tT(panltag) - 12) And tile(panltag).Top <= (tT(panltag) + 12) Then
                        tile(panltag).Left = tL(panltag)
                        tile(panltag).Top = tT(panltag)
                        inplace(panltag) = "Yes"
                    End If
                End If
        End Select
    End If
End Sub
 
Upvote 0

AlexOfOz

Active Member
Licensed User
mj, I just made that small adjustment, ie. panltag = panl.Tag - 1 - and it didn't make any difference. :-(
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
mj, I just made that small adjustment, ie. panltag = panl.Tag - 1 - and it didn't make any difference. :-(



It was Not supposed to make a difference or solve anything ... it was just a 'neater' way to write it.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
I am not understanding your code.

1. why do you reduce the tag of the sender panel by -1.
2. again what is inplace(panltag) ** Not what it does ... but what is it . ie: String Array ?

Again it might be best to upload a small demo project (with comments) . File > Export as Zip
Obviously it is some form of Jigsaw puzzle or similar.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
Thanks mj. Yes it is a very simplistic jigsaw that I'm actually quite happy with. I'm just using it to improve my knowledge and skills. I will do what I've done with previous projects and use the skills that I learn and get from all of you good people, to come back to this unknown in the future and say DUH, and then fix it up. I was hoping that there was a key bit that applied to panels and not buttons, but it would appear not. Thanks for your help. I appreciate it.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Already 10 posts and still no 'solution'!?
Why don't you post your project as a zip file so we see what exactly you have done and how and give you a concrete answer and solution.
How many Panels do you have?
What do they represent?
etc.
I am almost sure that one Panel would be enough, but without knowing what exactly your problem is ,,,
 
Upvote 0

AlexOfOz

Active Member
Licensed User
OK Klaus. My first zip post.
Please keep in mind that I'm new'ish and not aiming for rocket science code. My aim is to have code that works, then gradually improve my coding as I learn stuff.

- Damn. I can't figure out how to upload the zip. I've tried attaching it, but it won't. Is it the b4a file I attach?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should first export the zip file in the IDE.

1584863746924.png


And then click on the
1584863874151.png
button at the bottom to attach the zip file to the post.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
My suggestions:
1. You should move all the Jsaw Panels onto the BasePanel, changing their Parent property.

1584867190104.png


The best way to do it is: to select all Jsaw Panels, Cut them and Paste them onto BasePanel.

2. Set the Event Name for all Jsaw Panels to Jsaw, without the number.

3. Rename the Panel_Touch event to Jsaw_Touch.
And it will works.
This is the first answer to your question.

I will look a bit further at the project and come back with other suggestions.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
Thanks Klaus; I will do what you suggest later tonight. I appreciate your guidance. I certainly appreciate your greater expertise.

I'm currently watching our Prime Minister on television telling the country that we are closing as of tomorrow, due to this terrible health crisis facing the world. That will give me a lot more time to play with my program. I plan on adding 2 extra puzzles to this project ..... eventually.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
Klaus, I am so very grateful. Yes, it is working, so you have shown me a piece of information that I was lacking. I will now use that piece of knowledge to improve my understanding and coding.
Thank-you.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Additional suggestions:
1. Use Int variable types for all positions and dimensions instead of Float.

2. Use dip (density independant pixel) values instead of pixel values.
Example:
If tile(panltag).Left >= (tL(panltag) - 12) And tile(panltag).Left . . .
If tile(panltag).Left >= (tL(panltag) - 12dip) And tile(panltag).Left . . .


3. Move all the code to position views from the code into the Designer Scipts in the Visual Designer.

4. Put the buttons onto a Panel, and use the vertical Anchor of the Panel to bottom.

5. Be aware that, in the layout, the BasePanel width is wider than the screen!

6. When a jsaw is positioned, you might send it to back: panl.SendToBack. Otherwise small jigsaws might be hidden and no more visible.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
Klaus, thank-you very much. Some of what you say I was already aware of (the problems), but hadn't yet figured out how to fix it. I had already tried to fix point #6 but had failed. I will do as you suggest. You have also touched on something else that I have been struggling with, being the inconvenient confusion of dip and no dip. I have been trying to get past my confusion with that, so you have helped. The buttons on the panel is something I knew that I would eventually get to, but hadn't bothered to this point.

Moving code into Designer Scripts is something I had seen, but is new for me to work with. That will be new knowledge for me.

I am very grateful for your help and, as I have said in a previous post, hope to be able to help others at some stage in the future in a similar way.
 
Upvote 0
Top