Search in sources :

Example 1 with StringFirstNameGenerator

use of tk.zielony.randomdata.person.StringFirstNameGenerator in project Carbon by ZieIony.

the class FlowLayoutActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    DrawableAvatarGenerator avatarGenerator = new DrawableAvatarGenerator(this);
    StringFirstNameGenerator nameGenerator = new StringFirstNameGenerator(Gender.Both, false, false);
    Random random = new Random();
    FlowLayout layout = findViewById(R.id.flowLayout);
    Stream.of(layout.getViews()).filter(v -> v instanceof Chip).forEach(v -> {
        final Chip chip = (Chip) v;
        DataContext dataContext = new DataContext();
        chip.setText(nameGenerator.next(dataContext));
        if (random.nextBoolean())
            chip.setIcon(avatarGenerator.next(dataContext));
        chip.setRemovable(random.nextBoolean());
        chip.setOnRemoveListener(() -> {
            chip.setVisibility(View.GONE);
        });
    });
    EditText addChip = findViewById(R.id.addChip);
    addChip.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
            Chip chip = new Chip(FlowLayoutActivity.this);
            chip.setText(addChip.getText());
            chip.setRemovable(random.nextBoolean());
            chip.setSelected(random.nextBoolean());
            layout.addView(chip);
            addChip.setText("");
        }
        return true;
    });
}
Also used : ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) Gender(tk.zielony.randomdata.person.Gender) Bundle(android.os.Bundle) KeyEvent(android.view.KeyEvent) Stream(com.annimon.stream.Stream) Chip(carbon.widget.Chip) Random(java.util.Random) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) StringFirstNameGenerator(tk.zielony.randomdata.person.StringFirstNameGenerator) EditText(carbon.widget.EditText) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) DataContext(tk.zielony.randomdata.DataContext) R(tk.zielony.carbonsamples.R) FlowLayout(carbon.widget.FlowLayout) View(android.view.View) EditText(carbon.widget.EditText) DataContext(tk.zielony.randomdata.DataContext) FlowLayout(carbon.widget.FlowLayout) Random(java.util.Random) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) StringFirstNameGenerator(tk.zielony.randomdata.person.StringFirstNameGenerator) Chip(carbon.widget.Chip)

Aggregations

Bundle (android.os.Bundle)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 Chip (carbon.widget.Chip)1 EditText (carbon.widget.EditText)1 FlowLayout (carbon.widget.FlowLayout)1 Stream (com.annimon.stream.Stream)1 Random (java.util.Random)1 R (tk.zielony.carbonsamples.R)1 SampleAnnotation (tk.zielony.carbonsamples.SampleAnnotation)1 ThemedActivity (tk.zielony.carbonsamples.ThemedActivity)1 DataContext (tk.zielony.randomdata.DataContext)1 DrawableAvatarGenerator (tk.zielony.randomdata.person.DrawableAvatarGenerator)1 Gender (tk.zielony.randomdata.person.Gender)1 StringFirstNameGenerator (tk.zielony.randomdata.person.StringFirstNameGenerator)1