}
}
-function stopListener(listenerId, method, data) {
+function stopListener(listenerId, method, data, doRemoval) {
if (!native_.isListenerSet(listenerId)) {
checkPrivilegesForMethod(method, data.type);
return;
}
- var result = native_.callSync(method, data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ if (doRemoval) {
+ var result = native_.callSync(method, data);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
- native_.removeListener(listenerId);
+ native_.removeListener(listenerId);
+ }
}
// Pedometer listener and accumulative pedometer listener are handled by a single
{name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityType)}
]);
- stopListener('HumanActivityMonitor_' + args.type,
- 'HumanActivityMonitorManager_stop',
- { type: args.type });
-
if (HumanActivityType.PEDOMETER === args.type) {
+ stopListener('HumanActivityMonitor_PEDOMETER',
+ 'HumanActivityMonitorManager_stop',
+ { type: HumanActivityType.PEDOMETER },
+ pedometerListener && !accumulativePedometerListener);
pedometerListener = null;
+ } else {
+ stopListener('HumanActivityMonitor_' + args.type,
+ 'HumanActivityMonitorManager_stop',
+ { type: args.type }, true);
}
if (HumanActivityType.GPS === args.type) {
};
HumanActivityMonitorManager.prototype.unsetAccumulativePedometerListener = function() {
- var oldPedometerListener = pedometerListener;
-
- // calling stop() will overwrite pedometerListener, needs to be restored afterwards
- this.stop(HumanActivityType.PEDOMETER);
-
+ stopListener('HumanActivityMonitor_PEDOMETER',
+ 'HumanActivityMonitorManager_stop',
+ { type: HumanActivityType.PEDOMETER },
+ accumulativePedometerListener && !pedometerListener);
accumulativePedometerListener = null;
- pedometerListener = oldPedometerListener;
};