use of immortalz.me.library.bean.InfoBean 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);
}
}
});
}
});
}
use of immortalz.me.library.bean.InfoBean in project TransitionHelper by ImmortalZ.
the class TransitionsHeleper method startActivity.
private static void startActivity(final Activity activity, final Class<?> cls, Intent intent, final View view, final String imgUrl) {
if (intent == null) {
intent = new Intent(activity, cls);
}
final InfoBean bean = new InfoBean();
final Intent finalIntent = intent;
view.post(new Runnable() {
@Override
public void run() {
//get statusBar height
view.getWindowVisibleDisplayFrame(bean.originRect);
bean.statusBarHeight = bean.originRect.top;
//get Origin View's rect
view.getGlobalVisibleRect(bean.originRect);
bean.originWidth = view.getWidth();
bean.originHeight = view.getHeight();
if (TextUtils.isEmpty(imgUrl)) {
bean.bitmap = createBitmap(view, bean.originWidth, bean.originHeight, false);
} else {
bean.setImgUrl(imgUrl);
}
finalIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
staticMap.put(finalIntent.getComponent().getClassName(), bean);
activity.startActivity(finalIntent);
activity.overridePendingTransition(0, 0);
}
});
}
use of immortalz.me.library.bean.InfoBean in project TransitionHelper by ImmortalZ.
the class FDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportFragmentManager().beginTransaction().replace(R.id.container, DetailFragment.newInstance()).commit();
TransitionsHeleper.getInstance().setShowMethod(new ColorShowMethod(R.color.bg_purple, R.color.bg_teal) {
@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();
}
@Override
public void loadTargetView(InfoBean bean, ImageView targetView) {
}
}).show(this, null);
}
Aggregations