Skip to content

Commit 3fa988b

Browse files
committed
added alert sound when a crash is detected
1 parent 08b848a commit 3fa988b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

androidApp/app/src/main/java/edu/temple/vehiclecollisiondetection/MyBluetoothGattCallback.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import android.graphics.Color
1212
import android.location.Location
1313
import android.location.LocationListener
1414
import android.location.LocationManager
15+
import android.media.MediaPlayer
1516
import android.net.Uri
1617
import android.os.Build
1718
import android.os.CountDownTimer
@@ -31,7 +32,6 @@ import com.google.gson.reflect.TypeToken
3132
import java.util.*
3233
private const val SAVE_KEY = "save_key"
3334
private const val emergencyServiceNum = "+14846391351" //test number (OBV we can't test call 911 whenever we want
34-
3535
class MyBluetoothGattCallback(currentContext: Context, currentActivity: Activity, connectionText: TextView) : BluetoothGattCallback(), LocationListener {
3636
val activeContext = currentContext
3737
val activeActivity = currentActivity
@@ -128,6 +128,8 @@ class MyBluetoothGattCallback(currentContext: Context, currentActivity: Activity
128128
Log.d("Characteristic Data", "Data Changed!")
129129
val data = String(value)
130130
if(data == "B" || data =="F") {
131+
val alertSoundPlayer: MediaPlayer? = MediaPlayer.create(activeContext, R.raw.alert_sound)
132+
alertSoundPlayer?.start()
131133
mTimeLeftInMillis = countdownStartTime
132134
activeActivity.runOnUiThread(){
133135
//if a crash is detected by the arduino device, initiate crash popup
@@ -147,6 +149,7 @@ class MyBluetoothGattCallback(currentContext: Context, currentActivity: Activity
147149
}
148150
override fun onFinish() { //countdown goes to 0
149151
mCountDownTimer?.cancel()
152+
alertSoundPlayer?.stop()
150153
crashAlertDialog.dismiss()
151154
//get list of saved emergency contacts and text them w/ emergency message
152155
preferences = activeActivity.getPreferences(AppCompatActivity.MODE_PRIVATE)
@@ -162,6 +165,7 @@ class MyBluetoothGattCallback(currentContext: Context, currentActivity: Activity
162165
val cancelButton = crashDialogView.findViewById<Button>(R.id.crash_cancel_button)
163166
cancelButton.setOnClickListener {
164167
mCountDownTimer?.cancel()
168+
alertSoundPlayer?.stop()
165169
crashAlertDialog.dismiss()
166170
}
167171
}
314 KB
Binary file not shown.

0 commit comments

Comments
 (0)