Search in sources :

Example 1 with NoneShowMethod

use of immortalz.me.library.method.NoneShowMethod in project TransitionHelper by ImmortalZ.

the class FabNoCircleActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TransitionsHeleper.getInstance().setShowMethod(new NoneShowMethod() {

        @Override
        public void loadCopyView(InfoBean bean, ImageView copyView) {
            AnimatorSet set = new AnimatorSet();
            set.playTogether(ObjectAnimator.ofFloat(copyView, "rotation", 0, 180), ObjectAnimator.ofFloat(copyView, "scaleX", 1, 0), ObjectAnimator.ofFloat(copyView, "scaleY", 1, 0));
            set.setInterpolator(new AccelerateInterpolator());
            set.setDuration(duration / 4 * 5).start();
        }
    }).show(this, null);
}
Also used : InfoBean(immortalz.me.library.bean.InfoBean) NoneShowMethod(immortalz.me.library.method.NoneShowMethod) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) AnimatorSet(android.animation.AnimatorSet) ImageView(android.widget.ImageView)

Example 2 with NoneShowMethod

use of immortalz.me.library.method.NoneShowMethod in project TransitionHelper by ImmortalZ.

the class TransitionsHeleper method show.

public void show(final Activity activity, final ImageView targetView) {
    final InfoBean bean = staticMap.get(activity.getClass().getName());
    if (bean == null) {
        return;
    }
    if (showMethod == null) {
        showMethod = new NoneShowMethod();
    }
    final ViewGroup parent = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
    //if TranslucentStatus is true , statusBarHeight = 0
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (activity.getWindow().getStatusBarColor() == 0 || (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS & activity.getWindow().getAttributes().flags) == WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) {
            bean.statusBarHeight = 0;
        }
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if ((WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS & activity.getWindow().getAttributes().flags) == WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) {
            bean.statusBarHeight = 0;
        }
    }
    parent.post(new Runnable() {

        @Override
        public void run() {
            bean.windowWidth = parent.getWidth();
            bean.windowHeight = parent.getHeight();
            bean.titleHeight = parent.getTop();
            final CirleAnimView cirleAnimView;
            if (showMethod instanceof InflateShowMethod) {
                cirleAnimView = new CirleAnimView(activity, createBitmap(((InflateShowMethod) showMethod).inflateView, bean.windowWidth, bean.windowHeight, true));
            } else {
                cirleAnimView = new CirleAnimView(activity);
            }
            final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            parent.addView(cirleAnimView, params);
            if (targetView != null) {
                //get Target View's position
                targetView.getGlobalVisibleRect(bean.targetRect);
                bean.targetWidth = bean.targetRect.right - bean.targetRect.left;
                bean.targetHeight = bean.targetRect.bottom - bean.targetRect.top;
                bean.translationX = bean.originRect.left + bean.originWidth / 2 - bean.targetRect.left - bean.targetWidth / 2;
                bean.translationY = bean.originRect.top + bean.originHeight / 2 - bean.targetRect.top - bean.targetHeight / 2;
            } else {
                bean.targetRect.left = bean.originRect.left;
                bean.targetRect.top = bean.originRect.top;
                bean.targetWidth = bean.originWidth;
                bean.targetHeight = bean.originHeight;
                bean.translationX = 0;
                bean.translationY = 0;
            }
            //create a temp ImageView to replace origin view
            final ImageView ivTemp = new ImageView(activity);
            if (bean.bitmap != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    ivTemp.setImageDrawable(new BitmapDrawable(bean.bitmap));
                } else {
                    ivTemp.setBackgroundDrawable(new BitmapDrawable(bean.bitmap));
                }
            }
            if (bean.originRect.top + bean.originHeight > (bean.windowHeight + bean.statusBarHeight + bean.titleHeight)) {
                bean.scalling = (float) (bean.windowHeight + bean.statusBarHeight + bean.titleHeight - bean.originRect.top) / bean.targetHeight;
            } else {
                bean.scalling = (float) bean.originHeight / bean.targetHeight;
            }
            RelativeLayout.LayoutParams ivTempParams = new RelativeLayout.LayoutParams((int) (bean.targetWidth * bean.scalling), (int) (bean.targetHeight * bean.scalling));
            ivTempParams.setMargins((int) (bean.originRect.left + (bean.originWidth / 2 - bean.targetWidth * bean.scalling / 2)), bean.originRect.top - (parent.getTop() + bean.statusBarHeight), 0, 0);
            bean.translationY = bean.originRect.top + (int) (bean.targetHeight * bean.scalling) / 2 - bean.targetRect.top - bean.targetHeight / 2;
            bean.translationX = bean.originRect.left + bean.originWidth / 2 - bean.targetRect.left - bean.targetWidth / 2;
            cirleAnimView.addView(ivTemp, ivTempParams);
            showMethod.translate(bean, cirleAnimView, ivTemp);
            showMethod.loadCopyView(bean, ivTemp);
            showMethod.set.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    cirleAnimView.startCircleAnim(bean);
                    if (showMethod != null && targetView != null) {
                        showMethod.loadTargetView(bean, targetView);
                    }
                }
            });
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) BitmapDrawable(android.graphics.drawable.BitmapDrawable) InflateShowMethod(immortalz.me.library.method.InflateShowMethod) CirleAnimView(immortalz.me.library.view.CirleAnimView) InfoBean(immortalz.me.library.bean.InfoBean) Animator(android.animation.Animator) NoneShowMethod(immortalz.me.library.method.NoneShowMethod) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) RelativeLayout(android.widget.RelativeLayout) ImageView(android.widget.ImageView)

Aggregations

ImageView (android.widget.ImageView)2 InfoBean (immortalz.me.library.bean.InfoBean)2 NoneShowMethod (immortalz.me.library.method.NoneShowMethod)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ViewGroup (android.view.ViewGroup)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 RelativeLayout (android.widget.RelativeLayout)1 InflateShowMethod (immortalz.me.library.method.InflateShowMethod)1 CirleAnimView (immortalz.me.library.view.CirleAnimView)1