<commit_before>---
layout: post
title: Cluster for Android
---

Say hello to Cluster, a collection of helper classes and utility methods for Android. I find myself routinely writing code to do basic things from project to project. Cluster is meant to be an expansive library that minimizes how much utility code needs to be written for each project.

## Components

Cluster is currently composed of the following:

### Service Connection Manager
There are two major types of services in Android: the ones you start, and the ones you bind. In the latter case, you cannot communicate with the service until you have successfully connected to it. Service connections are asynchronous and require code to keep your activity/fragment in sync with this state. Favor contains a `ServiceConnectionManager` that you can use to connect to your service. You can also feed the manager commands that will be executed once the service is successfully connected.

For each service that you want to manage, create an extension of the service manager:

{% highlight java %}
class MyServiceConnectionManager extends ServiceConnectionManager<MyService, MyServiceBinder> {

  @Override
  protected Class<MyService> getServiceClass() {
    return MyService.class;
  }

}
{% endhighlight %}

Then use it in your Activity or Fragment as follows:

{% highlight java %}
class MainActivity extends Activity {

  private MyServiceConnectionManager manager;

  @Override<commit_msg>Added links to Cluster project page<commit_after>---
layout: post
title: Cluster for Android
---

Say hello to [Cluster](https://github.com/DevBytes/cluster), a collection of helper classes and utility methods for Android. I find myself routinely writing code to do basic things from project to project. Cluster is meant to be an expansive library that minimizes how much utility code needs to be written for each project.

## Project Page

https://github.com/DevBytes/cluster

## Components

Cluster is currently composed of the following:

### Service Connection Manager
There are two major types of services in Android: the ones you start, and the ones you bind. In the latter case, you cannot communicate with the service until you have successfully connected to it. Service connections are asynchronous and require code to keep your activity/fragment in sync with this state. Favor contains a `ServiceConnectionManager` that you can use to connect to your service. You can also feed the manager commands that will be executed once the service is successfully connected.

For each service that you want to manage, create an extension of the service manager:

{% highlight java %}
class MyServiceConnectionManager extends ServiceConnectionManager<MyService, MyServiceBinder> {

  @Override
  protected Class<MyService> getServiceClass() {
    return MyService.class;
  }

}
{% endhighlight %}

Then use it in your Activity or Fragment as follows:

{% highlight java %}
class MainActivity extends Activity {

  private MyServiceConnectionManager manager;

  @Override
{'fraction_non_alphanumeric': 0.048296394310287795, 'fraction_numerical': 0.0, 'mean_word_length': 4.749049429657795, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7306973', 'n_tokens_mistral': 705, 'n_tokens_neox': 662, 'n_words': 403}