| |
---|
| | import android.util.AttributeSet; |
---|
| | import android.view.MotionEvent; |
---|
| | import android.view.View; |
---|
| | |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.List; |
---|
| | |
---|
| | import androidx.annotation.Nullable; |
---|
| | |
---|
| | public class MyPaint extends View { |
---|
| | |
---|
| | private Path path; |
---|
| | private Paint paint; |
---|
| | private ArrayList<Float> xlen = new ArrayList<Float>(); |
---|
| | private ArrayList<Float> ylen = new ArrayList<Float>(); |
---|
| | |
---|
| | public MyPaint(Context context, @Nullable AttributeSet attrs) { |
---|
| | super(context, attrs); |
---|
| | |
---|
| |
---|
| | 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: |
---|
| |
---|
| | |
---|
| | |
---|
| | //4)クリア処理 |
---|
| | public void clearCanvas(){ |
---|
| | System.out.println(xlen.toArray()); |
---|
| | path.reset(); |
---|
| | invalidate(); |
---|
| | } |
---|
| | |
---|
| | |