Search in sources :

Example 1 with RandomData

use of tk.zielony.randomdata.RandomData 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 2 with RandomData

use of tk.zielony.randomdata.RandomData in project Carbon by ZieIony.

the class QuickReturnActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    List<Serializable> items = Arrays.asList(// new PaddingItem(getResources().getDimensionPixelSize(R.dimen.carbon_toolbarHeight) + getResources().getDimensionPixelSize(R.dimen.carbon_paddingHalf)),
    new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem(), new DefaultImageTextSubtextDateItem());
    RandomData randomData = new RandomData();
    randomData.addGenerator(Drawable.class, new DrawableImageGenerator(this));
    randomData.addGenerator(String.class, new StringNameGenerator().withMatcher(f -> f.getName().equals("text") && f.getDeclaringClass().equals(DefaultImageTextSubtextDateItem.class)));
    randomData.addGenerator(String.class, new TextGenerator().withMatcher(f -> f.getName().equals("subtext")));
    randomData.addGenerator(String.class, new DateGenerator().withTransformer(new DateToStringTransformer()));
    randomData.fill(items);
    RecyclerView recycler = findViewById(R.id.recycler);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    RowListAdapter<Serializable> adapter = new RowListAdapter<>(DefaultImageTextSubtextDateItem.class, ImageTextSubtextDateRow::new);
    adapter.putFactory(DefaultHeaderItem.class, PaddedHeaderRow::new);
    recycler.setAdapter(adapter);
    adapter.setItems(items);
    final FloatingActionButton fab = findViewById(R.id.fab);
    final Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(getTitle());
    recycler.addOnScrollListener(new androidx.recyclerview.widget.RecyclerView.OnScrollListener() {

        int yScroll = 0;

        @Override
        public void onScrolled(androidx.recyclerview.widget.RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (fab.getVisibility() == View.VISIBLE && fab.getAnimator() == null && yScroll > 50 * Carbon.getDip(getApplicationContext())) {
                yScroll = 0;
                fab.animateVisibility(View.GONE);
                toolbar.animateVisibility(View.GONE);
            }
            if (fab.getVisibility() != View.VISIBLE && fab.getAnimator() == null && yScroll < -50 * Carbon.getDip(getApplicationContext())) {
                yScroll = 0;
                fab.animateVisibility(View.VISIBLE);
                toolbar.animateVisibility(View.VISIBLE);
            }
            if (Math.signum(dy) != Math.signum(yScroll))
                yScroll = 0;
            yScroll += dy;
        }
    });
}
Also used : DefaultHeaderItem(carbon.component.DefaultHeaderItem) Arrays(java.util.Arrays) Bundle(android.os.Bundle) DrawableImageGenerator(tk.zielony.randomdata.common.DrawableImageGenerator) TextGenerator(tk.zielony.randomdata.common.TextGenerator) Drawable(android.graphics.drawable.Drawable) StringNameGenerator(tk.zielony.randomdata.person.StringNameGenerator) PaddedHeaderRow(carbon.component.PaddedHeaderRow) DateToStringTransformer(tk.zielony.randomdata.transformer.DateToStringTransformer) RecyclerView(carbon.widget.RecyclerView) DateGenerator(tk.zielony.randomdata.common.DateGenerator) RandomData(tk.zielony.randomdata.RandomData) FloatingActionButton(carbon.widget.FloatingActionButton) View(android.view.View) RowListAdapter(carbon.recycler.RowListAdapter) DefaultImageTextSubtextDateItem(carbon.component.DefaultImageTextSubtextDateItem) ImageTextSubtextDateRow(carbon.component.ImageTextSubtextDateRow) ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) Serializable(java.io.Serializable) List(java.util.List) DefaultHeaderItem(carbon.component.DefaultHeaderItem) Carbon(carbon.Carbon) Toolbar(carbon.widget.Toolbar) R(tk.zielony.carbonsamples.R) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Serializable(java.io.Serializable) RandomData(tk.zielony.randomdata.RandomData) DefaultImageTextSubtextDateItem(carbon.component.DefaultImageTextSubtextDateItem) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageTextSubtextDateRow(carbon.component.ImageTextSubtextDateRow) FloatingActionButton(carbon.widget.FloatingActionButton) TextGenerator(tk.zielony.randomdata.common.TextGenerator) DateToStringTransformer(tk.zielony.randomdata.transformer.DateToStringTransformer) Toolbar(carbon.widget.Toolbar) StringNameGenerator(tk.zielony.randomdata.person.StringNameGenerator) DateGenerator(tk.zielony.randomdata.common.DateGenerator) DrawableImageGenerator(tk.zielony.randomdata.common.DrawableImageGenerator) RowListAdapter(carbon.recycler.RowListAdapter) PaddedHeaderRow(carbon.component.PaddedHeaderRow) RecyclerView(carbon.widget.RecyclerView)

Example 3 with RandomData

use of tk.zielony.randomdata.RandomData 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

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