ChipCloud


Source link: https://github.com/adroitandroid/ChipCloud

ChipCloud

The ChipCloud library was originally a (very) quickly knocked up Android view for some larger hackathon project by fiskurgit. It creates a wrapping cloud of material ' Chips'. Basic demo of their version is available on the Play Store - I'm maintaining this fork for features I required in it.

Usage

Add to your Android layout xml:

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

Configure in xml:

<com.adroitandroid.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"
  chipcloud:allCaps="true"
  chipcloud:gravity="staggered"
  chipcloud:minHorizontalSpacing="32dp"
  chipcloud:verticalSpacing="16dp"
  chipcloud:textSize="14sp"

chipcloud:typeface="RobotoSlab-Regular.ttf"/> <!--path relative to assets folder-->

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)

.allCaps(false)

.gravity(ChipCloud.Gravity.CENTER)

.textSize(getResources().getDimensionPixelSize(R.dimen.default_textsize))

.verticalSpacing(getResources().getDimensionPixelSize(R.dimen.vertical_spacing))

.minHorizontalSpacing(getResources().getDimensionPixelSize(R.dimen.min_horizontal_spacing))

.typeface(Typeface.createFromAsset(getContext().getAssets(), "RobotoSlab-Regular.ttf"))

.chipListener(new ChipListener() {

 @Override

 public void chipSelected(int index) {

  //...

 
}

 @Override

 public void chipDeselected(int index) {

  //...

 
}

}
)

.build();

Default value of textSize is equivalent to 13sp, of verticalSpacing is equivalent to 8dp, of minHorizontalSpacing is equivalent to 8dp, of allCaps is false.

All chips have a height of 32dp and a padding of 12dp on left and right within the chip, as per material guidelines.

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:

Labels can also be updated in-place, e.g.

from to using update() as illustrated below

new ChipCloud.Configure().chipCloud(binding.chipCloud).labels(newChipLabels).update();

Modes

public enum Mode {

SINGLE, MULTI, REQUIRED, NONE 
}

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); . If you want to deactiviate selecting of chips you can set the select mode to chipCloud.setMode(ChipCloud.Mode.NONE); .

Gravity

public enum Gravity {

LEFT, RIGHT, CENTER, STAGGERED 
}

The default gravity is LEFT. CENTER and STAGGERED are similar except that CENTER leaves only minimum horizontal spacing between the chips whereas in STAGGERED chips occupy the available space equally while having at least minimum horizontal spacing between them.

LEFT RIGHT CENTER STAGGERED

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.adroitandroid:ChipCloud:2.2.1' 
}

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

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.

Resources

Reactive SharedPreferences for Android.

FilterSelectorListView is useful for making multiple selection with see selection on the top of ListView.

Beautify your RecyclerViews with a great parallax effect !

Abstract, easy, quick, flexible and extendable Rapid Android development.

An Android module that makes WebRTC signaling easy!

A Java-language API for doing compile time or runtime code generation targeting the Dalvik VM. Unlike cglib or ASM, this library creates Dalvik .dex files instead of Java .class files.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes