GithubHelp home page GithubHelp logo

novocation's Introduction

Novocation

Novocation is a project to hide Android location logic away in a jar. Most of the code originates from Reto Meier’s Android Protips: A Deep Dive Into Location. It’s also heaviliy inspired by Stefano Dacchille’s Ignition Location.

How to use the library

Using maven

If you are using maven you need to define the repo and then the dependency

<repositories>
  <repository>
    <id>public-mvn-repo-releases</id>
    <url>https://github.com/novoda/public-mvn-repo/raw/master/releases</url>
  </repository>
</repositories>
<dependency>
  <groupId>com.novoda.location</groupId>
  <artifactId>novocation-core</artifactId>
  <version>1.0.3</version>
</dependency>

Direct jar usage

If you don’t care about building tool you can just download the jar manually from this link

download jar

Implementation

Application

In the application you can keep a reference to the locator in this way :


  @Override
  public void onCreate() {
    super.onCreate();
    LocatorSettings settings = new LocatorSettings(PACKAGE_NAME, LOCATION_UPDATE_ACTION);
    settings.setUpdatesInterval(3 * 60 * 1000);
    settings.setUpdatesDistance(50);
    locator = LocatorFactory.getInstance();
    locator.prepare(getApplicationContext(), settings);
  }

In the Activity using the location

You need to to start the locator in the onResume and stop it in the onPause method. Something similar to:


@Override
public void onResume() {
  super.onResume();
  IntentFilter f = new IntentFilter();
  f.addAction(LocationDemo.LOCATION_UPDATE_ACTION);
  registerReceiver(freshLocationReceiver, f);
  try {
    locator.startLocationUpdates();
  } catch(NoProviderAvailable np) {
    //TODO add implementation
  }
}

@Override
public void onPause() {
  unregisterReceiver(freshLocationReceiver);
  locator.stopLocationUpdates();
  super.onPause();
}

public BroadcastReceiver freshLocationReceiver = new BroadcastReceiver() {
   @Override
   public void onReceive(Context context, Intent intent) {
      locator.getLocation();
   }
};

Manifest


<receiver android:name="com.novoda.location.receiver.LocationChanged">
  <intent-filter>
    <action android:name="com.novoda.location.ACTIVE_LOCATION_UPDATE_ACTION"/>
  </intent-filter>
</receiver>

<receiver android:name="com.novoda.location.receiver.PassiveLocationChanged"/>

<receiver android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLostConnectivity" enabled="false">
  <intent-filter>
    <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
  </intent-filter>
</receiver>

<receiver android:name="com.novoda.location.receiver.UnregesterPassiveListenerOnLowBattery">
  <intent-filter>
    <action android:name="android.intent.action.BATTERY_LOW"/>
    <action android:name="android.intent.action.BATTERY_OKAY"/>
  </intent-filter>
</receiver>

<receiver android:name="com.novoda.location.receiver.RestorePassiveListenerBoot">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED"/>
  </intent-filter>
</receiver>

License

Novocation is licensed under the Apache License 2.0.

Demo app

If you want to see the capabilities of the library you can try out the Novocation demo. This will also help us in improving the library as we track with analytics the quality of the position and the time to get it.

Issues

Please report bugs, tell us about your problems or request features by creating issues on GitHub.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.