SoNDa Kit
- Details Andrei Bucur Hits: 8593
1. Introduction
SoNDa Kit is an application designed and implemented at Suceava Hard & Soft contest to provide an overview of the interaction between an Android phone and it's accelerometer, focusing on displaying the powerful platform API. The use case is simple and was proposed by the jury: an application for elders owning a smartphone that warns their family if they fall and get injured.
The time frame was short, 1 day, but we managed to include many features like: text-to-speech (TTS), SMS sending, access of the phone-book, background services.
2. User's Manual
The application is very compact and contains the entire user interface in a single activity. The user can configure the following attributes:
- - the phone number where the SMS should be sent; the user can list the phone-book and select a number from there;
- - the message to be sent to the number inserted in the previous step;
- - the alert phrase to be used by the TTS engine if freefall is detected;
- - whether the freefall detection (the "service") is enabled or disabled;
The user can see if the service is running by checking if the fall icon is displayed in the status bar. If freefall is detected while the service is enabled, the application starts repeatedly spelling the alert phrase and the user has 10 seconds to cancel the SMS warning. Unfortunately we didn't have time to implement the "112" feature.
The settings are saved when the user quits the configuration activity.
3. Dev's Manual
The application has two components: the background service that monitors the accelerometer sensor (SondaService) and the service configuration activity (SondaKit). Due to the simplicity of the application, the communication between the two is made using static variables, not IBinder objects.
3.1 The Service
The service has a single static variable (isStarted) which is used by the activity to see if freefall detection is enabled or not. The interface with the accelerometer is made in a separate Looper thread that is signaled every time there is a variation in the sensor's output. The value reported by the accelerometer is then compared with a threshold value and if it's smaller, the alert mode is enabled and the activity is started in a new task or brought to front using Intent.FLAG_ACTIVITY_NEW_TASK. In alert mode the service also starts the TTS engine and periodically spells the alert message using a message handler. When the current phrase ends a new one is scheduled to run on the message handler. If the user cancels the alert mode, the phrase stops being rescheduled to the TTS engine.
3.2 The Activity
The activity shares the isAlerting flag that indicates whether freefall has been detected or not. The root view is a RelativeLayout where all the controls are placed independent of the screen size or coordinates. The activity can be started by the user or by the service. If the activity was already running it's brought to front and onNewIntent() is called. In both cases, if isAlerting is true a custom AlertDialog is displayed that asks the user if there is a false alarm. The dialog is contains a ProgressBar controlled by a thread that updates it's value every 100ms. If the user doesn't cancel the dialog an SMS is sent to the saved number after 10s.
The settings are saved in both static variables and in SharedPreferences so they can be restored after the activity is destroyed and application closed.
4. Conclusions
The Android platform provides an easy to use and powerful API over Java. This allowed us to implement the application in very short time-frame.