Git Product home page Git Product logo

groundy's Introduction

Groundy library for Android

@Deprecated

Unfortunatenly this library is no longer maintained, we encourage you to use other widely supported solutions like RxJava.

Groundy

Groundy is a fun, sexy way to do background work on your Android app; it's specially useful for running tasks that must be executed even if your activities/fragments are destroyed. It allows you to receive notifications from the background task directly to your activity or any object.

It is useful for several scenarios like executing calls to external services (e.g. RESTful web services), download and/or process files, encoding audio/video and any kind of task that could block the main thread.

Basic usage

Create a subclass of GroundyTask:

public class ExampleTask extends GroundyTask {
  @Override
  protected TaskResult doInBackground() {
    // you can send parameters to the task using a Bundle (optional)
    String exampleParam = getStringArg("arg_name");

    // lots of code

    // return a TaskResult depending on the success of your task
    // and optionally pass some results back
    return succeeded().add("the_result", "some result");
  }
}

Whenever you want to execute the task, just do this:

// this is usually performed from within an Activity
Groundy.create(ExampleTask.class)
    .callback(callbackObj)        // required if you want to get notified of your task lifecycle
    .arg("arg_name", "foo")       // optional
    .queueUsing(YourActivity.this);

You will get results in your callback object(s) (in the main thread):

@OnSuccess(ExampleTask.class)
public void onSuccess(@Param("the_result") String result) {
  // do something with the result
}

Do not forget to add GroundyService to the AndroidManifest.xml file:

<service android:name="com.telly.groundy.GroundyService"/>

Extending callback system

There are some already defined onCallback annotations: @OnSuccess, @OnFailed, @OnCancel, @OnProgress and @OnStart, but you can also create your own callback types like:

@OnCallback(task = ChuckTask.class, name = "kick")
public void onChuckNorrisAttack(@Param("target") String target) {
  Toast.makeText(this, "Chuck Norris kicked your " + target, Toast.LENGTH_SHORT).show();
}

Take a look at the custom callbacks example for details on this.

Integration

In order to use this library from you Android project using Maven your pom should look like this:

<dependency>
  <groupId>com.telly</groupId>
  <artifactId>groundy</artifactId>
  <version>(insert latest version)</version>
</dependency>

<!-- enables groundy JSR-269 processor which makes everything up to 5 times faster -->
<dependency>
  <groupId>com.telly</groupId>
  <artifactId>groundy-compiler</artifactId>
  <version>(insert latest version)</version>
</dependency>

For Gradle projects use:

compile 'com.telly:groundy:(insert latest version)'
provided 'com.telly:groundy-compiler:(insert latest version)'

Note: provided dependencies are supported by android gradle plugin v0.8 or later.

At this point latest version is 1.5.

Proguard

If you are using proguard, please add these rules

-keepattributes *Annotation*

-keepclassmembers,allowobfuscation class * {
    @com.telly.groundy.annotations.* *;
    <init>();
}

-keepnames class com.telly.groundy.generated.*
-keep class com.telly.groundy.generated.*
-keep class com.telly.groundy.ResultProxy
-keepnames class * extends com.telly.groundy.ResultProxy
-keep class * extends com.telly.groundy.GroundyTask

groundy's People

Contributors

constantinexvi avatar eveliotc avatar hamsterksu avatar margge avatar mkraemer avatar

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.