Recent

Author Topic: Animations  (Read 4800 times)

polypress

  • Jr. Member
  • **
  • Posts: 91
Animations
« on: August 30, 2014, 05:34:26 pm »
I have a Lazarus for android app which displays a daily graph of periodic quantities. It works well for a single day's observations, but when scanning over several days, it only displays the last day's graph, although it does handle the data for previous days, but it does not display them.
I assume that android can handle animations, so how are they displayed during the operation of the app, or does each frame have to be saved and displayed when the app has finished?

Regards

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Animations
« Reply #1 on: August 31, 2014, 08:53:51 am »
There are many ways to display data on screen, what is the one you are using, and can show some code?

polypress

  • Jr. Member
  • **
  • Posts: 91
Re: Animations
« Reply #2 on: August 31, 2014, 11:03:00 pm »
Sorry for the delay in replying but I've not been on the website until now.

I am drawing closely spaced lines with LineTo on the Canvas and then using FormPaint to display them, but they only display when the app has finished.

What other techniques are there to display, and I'll try them?

Regards

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Animations
« Reply #3 on: August 31, 2014, 11:43:49 pm »
try to call application.processMessages in regular intervals inside your animation loop or use a timer to draw each frame instead of a tight loop to allow the application to process screen refresh messages.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

polypress

  • Jr. Member
  • **
  • Posts: 91
Re: Animations
« Reply #4 on: September 01, 2014, 05:07:54 am »
Thank you for your reply taazz.
Unfortunately, android does not recognise the Application.ProcessMessages procedure; it works for Windows only. I did try it, though. Apparently it is the nature of the android operating system that prevents it from working, although it doesn't list an error when included - it just ignores it.

Regards

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Animations
« Reply #5 on: September 01, 2014, 10:46:59 am »
Try putting the drawing commands in the form's onPaint event, then call Repaint (or Invalidate?) in timer.

polypress

  • Jr. Member
  • **
  • Posts: 91
Re: Animations
« Reply #6 on: September 01, 2014, 03:10:56 pm »
Thank you for your suggestion User 137.
Unfortunately it still doesn't respond. The button to start the scan turns green, as before, (presumably indicating the process is underway) but nothing happens until the end of the scan, when the final graphic is displayed. In between the start and end there should have been 11 graphics displayed.
I'm wondering if it's to do with the Java side of android rather than the pascal side of Lazarus.
Any experts on Java activity?

Regards

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Animations
« Reply #7 on: September 01, 2014, 03:42:27 pm »
can you use threads in android? if yes how about running the scan process in a thread and copy the image to a screen image at an interval avoiding this way the GUI lock up?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Animations
« Reply #8 on: September 01, 2014, 05:14:25 pm »
People here have said that TTimer should work for Android. If it does, it should be much preferred over other thread.

You still haven't shown any code. Do you perhaps have a while- or for-loop inside the timer that is displaying all the images? You can have a separate int variable that adds up, like:

Code: [Select]
procedure Timer1Timer(Sender: TObject);
begin
  if img < MaxImg-1 then begin
    img := img+1; 
    Invalidate;
    //Application.ProcessMessages; // optional
  end;
end;

procedure FormPaint(......);
begin
  DrawImage(img);
end;

polypress

  • Jr. Member
  • **
  • Posts: 91
Re: Animations
« Reply #9 on: September 01, 2014, 07:12:02 pm »
Hi taazz and User 137. There is a for loop scanning through a mass of data which is put through various formulae and the results are 1500 points per image linked by LineTo. At this stage FormPaint is called, then the next group of points are evaluated. I tried using TTimer and  a separate thread calling invalidate, paint, refresh etc, but that didn't display the graphics, except the last one, again. The graphics can be converted from (effectively) a vector image to a bitmap, but there is also a grid on the form displaying key values from the data. That cannot be rasterized otherwise I would lose the scrolling facility to monitor the results.
It works well in Windows. That's why I think it may be to do with android rather than Lazarus, and finding a way to modify the activity.java file may be a solution. I do not have sufficient knowledge of android and Java to answer this, but I am investigating it.

Regards

 

TinyPortal © 2005-2018