Android Question Refreshing a Layout (clearing a plot in a panel)

Chris Salonikas

Member
Licensed User
Hello, still new so please correct me if I am not posting correctly.
I read this latest post (3) Multiple executions of the same loadlayout | B4X Programming Forum
My question is may be considered similar and not sure whether to respond to that thread or start a new one, I started new to be on the safe side.
My question arise as a result experimenting with my plotting project Plotting like a geometric lathe. | B4X Programming Forum
In a Layout I have a button(Plot), a panel and a button(Clear) When I press Plot button which has a loop and random variable values, the plotting start on the Panel.
It may take up to 1min to complete the plot. If I wait for the plot to complete and press the Clear button that has the statement Activity.LoadLayout("Layout1") it clears the panel like as in the old times (Clearscreen), not the buttons. Now if didn't like the plot and not wait for the plot to complete and press clear, it clears the plot but it automatically continues to plot where it left off and if the plot button is pressed an new plot starts on top of it. Moving back and forward from one activity to another does not clear the panel, but if I press the phones back button all the way to put it in the background and bring it back, all results in all the layouts have been cleared (refreshed) even if the plotting has not completed. So I should cut my story short and ask the question.
How to properly clear my plotting panel and any actions not completed?
 

klaus

Expert
Licensed User
The most efficient way to help you would be if you posted your current project as a zip file, I think that it has evolved.
So we could see what exactly you have done and how.
Just some thoughts about your question.
- You might use a Timer for the sequencing.
- To stop the drawing, stop the Timer.
- To erase the drawing, clear the Panel, BUT, don't reload the layout. Reuse the existing ones
Each time you load a new layout you add all the views in the layout to the existing views.
To see this, add this line :
Log(Activity.NumberOfViews)
after Activity.LoadLayout("Layout1").
You will see that the number increases each time.
 
Upvote 0

Mahares

Expert
Licensed User
I played a little bit with your project.
Exquisite illustration. The drawing does not stop after one full rotation and the Start/Stop button text does not switch back to 'Start'. So I added 4 lines. See code below. Give me your opinion if it makes sense or not:
B4X:
If Angle > 2 * cPI Then
        Angle = 0
        LineColor = Colors.RGB(Rnd(50, 250), Rnd(50, 250), Rnd(50, 250))
        
        'below 4 lines added by Mahares
        Timer1.Enabled = False
        Log("Finished full rotation")
        btnStartStop.Text = "Start"
        btnStartStop.SetColorAndBorder(0xFF006400, 1dip, 0xFF90EE90, 5dip)    
    End If
 
Upvote 0

klaus

Expert
Licensed User
Give me your opinion if it makes sense or not:
Of course it makes sense, it is a different vision of how a program could work.

My vision was a bit different.
The Start / Stop button simply starts or stops the drawing, it is a kind of toggle button, the text and color change with each touch.
At full rotation, the color changes.
The Clear button clears and initializes the drawing, it doesn't stop the drawing.
This was my 'playing' vision just to show what could be done, up to Chris Salonikas to use what he likes.
 
Last edited:
Upvote 0

Chris Salonikas

Member
Licensed User
Thank you Mahares and klaus, I was able to get similar effects but the above but, with your ideas I am learning better programming.
In my other post Plotting like a geometric lathe. | B4X Programming Forum I have added another more complex formula for all who like to play with such illustration.
I don't know if you have noticed an undesirable effect, the plotting is sometimes not consistent throughout the cycle.
It slows down slightly and picks up again. it is more pronounced if a timer is used. It may show the effect more obviously with the more complex formula I included in the other post. This is in Release Mode installed. Then again it may be my device (phone Galaxy S4 Note).
 
Upvote 0

klaus

Expert
Licensed User
I had seen some speed differences depending on the drawing position.
As the drawing is time driven, with angle increments, the length of the line elements is not constant.
Longer for a big 'radius' and shorter for a smaller 'radius'.
 
Upvote 0
Top