use of tk.zielony.randomdata.DataContext 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;
});
}
Aggregations