Browse Source

Pendel Logic READY

Pendelsession information save in profile in progress
new fragment "fragment_start_pendulum"
master
Feyzu 3 years ago
parent
commit
eb00da0a8e
27 changed files with 383 additions and 163 deletions
  1. +17
    -0
      .idea/deploymentTargetDropDown.xml
  2. +3
    -1
      .idea/misc.xml
  3. +6
    -6
      app/build.gradle
  4. +59
    -0
      app/src/main/java/com/example/acapendulum20/StartPendulum.kt
  5. +82
    -46
      app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt
  6. +4
    -0
      app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt
  7. +4
    -0
      app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt
  8. +4
    -0
      app/src/main/java/com/example/acapendulum20/data/SessionDao.kt
  9. +4
    -0
      app/src/main/java/com/example/acapendulum20/data/SessionDatabase.kt
  10. +5
    -5
      app/src/main/java/com/example/acapendulum20/data/UserDao.kt
  11. +2
    -1
      app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt
  12. +1
    -1
      app/src/main/java/com/example/acapendulum20/fragments/list/ListAdapter.kt
  13. +1
    -1
      app/src/main/java/com/example/acapendulum20/fragments/list/ListFragment.kt
  14. +5
    -15
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt
  15. +3
    -3
      app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt
  16. +27
    -0
      app/src/main/java/com/example/acapendulum20/model/Measurement.kt
  17. +21
    -0
      app/src/main/java/com/example/acapendulum20/model/Session.kt
  18. +2
    -2
      app/src/main/java/com/example/acapendulum20/model/User.kt
  19. +4
    -0
      app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt
  20. +4
    -0
      app/src/main/java/com/example/acapendulum20/repository/SessionRepository.kt
  21. +4
    -0
      app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt
  22. +4
    -0
      app/src/main/java/com/example/acapendulum20/viewmodel/SessionViewmodel.kt
  23. +43
    -71
      app/src/main/res/layout/fragment_pendulum.xml
  24. +46
    -0
      app/src/main/res/layout/fragment_start_pendulum.xml
  25. +11
    -6
      app/src/main/res/layout/fragment_update.xml
  26. +15
    -3
      app/src/main/res/navigation/my_nav.xml
  27. +2
    -2
      build.gradle

+ 17
- 0
.idea/deploymentTargetDropDown.xml View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\Feyzu\.android\avd\Pixel_4_API_30.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-06-09T14:25:36.652444900Z" />
</component>
</project>

+ 3
- 1
.idea/misc.xml View File

@ -13,9 +13,11 @@
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/custom_row.xml" value="0.384375" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/custom_row.xml" value="0.384375" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_add.xml" value="0.45416666666666666" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_add.xml" value="0.45416666666666666" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_list.xml" value="0.45416666666666666" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_list.xml" value="0.45416666666666666" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum.xml" value="0.5" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum.xml" value="0.37640449438202245" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum2.xml" value="0.5541666666666667" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum2.xml" value="0.5541666666666667" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_start_pendulum.xml" value="0.3880208333333333" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_update.xml" value="0.33" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_update.xml" value="0.33" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/start_pendulum_fragment.xml" value="0.38697916666666665" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/menu/delete_menu.xml" value="0.5541666666666667" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/menu/delete_menu.xml" value="0.5541666666666667" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/mipmap-anydpi-v26/elektromagnet.xml" value="0.3165" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/mipmap-anydpi-v26/elektromagnet.xml" value="0.3165" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/mipmap-anydpi-v26/elektromagnet_round.xml" value="0.5255" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/mipmap-anydpi-v26/elektromagnet_round.xml" value="0.5255" />


+ 6
- 6
app/build.gradle View File

@ -59,8 +59,8 @@ dependencies {
// Navigation Component // Navigation Component
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.0'
// Room components // Room components
implementation "androidx.room:room-runtime:2.4.2" implementation "androidx.room:room-runtime:2.4.2"
@ -70,13 +70,13 @@ dependencies {
// Lifecycle components // Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
implementation "androidx.lifecycle:lifecycle-common-java8:2.5.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0"
// Kotlin components // Kotlin components
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.20" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.20"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1"
} }

+ 59
- 0
app/src/main/java/com/example/acapendulum20/StartPendulum.kt View File

@ -0,0 +1,59 @@
package com.example.acapendulum20
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
/**
* A simple [Fragment] subclass.
* Use the [StartPendulum.newInstance] factory method to
* create an instance of this fragment.
*/
class StartPendulum : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
param2 = it.getString(ARG_PARAM2)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_start_pendulum, container, false)
}
companion object {
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment StartPendulum.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
fun newInstance(param1: String, param2: String) =
StartPendulum().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
}
}
}
}

+ 82
- 46
app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt View File

@ -1,17 +1,11 @@
package com.example.acapendulum20.canvas package com.example.acapendulum20.canvas
import android.R
import android.content.Context import android.content.Context
import android.content.res.Resources
import android.graphics.BitmapFactory
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Color import android.graphics.Color
import android.graphics.Paint import android.graphics.Paint
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import kotlin.math.PI
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.sin import kotlin.math.sin
@ -34,97 +28,139 @@ class CanvasPendulum @JvmOverloads constructor(
//println("ONDRAW") //println("ONDRAW")
//draw line //draw line
mPendulum.startPosition.x = (width/2).toFloat()
mPendulum.startPosition.x = (width / 2).toFloat()
paint.isAntiAlias = true paint.isAntiAlias = true
paint.style = Paint.Style.STROKE paint.style = Paint.Style.STROKE
paint.color = Color.RED paint.color = Color.RED
paint.strokeWidth = 10f paint.strokeWidth = 10f
this.canvas.drawLine(mPendulum.startPosition.x, mPendulum.startPosition.y, mPendulum.stopPosition.x, mPendulum.stopPosition.y, paint)
this.canvas.drawLine(
mPendulum.startPosition.x,
mPendulum.startPosition.y,
mPendulum.stopPosition.x,
mPendulum.stopPosition.y,
paint
)
//draw circle //draw circle
paint.style = Paint.Style.FILL_AND_STROKE paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 1f paint.strokeWidth = 1f
paint.color = Color.GRAY paint.color = Color.GRAY
canvas?.drawCircle(mPendulum.stopPosition.x, mPendulum.stopPosition.y, mPendulum.ballr, paint)
//draw magnet as black circle
paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 1f
paint.color = Color.DKGRAY
canvas?.drawCircle((width/2).toFloat(),1150f, 30f, paint)
canvas?.drawCircle(
mPendulum.stopPosition.x,
mPendulum.stopPosition.y,
mPendulum.ballr,
paint
)
//draw sensor left //draw sensor left
paint.style = Paint.Style.FILL_AND_STROKE paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 1f paint.strokeWidth = 1f
paint.color = Color.RED paint.color = Color.RED
if (mPendulum.angleVelocity > 0 ){
if (mPendulum.stopPosition.x < (width/3) - 30f && mPendulum.stopPosition.x +30 > (width/3) - 30f - mPendulum.ballr){
if (mPendulum.angleVelocity > 0) {
if (mPendulum.stopPosition.x < (width / 3) - 30f && mPendulum.stopPosition.x + 30 > (width / 3) - 30f - mPendulum.ballr) {
paint.style = Paint.Style.FILL_AND_STROKE paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 10f paint.strokeWidth = 10f
paint.color = Color.GREEN paint.color = Color.GREEN
} }
} }
canvas?.drawCircle((width/3).toFloat(),910f, 30f, paint)
canvas?.drawCircle((width / 3).toFloat(), 910f, 30f, paint)
//draw sensor right //draw sensor right
paint.style = Paint.Style.FILL_AND_STROKE paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 10f
paint.strokeWidth = 1f
paint.color = Color.RED paint.color = Color.RED
if (mPendulum.angleVelocity < 0 ){
if (mPendulum.stopPosition.x > (width/1.5) - 30f && mPendulum.stopPosition.x +30 < (width/1.5) + 30f + mPendulum.ballr){
if (mPendulum.angleVelocity < 0) {
if (mPendulum.stopPosition.x > (width / 1.5) - 30f && mPendulum.stopPosition.x + 30 < (width / 1.5) + 30f + mPendulum.ballr) {
paint.style = Paint.Style.FILL_AND_STROKE paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 10f paint.strokeWidth = 10f
paint.color = Color.GREEN paint.color = Color.GREEN
} }
} }
canvas?.drawCircle((width/1.5).toFloat(),910f, 30f, paint)
canvas?.drawCircle((width / 1.5).toFloat(), 910f, 30f, paint)
startPendulum() startPendulum()
invalidate() invalidate()
} }
fun startPendulum() { fun startPendulum() {
val gravity = 0.981f
val damping = 0.996f
mPendulum.angleAcceleration = ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat()
mPendulum.angleVelocity += mPendulum.angleAcceleration
mPendulum.angleVelocity *= damping
mPendulum.angle += mPendulum.angleVelocity
//Polar to cartesian conversion
mPendulum.stopPosition.x = mPendulum.r * (sin(mPendulum.angle)).toFloat()
mPendulum.stopPosition.y = mPendulum.r * (cos(mPendulum.angle)).toFloat()
//Origin transition
mPendulum.stopPosition.x += mPendulum.startPosition.x
}
if (mPendulum.magneticField) {
var gravity = 0.981f
var damping = 0.996f
if (mPendulum.stopPosition.x > canvas.width / 4.toFloat() && mPendulum.stopPosition.x <= canvas.width * 0.75.toFloat()) {
gravity = 1.981f
if (mPendulum.stopPosition.x > canvas.width / 3.toFloat() && mPendulum.stopPosition.x <= canvas.width / 1.5.toFloat()) {
gravity = 2.981f
fun startMagnet(){
//if Circle = sensor -> circle/angleVelocity ++
if (mPendulum.stopPosition.x == canvas.width/2f) {
mPendulum.angleVelocity = 0f
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.angleVelocity += mPendulum.angleAcceleration
mPendulum.angleVelocity *= damping
mPendulum.angle += mPendulum.angleVelocity
//Polar to cartesian conversion
mPendulum.stopPosition.x = mPendulum.r * (sin(mPendulum.angle)).toFloat()
mPendulum.stopPosition.y = mPendulum.r * (cos(mPendulum.angle)).toFloat()
//Origin transition
mPendulum.stopPosition.x += mPendulum.startPosition.x
}
if (!mPendulum.magneticField) {
val gravity = 0.981f
val damping = 0.996f
mPendulum.angleAcceleration =
((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat()
mPendulum.angleVelocity += mPendulum.angleAcceleration
mPendulum.angleVelocity *= damping
mPendulum.angle += mPendulum.angleVelocity
//Polar to cartesian conversion
mPendulum.stopPosition.x = mPendulum.r * (sin(mPendulum.angle)).toFloat()
mPendulum.stopPosition.y = mPendulum.r * (cos(mPendulum.angle)).toFloat()
//Origin transition
mPendulum.stopPosition.x += mPendulum.startPosition.x
} }
} }
fun stopMagnet(){
fun startMagnet(magnet: Boolean) {
println("startMagnet")
println(magnet)
mPendulum.magneticField = magnet
}
fun stopMagnet(magnet: Boolean) {
println("stopMagnet")
println(magnet)
mPendulum.magneticField = magnet
} }
} }
class Position(var x: Float, var y: Float){
class Position(var x: Float, var y: Float) {
} }
class Pendulum { class Pendulum {
var startPosition: Position = Position(0f, 0f) var startPosition: Position = Position(0f, 0f)
var stopPosition: Position = Position(0f,0f)
var stopPosition: Position = Position(0f, 0f)
var r = 800f var r = 800f
//PI/6 Max ausschwingen //PI/6 Max ausschwingen
var angle : Double = Math.PI/6
var angleVelocity : Float = 0.0f //
var angleAcceleration : Float = 0.0f //
var ballr : Float = 70.0f //
var angle: Double = Math.PI / 12
var angleVelocity: Float = 0.0f //
var angleAcceleration: Float = 0.0f //
var ballr: Float = 70.0f //
var magneticField: Boolean = false
} }

+ 4
- 0
app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt View File

@ -0,0 +1,4 @@
package com.example.acapendulum20.data
class MeasurementDao {
}

+ 4
- 0
app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt View File

@ -0,0 +1,4 @@
package com.example.acapendulum20.data
class MeasurementDatabase {
}

+ 4
- 0
app/src/main/java/com/example/acapendulum20/data/SessionDao.kt View File

@ -0,0 +1,4 @@
package com.example.acapendulum20.data
class SessionDao {
}

+ 4
- 0
app/src/main/java/com/example/acapendulum20/data/SessionDatabase.kt View File

@ -0,0 +1,4 @@
package com.example.acapendulum20.data
class SessionDatabase {
}

+ 5
- 5
app/src/main/java/com/example/acapendulum20/data/UserDao.kt View File

@ -8,18 +8,18 @@ import com.example.acapendulum20.model.User
interface UserDao { interface UserDao {
@Insert(onConflict = OnConflictStrategy.IGNORE ) @Insert(onConflict = OnConflictStrategy.IGNORE )
suspend fun addUser(user: User)
fun addUser(user: User)
@Update @Update
suspend fun updateUser(user: User)
fun updateUser(user: User)
@Delete @Delete
suspend fun deleteUser(user: User)
fun deleteUser(user: User)
@Query("DELETE FROM user_table") @Query("DELETE FROM user_table")
suspend fun deleteAllUsers()
fun deleteAllUsers()
@Query("SELECT * FROM user_table ORDER BY id ASC")
@Query("SELECT * FROM user_table ORDER BY lastName ASC")
fun readAllData(): LiveData<List<User>> fun readAllData(): LiveData<List<User>>
} }

+ 2
- 1
app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt View File

@ -15,6 +15,7 @@ import com.example.acapendulum20.model.User
import com.example.acapendulum20.viewmodel.UserViewmodel import com.example.acapendulum20.viewmodel.UserViewmodel
import kotlinx.android.synthetic.main.fragment_add.* import kotlinx.android.synthetic.main.fragment_add.*
import kotlinx.android.synthetic.main.fragment_add.view.* import kotlinx.android.synthetic.main.fragment_add.view.*
import java.util.*
class AddFragment : Fragment() { class AddFragment : Fragment() {
@ -45,7 +46,7 @@ class AddFragment : Fragment() {
if(inputCheck(firstName, lastName, sex, handiness, age)){ if(inputCheck(firstName, lastName, sex, handiness, age)){
//Create User Objeect //Create User Objeect
val user = User(0, firstName, lastName,Integer.parseInt(age.toString()), sex, handiness)
val user = User(UUID.randomUUID().toString(), firstName, lastName,Integer.parseInt(age.toString()), sex, handiness)
//Add Data to Database //Add Data to Database
mUserViewModel.addUser(user) mUserViewModel.addUser(user)
Toast.makeText(requireContext(),"Successfully added!", Toast.LENGTH_LONG).show() Toast.makeText(requireContext(),"Successfully added!", Toast.LENGTH_LONG).show()


+ 1
- 1
app/src/main/java/com/example/acapendulum20/fragments/list/ListAdapter.kt View File

@ -27,7 +27,7 @@ class ListAdapter: RecyclerView.Adapter<ListAdapter.MyViewHolder>() {
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val currentItem = userList[position] val currentItem = userList[position]
holder.itemView.id_txt.text = currentItem.id.toString()
holder.itemView.id_txt.text = (position+1).toString()
holder.itemView.firstName_txt.text = currentItem.firstName holder.itemView.firstName_txt.text = currentItem.firstName
holder.itemView.lastName_txt.text = currentItem.lastName holder.itemView.lastName_txt.text = currentItem.lastName
holder.itemView.age_txt.text = currentItem.age.toString() holder.itemView.age_txt.text = currentItem.age.toString()


+ 1
- 1
app/src/main/java/com/example/acapendulum20/fragments/list/ListFragment.kt View File

@ -65,7 +65,7 @@ class ListFragment : Fragment() {
mUserViewModel.deleteAllUsers() mUserViewModel.deleteAllUsers()
Toast.makeText( Toast.makeText(
requireContext(), requireContext(),
"Succesfully removed everything!",
"Successfully removed everything!",
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} }


+ 5
- 15
app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt View File

@ -2,16 +2,15 @@ package com.example.acapendulum20.fragments.pendulum
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.os.SystemClock
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.View.OnTouchListener
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 com.example.acapendulum20.R import com.example.acapendulum20.R
import com.example.acapendulum20.canvas.CanvasPendulum import com.example.acapendulum20.canvas.CanvasPendulum
import java.util.*
class PendulumFragment : Fragment() { class PendulumFragment : Fragment() {
@ -35,29 +34,20 @@ class PendulumFragment : Fragment() {
button.setOnTouchListener(object : View.OnTouchListener{ button.setOnTouchListener(object : View.OnTouchListener{
var pushed = false
override fun onTouch(v: View?, event: MotionEvent?): Boolean { override fun onTouch(v: View?, event: MotionEvent?): Boolean {
var steps: Int
var startTime: Long
if (event?.action == MotionEvent.ACTION_DOWN){ if (event?.action == MotionEvent.ACTION_DOWN){
startTime = SystemClock.elapsedRealtime()
pushed = true
do {
mCanvasPendulum.startMagnet()
steps =- 1
}while (pushed)
println("button action DOWN")
mCanvasPendulum.startMagnet(true)
} }
if (event?.action == MotionEvent.ACTION_UP){ if (event?.action == MotionEvent.ACTION_UP){
pushed = false
mCanvasPendulum.stopMagnet()
println("button action up")
println("button action UP")
mCanvasPendulum.stopMagnet(false)
} }
return true return true
} }
}) })
//System.currentTimeMillis() //System.currentTimeMillis()
//System.nanoTime() //System.nanoTime()


+ 3
- 3
app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt View File

@ -29,7 +29,7 @@ class UpdateFragment : Fragment() {
// Inflate the layout for this fragment // Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_update, container, false) val view = inflater.inflate(R.layout.fragment_update, container, false)
mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java)
mUserViewModel = ViewModelProvider(this)[UserViewmodel::class.java]
view.updateFirstName_et.setText(args.currentUser.firstName) view.updateFirstName_et.setText(args.currentUser.firstName)
view.updateLastName_et.setText(args.currentUser.lastName) view.updateLastName_et.setText(args.currentUser.lastName)
@ -37,9 +37,9 @@ class UpdateFragment : Fragment() {
view.updateSex_et.setText(args.currentUser.sex) view.updateSex_et.setText(args.currentUser.sex)
view.updateHandiness_et.setText(args.currentUser.handiness) view.updateHandiness_et.setText(args.currentUser.handiness)
//navigate to fragment_pendulum
//navigate to fragment_start_pendulum
view.startTest_btn.setOnClickListener{ view.startTest_btn.setOnClickListener{
findNavController().navigate(R.id.action_updateFragment_to_pendulumFragment)
findNavController().navigate(R.id.action_updateFragment_to_startPendulum)
} }
//navigate to fragment_update //navigate to fragment_update


+ 27
- 0
app/src/main/java/com/example/acapendulum20/model/Measurement.kt View File

@ -0,0 +1,27 @@
package com.example.acapendulum20.model
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.ForeignKey
import com.example.acapendulum20.data.UserDao
import com.example.acapendulum20.data.UserDao_Impl
import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity(tableName = "measurement_table", foreignKeys = [ForeignKey(entity = Session::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("sessionRef"),
onDelete = ForeignKey.CASCADE)]
)
data class Measurement (
@PrimaryKey
val id: String,
val testNr: Int,
val targetVelocity: Int,
val maxAttemptTime: Int,
val attemptTime: Int,
val sessionRef: String,
): Parcelable

+ 21
- 0
app/src/main/java/com/example/acapendulum20/model/Session.kt View File

@ -0,0 +1,21 @@
package com.example.acapendulum20.model
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity(tableName = "session_table", foreignKeys = [ForeignKey(entity = User::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("userRef"),
onDelete = ForeignKey.CASCADE)])
data class Session (
@PrimaryKey
val id: String,
val sessionStart: Long,
val sessionEnd: Long,
val userRef: String,
): Parcelable

+ 2
- 2
app/src/main/java/com/example/acapendulum20/model/User.kt View File

@ -8,8 +8,8 @@ import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
@Entity(tableName = "user_table") @Entity(tableName = "user_table")
data class User ( data class User (
@PrimaryKey(autoGenerate = true)
val id: Int,
@PrimaryKey
val id: String,
val firstName: String, val firstName: String,
val lastName: String, val lastName: String,
val age: Int, val age: Int,


+ 4
- 0
app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt View File

@ -0,0 +1,4 @@
package com.example.acapendulum20.repository
class MeasurementRepository {
}

+ 4
- 0
app/src/main/java/com/example/acapendulum20/repository/SessionRepository.kt View File

@ -0,0 +1,4 @@
package com.example.acapendulum20.repository
class SessionRepository {
}

+ 4
- 0
app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt View File

@ -0,0 +1,4 @@
package com.example.acapendulum20.viewmodel
class MeasurementViewmodel {
}

+ 4
- 0
app/src/main/java/com/example/acapendulum20/viewmodel/SessionViewmodel.kt View File

@ -0,0 +1,4 @@
package com.example.acapendulum20.viewmodel
class SessionViewmodel {
}

+ 43
- 71
app/src/main/res/layout/fragment_pendulum.xml View File

@ -10,95 +10,67 @@
<TextView <TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="48dp"
android:text="TextView"
android:id="@+id/actV_view"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="act. V"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView6" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="20dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView4"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintEnd_toStartOf="@+id/activate_btn"
app:layout_constraintHorizontal_bias="0.548"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.791" />
<TextView <TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="48dp"
android:text="TextView"
android:id="@+id/maxTime_view"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="52dp"
android:text="max time"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView5" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/speichern_btn"
app:layout_constraintTop_toBottomOf="@+id/timer_view"
app:layout_constraintVertical_bias="0.933" />
<TextView <TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="48dp"
android:text="TextView"
android:id="@+id/goalV_view"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="52dp"
android:text="goal v"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView4" />
app:layout_constraintEnd_toStartOf="@+id/speichern_btn"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/actV_view"
app:layout_constraintVertical_bias="0.965" />
<TextView <TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="48dp"
android:text="TextView"
android:id="@+id/timer_view"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="Timer"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="20dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView6"
app:layout_constraintStart_toEndOf="@+id/textView9" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="20dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView7"
app:layout_constraintStart_toEndOf="@+id/textView10" />
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="20dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView5"
app:layout_constraintStart_toEndOf="@+id/textView8" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.483"
app:layout_constraintStart_toEndOf="@+id/activate_btn"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.789" />
<Button <Button
android:id="@+id/speichern_btn" android:id="@+id/speichern_btn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:text="Speichern" android:text="Speichern"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.857"
app:layout_constraintStart_toEndOf="@+id/textView11" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/activate_btn"
app:layout_constraintVertical_bias="0.187" />
<Button <Button
android:id="@+id/activate_btn" android:id="@+id/activate_btn"


+ 46
- 0
app/src/main/res/layout/fragment_start_pendulum.xml View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp"
tools:context=".StartPendulum">
<Button
android:id="@+id/startPendulum_btn"
android:layout_width="160dp"
android:layout_height="60dp"
android:text="start pendulum"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.632" />
<TextView
android:id="@+id/goalVSet_view"
android:layout_width="160dp"
android:layout_height="60dp"
android:text="goal velocity set"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.366" />
<TextView
android:id="@+id/maxTimeSet_view"
android:layout_width="160dp"
android:layout_height="60dp"
android:text="max time set"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/goalVSet_view"
app:layout_constraintVertical_bias="0.079" />
</androidx.constraintlayout.widget.ConstraintLayout>

+ 11
- 6
app/src/main/res/layout/fragment_update.xml View File

@ -13,8 +13,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="10" android:ems="10"
android:inputType="textPersonName"
android:hint="First Name" android:hint="First Name"
android:inputType="textPersonName"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -25,8 +26,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:ems="10" android:ems="10"
android:inputType="textPersonName"
android:hint="Last Name" android:hint="Last Name"
android:inputType="textPersonName"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateFirstName_et" /> app:layout_constraintTop_toBottomOf="@+id/updateFirstName_et" />
@ -37,8 +39,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:ems="10" android:ems="10"
android:inputType="number"
android:hint="Age" android:hint="Age"
android:inputType="number"
android:minHeight="48dp"
app:layout_constraintTop_toBottomOf="@+id/updateLastName_et" app:layout_constraintTop_toBottomOf="@+id/updateLastName_et"
tools:layout_editor_absoluteX="100dp" /> tools:layout_editor_absoluteX="100dp" />
@ -48,8 +51,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:ems="10" android:ems="10"
android:inputType="textPersonName"
android:hint="Sex" android:hint="Sex"
android:inputType="textPersonName"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateAge_et" /> app:layout_constraintTop_toBottomOf="@+id/updateAge_et" />
@ -60,8 +64,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:ems="10" android:ems="10"
android:inputType="textPersonName"
android:hint="Handiness" android:hint="Handiness"
android:inputType="textPersonName"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateSex_et" /> app:layout_constraintTop_toBottomOf="@+id/updateSex_et" />
@ -86,7 +91,7 @@
app:layout_constraintTop_toBottomOf="@+id/update_btn" /> app:layout_constraintTop_toBottomOf="@+id/update_btn" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/testResultRecyclerview"
android:id="@+id/SessionRecyclerview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"


+ 15
- 3
app/src/main/res/navigation/my_nav.xml View File

@ -38,8 +38,8 @@
android:name="currentUser" android:name="currentUser"
app:argType="com.example.acapendulum20.model.User" /> app:argType="com.example.acapendulum20.model.User" />
<action <action
android:id="@+id/action_updateFragment_to_pendulumFragment"
app:destination="@id/pendulumFragment" />
android:id="@+id/action_updateFragment_to_startPendulum"
app:destination="@id/startPendulum" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/pendulumFragment" android:id="@+id/pendulumFragment"
@ -47,7 +47,19 @@
android:label="fragment_pendulum" android:label="fragment_pendulum"
tools:layout="@layout/fragment_pendulum" > tools:layout="@layout/fragment_pendulum" >
<action <action
android:id="@+id/action_pendulumFragment_to_updateFragment"
android:id="@+id/action_pendulumFragment_to_startPendulum"
app:destination="@id/startPendulum" />
</fragment>
<fragment
android:id="@+id/startPendulum"
android:name="com.example.acapendulum20.StartPendulum"
android:label="fragment_start_pendulum"
tools:layout="@layout/fragment_start_pendulum" >
<action
android:id="@+id/action_startPendulum_to_pendulumFragment"
app:destination="@id/pendulumFragment" />
<action
android:id="@+id/action_startPendulum_to_updateFragment"
app:destination="@id/updateFragment" /> app:destination="@id/updateFragment" />
</fragment> </fragment>
</navigation> </navigation>

+ 2
- 2
build.gradle View File

@ -5,14 +5,14 @@ buildscript {
} }
dependencies { dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0")
} }
} }
plugins { plugins {
id 'com.android.application' version '7.2.0' apply false id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
} }
task clean(type: Delete) { task clean(type: Delete) {


Loading…
Cancel
Save