Git Product home page Git Product logo

gbrutsche / android-material-chips Goto Github PK

View Code? Open in Web Editor NEW

This project forked from doodlescheduling/android-material-chips

0.0 1.0 0.0 1.31 MB

A different approach to implement android material chips since using transformed images inside an EditText cause too many exceptions on older devices and older versions.

Home Page: http://doodle.com

License: Apache License 2.0

Java 100.00%

android-material-chips's Introduction

Android Material Chips

A different approach to implement android material chips since using transformed images inside an EditText cause too many exceptions on older devices and older versions.

Features

Enter an email address and it will automatically transform into a chip

Email validation dialog

*** UPDATE: The dialog is not included in version 1.2.0 anymore. Show your own dialog instead. ***

Customize your layout and text

Sample

APK: sample-apk-1.0.1

Download

Gradle:

via jCenter

buildscript {
    repositories {
        jcenter()
    }
}

dependencies {
    compile 'com.doodle.android:android-material-chips:1.2.0'
}

via JitPack.io

repositories {
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.github.DoodleScheduling:android-material-chips:1.2.0'
}

Usage

Use the ChipsView class in your layout file.

<com.doodle.android.chips.ChipsView
    android:id="@+id/chipsView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Customize

Layout

Include xmlns:app="http://schemas.android.com/apk/res-auto" and customize your layout file.

<com.doodle.android.chips.ChipsView
	android:id="@+id/chipsView"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	app:cv_max_height="120dp"
	app:cv_vertical_spacing="2dp"
	app:cv_bg_color="#f00"
	app:cv_bg_color_clicked="#0f0"
	app:cv_color="#00f"
	app:cv_color_clicked="#721"
	app:cv_text_color="#199"
	app:cv_text_color_clicked="#180"
	app:cv_bg_color_indelible="#f00"
	app:cv_text_color_indelible="#0f0"
	app:cv_icon_placeholder="@drawable/ic_bug_report_24dp"
	app:cv_icon_placeholder_tint="#06f"
	app:cv_icon_delete="@drawable/ic_close_24dp"
	app:cv_text_hint="This is the hint text"
	app:cv_chips_margin="2dp"

====== Find the View in your Activity or Fragment class.

mChipsView = (ChipsView) findViewById(R.id.chipsView);

Listener

The ChipsView provides a listener to interact with your data.

mChipsView.setChipsListener(new ChipsView.ChipsListener() {
    @Override
    public void onChipAdded(ChipsView.Chip chip) {
        // chip added
    }

    @Override
    public void onChipDeleted(ChipsView.Chip chip) {
        // chip deleted
    }

    @Override
    public void onTextChanged(CharSequence text) {
        // text was changed
    }
            
    @Override
    public boolean onInputNotRecognized(String text) {
        // return true to delete the input
        return false; // keep the typed text
    }
});

Add a new chip

mChipsView.addChip(email, imgUrl, contact);

Add a non-removable chip.

mChipsView.addChip(email, imgUrl, contact, true);

Remove a chip

mChipsView.removeChipBy(contact);

Add Custom chip validator

mChipsView.setChipsValidator(new ChipsView.ChipValidator() {
    @Override
    public boolean isValid(Contact contact) {
        return true;
    }
});

Apps with Android chips:

License

Copyright (C) 2016 Doodle AG.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-material-chips's People

Contributors

gbrutsche avatar alexanderthiele avatar myacxy avatar pravsonawane avatar bryant1410 avatar

Watchers

James Cloos avatar

android-material-chips's Issues

addLeadingMarginSpan causes NPE on Android 9.

ChipsView.java::addLeadingMarginSpan()

    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
        at android.text.SpannableStringBuilder.equals(SpannableStringBuilder.java:1616)
        at android.widget.TextView.notifyAutoFillManagerAfterTextChangedIfNeeded(TextView.java:9792)
        at android.widget.TextView.sendAfterTextChanged(TextView.java:9775)
        at android.widget.TextView.setText(TextView.java:5739)
        at android.widget.TextView.setText(TextView.java:5571)
        at android.widget.EditText.setText(EditText.java:122)
        at android.widget.TextView.setText(TextView.java:5528)
        at com.doodle.android.chips.ChipsView.addLeadingMarginSpan(ChipsView.java:414)
        at com.doodle.android.chips.ChipsView.onChipsChanged(ChipsView.java:399)
        at com.doodle.android.chips.ChipsView.access$400(ChipsView.java:68)
        at com.doodle.android.chips.ChipsView$4.run(ChipsView.java:390)

For the mean time, I've wrapped it in a try/catch for NPEs and this seems to avoid the issue.

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.