achubutkin / cordova-plugin-stepper Goto Github PK
View Code? Open in Web Editor NEWLightweight pedometer Cordova/Phonegap plugin for Android using the hardware step sensor, with notifications
License: Other
Lightweight pedometer Cordova/Phonegap plugin for Android using the hardware step sensor, with notifications
License: Other
window.stepper.startStepperUpdates(
offset,
this.stepsSuccess,
this.stepsError,
this.pedometerOptions
);
pedometerOptions: {
pedometerIsCountingText: ' counts your steps',
pedometerStepsToGoFormatText: '~%s steps to finish',
pedometerYourProgressFormatText: '~%s progress',
pedometerGoalReachedFormatText: '%s congrats finish!',
},
then to pause, like, enable / disable.
window.stepper.stopStepperUpdates(
() => {
// ignore
},
this.stepsError,
);
then we start again with startStepperUpdates to cintinue steps count but steps_today in response for stepsSuccess method for today with goal reset to 0?!
Offset supposed to be added to the total steps counted in this session. But it does not
eg
pperUpdates(
555,
this.stepsSuccess,
this.stepsError,
this.pedometerOptions
);
is always starts from 0
Stepper.prototype.startStepperUpdates = function (offset, onSuccess, onError, options) {
offset = parseInt(offset) || 0;
options = options || {};
exec(onSuccess, onError, "Stepper", "startStepperUpdates", [offset, options]);
};
{"steps":-21760}
var interval = 1000 * 60 * 60 * 24,
start = Math.floor(Date.now() / interval) * interval - (interval * 3),
end = Math.floor(Date.now() / interval) * interval;
window.stepper.getStepsByPeriod(start, end, steps3=>{
console.log(JSON.stringify(steps3));
},() =>{});
window.stepper.startStepperUpdates(
offset,
this.updateStepsSuccess,
this.pedometerError,
{}
);
updateStepsSuccess (result) {
alert(JSON.stringify(result));
},
alert is called only if you hide app and reopen.
I was realy mad because there not much docs about how to init cordova plugins.
We use nuxt (vue) + vuetify.
Cordova treated as plugin
try {
this.initStepsCounter()
}
catch (err) {
console.log(`error`, err);
alert(JSON.stringify(err));
}
},
initStepsCounter () {
Vue.stepper = window.stepper;
const {Stepper} = window;
console.log(`Stepper`, Stepper);
console.log(`window.Stepper`, window.Stepper);
console.log(`window.stepper`, window.stepper);
console.log(`window`, window);
console.log(`navigator.stepper`, navigator.stepper);
console.log(`navigator`, navigator);
console.log(`Vue.cordova`, Vue.cordova);
console.log(`this`, this);
console.log(`this.cordova`, this.cordova);
console.log(`window.cordova`, window.cordova);
console.log(`navigator.cordova`, navigator.cordova);
console.log(`navigator.camera`, navigator.camera);
var offset = 0, options = {
pedometerIsCountingText: 'Pedometer is counting',
pedometerStepsToGoFormatText: '%s steps to go'
};
window.stepper.startStepperUpdates(
offset,
result => {
var stepsToday = result.steps_today;
console.log(`stepsToday`, stepsToday);
},
err => {
console.error(err);
},
options
);
},
window.stepper 222 undefined
cordova.js:1021 adding proxy for Camera
Stepper undefined
window.Stepper undefined
window.stepper Stepper
window Window
navigator.stepper undefined
navigator Navigator
Vue ƒ Tn(t){this._init(t)}
Vue.cordova undefined
this ObjectinitCustomUrlScheme: ƒ ()initStatusBar: ƒ ()initStepsCounter: ƒ ()initWKWebView: ƒ ()initialize: ƒ ()onDeviceReady: ƒ ()__proto__: Object
this.cordova undefined
window.cordova Object
navigator.cordova undefined
navigator.camera Object
cordova.js:1001 Error: exec proxy not found for :: Stepper :: startStepperUpdates
How do we use your plugin?
How to access it???
Semple configs here this project were used as skeleton
Stepper.prototype.getSteps = function (date, onSuccess, onError) {
exec(onSuccess, onError, "Stepper", "getSteps", [date]);
};
window.stepper.getSteps(start, end, ()=>{}, steps3=>{
console.log(JSON.stringify(steps3));
});
Currently, there is no way to disable the goal and the associated count down in notification.
I would love to be able to disable it and simply have a count up in this text placeholder.
i.e. to replace "653 steps to go" by "347 steps today"
It seems that ACTIVITY_RECOGNITION requirement is not handled by the plugin.
It have to be explicitly requested on Android 10+
Without this permission, I had no visible error but steps where not raised.
In order to makes it work, I had to:
1°) Add permission to manifest
<platform name="android">
...
<config-file after="uses-permission" parent="/manifest" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
</config-file>
...
</platform>
2°) Request permission before initializing steps using cordova-plugin-android-permissions plugin
const permissions = window.cordova.plugins.permissions;
permissions.requestPermission(permissions.ACTIVITY_RECOGNITION, result => {
if (result.hasPermission) {
window.stepper.startStepperUpdates(...);
}
});
Afterward it works well on any device
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.