Search in sources :

Example 1 with Chip

use of carbon.widget.Chip in project Carbon by ZieIony.

the class FlowLayoutActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flowlayout);
    FlowLayout layout = (FlowLayout) findViewById(R.id.flowLayout);
    Stream.of(layout.getViews()).filter(v -> v instanceof Chip).forEach(v -> {
        final Chip chip = (Chip) v;
        chip.setText(fruits.get((int) (Math.random() * fruits.size())));
        if (Math.random() > 0.5) {
            chip.setIconVisible(true);
            String image = "http://lorempixel.com/100/100/people/#" + System.currentTimeMillis();
            Picasso.with(this).load(image).into((ImageView) chip.getIconView());
        } else {
            chip.setIconVisible(false);
        }
        if (Math.random() > 0.5) {
            chip.setRemovable(true);
            chip.setOnRemoveListener(() -> {
                chip.setOutAnimation(AnimUtils.Style.Fade);
                chip.setVisibility(View.GONE);
            });
        } else {
            chip.setRemovable(false);
        }
    });
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) Chip(carbon.widget.Chip) ImageView(android.widget.ImageView) ArrayList(java.util.ArrayList) Picasso(com.squareup.picasso.Picasso) List(java.util.List) SamplesActivity(tk.zielony.carbonsamples.SamplesActivity) R(tk.zielony.carbonsamples.R) FlowLayout(carbon.widget.FlowLayout) View(android.view.View) AnimUtils(carbon.animation.AnimUtils) FlowLayout(carbon.widget.FlowLayout) Chip(carbon.widget.Chip)

Aggregations

Bundle (android.os.Bundle)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 AnimUtils (carbon.animation.AnimUtils)1 Chip (carbon.widget.Chip)1 FlowLayout (carbon.widget.FlowLayout)1 Stream (com.annimon.stream.Stream)1 Picasso (com.squareup.picasso.Picasso)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 R (tk.zielony.carbonsamples.R)1 SamplesActivity (tk.zielony.carbonsamples.SamplesActivity)1