Merge branch 'qa_topview' into qa

This commit is contained in:
tongchenfei
2020-06-17 15:46:10 +08:00
4 changed files with 91 additions and 35 deletions

View File

@@ -49,7 +49,6 @@ import com.mogo.service.module.IMogoRegisterCenter;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.IMogoStatusManager;
import com.mogo.service.statusmanager.StatusDescriptor;
import com.mogo.utils.AppUtils;
import com.mogo.utils.LaunchUtils;
import com.mogo.utils.ResourcesHelper;
import com.mogo.utils.UiThreadHandler;
@@ -184,6 +183,8 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
private List< View > demoCache = new ArrayList<>();
private int[] heights = new int[]{100,200,300};
@Override
protected void initViews() {
mApis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation( getContext() );
@@ -200,9 +201,12 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
// // todo 测试动画
// View v = LayoutInflater.from(getContext()).inflate(R.layout.demo_top, null);
// TextView tv = v.findViewById(R.id.tvIndex);
// tv.setText(demoCache.size() + ": " + v);
// Random random = new Random();
// int height = heights[random.nextInt(3)];
// tv.setText(demoCache.size()+" height: "+height + ": " + v);
// demoCache.add(v);
// mApis.getTopViewManager().addView(v, new IMogoTopViewStatusListener() {
// LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, height);
// mApis.getTopViewManager().addView(v, params,new IMogoTopViewStatusListener() {
// @Override
// public void onViewAdded(View view) {
// Logger.d(TAG, "onViewAdded: " + view);
@@ -212,6 +216,16 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
// public void onViewRemoved(View view) {
// Logger.d(TAG, "onViewRemoved: " + view);
// }
//
// @Override
// public void beforeViewAddAnim(View view) {
// Logger.d(TAG, "beforeViewAddAnim: " + view);
// }
//
// @Override
// public void beforeViewRemoveAnim(View view) {
// Logger.d(TAG, "beforeViewRemoveAnim: " + view);
// }
// });
// 原始逻辑
showShareDialog();

View File

@@ -82,6 +82,12 @@ public class TopView extends FrameLayout {
});
}
@Override
public void onViewRemoved(View child) {
super.onViewRemoved(child);
Logger.d("TopView", "onViewRemoved: " + child);
}
public interface OnChildAddedListener {
/**
* 子view添加完成但是并不确定已经绘制完成

View File

@@ -8,6 +8,7 @@ import android.transition.TransitionManager;
import android.util.ArrayMap;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.BounceInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
@@ -152,7 +153,7 @@ public class TopViewAnimHelper {
hideNaviView();
}
private boolean isTopViewOut = true;
private volatile boolean isTopViewOut = true;
private List<View> viewCaches = new ArrayList<>();
private Map<View, IMogoTopViewStatusListener> statusListenerMap = new ArrayMap<>();
@@ -174,12 +175,38 @@ public class TopViewAnimHelper {
}
if (!viewCaches.contains(view)) {
// 判断此view是否已经增加到了顶部view如果增加过就不增加了
view.setTranslationY(0);
statusListenerMap.put(view, statusListener);
Logger.d(TAG, "开始执行");
isTopViewOut = false;
if (topContainer.getChildCount() > 0) {
// 顶部view已经有了内容新增内容无需整体布局变化只是新增布局加个动画
viewCaches.add(view);
// 生硬的删掉上一个view
View lastView = topContainer.getChildAt(0);
if (statusListenerMap.get(lastView) != null) {
statusListenerMap.get(lastView).beforeViewRemoveAnim(lastView);
}
topContainer.removeView(lastView);
viewCaches.remove(lastView);
if (statusListenerMap.get(lastView) != null) {
statusListenerMap.remove(lastView).onViewRemoved(lastView);
}
// 如果高度变化,生硬的变化一下高度
Logger.d(TAG,"container.height: "+topContainer.getHeight());
if (topContainer.getHeight() != params.height) {
constraintSet.clone(topMotionLayout);
LayoutParams p = topContainer.getLayoutParams();
p.height = params.height;
topContainer.setLayoutParams(p);
constraintSet.connect(naviBg.getId(), ConstraintSet.TOP,
R.id.module_entrance_id_top_motion_layout, ConstraintSet.TOP,
computeNaviMarginTop(params.height));
constraintSet.applyTo(topMotionLayout);
Logger.d(TAG,"改变container的高度===");
}
view.setTranslationY(-(params.height));
topContainer.addView(view, params);
Logger.d(TAG, "顶部view已经有布局了增加新增view滑入动画: " + view.getTranslationY() + " height:" +
@@ -220,10 +247,13 @@ public class TopViewAnimHelper {
// tvNextRoad.setTextSize(getDimen(R.dimen.dp_34));
// }
topContainer.addView(view, params);
Logger.d(TAG, "整体进入==== view.visibility: " + view.getVisibility() + " view" +
".position: (" + view.getX() + ", " + view.getY() + ") params.width: " + params.width + " params.height: " + params.height);
if (statusListenerMap.get(view) != null) {
statusListenerMap.get(view).beforeViewAddAnim(view);
}
topContainer.setChildAddedListener(child -> {
topContainer.setChildAddedListener(null);
if (naviBg.getVisibility() == View.VISIBLE) {
remainDistanceGroup.setVisibility(View.GONE);
remainTimeGroup.setVisibility(View.GONE);
@@ -258,7 +288,7 @@ public class TopViewAnimHelper {
constraintSet.connect(naviBg.getId(), ConstraintSet.TOP,
R.id.module_entrance_id_top_motion_layout, ConstraintSet.TOP,
(int) getDimen(R.dimen.dp_316));
computeNaviMarginTop(params.height));
}
constraintSet.applyTo(topMotionLayout);
ivTurnIcon.getLayoutParams().height =
@@ -452,7 +482,7 @@ public class TopViewAnimHelper {
(int) topMotionLayout.getContext().getResources().getDimension(R.dimen.dp_46));
constraintSet.connect(naviBg.getId(), ConstraintSet.TOP,
R.id.module_entrance_id_top_motion_layout, ConstraintSet.TOP,
(int) getDimen(R.dimen.dp_316));
computeNaviMarginTop(topContainer.getHeight()));
// ivTurnIcon.getLayoutParams().height =
// (int) getDimen(R.dimen.module_ext_navi_info_panel_turn_icon_small_height);
// ivTurnIcon.getLayoutParams().width =
@@ -521,6 +551,12 @@ public class TopViewAnimHelper {
return (int) topMotionLayout.getContext().getResources().getDimension(resId);
}
private int computeNaviMarginTop(int height) {
int result = (int) (height - (getDimen(R.dimen.dp_350) - getDimen(R.dimen.dp_316)));
Logger.d(TAG, "computeNaviMarginTop: " + height + " result: " + result);
return result;
}
interface OnTopViewAnimSimpleListener {
void onAnimStart();