diff --git a/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt b/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt index 2f96c26..2115a21 100644 --- a/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt +++ b/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt @@ -2,6 +2,7 @@ package com.example.acapendulum20.canvas import android.content.Context import android.graphics.Canvas +import android.graphics.Color import android.graphics.Paint import android.util.AttributeSet import android.view.View @@ -11,32 +12,48 @@ class CanvasPendulum @JvmOverloads constructor( ) : View(context, attrs, defStyleAttr) { - val paint: Paint = Paint() - lateinit var canvas: Canvas + private val paint: Paint = Paint() + private lateinit var canvas: Canvas + private var pendulumLineStopX = 200f + private var pendulumLineStopY = 600f + //var pendulumOnMove = false + + + override fun onDraw(canvas: Canvas?) { super.onDraw(canvas) + paint.style = Paint.Style.STROKE + //paint.strokeWidth = 10f + //canvas?.drawCircle(500f, 700f, 70f, paint) + paint.strokeWidth = 9f + canvas?.drawLine(455f,0f,500f, 630f,paint) + //if canvas not NULL then this canvas = it canvas?.let { this.canvas = it } - } - fun drawPendulum() { + fun startPendulum() { + //pendulumOnMove = false paint.style = Paint.Style.STROKE - paint.strokeWidth = 10f - canvas.drawCircle(500f, 700f, 70f, paint) + //paint.strokeWidth = 10f + //canvas.drawCircle(200f, 700f, 70f, paint)// cx&cy -> Variable paint.strokeWidth = 9f - canvas.drawLine(455f,0f,500f, 630f,paint) + canvas.drawColor(Color.WHITE) + canvas.drawLine(455f,0f,pendulumLineStopX, pendulumLineStopY,paint) //stopX&stopY -> Variable + println("excess to startPendulum function") } fun stopDrawingPendulum() { - canvas.drawCircle(400f, 300f, 70f, paint) + //canvas.drawCircle(400f, 300f, 70f, paint) + //pendulumOnMove = false + //canvas.drawColor(Color.WHITE) + //canvas.drawLine(455f,0f,500f, 630f,paint) //stopX&stopY -> Variable + println("excess to stopDrawingPendulum function") } - - } diff --git a/app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt b/app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt index 63598db..39bc833 100644 --- a/app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt +++ b/app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt @@ -1,6 +1,6 @@ package com.example.acapendulum20.fragments.pendulum -import android.graphics.Canvas +import android.annotation.SuppressLint import android.os.Bundle import android.view.LayoutInflater import android.view.MotionEvent @@ -8,58 +8,53 @@ import android.view.View import android.view.ViewGroup import android.widget.Button import androidx.fragment.app.Fragment -import androidx.lifecycle.ViewModelProvider import com.example.acapendulum20.R import com.example.acapendulum20.canvas.CanvasPendulum -import com.google.android.material.canvas.CanvasCompat -import kotlinx.android.synthetic.main.fragment_pendulum.view.* class PendulumFragment : Fragment() { + @SuppressLint("ClickableViewAccessibility") override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment val view = inflater.inflate(R.layout.fragment_pendulum, container, false) - val mCanvasPendulum: CanvasPendulum - mCanvasPendulum = view.findViewById(R.id.canvasContainer)!! + val mCanvasPendulum: CanvasPendulum = view.findViewById(R.id.canvasContainer)!! //activate the magnet val button = view.findViewById