Skip to content

rafael-munoz/merlin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Merlin

####"An ok name for a library"

Merlin aims to simplify network monitoring by providing 3 registerable callbacks. onConnect() , onDisconnect() and onBind(NetworkStatus networkStatus).

Download the jar from here

or if you're using Maven

The repository is needed until the project is released on Maven Central, sorry about that

<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.merlin</groupId>
  <artifactId>merlin-core</artifactId>
  <version>0.4</version>
</dependency>

##Usecases##

####onConnect()####

When the network state changes from disconnected to connected and a successful host ping has completed.

Because you have just aquired a valid network connection, time to update stale data!

####onDisconnect()####

When the network state changes from connected to disconnected.

Because you probably want to tell the user they're now offline! or disable certain functionality until a reliable connection is available again.

####onBind(NetworkStatus networkStatus)####

When the MerlinService has binded, the current NetworkStatus is provided, although this is without pinging a host.

Because you may need to know the current state of the network before a network change occurs.

##Setup

You'll need to add a few things to your manifest :

These permissions (if you don't already have them)

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

this service

<service android:exported="false" android:name="com.novoda.merlin.service.MerlinService" />

and this receiver

<receiver android:name="com.novoda.merlin.receiver.ConnectivityReceiver">
  <intent-filter>
    <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
  </intent-filter>
</receiver>

##Simple usage

Create Merlin (using Merlin.Builder())

merlin = new Merlin.Builder().withConnectableCallbacks().build(context);

Bind and unbind the service in your activity

@Override
protected void onResume() {
    super.onResume();
    merlin.bind();
}

@Override
protected void onPause() {
    super.onPause();
    merlin.unbind();
}

Register for callbacks

merlin.registerConnectable(new Connectable() {
        @Override
        public void onConnect() {
            // Do something!
        }
});

The MerlinActivity within the demo shows a simple way to declutter Merlin from your main application code.

##Changelog

###0.4###

  • workaround for issue #4 which causes the Android Runtime to restart after uninstalling
  • code tidying

###0.3-SNAPSHOT###

###0.2###

  • Removed bindListener.
  • Added bindable to match connectable and disconnectable.
  • Tidied code up.

###0.2-SNAPSHOT###

  • Initial release.

##Contributing!

If you would like to help out (and everyone should!!) please code against the develop branch

and be sure write tests where possible!

About

An ok name for a library

Resources

Stars

Watchers

Forks

Packages

No packages published