@@ -12,6 +12,7 @@ import android.graphics.Color
1212import android.location.Location
1313import android.location.LocationListener
1414import android.location.LocationManager
15+ import android.media.MediaPlayer
1516import android.net.Uri
1617import android.os.Build
1718import android.os.CountDownTimer
@@ -31,7 +32,6 @@ import com.google.gson.reflect.TypeToken
3132import java.util.*
3233private const val SAVE_KEY = " save_key"
3334private const val emergencyServiceNum = " +14846391351" // test number (OBV we can't test call 911 whenever we want
34-
3535class 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 }
0 commit comments