|
@ -1,6 +1,6 @@ |
|
|
package com.example.acapendulum20.fragments.pendulum |
|
|
package com.example.acapendulum20.fragments.pendulum |
|
|
|
|
|
|
|
|
import android.graphics.Canvas |
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
import android.os.Bundle |
|
|
import android.os.Bundle |
|
|
import android.view.LayoutInflater |
|
|
import android.view.LayoutInflater |
|
|
import android.view.MotionEvent |
|
|
import android.view.MotionEvent |
|
@ -8,58 +8,53 @@ import android.view.View |
|
|
import android.view.ViewGroup |
|
|
import android.view.ViewGroup |
|
|
import android.widget.Button |
|
|
import android.widget.Button |
|
|
import androidx.fragment.app.Fragment |
|
|
import androidx.fragment.app.Fragment |
|
|
import androidx.lifecycle.ViewModelProvider |
|
|
|
|
|
import com.example.acapendulum20.R |
|
|
import com.example.acapendulum20.R |
|
|
import com.example.acapendulum20.canvas.CanvasPendulum |
|
|
import com.example.acapendulum20.canvas.CanvasPendulum |
|
|
import com.google.android.material.canvas.CanvasCompat |
|
|
|
|
|
import kotlinx.android.synthetic.main.fragment_pendulum.view.* |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PendulumFragment : Fragment() { |
|
|
class PendulumFragment : Fragment() { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility") |
|
|
override fun onCreateView( |
|
|
override fun onCreateView( |
|
|
inflater: LayoutInflater, container: ViewGroup?, |
|
|
inflater: LayoutInflater, container: ViewGroup?, |
|
|
savedInstanceState: Bundle? |
|
|
savedInstanceState: Bundle? |
|
|
): View? { |
|
|
): View? { |
|
|
// Inflate the layout for this fragment |
|
|
// Inflate the layout for this fragment |
|
|
val view = inflater.inflate(R.layout.fragment_pendulum, container, false) |
|
|
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 |
|
|
//activate the magnet |
|
|
val button = view.findViewById<Button>(R.id.activate_btn) |
|
|
val button = view.findViewById<Button>(R.id.activate_btn) |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
button.setOnClickListener{ |
|
|
|
|
|
mCanvasPendulum.drawBob() |
|
|
|
|
|
mCanvasPendulum.drawLine() |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
button.setOnTouchListener { v, event -> |
|
|
|
|
|
val action = event.action |
|
|
|
|
|
when(action){ |
|
|
|
|
|
|
|
|
//button.setOnClickListener{ |
|
|
|
|
|
// mCanvasPendulum.startPendulum() |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button.setOnTouchListener { _, event -> |
|
|
|
|
|
when (event.action) { |
|
|
|
|
|
|
|
|
MotionEvent.ACTION_DOWN -> { |
|
|
MotionEvent.ACTION_DOWN -> { |
|
|
mCanvasPendulum.drawPendulum() |
|
|
|
|
|
|
|
|
println("button gedrückt") |
|
|
|
|
|
mCanvasPendulum.startPendulum() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
MotionEvent.ACTION_MOVE -> { } |
|
|
|
|
|
|
|
|
//MotionEvent.ACTION_MOVE -> {} |
|
|
|
|
|
|
|
|
MotionEvent.ACTION_UP -> { |
|
|
MotionEvent.ACTION_UP -> { |
|
|
|
|
|
println("button losgelassen") |
|
|
mCanvasPendulum.stopDrawingPendulum() |
|
|
mCanvasPendulum.stopDrawingPendulum() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
MotionEvent.ACTION_CANCEL -> { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//MotionEvent.ACTION_CANCEL -> { } |
|
|
|
|
|
|
|
|
else ->{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//else -> {} |
|
|
} |
|
|
} |
|
|
true |
|
|
true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//System.currentTimeMillis() |
|
|
//System.currentTimeMillis() |
|
|
//System.nanoTime() |
|
|
//System.nanoTime() |
|
|
|
|
|
|
|
|