You could have two singletons that keep track if the phone is vibrating or not and manage the Vibrator
and the Accelerometer
.
The Accelerometer
manager should expose the methods that you use for the Accelerometer
and should pass on all events if the Vibrator
isn't running (this is just like a filter for the accelerometer data). You should have an internal flag for if the phone is vibrating on the Accelerometer
manager and methods to set it.
The Vibrator
manager should expose the methods that you use for the Vibrator
and should also update the Accelerometer
manager's flag when the phone starts vibrating.
These are basically wrappers for the Vibrator
and Accelerometer
instances in your app, but they should allow you to use the Accelerometer
without having to worry about the Vibrator
flag everywhere in your app (only the manager objects should take care of that flag).
I know this solution does require an extra flag, but it allows you to manage that flag in just two places (in the two singletons) and you don't have to keep track of it in your entire app. If you do implement the two singletons, make sure that you don't use the Vibrator
or Accelerometer
directly (as you would have to keep track of the vibration flag to do that).