Tell me why it can podtarmazhivat?

There is an ArrayList in which I store what I need to draw

public ArrayList<touchXYA> mPointList = new ArrayList<>(); 

There is a method to add objects (at the touch of the screen) to this ArrayList

 synchronized (surfaceHolder) { mPointList.add(new touchXYA(posX, posY, StartProgress, touchRadius)); } 

I draw everything in the stream:

  public void run() { this.run = true; Canvas c = null; while (run) { try { c = this.surfaceHolder.lockCanvas(null); synchronized (this.surfaceHolder) { doDraw(c); } } catch (Exception e) { e.printStackTrace(); } finally { if (c != null) { this.surfaceHolder.unlockCanvasAndPost(c); } } try { Thread.sleep(settings_pause); } catch (InterruptedException e) { e.printStackTrace(); } } } private void doDraw(Canvas canvas) { //Drawing back image and fog on it try { backPaint.setAlpha(255); canvas.drawRect(0, 0, width, height, backPaint); fogPaint.setAlpha(120); canvas.drawRect(0, 0, width, height, fogPaint); } catch (Exception e) { Log.v("Exception : ", e.toString()); } // Drawing mPointList touches for (touchXYA tempPoint : mPointList) { double percentOfProgress = tempPoint.progress / StartProgress; Log.v("percentOfProgress: ", Double.toString(percentOfProgress)); backPaint.setAlpha(255); double tempRadius = tempPoint.radius; tempRadius = 0.5 * (tempRadius + tempRadius * Math.sqrt(percentOfProgress)); canvas.drawCircle(tempPoint.x, tempPoint.y, (float) tempRadius, backPaint); fogPaint.setAlpha((int) (settings_StartTouchAlpha + (1 - percentOfProgress) * settings_EndTouchAlpha)); canvas.drawCircle(tempPoint.x, tempPoint.y, (float) tempRadius, fogPaint); } } 
  • And why do this.run = true; and while (run) ? The thread has a special check isInterrupted() . When you need to stop the thread, you need to call its interrupt() method, and inside the check, do while(!isInterrupted()) . - Pavel Krizhanovskiy
  • one
    For this code, to say nothing, you never know what is written there in doDraw (). - Evgeny Karavashkin
  • Pavel, thanks for the comment, I'll think about it, but I do not think that the brakes are due to this. - Igor
  • Eugene, added the doDraw method to the question. I’ve done the following: dajver.blogspot.com/2012/02/android.html - Igor
  • Maybe it's in sleep(settings_pause) ? .. why is there a pause here? - Sergey Sereda

0