npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-stepcounter

v1.0.2

Published

A Cordova plugin for step counting on Android.

Downloads

19

Readme

Cordova StepCounter Plugin

📝 التوثيق بالعربية 📝 English Documentation

License npm version VIEWS

Overview

The Cordova StepCounter Plugin allows you to track steps using the device's step counter sensor. It's designed for Android and can be easily integrated into your Cordova applications.

Features

  • Start and stop step counting.
  • Retrieve the current step count.
  • Handle permissions automatically.

Installation

Adding the Plugin

To install the StepCounter plugin into your Cordova project, use the following command:

cordova plugin add cordova-stepcounter

Alternatively, you can install it directly from the plugin's repository:

cordova plugin add https://github.com/rn0x/cordova-plugin-stepcounter.git

Removing the Plugin

If you need to remove the plugin from your project, use the following command:

cordova plugin rm cordova-plugin-stepcounter

Directory Structure

cordova-plugin-stepcounter/
├── src/
│   └── android/
│       └── StepCounter.java
├── www/
│   └── StepCounter.js
├── plugin.xml
└── package.json

Usage

JavaScript API

The plugin provides three main methods: start, stop, and getStepCount.

Start Step Counting

Start the step counter sensor and begin counting steps.

cordova.plugins.stepCounter.start(
    function(successMessage) {
        console.log(successMessage);
    },
    function(errorMessage) {
        console.error(errorMessage);
    }
);

Stop Step Counting

Stop the step counter sensor.

cordova.plugins.stepCounter.stop(
    function(successMessage) {
        console.log(successMessage);
    },
    function(errorMessage) {
        console.error(errorMessage);
    }
);

Get Current Step Count

Retrieve the current step count.

cordova.plugins.stepCounter.getStepCount(
    function(stepCount) {
        console.log("Current step count: " + stepCount);
    },
    function(errorMessage) {
        console.error(errorMessage);
    }
);

React Integration

To use the StepCounter plugin in a React application, you need to ensure that Cordova is properly integrated. Here's an example of how you might use the plugin within a React component.

Example React Component

import React, { useEffect, useState } from 'react';

function StepCounterComponent() {
    const [stepCount, setStepCount] = useState(0);
    const [isCounting, setIsCounting] = useState(false);

    useEffect(() => {
        document.addEventListener("deviceready", onDeviceReady, false);
        return () => {
            document.removeEventListener("deviceready", onDeviceReady, false);
        };
    }, []);

    const onDeviceReady = () => {
        console.log("Device is ready");
    };

    const startCounting = () => {
        cordova.plugins.stepCounter.start(
            (successMessage) => {
                console.log(successMessage);
                setIsCounting(true);
            },
            (errorMessage) => {
                console.error(errorMessage);
            }
        );
    };

    const stopCounting = () => {
        cordova.plugins.stepCounter.stop(
            (successMessage) => {
                console.log(successMessage);
                setIsCounting(false);
            },
            (errorMessage) => {
                console.error(errorMessage);
            }
        );
    };

    const fetchStepCount = () => {
        cordova.plugins.stepCounter.getStepCount(
            (count) => {
                setStepCount(count);
            },
            (errorMessage) => {
                console.error(errorMessage);
            }
        );
    };

    return (
        <div>
            <h1>Step Counter</h1>
            <p>Steps: {stepCount}</p>
            <button onClick={startCounting} disabled={isCounting}>
                Start Counting
            </button>
            <button onClick={stopCounting} disabled={!isCounting}>
                Stop Counting
            </button>
            <button onClick={fetchStepCount}>Get Step Count</button>
        </div>
    );
}

export default StepCounterComponent;

Contributing

How to Contribute

We welcome contributions to the Cordova StepCounter Plugin. You can contribute by:

  • Reporting bugs and suggesting features through GitHub Issues.
  • Submitting pull requests with bug fixes or new features.

Development Setup

  1. Clone the repository:

    git clone https://github.com/your-repo/cordova-plugin-stepcounter.git
    cd cordova-plugin-stepcounter
  2. Make your changes and test them locally with your Cordova project.

  3. Submit a pull request with a clear description of your changes.

Licensing

This plugin is licensed under the GPL 3.0 License. See the LICENSE file for more information.

Contact

For any questions or feedback, feel free to open an issue on the GitHub repository.