Search in sources :

Example 1 with LinearLayout

use of carbon.widget.LinearLayout in project Carbon by ZieIony.

the class ShareToolbarActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    final LinearLayout shareToolbar = findViewById(R.id.shareToolbar);
    final View root = shareToolbar.getRootView();
    findViewById(R.id.shareIcon).setOnClickListener(view -> {
        view.setVisibility(View.GONE);
        final ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.addUpdateListener(animation -> {
            float frac = animator.getAnimatedFraction();
            float cornerRadius = MathUtils.lerp(shareToolbar.getHeight() / 2.0f, 0, frac);
            shareToolbar.setCornerRadius((int) cornerRadius);
            float left = MathUtils.lerp(root.getWidth() - shareToolbar.getHeight() - getResources().getDimension(R.dimen.carbon_padding), 0, frac);
            float right = MathUtils.lerp(root.getWidth() - getResources().getDimension(R.dimen.carbon_padding), root.getWidth(), frac);
            shareToolbar.layout((int) left, shareToolbar.getTop(), (int) right, shareToolbar.getBottom());
            shareToolbar.setElevation(frac);
            int inColor = Carbon.getThemeColor(this, R.attr.colorSecondary);
            int outColor = Carbon.getThemeColor(this, R.attr.colorSurface);
            shareToolbar.setBackgroundColor(AnimUtils.lerpColor(frac, inColor, outColor));
        });
        animator.setDuration(300);
        view.setOnClickListener(null);
        animator.start();
        final List<View> viewsWithTag = shareToolbar.findViewsWithTag("animate");
        view.getHandler().postDelayed(() -> {
            for (int i = 0; i < viewsWithTag.size(); i++) {
                final int finalI = i;
                view.getHandler().postDelayed(() -> viewsWithTag.get(finalI).setVisibility(View.VISIBLE), i * 40);
            }
        }, 200);
    });
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) LinearLayout(carbon.widget.LinearLayout)

Example 2 with LinearLayout

use of carbon.widget.LinearLayout in project Carbon by ZieIony.

the class EditTextMenu method dismiss.

@Override
public void dismiss() {
    LinearLayout content = getContentView().findViewById(R.id.carbon_menuContainer);
    content.setVisibility(View.INVISIBLE);
    content.getAnimator().addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            EditTextMenu.super.dismiss();
        }
    });
}
Also used : Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) LinearLayout(carbon.widget.LinearLayout)

Example 3 with LinearLayout

use of carbon.widget.LinearLayout in project Carbon by ZieIony.

the class EditTextMenu method showImmediate.

public boolean showImmediate(EditText anchor) {
    editText = anchor;
    super.showAtLocation(anchor, Gravity.START | Gravity.TOP, 0, 0);
    update();
    LinearLayout content = getContentView().findViewById(R.id.carbon_menuContainer);
    content.setVisibility(View.VISIBLE);
    return true;
}
Also used : LinearLayout(carbon.widget.LinearLayout)

Example 4 with LinearLayout

use of carbon.widget.LinearLayout in project Carbon by ZieIony.

the class EditTextMenu method update.

public void update() {
    if (editText == null)
        return;
    final Resources res = getContentView().getContext().getResources();
    int margin = (int) res.getDimension(R.dimen.carbon_padding);
    int itemHeight = (int) res.getDimension(R.dimen.carbon_menuHeight);
    Rect windowRect = new Rect();
    editText.getWindowVisibleDisplayFrame(windowRect);
    int[] location = new int[2];
    editText.getLocationInWindow(location);
    LinearLayout content = getContentView().findViewById(R.id.carbon_menuContent);
    content.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(itemHeight, View.MeasureSpec.EXACTLY));
    int popupX = location[0] - margin;
    int popupY = location[1] - margin * 2 - content.getMeasuredHeight();
    update(popupX, popupY, content.getMeasuredWidth() + margin * 2, content.getMeasuredHeight() + margin * 2);
    super.update();
}
Also used : Rect(android.graphics.Rect) Resources(android.content.res.Resources) LinearLayout(carbon.widget.LinearLayout)

Example 5 with LinearLayout

use of carbon.widget.LinearLayout 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;
    });
}
Also used : DrawableImageGenerator(tk.zielony.randomdata.common.DrawableImageGenerator) PointF(android.graphics.PointF) FastOutSlowInInterpolator(androidx.interpolator.view.animation.FastOutSlowInInterpolator) ImageView(carbon.widget.ImageView) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) ImageView(carbon.widget.ImageView) LinearLayout(carbon.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint) NURBS(carbon.internal.NURBS) SuppressLint(android.annotation.SuppressLint)

Aggregations

LinearLayout (carbon.widget.LinearLayout)5 ValueAnimator (android.animation.ValueAnimator)2 View (android.view.View)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 PointF (android.graphics.PointF)1 Rect (android.graphics.Rect)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 FastOutSlowInInterpolator (androidx.interpolator.view.animation.FastOutSlowInInterpolator)1 NURBS (carbon.internal.NURBS)1 ImageView (carbon.widget.ImageView)1 DrawableImageGenerator (tk.zielony.randomdata.common.DrawableImageGenerator)1