Search in sources :

Example 1 with DrawableAvatarGenerator

use of tk.zielony.randomdata.person.DrawableAvatarGenerator 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)

Example 2 with DrawableAvatarGenerator

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

the class SearchToolbarActivity method generateItems.

@NotNull
private List<DefaultAvatarTextItem> generateItems() {
    RandomData randomData = new RandomData();
    randomData.addGenerator(Drawable.class, new DrawableAvatarGenerator(this));
    randomData.addGenerator(String.class, new StringNameGenerator().withMatcher(f -> f.getName().equals("text")));
    return randomData.generateList(DefaultAvatarTextItem.class, 20);
}
Also used : ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) Bundle(android.os.Bundle) FastOutSlowInInterpolator(androidx.interpolator.view.animation.FastOutSlowInInterpolator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) Drawable(android.graphics.drawable.Drawable) StringNameGenerator(tk.zielony.randomdata.person.StringNameGenerator) ArrayList(java.util.ArrayList) AvatarTextRow(carbon.component.AvatarTextRow) SearchEditText(carbon.widget.SearchEditText) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) List(java.util.List) RecyclerView(carbon.widget.RecyclerView) ListSearchAdapter(carbon.widget.ListSearchAdapter) Toolbar(carbon.widget.Toolbar) RandomData(tk.zielony.randomdata.RandomData) R(tk.zielony.carbonsamples.R) DefaultAvatarTextItem(carbon.component.DefaultAvatarTextItem) View(android.view.View) RowListAdapter(carbon.recycler.RowListAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NotNull(org.jetbrains.annotations.NotNull) FrameLayout(carbon.widget.FrameLayout) StringNameGenerator(tk.zielony.randomdata.person.StringNameGenerator) RandomData(tk.zielony.randomdata.RandomData) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with DrawableAvatarGenerator

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

the class BehaviorActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView recycler = findViewById(R.id.recycler);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    RowListAdapter<DefaultAvatarTextItem> adapter = new RowListAdapter<>(DefaultAvatarTextItem.class, AvatarTextRow::new);
    recycler.setAdapter(adapter);
    List<DefaultAvatarTextItem> items = Stream.generate(DefaultAvatarTextItem::new).limit(10).collect(Collectors.toList());
    RandomData randomData = new RandomData();
    randomData.addGenerator(Drawable.class, new DrawableAvatarGenerator(this));
    randomData.addGenerator(String.class, new StringNameGenerator().withMatcher(f -> f.getName().equals("text")));
    randomData.fill(items);
    adapter.setItems(items);
    RelativeLayout layout = findViewById(R.id.layout);
    LandscapeView landscapeView = findViewById(R.id.landscape);
    float minHeight = getResources().getDimension(carbon.R.dimen.carbon_toolbarHeight);
    float maxHeight = minHeight * 4;
    layout.addBehavior(new HeightBehavior<>(landscapeView, minHeight, maxHeight, HeightBehavior.Direction.Up));
    layout.addBehavior(new RecyclerScrollBehavior(recycler));
    layout.addBehavior(new HeightBehavior<>(landscapeView, minHeight, maxHeight, HeightBehavior.Direction.Down));
}
Also used : ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) LandscapeView(tk.zielony.landscapeview.LandscapeView) Bundle(android.os.Bundle) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) HeightBehavior(carbon.behavior.HeightBehavior) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) Drawable(android.graphics.drawable.Drawable) StringNameGenerator(tk.zielony.randomdata.person.StringNameGenerator) AvatarTextRow(carbon.component.AvatarTextRow) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) List(java.util.List) RecyclerView(carbon.widget.RecyclerView) RandomData(tk.zielony.randomdata.RandomData) RelativeLayout(carbon.widget.RelativeLayout) R(tk.zielony.carbonsamples.R) DefaultAvatarTextItem(carbon.component.DefaultAvatarTextItem) RecyclerScrollBehavior(carbon.behavior.RecyclerScrollBehavior) RowListAdapter(carbon.recycler.RowListAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StringNameGenerator(tk.zielony.randomdata.person.StringNameGenerator) RecyclerScrollBehavior(carbon.behavior.RecyclerScrollBehavior) RandomData(tk.zielony.randomdata.RandomData) DefaultAvatarTextItem(carbon.component.DefaultAvatarTextItem) RowListAdapter(carbon.recycler.RowListAdapter) AvatarTextRow(carbon.component.AvatarTextRow) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LandscapeView(tk.zielony.landscapeview.LandscapeView) RelativeLayout(carbon.widget.RelativeLayout) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) RecyclerView(carbon.widget.RecyclerView)

Aggregations

Bundle (android.os.Bundle)3 R (tk.zielony.carbonsamples.R)3 SampleAnnotation (tk.zielony.carbonsamples.SampleAnnotation)3 ThemedActivity (tk.zielony.carbonsamples.ThemedActivity)3 DrawableAvatarGenerator (tk.zielony.randomdata.person.DrawableAvatarGenerator)3 Drawable (android.graphics.drawable.Drawable)2 View (android.view.View)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 AvatarTextRow (carbon.component.AvatarTextRow)2 DefaultAvatarTextItem (carbon.component.DefaultAvatarTextItem)2 RowListAdapter (carbon.recycler.RowListAdapter)2 RecyclerView (carbon.widget.RecyclerView)2 Stream (com.annimon.stream.Stream)2 List (java.util.List)2 RandomData (tk.zielony.randomdata.RandomData)2 StringNameGenerator (tk.zielony.randomdata.person.StringNameGenerator)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 KeyEvent (android.view.KeyEvent)1 FastOutSlowInInterpolator (androidx.interpolator.view.animation.FastOutSlowInInterpolator)1