Java Code Examples for ru.noties.ccf.CCFAnimator

The following examples show how to use ru.noties.ccf.CCFAnimator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ColorCrossFade   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private CCFAnimator animator() {

        final int fromColor = mPendingAnimationConfig.fromColor;
        final int toColor = mPendingAnimationConfig.toColor;

        switch (mType) {

            case HSV:
                return CCFAnimator.hsv(fromColor, toColor);

            case HSV_WITH_ALPHA:
                final int fromAlpha = Color.alpha(fromColor);
                final int toAlpha = Color.alpha(toColor);
                return CCFAnimator.hsv(fromColor, toColor, fromAlpha, toAlpha);

            case RGB:
                return CCFAnimator.rgb(fromColor, toColor);

            case ARGB:
                return CCFAnimator.argb(fromColor, toColor);

            default:
                throw new IllegalStateException("Unknown CCFType: " + mType);
        }

    }
 
Example 2
public SampleHeaderViewOnScrollChangedListener(SampleHeaderView view) {
    mView = view;
    mCCFAnimator = CCFAnimator.rgb(view.getExpandedColor(), view.getCollapsedColor());
}
 
Example 3
Source Project: Scrollable   Source File: ScrollHeaderActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle sis) {
    super.onCreate(sis);

    setContentView(R.layout.activity_scroll_header);

    final ScrollableLayout scrollableLayout = findView(R.id.scrollable_layout);
    final RecyclerView headerRecyclerView = findView(R.id.recycler_view_header);
    final RecyclerView contentRecyclerView = findView(R.id.recycler_view);
    final View header = findViewById(R.id.header);

    final ViewTypesAdapter<String> adapter = ViewTypesAdapter.builder(String.class)
            .register(String.class, new ViewTypeItem())
            .build(this);
    adapter.setItems(ItemsGenerator.generate(100));

    headerRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    contentRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    headerRecyclerView.setAdapter(adapter);
    contentRecyclerView.setAdapter(adapter);

    scrollableLayout.setFriction(.035F);
    scrollableLayout.setDraggableView(header);

    scrollableLayout.setCanScrollVerticallyDelegate(new CanScrollVerticallyDelegate() {
        @Override
        public boolean canScrollVertically(int direction) {
            return contentRecyclerView.canScrollVertically(direction);
        }
    });

    scrollableLayout.addOnScrollChangedListener(new OnScrollChangedListener() {

        final CCFAnimator mCCFAnimator = CCFAnimator.rgb(
                ContextCompat.getColor(ScrollHeaderActivity.this, R.color.md_teal_300),
                ContextCompat.getColor(ScrollHeaderActivity.this, R.color.md_teal_500)
        );

        @Override
        public void onScrollChanged(int y, int oldY, int maxY) {
            final float ratio = (float) y / maxY;
            headerRecyclerView.setBackgroundColor(mCCFAnimator.getColor(ratio));
        }
    });
}