Search in sources :

Example 1 with DefaultHeaderItem

use of carbon.component.DefaultHeaderItem in project Carbon by ZieIony.

the class ImageTextSubtextDateListItemActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listcomponent);
    Samples.initToolbar(this, getString(R.string.imageTextSubtextDateListItemActivity_title));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    RowListAdapter adapter = new RowListAdapter<>(DefaultImageTextSubtextDateItem.class, ImageTextSubtextDateRow::new);
    adapter.addFactory(DefaultHeaderItem.class, PaddedHeaderRow.FACTORY);
    recycler.setAdapter(adapter);
    Drawable drawable = getResources().getDrawable(R.drawable.watermelon);
    String date = format.format(new Date().getTime());
    adapter.setItems(Arrays.asList(new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date)));
}
Also used : DefaultHeaderItem(carbon.component.DefaultHeaderItem) ImageTextSubtextDateRow(carbon.component.ImageTextSubtextDateRow) Drawable(android.graphics.drawable.Drawable) RowListAdapter(carbon.recycler.RowListAdapter) RecyclerView(carbon.widget.RecyclerView) DefaultImageTextSubtextDateItem(carbon.component.DefaultImageTextSubtextDateItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Date(java.util.Date)

Example 2 with DefaultHeaderItem

use of carbon.component.DefaultHeaderItem 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)

Aggregations

Drawable (android.graphics.drawable.Drawable)2 DefaultHeaderItem (carbon.component.DefaultHeaderItem)2 DefaultImageTextSubtextDateItem (carbon.component.DefaultImageTextSubtextDateItem)2 ImageTextSubtextDateRow (carbon.component.ImageTextSubtextDateRow)2 RowListAdapter (carbon.recycler.RowListAdapter)2 RecyclerView (carbon.widget.RecyclerView)2 Bundle (android.os.Bundle)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 View (android.view.View)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 Carbon (carbon.Carbon)1 PaddedHeaderRow (carbon.component.PaddedHeaderRow)1 FloatingActionButton (carbon.widget.FloatingActionButton)1 Toolbar (carbon.widget.Toolbar)1 Serializable (java.io.Serializable)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 List (java.util.List)1 R (tk.zielony.carbonsamples.R)1 SampleAnnotation (tk.zielony.carbonsamples.SampleAnnotation)1