Help me optimize this graphic animation

I need help with this simple animation on my Android phone. I am new to animation and graphics.

I collect accelerometer data as a window of a moving time series. When new accelerometer data is read, its data is displayed on the right, pushing the previous data to the left, as shown below:

enter image description here

My program works pretty smoothly, but I would like some help optimizing the animation. Here are my main concerns:

  • My current implementation reads all the accelerometer data in one stream and saves the data in a FIFO queue of a fixed size to fix the window width of the time series. Then I use Timer.scheduleAtFixedRate () to plot the entire contents of the queue so that the entire graph is redrawn every 50 milliseconds. Can i improve this? Do I really need to re-draw a graph as often as this? In another similar program that I saw, each column of pixels is copied one pixel to the left, ripples down the graph; the newest data column is drawn in the rightmost column of the pixel. This is better?

  • I redraw the legend (in the upper left corner) in the drawing stream, which launches the drawing function every 50 milliseconds. Is there a way to โ€œsaveโ€ this legend instead of constantly re-drawing it?

Any other help would be greatly appreciated. I have heard about optimizations such as double buffering, but I donโ€™t know if this would help me.

+4
source share
1 answer

If the legend and the crosshair need only be drawn once, you should place it in the bitmap image of the buffer. For your chart line, perhaps try using the Path object to draw the lines. When he gets time to draw lines, just drawLine goes to the corresponding point, and then translates the canvas to the left, respectively. If

+1
source

Source: https://habr.com/ru/post/1345958/


All Articles