ChipCloud


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

ChipCloud

An easy to use implementation of Google's Material Design 'Chip' ui element. Version 3 was a fresh rewrite of the original quickly hacked together library, version 3.0.4 introduces support for images/avatars and the close icon and matches the Google spec. The previous iteration was becoming popular as an easy replacement for a dropdown/spinner with improved UX and more efficient use of screen real estate. Versions 3+ have an improved API with a fraction of the code. The biggest change is it's now not a custom Layout, it's a simple helper class that adds Chips to a supplied ViewGroup, complex layout is delegated to dedicated layout libraries such as FlexboxLayout.

Usage

Although ChipCloud can be used with any ViewGroup to get the wrapping 'Chip Cloud' that was the original focus of the library you should use Google's FlexboxLayout - see the demo project for a full example.

//To create the same wrapping cloud as previous incarnation use Google's FlexboxLayout: FlexboxLayout flexbox = (FlexboxLayout) findViewById(R.id.flexbox);
  //Create a new ChipCloud with a Context and ViewGroup: ChipCloud chipCloud = new ChipCloud(this, flexbox);
  //Add a single Chip: chipCloud.addChip("HelloWorld!");
  //or pass a List or Array of any Object: String[] demoArray = getResources().getStringArray(R.array.demo_array);
 chipCloud.addChips(demoArray);

Customisation

Use the ChipCloudConfig builder to customise colors, fonts, turn padding on, and set select mode:

FlexboxLayout flexbox = (FlexboxLayout) findViewById(R.id.flexbox);
  ChipCloudConfig config = new ChipCloudConfig()
  .selectMode(ChipCloud.SelectMode.multi)
  .checkedChipColor(Color.parseColor("#ddaa00"))
  .checkedTextColor(Color.parseColor("#ffffff"))
  .uncheckedChipColor(Color.parseColor("#efefef"))
  .uncheckedTextColor(Color.parseColor("#666666"))
  .useInsetPadding(true)
  .typeface(someCustomeTypeface);
  ChipCloud chipCloud = new ChipCloud(this, flexbox, config);
 

Images/Avatars

Pass a drawable when you create a chip, they'll be made round and scaled to 32dp, but pass appropriately sized images - scaling images is expensive:

ChipCloud avatarChipCloud = new ChipCloud(this, avatarLayout, chipcloudConfig);
 drawableChipCloud.addChip("Anna A", ContextCompat.getDrawable(this, R.drawable.anna_a));

Delete/Remove

With avatars:

Labels only:

Use showClose in ChipCloudConfig, the colour is the tint for the cross icon, the long value is an optional fadeout time when the chip is deleted:

 ChipCloudConfig chipcloudConfig = new ChipCloudConfig()

.selectMode(ChipCloud.SelectMode.multi)

.checkedChipColor(Color.parseColor("#ddaa00"))

.checkedTextColor(Color.parseColor("#ffffff"))

.uncheckedChipColor(Color.parseColor("#e0e0e0"))

.uncheckedTextColor(Color.parseColor("#000000"))

.showClose(Color.parseColor("#a6a6a6"), 500);

alternatively just use .showClose(Color.parseColor("#a6a6a6") and the chip will pop with no animation. Add a listener so you can update your model when a user deletes a chip (the index will shuffle so you must do this, or you'll have issues):

 deleteableCloud.setDeleteListener(new ChipDeletedListener() {

 @Override

 public void chipDeleted(int index, String label) {

Log.d(TAG, String.format("chipDeleted at index: %d label: %s", index, label));

 
}

  
}
);

Modes

Multi

ChipCloud.SelectMode.multi

The default mode; multiple chips can be selected.

Single

ChipCloud.SelectMode.single

Only one chip can be selected at a time.

Mandatory

ChipCloud.SelectMode.mandatory

Similar to a RadioGroup, only one chip can be selected, and once one has been chosen it's not possible to deselect it, you can click on another chip but one will always be checked.

None

ChipCloud.SelectMode.none

No interaction, the chips just act as feedback for a user (eg. to display a list of tags associated with a news article).

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:3.0.5' 
}

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.

Resources

Utilities to make the life of an Android developer easier.

Utilize the window background during cold start time (the time between user launches your app and Activity.onCreate() is called) to make your app look faster.

Command-line tools for convert SVG to Android vector drawable.

This library provides some expressions, IF, Match like Scala. IF enables java if-statement to return a value as Scala if-expression. Match also enables java to use pattern-match expression.

Pull down, and execute more action!

Beautiful and customizable Android Activity that shows web pages within an app.

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