use of immortalz.me.library.view.CirleAnimView 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);
}
}
});
}
});
}
Aggregations