After searching for a while I did not find any way to isolate translation acceleration direction from rotation.
Im looking yo find a way to get acceleration direction independently of how mobile phone is rotated (and of course independently of how it will be rotated).
Basically this would allow me to make the difference among acceleration, deceleration and change of direction.
I tried to compensate acceleration sensor angles with the ones obtained from getOrientation but I experimented that getOrientation angles (Azimut, pitch, and roll) are not the same when device has translation movement (acceleration).
I would need one of both: acceleration direction no matter how device is rotating or orientation values no matter how device is being accelerated.
Is that even possible?
Finally we found it!
After Android documentation we can get rotation Matrix (getRotationMatrix) to change coordinates system of mobile: the rotation matrix R transforms a vector from the device coordinate system to the world's coordinate system.
But in parameters documentation says (and here is the quiz):
Well then if you use as documentation says the accelerometer values as paremeter on rotation matrix, of course acceleration will be afected while mobile translation and matrix will be all useless.
Instead of using accelerometer sensor values you have to use gravity sensor values (sensor of type TYPE_GRAVITY
As this sensor does not get affected with mobile translation rotation matrix can be used while mobile is being translated.
At the end the code that works for us would be:
Where
Then in trueAcceleration vector we have acceleration in mobile translation, no matter how mobile moves its orientation.