Browse Source

Finale Version

master
Feyzu 2 years ago
parent
commit
ec67e0101c
16 changed files with 28 additions and 47 deletions
  1. +2
    -0
      .idea/misc.xml
  2. +10
    -11
      app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt
  3. +2
    -1
      app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt
  4. +1
    -1
      app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt
  5. +1
    -2
      app/src/main/java/com/example/acapendulum20/data/UserDao.kt
  6. +1
    -0
      app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt
  7. +0
    -9
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt
  8. +1
    -2
      app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt
  9. +1
    -0
      app/src/main/java/com/example/acapendulum20/model/Measurement.kt
  10. +2
    -1
      app/src/main/java/com/example/acapendulum20/model/User.kt
  11. +1
    -2
      app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt
  12. +1
    -1
      app/src/main/java/com/example/acapendulum20/repository/UserRepository.kt
  13. +1
    -1
      app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt
  14. +1
    -2
      app/src/main/java/com/example/acapendulum20/viewmodel/UserViewmodel.kt
  15. +3
    -2
      app/src/main/res/layout/fragment_pendulum.xml
  16. +0
    -12
      app/src/main/res/navigation/my_nav.xml

+ 2
- 0
.idea/misc.xml View File

@ -12,10 +12,12 @@
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/activity_main.xml" value="0.29713114754098363" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/activity_main.xml" value="0.29713114754098363" />
<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/custom_row_measurement.xml" value="0.5" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/custom_row_measurement.xml" value="0.5" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/dropdown_item.xml" value="0.30570652173913043" />
<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.33" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum.xml" value="0.33" />
<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_pendulum_settings.xml" value="0.3984375" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_start_pendulum.xml" value="0.33" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_start_pendulum.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/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/layout/start_pendulum_fragment.xml" value="0.38697916666666665" />


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

@ -26,7 +26,6 @@ class CanvasPendulum @JvmOverloads constructor(
this.canvas = it this.canvas = it
} }
//println("ONDRAW")
//draw line //draw line
mPendulum.startPosition.x = (width / 2).toFloat() mPendulum.startPosition.x = (width / 2).toFloat()
paint.isAntiAlias = true paint.isAntiAlias = true
@ -84,25 +83,26 @@ class CanvasPendulum @JvmOverloads constructor(
fun startPendulum() { fun startPendulum() {
//when active button is pushed
if (mPendulum.magneticField) { if (mPendulum.magneticField) {
var gravity = 0.981f var gravity = 0.981f
var damping = 0.996f 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) { if (mPendulum.stopPosition.x > canvas.width / 4f && mPendulum.stopPosition.x <= canvas.width * 0.75f) {
gravity = 1.981f 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()) { if (mPendulum.stopPosition.x > canvas.width / 3.toFloat() && mPendulum.stopPosition.x <= canvas.width / 1.5.toFloat()) {
gravity = 2.981f 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) { if (mPendulum.stopPosition.x >= canvas.width / 2.toFloat() - 3 && mPendulum.stopPosition.x <= canvas.width / 2.toFloat() + 3) {
damping = 0.3f 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 += mPendulum.angleAcceleration
mPendulum.angleVelocity *= damping mPendulum.angleVelocity *= damping
mPendulum.angle += mPendulum.angleVelocity mPendulum.angle += mPendulum.angleVelocity
@ -113,12 +113,12 @@ class CanvasPendulum @JvmOverloads constructor(
mPendulum.stopPosition.x += mPendulum.startPosition.x mPendulum.stopPosition.x += mPendulum.startPosition.x
} }
//when active button released
if (!mPendulum.magneticField) { if (!mPendulum.magneticField) {
val gravity = 0.981f val gravity = 0.981f
val damping = 0.996f 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 += mPendulum.angleAcceleration
mPendulum.angleVelocity *= damping mPendulum.angleVelocity *= damping
mPendulum.angle += mPendulum.angleVelocity mPendulum.angle += mPendulum.angleVelocity
@ -156,10 +156,9 @@ class Pendulum {
var stopPosition: Position = Position(0f, 0f) var stopPosition: Position = Position(0f, 0f)
var r = 800f var r = 800f
//PI/6 Max ausschwingen
var angle: Double = Math.PI / 12 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 var magneticField: Boolean = false
} }

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

@ -21,4 +21,5 @@ interface MeasurementDao {
@Query("SELECT * FROM measurement_table ") @Query("SELECT * FROM measurement_table ")
fun readAllData(): LiveData<List<Measurement>> fun readAllData(): LiveData<List<Measurement>>
}
}

+ 1
- 1
app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt View File

@ -32,4 +32,4 @@ abstract class PendulumDatabase: RoomDatabase() {
} }
} }
} }
}
}

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

@ -21,5 +21,4 @@ interface UserDao {
@Query("SELECT * FROM user_table ORDER BY lastName ASC") @Query("SELECT * FROM user_table ORDER BY lastName ASC")
fun readAllData(): LiveData<List<User>> fun readAllData(): LiveData<List<User>>
}
}

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

@ -34,6 +34,7 @@ class AddFragment : Fragment() {
mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java) mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java)
//dropdown sex //dropdown sex
val sex = resources.getStringArray(R.array.sex) val sex = resources.getStringArray(R.array.sex)
val arrayAdapterSex = ArrayAdapter(requireContext(), R.layout.dropdown_item, sex) val arrayAdapterSex = ArrayAdapter(requireContext(), R.layout.dropdown_item, sex)
view.chooseSex_et.setAdapter(arrayAdapterSex) view.chooseSex_et.setAdapter(arrayAdapterSex)


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

@ -38,7 +38,6 @@ class PendulumFragment : Fragment() {
val mCanvasPendulum: CanvasPendulum = view.findViewById(R.id.canvasContainer)!! val mCanvasPendulum: CanvasPendulum = view.findViewById(R.id.canvasContainer)!!
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java) mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
//activate the magnet //activate the magnet
val magnetButton = view.findViewById<Button>(R.id.activate_btn) val magnetButton = view.findViewById<Button>(R.id.activate_btn)
@ -56,9 +55,6 @@ class PendulumFragment : Fragment() {
val timer = view.findViewById<TextView>(R.id.timer_view) val timer = view.findViewById<TextView>(R.id.timer_view)
val currentVelocity = view.findViewById<TextView>(R.id.actV_view) val currentVelocity = view.findViewById<TextView>(R.id.actV_view)
// Value endTime
//val endTIme: Long
targetVelocity.text = args.measurement.targetVelocity.toString() + "cm/s" targetVelocity.text = args.measurement.targetVelocity.toString() + "cm/s"
maxAttemptTime.text = args.measurement.maxAttemptTime.toString() + "sec" maxAttemptTime.text = args.measurement.maxAttemptTime.toString() + "sec"
@ -86,18 +82,15 @@ class PendulumFragment : Fragment() {
if (event?.action == MotionEvent.ACTION_DOWN){ if (event?.action == MotionEvent.ACTION_DOWN){
println("button action DOWN") println("button action DOWN")
mCanvasPendulum.startMagnet(true) mCanvasPendulum.startMagnet(true)
//mCanvasPendulum.magnet(true)
} }
if (event?.action == MotionEvent.ACTION_UP){ if (event?.action == MotionEvent.ACTION_UP){
println("button action UP") println("button action UP")
mCanvasPendulum.stopMagnet(false) mCanvasPendulum.stopMagnet(false)
//mCanvasPendulum.magnet(false)
} }
return true return true
} }
}) })
return view return view
} }
@ -121,6 +114,4 @@ class PendulumFragment : Fragment() {
val action = PendulumFragmentDirections.actionPendulumFragmentToUpdateFragment(args.currentUser) val action = PendulumFragmentDirections.actionPendulumFragmentToUpdateFragment(args.currentUser)
findNavController().navigate(action) findNavController().navigate(action)
} }
} }

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

@ -152,5 +152,4 @@ class UpdateFragment : Fragment() {
builder.setMessage("Are you sure you want to delete ${args.currentUser.firstName}?") builder.setMessage("Are you sure you want to delete ${args.currentUser.firstName}?")
builder.create().show() builder.create().show()
} }
}
}

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

@ -24,3 +24,4 @@ data class Measurement(
val usedHand: String, val usedHand: String,
val owner: String, val owner: String,
): Parcelable ): Parcelable

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

@ -15,4 +15,5 @@ data class User(
val birthday: String, val birthday: String,
val sex: String, val sex: String,
val handiness: String, val handiness: String,
): Parcelable
): Parcelable

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

@ -23,6 +23,5 @@ class MeasurementRepository(private val measurementDao: MeasurementDao) {
suspend fun deleteMeasurement(measurement: Measurement){ suspend fun deleteMeasurement(measurement: Measurement){
measurementDao.deleteMeasurement(measurement) measurementDao.deleteMeasurement(measurement)
} }
}
}

+ 1
- 1
app/src/main/java/com/example/acapendulum20/repository/UserRepository.kt View File

@ -23,4 +23,4 @@ class UserRepository(private val userDao: UserDao) {
suspend fun deleteAllUser(){ suspend fun deleteAllUser(){
userDao.deleteAllUsers() userDao.deleteAllUsers()
} }
}
}

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

@ -41,4 +41,4 @@ class MeasurementViewmodel(application: Application): AndroidViewModel(applicati
repository.deleteMeasurement(measurement) repository.deleteMeasurement(measurement)
} }
} }
}
}

+ 1
- 2
app/src/main/java/com/example/acapendulum20/viewmodel/UserViewmodel.kt View File

@ -26,7 +26,6 @@ class UserViewmodel(application: Application): AndroidViewModel(application) {
repository.addUser(user) repository.addUser(user)
} }
} }
fun updateUser(user: User){ fun updateUser(user: User){
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
repository.updateUser(user) repository.updateUser(user)
@ -44,4 +43,4 @@ class UserViewmodel(application: Application): AndroidViewModel(application) {
repository.deleteAllUser() repository.deleteAllUser()
} }
} }
}
}

+ 3
- 2
app/src/main/res/layout/fragment_pendulum.xml View File

@ -65,12 +65,13 @@
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:text="Speichern"
android:text="Save"
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.498"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/activate_btn" app:layout_constraintTop_toBottomOf="@+id/activate_btn"
app:layout_constraintVertical_bias="0.187" />
app:layout_constraintVertical_bias="0.675" />
<Button <Button
android:id="@+id/activate_btn" android:id="@+id/activate_btn"


+ 0
- 12
app/src/main/res/navigation/my_nav.xml View File

@ -55,9 +55,6 @@
<argument <argument
android:name="currentUser" android:name="currentUser"
app:argType="com.example.acapendulum20.model.User" /> app:argType="com.example.acapendulum20.model.User" />
<action
android:id="@+id/action_startPendulumFragment_to_pendulumSettingsFragment"
app:destination="@id/pendulumSettingsFragment" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/pendulumFragment" android:id="@+id/pendulumFragment"
@ -74,13 +71,4 @@
android:name="currentUser" android:name="currentUser"
app:argType="com.example.acapendulum20.model.User" /> app:argType="com.example.acapendulum20.model.User" />
</fragment> </fragment>
<fragment
android:id="@+id/pendulumSettingsFragment"
android:name="com.example.acapendulum20.PendulumSettingsFragment"
android:label="fragment_pendulum_settings"
tools:layout="@layout/fragment_pendulum_settings" >
<action
android:id="@+id/action_pendulumSettingsFragment_to_startPendulumFragment"
app:destination="@id/startPendulumFragment" />
</fragment>
</navigation> </navigation>

Loading…
Cancel
Save