diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5292b8d..96b0eed 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -11,9 +11,10 @@
+
-
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index cbcbe74..4d9c6dd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,14 +1,17 @@
+ package="com.example.acapendulum20"
+ android:versionCode="2">
+
+
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 0fa4b7b..fca999d 100644
--- a/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt
+++ b/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt
@@ -6,8 +6,8 @@ import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
-import kotlin.math.cos
-import kotlin.math.sin
+import kotlinx.coroutines.delay
+import kotlin.math.*
class CanvasPendulum @JvmOverloads constructor(
@@ -142,6 +142,13 @@ class CanvasPendulum @JvmOverloads constructor(
println(magnet)
mPendulum.magneticField = magnet
}
+
+ fun getVelocity(): Double {
+ var currentVelocity = mPendulum.angleVelocity * 1000
+
+ val roundoff = (currentVelocity * 100.0).roundToInt() / 100.0
+ return abs(roundoff)
+ }
}
class Position(var x: Float, var y: Float) {
diff --git a/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt b/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt
index 42e932d..69c21f0 100644
--- a/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt
+++ b/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt
@@ -11,5 +11,14 @@ interface MeasurementDao {
@Insert(onConflict = OnConflictStrategy.IGNORE )
fun addMeasurement(measurement: Measurement)
+ @Update
+ fun finishMeasurement(measurement: Measurement)
+
+ @Query("SELECT * FROM measurement_table WHERE owner =:id")
+ fun readAllData(id: String): LiveData>
+
+ @Query("SELECT * FROM measurement_table ")
+ fun readAllData(): LiveData>
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt b/app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt
similarity index 65%
rename from app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt
rename to app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt
index 136d79b..9e5f224 100644
--- a/app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt
+++ b/app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt
@@ -1,22 +1,22 @@
package com.example.acapendulum20.data
import android.content.Context
-import android.icu.util.Measure
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
-import com.example.acapendulum20.model.User
import com.example.acapendulum20.model.Measurement
+import com.example.acapendulum20.model.User
-@Database(entities = [Measurement::class], version = 1, exportSchema = false)
-abstract class MeasurementDatabase: RoomDatabase() {
+@Database(entities = [Measurement::class, User::class], version = 1, exportSchema = false)
+abstract class PendulumDatabase: RoomDatabase() {
+ abstract fun userDao(): UserDao
abstract fun measurementDao(): MeasurementDao
companion object {
@Volatile
- private var INSTANCE: MeasurementDatabase? = null
+ private var INSTANCE: PendulumDatabase? = null
- fun getDatabase(context: Context): MeasurementDatabase{
+ fun getDatabase(context: Context): PendulumDatabase{
val tempInstance = INSTANCE
if(tempInstance != null){
return tempInstance
@@ -24,8 +24,8 @@ abstract class MeasurementDatabase: RoomDatabase() {
synchronized(this){
val instance = Room.databaseBuilder(
context.applicationContext,
- MeasurementDatabase::class.java,
- "measurement_database"
+ PendulumDatabase::class.java,
+ "user_database"
).build()
INSTANCE = instance
return instance
diff --git a/app/src/main/java/com/example/acapendulum20/data/UserDatabase.kt b/app/src/main/java/com/example/acapendulum20/data/UserDatabase.kt
deleted file mode 100644
index ff15845..0000000
--- a/app/src/main/java/com/example/acapendulum20/data/UserDatabase.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.example.acapendulum20.data
-
-import android.content.Context
-import androidx.room.Database
-import androidx.room.Room
-import androidx.room.RoomDatabase
-import com.example.acapendulum20.model.User
-
-@Database(entities = [User::class], version = 1, exportSchema = false)
-abstract class UserDatabase: RoomDatabase() {
- abstract fun userDao(): UserDao
-
- companion object {
- @Volatile
- private var INSTANCE: UserDatabase? = null
-
- fun getDatabase(context: Context): UserDatabase{
- val tempInstance = INSTANCE
- if(tempInstance != null){
- return tempInstance
- }
- synchronized(this){
- val instance = Room.databaseBuilder(
- context.applicationContext,
- UserDatabase::class.java,
- "user_database"
- ).build()
- INSTANCE = instance
- return instance
- }
- }
- }
-}
\ No newline at end of file
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 985c004..91db921 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
@@ -6,23 +6,26 @@ import android.os.CountDownTimer
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
-import android.view.View.OnTouchListener
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.fragment.app.Fragment
+import androidx.lifecycle.ViewModelProvider
+import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.example.acapendulum20.R
import com.example.acapendulum20.canvas.CanvasPendulum
+import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.viewmodel.MeasurementViewmodel
import kotlinx.android.synthetic.main.fragment_pendulum.*
-import java.time.LocalDateTime
+import java.text.DateFormat
+import java.text.SimpleDateFormat
+import java.util.*
class PendulumFragment : Fragment() {
private val args by navArgs()
-
private lateinit var mMeasurementViewmodel: MeasurementViewmodel
@SuppressLint("ClickableViewAccessibility")
@@ -33,35 +36,41 @@ class PendulumFragment : Fragment() {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_pendulum, container, false)
val mCanvasPendulum: CanvasPendulum = view.findViewById(R.id.canvasContainer)!!
+ mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
+
//activate the magnet
- val button = view.findViewById