/ChipCloud

Android UI library that creates 'chip' clouds

Primary LanguageJavaMIT LicenseMIT

ChipCloud

Release Build Status license Codacy Badge Gitter

ChipCloud is an Android view (very) quickly knocked up for a larger hackathon project, it creates a wrapping cloud of 'Chips'. Basic demo available on the Play Store

Trainer Sizes

Usage

Add to your Android layout xml:

<eu.fiskur.chipcloud.ChipCloud
    android:id="@+id/chip_cloud"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

Configure in xml:

<eu.fiskur.chipcloud.ChipCloud
    xmlns:chipcloud="http://schemas.android.com/apk/res-auto"
    android:id="@+id/chip_cloud"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    chipcloud:deselectedColor="@color/deselected_color"
    chipcloud:deselectedFontColor="@color/deselected_font_color"
    chipcloud:selectedColor="@color/selected_color"
    chipcloud:selectedFontColor="@color/selected_font_color"
    chipcloud:deselectTransitionMS="500"
    chipcloud:selectTransitionMS="750"
    chipcloud:labels="@array/labels"
    chipcloud:selectMode="required"/>

or in code:

ChipCloud chipCloud = (ChipCloud) findViewById(R.id.chip_cloud);

new ChipCloud.Configure()
        .chipCloud(chipCloud)
        .selectedColor(Color.parseColor("#ff00cc"))
        .selectedFontColor(Color.parseColor("#ffffff"))
        .deselectedColor(Color.parseColor("#e1e1e1"))
        .deselectedFontColor(Color.parseColor("#333333"))
        .selectTransitionMS(500)
        .deselectTransitionMS(250)
        .labels(someStringArray)
        .mode(ChipCloud.Mode.MULTI)
        .chipListener(new ChipListener() {
            @Override
            public void chipSelected(int index) {
                //...
            }
            @Override
            public void chipDeselected(int index) {
                //...
            }
        })
        .build();

Add items dynamically too:

chipCloud.addChip("Foo");
chipCloud.addChip("Bar");

//or

chipCloud.addChips(someStringArray);

Set the selected index using chipCloud.setSelectedChip(2)

Real-world example for shoe sizes:
Shoe Sizes

Modes

public enum Mode {
  SINGLE, MULTI, REQUIRED
}

The default mode is single choice (where it's valid to have no chip selected), if you want a RadioGroup manadatory style where once a chip is selected there must always be a selected item use chipCloud.setMode(ChipCloud.Mode.REQUIRED); (or set in xml or the builder). There's a multiple select mode too: chipCloud.setMode(ChipCloud.Mode.MULTIPLE);

Dependency

Add jitpack.io to your root build.gradle, eg:

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

then add the dependency to your project build.gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.github.fiskurgit:ChipCloud:2.1.0'
}

You can find the latest version in the releases tab above: https://github.com/fiskurgit/ChipCloud/releases

More options at jitpack.io: https://jitpack.io/#fiskurgit/ChipCloud

##Licence

Full licence here: https://github.com/fiskurgit/ChipCloud/blob/master/LICENSE

In short:

The MIT License is a permissive license that is short and to the point. It lets people do anything they want with your code as long as they provide attribution back to you and don’t hold you liable.