Search in sources :

Example 1 with DefaultAvatarTextItem

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

the class AvatarTextListItemActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listcomponent);
    Samples.initToolbar(this, getString(R.string.avatarTextListItemActivity_title));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    RowListAdapter adapter = new RowListAdapter<>(DefaultAvatarTextItem.class, AvatarTextRow.FACTORY);
    adapter.addFactory(DividerItem.class, DividerRow.FACTORY);
    recycler.setAdapter(adapter);
    Drawable avatar = getResources().getDrawable(R.drawable.iceland);
    adapter.setItems(Arrays.asList(new DefaultAvatarTextItem(avatar, "text"), new DefaultAvatarTextItem(avatar, "text"), new DividerItem(), new DefaultAvatarTextItem(avatar, "text"), new DefaultAvatarTextItem(avatar, "text")));
}
Also used : Drawable(android.graphics.drawable.Drawable) DefaultAvatarTextItem(carbon.component.DefaultAvatarTextItem) RowListAdapter(carbon.recycler.RowListAdapter) RecyclerView(carbon.widget.RecyclerView) DividerItem(carbon.component.DividerItem)

Example 2 with DefaultAvatarTextItem

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

the class SearchToolbarActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    List<DefaultAvatarTextItem> items = generateItems();
    RowListAdapter<DefaultAvatarTextItem> adapter = new RowListAdapter<>(items, AvatarTextRow::new);
    RecyclerView recyclerView = findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);
    searchEditText = findViewById(R.id.searchEditText);
    searchEditText.setDataProvider(new ListSearchAdapter<DefaultAvatarTextItem>(items) {

        @NotNull
        @Override
        public String[] getItemWords(DefaultAvatarTextItem item) {
            return new String[] { item.getText() };
        }
    });
    searchEditText.setOnFilterListener((SearchEditText.OnFilterListener<DefaultAvatarTextItem>) filterResults -> {
        if (filterResults == null) {
            adapter.setItems(items);
        } else if (filterResults.size() == 2) {
            adapter.setItems(new ArrayList<>());
        } else {
            adapter.setItems(filterResults);
        }
    });
    findViewById(R.id.clear).setOnClickListener(v -> searchEditText.setText(""));
    searchBar = findViewById(R.id.searchbar);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setOnMenuItemClicked((view, item, position) -> openSearch(view));
    closeButton = findViewById(R.id.close);
    closeButton.setOnClickListener(v -> closeSearch());
}
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) DefaultAvatarTextItem(carbon.component.DefaultAvatarTextItem) RowListAdapter(carbon.recycler.RowListAdapter) AvatarTextRow(carbon.component.AvatarTextRow) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NotNull(org.jetbrains.annotations.NotNull) SearchEditText(carbon.widget.SearchEditText) RecyclerView(carbon.widget.RecyclerView) Toolbar(carbon.widget.Toolbar)

Example 3 with DefaultAvatarTextItem

use of carbon.component.DefaultAvatarTextItem 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 4 with DefaultAvatarTextItem

use of carbon.component.DefaultAvatarTextItem 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)4 DefaultAvatarTextItem (carbon.component.DefaultAvatarTextItem)4 RowListAdapter (carbon.recycler.RowListAdapter)4 RecyclerView (carbon.widget.RecyclerView)4 Bundle (android.os.Bundle)3 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)3 AvatarTextRow (carbon.component.AvatarTextRow)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 DrawableAvatarGenerator (tk.zielony.randomdata.person.DrawableAvatarGenerator)3 StringNameGenerator (tk.zielony.randomdata.person.StringNameGenerator)3 Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 View (android.view.View)2 FastOutSlowInInterpolator (androidx.interpolator.view.animation.FastOutSlowInInterpolator)2 FrameLayout (carbon.widget.FrameLayout)2 ListSearchAdapter (carbon.widget.ListSearchAdapter)2