Coder Social home page Coder Social logo

davidpizarro / autolabelui Goto Github PK

View Code? Open in Web Editor NEW
636.0 21.0 109.0 4.23 MB

Android library to place labels next to another. If there is not enough space for the next label, it will be added in a new line.

License: Apache License 2.0

Java 100.00%

autolabelui's Introduction

AutoLabelUI

Android Arsenal Maven Central

Android library to place labels next to another. If there is not enough space for the next label, it will be added in a new line.

Example screenshot

Try out the sample application on Google Play.

AutoLabelUI Sample on Google Play

Demo

Example gif

Including in Your Project

Last version is 1.0.1

Just add the following statement in your build.gradle

compile 'com.github.davidpizarro:autolabelui:VERSION'

You may also add the library as an Android Library to your project. All the library files live in library.

Usage

To add the AutoLabelUI to your layout, add this to your xml

<com.dpizarro.autolabel.library.AutoLabelUI
        android:id="@+id/label_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

You can add custom attributes in your xml to customize: drawables, colors, counters, background, behaviors...

<com.dpizarro.autolabel.library.AutoLabelUI
        android:id="@+id/label_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        autolabel:max_labels="10"
        autolabel:show_cross="true"
        autolabel:text_color="@android:color/white"
        autolabel:text_size="@dimen/label_title_size"
        autolabel:icon_cross="@drawable/cross"
        autolabel:label_background_res="@color/default_background_label"
        autolabel:label_padding="@dimen/label_padding"
        autolabel:label_clickable="true"/>
        

Review attrs.xml file to know the list of shapes ready to be used in the library.

This configuration can be also provided programmatically. You can use AutoLabelUI programatically, using the Builder class to set the settings and the desired functionalities:

AutoLabelUI mAutoLabel = (AutoLabelUI) view.findViewById(R.id.label_view);

AutoLabelUISettings autoLabelUISettings = new AutoLabelUISettings.Builder()
                                                                 .withMaxLabels(5)
                                                                 .withIconCross(R.drawable.cross)
                                                                 .withBackgroundResource(R.drawable.round_corner_background)
                                                                 .withLabelsClickables(false)
                                                                 .withShowCross(true)
                                                                 .withTextColor(android.R.color.holo_red_dark)
                                                                 .withTextSize(R.dimen.label_title_size)
                                                                 .withLabelPadding(R.dimen.label_padding)
                                                                 .build();

mAutoLabel.setSettings(autoLabelUISettings);

You can set/get values programatically:

mAutoLabel.getBackgroundResource();
mAutoLabel.getTextColor();
mAutoLabel.getTextSize();
mAutoLabel.isLabelsClickables();
mAutoLabel.setTextColor(android.R.color.holo_red_dark);
mAutoLabel.setMaxLabels(5);
mAutoLabel.setBackgroundResource(R.drawable.round_corner_background);
...

You can get Label using:

Label label = mAutoLabel.getLabel(1);
List<Label> labels = mAutoLabel.getLabels();

or remove them all:

mAutoLabel.clear();

To know when you have reached the limit of Labels to add, you will need to implement the onLabelsCompleted interface:

mAutoLabel.setOnLabelsCompletedListener(new AutoLabelUI.OnLabelsCompletedListener() {
    @Override
    public void onLabelsCompleted() {
        Toast.makeText(getActivity(), "Completed!", Toast.LENGTH_SHORT).show();
    }
});

To know when you have deleted all Labels, you will need to implement the onLabelsEmpty interface:

mAutoLabel.setOnLabelsEmptyListener(new AutoLabelUI.OnLabelsEmptyListener() {
    @Override
    public void onLabelsEmpty() {
        Toast.makeText(getActivity(), "EMPTY!", Toast.LENGTH_SHORT).show();
    }
});

To know when you have deleted a Label, you will need to implement the onRemoveLabel interface:

mAutoLabel.setOnRemoveLabelListener(new AutoLabelUI.OnRemoveLabelListener() {
    @Override
    public void onRemoveLabel(View view, int position) {
        adapter.setItemSelected(position, false);
    }
});

To know when you have clicked a Label, you will need to implement the onClickLabel interface:

mAutoLabel.setOnLabelClickListener(new AutoLabelUI.OnLabelClickListener() {
    @Override
    public void onClickLabel(View v) {
        Toast.makeText(getActivity(), ((Label) v).getText() , Toast.LENGTH_SHORT).show();
    }
});

Or browse the source code of the sample application for a complete example of use.

Contribution

Pull requests are welcome!

I'd like to improve this library with your help! If you've fixed a bug or have a feature you've added, just create a pull request. Issues can be reported on the github issue tracker.

Who's using it

Does your app use AutoLabelUI? If you want to be featured on this list drop me a line.

Author

David Pizarro ([email protected])

Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2015 David Pizarro

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.

autolabelui's People

Contributors

davidpizarro avatar liaohuqiu avatar porksteak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autolabelui's Issues

setTextColor only takes id resource and sometimes color int

Hi,
I can't set the color in code, Im trying to use android palette and the int color I get won't be set as a color, but sometimes works.
I find out that the setTextColor only takes a resource id and if an exception is thrown then the color int is set.

Could you add a another setColor that takes a color int?

AutoLabel.setOnLabelClickListener is not working

sir,
Method does not override from its super class

error occured while execute this code

mAutoLabel.setOnLabelClickListener(new AutoLabelUI.OnLabelClickListener() {

@Override
public void onClickLabel(Label labelClicked) {
    Snackbar.make(recyclerView, labelClicked.getText(), Snackbar.LENGTH_SHORT).show();
}

});

Align center tag content

Hi!
Congratulations for the library, it´s amazing. I would like to ask if there is any way to center horizontal tags, instead of floating them left (align left). Or if you have any clue where I may be working around to get it.

Thank you!.

getLabel problem

I added this library to gradle in Android studio. When I try to call getLabel or getLabels methods it shows that there are no such methods and in .class file I don't see them.
What can be the reason?

assigning an id to each label

Hi all,
I just want to assign id to each label. I tried mAutoLabel.setId("some_id"); but ((Label) v).getId() is returning -1 for every label.
How can I achieve it?

OnRemoveLabelListener position returnes -1

mAutoLabel.setOnRemoveLabelListener(new AutoLabelUI.OnRemoveLabelListener() {
    @Override
    public void onRemoveLabel(View view, int position) {
        Log.i("Position","Position: " + position); //<---- This always return -1 when clicking the x on the label.
    }
});

Adding/Removing items animation disturbs the whole layout.

I have a CollapsingToolbarLayout. In container layout , i have an EditText & a Submit Button. After adding/removing one or two items using AutoLableUI on clicking Submit Button, the whole layout moves towards upward and overlaps the collapsing toolbar layout. Same Issue in another layout, where i am using Toolbar Layout along with some tabs.

Label shape

Is it possible to change the shape? Rounded edges etc...?

Issue when adding more tags

When adding tags and lines are exceeded than 2 then issue occurs, tags are cutting from bottom as attached screen-shot
1

Can not add to project by gradle

I tried to add this lib to to my project with compile 'com.github.davidpizarro:autolabelui:VERSION' to my gradle file but I receive the message Error:(39, 13) Failed to resolve: com.github.davidpizarro:autolabelui:VERSION

Please help...

setOnRemoveLabelListener() is being invoked with position = -1

When I attach setOnRemoveLabelListener(), it is always being invoked with position equals to -1, not the index of label. I see it comes form this code:

    if (listenerOnRemoveLabel != null) {
        if (view.getTag() instanceof Integer) {
            listenerOnRemoveLabel.onRemoveLabel(view, (Integer) view.getTag());
        } else {
            listenerOnRemoveLabel.onRemoveLabel(view, -1);
        }
    }

but addLabel(String label) does sets tag on label as label.setTag(textLabel); so it will not work.

In general the whole concept seem fundamentally broken here, as this position should be obtained dynamically, not from tag, as removing any label is not updating stored position of remaining tags' which will cause troubles when one is i.e. trying to keep labels in sync with something else. For now the only solution seem to be to use labels (strings) and then sync base on this, but it's not efficient.

Add list of labels

For example

List<String> tags = new ArrayList<>();
tags.add("cars");
tags.add("home");
tags.add("people");

AutoLabelUI mAutoLabel = (AutoLabelUI) findViewById(R.id.tags);
mAutoLabel.addLabels(tags);

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.