Goal: The objective here was to implement the Shake feature based on Accelerometer.
The basic principle of shake feature is that if a user wants to delete something that he previously entered then he can do it by shaking the phone. He does not have to explicitly use a 'back' button or a 'clear' key. For implementing this feature i had a simple UI consisting of a Textbox. The user enters something into the Textbox and then he connects to the Sensor Simulator jar application. When the user shakes the graphical image of the phone in the sensor simulator, the data in the Textbox is cleared. When the phone is shaken the accelerometer values generated are tested against a threshold value. If these values are greater than the threshold then it is detected as a 'shake' motion. The values generated are written to a log file to help in debugging the code.
1) Test.java - It is the class which is initially executed and which connects to Sensor Simulator. The functionality for detecting the shake motion and capturing the [x,y,z] values during shaking of the phone is coded in this file. These values are also written to the log fileFig 1. Figure below shows the initial UI screen with Textbox and connection Button. |
Fig 2. Figure below shows the shaking of Sensor Simulator phone |
Fig 3. Figure below shows the empty text box due to shaking motion |
Fig 4. Figure below shows the values written to the log file. |