diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintCanvas.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintCanvas.java index ed8e222..6f0a508 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintCanvas.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintCanvas.java @@ -18,6 +18,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import androidx.annotation.Nullable; import androidx.lifecycle.LiveData; @@ -32,14 +34,14 @@ //----------------------------------------------------------------- // 描画キャンバスの本体 -public class PaintCanvas extends View { +public class PaintCanvas extends View implements Runnable{ private Path path; private Path path2; private Paint paint; private Paint paint2; private PaintViewModel paintViewModel; - + private ScheduledThreadPoolExecutor thread = new ScheduledThreadPoolExecutor(1); //----------------------------------------------------------------- //----------------------------------------------------------------- public PaintCanvas(Context context, @Nullable AttributeSet attrs) { @@ -55,6 +57,7 @@ paint2.setColor(Color.RED);//色の指定 paint2.setStyle(Paint.Style.STROKE);//線をひく paint2.setStrokeWidth(20);//幅 + thread.scheduleWithFixedDelay(this, 1000L, 200L, TimeUnit.MILLISECONDS); } //----------------------------------------------------------------- @@ -71,7 +74,6 @@ super.onDraw(canvas); canvas.drawPath(path, paint); canvas.drawPath(path2, paint2); - getCanvas(); } //----------------------------------------------------------------- @@ -118,7 +120,7 @@ //----------------------------------------------------------------- // 押した瞬間の処理 private void onTouched(float x, float y) { - path = new Path(); + //path = new Path(); path.moveTo(x, y); invalidate(); } @@ -134,7 +136,7 @@ //----------------------------------------------------------------- // 押した瞬間の処理 private void onTouched2(float x, float y) { - path2 = new Path(); + //path2 = new Path(); path2.moveTo(x, y); invalidate(); } @@ -149,6 +151,7 @@ //描写するための取得 public void getCanvas() { int cnt = 0; + path2.reset();//ここで一旦クリア for (Stroke s : paintViewModel.getStroke().getValue()) { for (Position p : s.getPositions()) { if (cnt == 0) { @@ -161,4 +164,10 @@ cnt = 0; } } + + // 一定間隔でサーバー上の筆跡を取得する(GET) + @Override + public void run() { + getCanvas(); + } } \ No newline at end of file