This may be a simple question, but I'm stuck. I am trying to implement the "shake to erase" function in a drawing program (a simple drawing application). I can not make it work. Here is my code:
private final SensorEventListener mSensorListener = new SensorEventListener() { public void onSensorChanged(SensorEvent se) { float x = se.values[0]; float y = se.values[1]; float z = se.values[2]; mAccelLast = mAccelCurrent; mAccelCurrent = (float) Math.sqrt((double) (x*x + y*y + z*z)); float delta = mAccelCurrent - mAccelLast; mAccel = mAccel * 0.9f + delta;
SensorEventListener is based on this example . I do this in an if statement, but the canvas will not be reset until I touch the screen (new touch event).
I want the canvas to be reset / erase during the shake event, without any additional requests from the user.
Any help would be great, thanks!
source share