From ec67e0101c7c548b87914fd290be95c63b42fbd0 Mon Sep 17 00:00:00 2001 From: Feyzu Date: Mon, 14 Nov 2022 10:25:17 +0100 Subject: [PATCH] Finale Version --- .idea/misc.xml | 2 ++ .../acapendulum20/canvas/CanvasPendulum.kt | 21 +++++++++---------- .../acapendulum20/data/MeasurementDao.kt | 3 ++- .../acapendulum20/data/PendulumDatabase.kt | 2 +- .../com/example/acapendulum20/data/UserDao.kt | 3 +-- .../fragments/add/AddFragment.kt | 1 + .../fragments/pendulum/PendulumFragment.kt | 9 -------- .../fragments/update/UpdateFragment.kt | 3 +-- .../acapendulum20/model/Measurement.kt | 1 + .../com/example/acapendulum20/model/User.kt | 3 ++- .../repository/MeasurementRepository.kt | 3 +-- .../repository/UserRepository.kt | 2 +- .../viewmodel/MeasurementViewmodel.kt | 2 +- .../acapendulum20/viewmodel/UserViewmodel.kt | 3 +-- app/src/main/res/layout/fragment_pendulum.xml | 5 +++-- app/src/main/res/navigation/my_nav.xml | 12 ----------- 16 files changed, 28 insertions(+), 47 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 16389f9..78e7a67 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,10 +12,12 @@ + + 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 aae0c75..0d4b5ef 100644 --- a/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt +++ b/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt @@ -26,7 +26,6 @@ class CanvasPendulum @JvmOverloads constructor( this.canvas = it } - //println("ONDRAW") //draw line mPendulum.startPosition.x = (width / 2).toFloat() paint.isAntiAlias = true @@ -84,25 +83,26 @@ class CanvasPendulum @JvmOverloads constructor( fun startPendulum() { + //when active button is pushed if (mPendulum.magneticField) { var gravity = 0.981f var damping = 0.996f + //Pendulum positioning inside magnetic field close to Sensor left and right if (mPendulum.stopPosition.x > canvas.width / 4f && mPendulum.stopPosition.x <= canvas.width * 0.75f) { gravity = 1.981f - + //Pendulum positioning inside magnetic field at Sensor left and right if (mPendulum.stopPosition.x > canvas.width / 3.toFloat() && mPendulum.stopPosition.x <= canvas.width / 1.5.toFloat()) { gravity = 2.981f - + //Pendulum positioning inside magnetic field close to magnet if (mPendulum.stopPosition.x >= canvas.width / 2.toFloat() - 3 && mPendulum.stopPosition.x <= canvas.width / 2.toFloat() + 3) { damping = 0.3f } } } - mPendulum.angleAcceleration = - ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() + mPendulum.angleAcceleration = ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() mPendulum.angleVelocity += mPendulum.angleAcceleration mPendulum.angleVelocity *= damping mPendulum.angle += mPendulum.angleVelocity @@ -113,12 +113,12 @@ class CanvasPendulum @JvmOverloads constructor( mPendulum.stopPosition.x += mPendulum.startPosition.x } + //when active button released if (!mPendulum.magneticField) { val gravity = 0.981f val damping = 0.996f - mPendulum.angleAcceleration = - ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() + mPendulum.angleAcceleration = ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() mPendulum.angleVelocity += mPendulum.angleAcceleration mPendulum.angleVelocity *= damping mPendulum.angle += mPendulum.angleVelocity @@ -156,10 +156,9 @@ class Pendulum { var stopPosition: Position = Position(0f, 0f) var r = 800f - //PI/6 Max ausschwingen var angle: Double = Math.PI / 12 - var angleVelocity: Float = 0.0f // - var angleAcceleration: Float = 0.0f // - var ballr: Float = 70.0f // + var angleVelocity: Float = 0.0f + var angleAcceleration: Float = 0.0f + var ballr: Float = 70.0f var magneticField: Boolean = false } \ No newline at end of file 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 51fe108..16dcaa8 100644 --- a/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt +++ b/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt @@ -21,4 +21,5 @@ interface MeasurementDao { @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/PendulumDatabase.kt b/app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt index 9e5f224..e932f08 100644 --- a/app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt +++ b/app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt @@ -32,4 +32,4 @@ abstract class PendulumDatabase: RoomDatabase() { } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/acapendulum20/data/UserDao.kt b/app/src/main/java/com/example/acapendulum20/data/UserDao.kt index 3f73304..14bc25d 100644 --- a/app/src/main/java/com/example/acapendulum20/data/UserDao.kt +++ b/app/src/main/java/com/example/acapendulum20/data/UserDao.kt @@ -21,5 +21,4 @@ interface UserDao { @Query("SELECT * FROM user_table ORDER BY lastName ASC") fun readAllData(): LiveData> - -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt b/app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt index f593112..224bf80 100644 --- a/app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt +++ b/app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt @@ -34,6 +34,7 @@ class AddFragment : Fragment() { mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java) //dropdown sex + val sex = resources.getStringArray(R.array.sex) val arrayAdapterSex = ArrayAdapter(requireContext(), R.layout.dropdown_item, sex) view.chooseSex_et.setAdapter(arrayAdapterSex) 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 8bf0c2e..4ea1ae1 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 @@ -38,7 +38,6 @@ class PendulumFragment : Fragment() { val mCanvasPendulum: CanvasPendulum = view.findViewById(R.id.canvasContainer)!! mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java) - //activate the magnet val magnetButton = view.findViewById