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); } }
this.run = true;
andwhile (run)
? The thread has a special checkisInterrupted()
. When you need to stop the thread, you need to call itsinterrupt()
method, and inside the check, dowhile(!isInterrupted())
. - Pavel Krizhanovskiysleep(settings_pause)
? .. why is there a pause here? - Sergey Sereda