diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/MyPaint.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/MyPaint.java deleted file mode 100644 index 7811213..0000000 --- a/app/src/main/java/org/ntlab/acanthus_client/views/paint/MyPaint.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.ntlab.acanthus_client.views.paint; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Path; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; - -import org.ntlab.acanthus_client.Acanthus; -import org.ntlab.acanthus_client.resources.HelloWorldRest; -import org.ntlab.acanthus_client.resources.gallery.StrokesRest; - -import java.util.ArrayList; -import java.util.List; - -import androidx.annotation.Nullable; -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; - -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; -import retrofit2.converter.jackson.JacksonConverterFactory; -import retrofit2.converter.scalars.ScalarsConverterFactory; - -public class MyPaint extends View { - - private Path path; - private Paint paint; - private ArrayList xlen = new ArrayList(); - private ArrayList ylen = new ArrayList(); - private Acanthus acanthus; - private MutableLiveData strokeNo; - - public MyPaint(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - - //1)コンストラクタ(≒必需品) - path = new Path();//線を引いたり、図形を描いたり、要するにグラフィック - - paint = new Paint();//筆の種類 - paint.setColor(Color.RED);//色の指定 - paint.setStyle(Paint.Style.STROKE);//線をひく - paint.setStrokeWidth(20);//幅 - this.acanthus = new Acanthus(); - this.strokeNo = new MutableLiveData(); - } - - //2)onDraw(描画の準備/プロペラが回りだした状態) - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - canvas.drawPath(path, paint); - } - - - //3)実際の操縦 (条件分岐:押したとき、動かしたとき、放した時) - - @Override - public boolean onTouchEvent(MotionEvent event) { - //(3-1)座標を取得(x座標、y座標) - float x = event.getX(); - float y = event.getY(); - xlen.add(x); - ylen.add(y); - - //(3-2)タッチの処理 - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - path.moveTo(x, y); - addStrokes(getAcanthus()); - invalidate(); - break; - case MotionEvent.ACTION_MOVE: - path.lineTo(x, y); - AddPositions(x, y, getStrokeNo()); - invalidate(); - break; - case MotionEvent.ACTION_UP: - break; - } - - //return super.onTouchEvent(event); - return true; - } - - - //4)クリア処理 - public void clearCanvas() { - System.out.println(xlen.toArray()); - path.reset(); - invalidate(); - } - - public void setAcanthus(Acanthus acanthus) { - this.acanthus = acanthus; - } - - public Acanthus getAcanthus() { - return acanthus; - } - - public MutableLiveData getStrokeNo() { - return strokeNo; - } - - public void setStrokeNo(int strokeNo) { - this.strokeNo.setValue(strokeNo); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////////////////// - //retrofit - public void AddPositions(double x, double y, MutableLiveData strokeno) { - Retrofit retrofit = new Retrofit.Builder() - .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") - .addConverterFactory(ScalarsConverterFactory.create()) - .addConverterFactory(JacksonConverterFactory.create()) - .build(); - final StrokesRest strokesRest = retrofit.create(StrokesRest.class); - Call call = strokesRest.addPositions(1111, strokeno.getValue(), x, y); - call.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - if (response.isSuccessful()) { - System.out.println("success"); - } else { - System.out.println("false"); - } - } - - @Override - public void onFailure(Call call, Throwable t) { - //mText.setValue("みす helloworld"); - } - }); - - } - - public void addStrokes(Acanthus acanthus) { - Retrofit retrofit = new Retrofit.Builder() - .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") - .addConverterFactory(ScalarsConverterFactory.create()) - .addConverterFactory(JacksonConverterFactory.create()) - .build(); - final StrokesRest strokesRest = retrofit.create(StrokesRest.class); - Call call = strokesRest.addStroke(1111, acanthus.getPreferenceUid(), acanthus.getPreferenceToken(), 1, 1, 1); - call.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - if (response.isSuccessful()) { - System.out.println("success"); - setStrokeNo(response.body().intValue()); - } else { - System.out.println("false"); - } - } - - @Override - public void onFailure(Call call, Throwable t) { - //mText.setValue("みす helloworld"); - } - }); - - } - - -} \ No newline at end of file