|
|
@ -1,42 +1,70 @@ |
|
|
|
package com.example.acapendulum20.fragments.pendulum |
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.graphics.* |
|
|
|
import android.graphics.drawable.Drawable |
|
|
|
import android.graphics.Canvas |
|
|
|
import android.os.Bundle |
|
|
|
import android.util.AttributeSet |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.MotionEvent |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.widget.ImageView |
|
|
|
import androidx.core.content.res.ResourcesCompat |
|
|
|
import android.widget.Button |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.lifecycle.ViewModelProvider |
|
|
|
import androidx.navigation.fragment.findNavController |
|
|
|
import com.example.acapendulum20.R |
|
|
|
import com.example.acapendulum20.canvas.CanvasView |
|
|
|
import com.example.acapendulum20.viewmodel.UserViewmodel |
|
|
|
import kotlinx.android.synthetic.main.fragment_pendulum.* |
|
|
|
import com.example.acapendulum20.canvas.CanvasPendulum |
|
|
|
import com.google.android.material.canvas.CanvasCompat |
|
|
|
import kotlinx.android.synthetic.main.fragment_pendulum.view.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_update.view.* |
|
|
|
|
|
|
|
|
|
|
|
class PendulumFragment : Fragment() { |
|
|
|
|
|
|
|
private lateinit var mCanvasView: CanvasView |
|
|
|
|
|
|
|
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)!! |
|
|
|
|
|
|
|
//activate the magnet |
|
|
|
view.activate_btn.setOnClickListener{ |
|
|
|
mCanvasView.drawBob() |
|
|
|
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){ |
|
|
|
|
|
|
|
MotionEvent.ACTION_DOWN -> { |
|
|
|
mCanvasPendulum.drawPendulum() |
|
|
|
} |
|
|
|
|
|
|
|
MotionEvent.ACTION_MOVE -> { } |
|
|
|
|
|
|
|
MotionEvent.ACTION_UP -> { |
|
|
|
mCanvasPendulum.stopDrawingPendulum() |
|
|
|
} |
|
|
|
|
|
|
|
MotionEvent.ACTION_CANCEL -> { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else ->{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
true |
|
|
|
} |
|
|
|
|
|
|
|
//System.currentTimeMillis() |
|
|
|
//System.nanoTime() |
|
|
|
|
|
|
|
return view |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|