use of tk.zielony.randomdata.common.DrawableImageGenerator in project Carbon by ZieIony.
the class PathAnimationActivity method onCreate.
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initToolbar();
ImageView imageView = findViewById(R.id.image);
imageView.setImageDrawable(new DrawableImageGenerator(this).next());
LinearLayout card = findViewById(R.id.card);
View layout = findViewById(R.id.layout);
layout.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) {
NURBS nurbs = new NURBS();
nurbs.addPoint(new PointF(card.getX() + card.getWidth() / 2, card.getY() + card.getHeight() / 2));
nurbs.addPoint(new PointF(event.getX(), card.getY() + card.getHeight() / 2));
nurbs.addPoint(new PointF(event.getX(), event.getY()));
nurbs.init();
ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
float srcWidth = card.getWidth();
float srcHeight = card.getHeight();
float destWidth = expanded ? getResources().getDimension(R.dimen.carbon_contentSpace) : layout.getWidth();
float destHeight = destWidth * 9.0f / 16;
animator.setDuration(500);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.addUpdateListener(animation -> {
PointF point = nurbs.getPoint((Float) animation.getAnimatedValue());
int w = (int) MathUtils.lerp(srcWidth, destWidth, (Float) animation.getAnimatedValue());
int h = (int) MathUtils.lerp(srcHeight, destHeight, (Float) animation.getAnimatedValue());
int x = (int) point.x - w / 2;
int y = (int) point.y - h / 2;
card.setBounds(x, y, w, h);
});
animator.start();
expanded = !expanded;
}
return true;
});
}
use of tk.zielony.randomdata.common.DrawableImageGenerator 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;
}
});
}
Aggregations