invalidate

mkvidyashankar

Active Member
Licensed User
Longtime User
What does Invalidate2 or Invalidate mean
i m little bit confused about its functionality
 

krokiz

Member
Licensed User
Longtime User
I need help about how to use Invalidate2 (or 3) method in order to actually "update" only the specified rect not the whole activity. I have read what the Invalidate2 and 3 methods (suppose to) do, but I am still seeing the activity totaly "updates" itself each time I use invalidate2 or 3. In my case I need to draw points and lines and draw them fast, so, how, in the world, I would draw a simple point or line on the activity's screen, without invalidate method redraws it all over ??? That consumes way too much time and CPU!
I am having the following app structure:
Activity
3 panels
each panels has a canvas, and they have bitmaps.

If anyone could suggest an idea how to do this faster, it would be of use to everyone!
P.S.: when one enables "Show touches" in Settings: Developer options, they can see the circle under their fingertips refreshing when moved, not the whole screen is refreshing.
Give me some good ideas, please!
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Where are you drawing the lines, on the Panels or on the Activity ?
When you use Invalidate2 or Invalidate3 how do you define the rectangles ?
You must invalidate the view you are drawing on.
If you draw on Panel1 you should invalidate Panel1 not the Activity.
When you draw a circle you must define it's surrounding rectangle and use it for Invalidate2 or Invalidate3.
If you draw several drawings you should invalidate only at the end.

Best regards.
 
Upvote 0

krokiz

Member
Licensed User
Longtime User
I am drawing on one of the two panels, the second one contains buttons. I define rectangle just around the points drawn and wish to invalidate the rect's content. whenever I need to invalidate2 the rect, the whole activity is refreshing, not only the rectangle or the panel. I do invalidate at the end of points drawing, not after each point. If you are keen on getting deep into my problem, I am posting the TestDraw.zip
 

Attachments

  • TestDraw.zip
    23.9 KB · Views: 221
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately, I can't test your program.
I get following error!

Parsing code. 0.34
Compiling code. 0.59
Compiling layouts code. 0.05
Generating R file. 0.36
Compiling generated Java code. Error
B4A line: 2399
End Sub
javac 1.7.0_17
src\B4A\Oscilloscope\main.java:8505: error: code too large for try statement
catch (Exception e) {
^
1 error


I don't know why this happens.

But, I don't think that this
B4X:
copyrect.Initialize(ii-invalidate_on_every_5,0,ii,GridH)
PanelMain.Invalidate2(copyrect)
invalidates the whole Panel.

Best regards.
 
Upvote 0

krokiz

Member
Licensed User
Longtime User
Thank you, Klaus! Invalidate2 proved to do what it suppose to. I was misled by the Android's option turned on, which caused the whole activity's panel flashing, not only the region being updated. Anyway, would you suggest some other and FASTER way of drawing and UPDATING the activity's panels? Thanks a lot!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I would try to have as few as possible drawing routines.
For example combine Draw_xx_Line and DrawADotInCherga.
Leave in the loops only what is really necessary and move everything else out of the loops.
But as I dont know what exactly you want to do it's difficult to othere advices.

Best regards.
 
Upvote 0

krokiz

Member
Licensed User
Longtime User
Unfortunately, I can't test your program.
I get following error!

Parsing code. 0.34
Compiling code. 0.59
Compiling layouts code. 0.05
Generating R file. 0.36
Compiling generated Java code. Error
B4A line: 2399
End Sub
javac 1.7.0_17
src\B4A\Oscilloscope\main.java:8505: error: code too large for try statement
catch (Exception e) {
^
1 error


I don't know why this happens.

But, I don't think that this
B4X:
copyrect.Initialize(ii-invalidate_on_every_5,0,ii,GridH)
PanelMain.Invalidate2(copyrect)
invalidates the whole Panel.

Best regards.

(Kind answer: the forementioned error happens, due to Compiler.Debug option selected (instead of Release). The resulting Java code contains a LOOOT of try-catch-finally statements, and also much more statements like
BA.debugLineNum = 123;BA.debugLine="current source line 123";
Debug.ShouldStop(....);
... and the Debug Source Code is enormous!)
(And YES, the this code does what it should! Thanks a lot for confirming that!)
 
Last edited:
Upvote 0

krokiz

Member
Licensed User
Longtime User
One suggestion to the Forum Moderators:
IF IT IS POSSIBLE, it would be a great addition to the forum's functionality if a member could know where they have been quoted/answerd (preferably: in short) so they knew if there was a continuation of the discussion of their question/problem. I may assure you that this suggestion is not due to pure narcissism, but in order to have more use of the forum. Cheers!
 
Upvote 0
Top