package com.application.zhangshi_app_android.widget;
|
|
import android.content.Context;
|
import android.graphics.Path;
|
import android.graphics.RectF;
|
import android.view.View;
|
import android.widget.ImageView;
|
|
import com.android.app_base.utils.ScreenSizeUtils;
|
import com.application.zhangshi_app_android.R;
|
import com.application.zhangshi_app_android.bean.HomeRootBean;
|
|
import java.util.List;
|
|
/**
|
* @author Ljj
|
* @date 2023.08.13. 7:39
|
* @desc 双亲节点
|
*/
|
public class DoubleNode extends Node{
|
private View memberItemView;//成员view
|
private ImageView expandIconView;//展开按钮
|
private View spouseView;//配偶view
|
|
public DoubleNode(Context context,HomeRootBean member) {
|
super(context,member);
|
member.getSpouse().setSpouse(member);
|
//双亲节点 前后路径长度 有两倍的 pathLength
|
if (member.getIdentity() > 1 && member.getChildList() != null && member.getChildList().size() > 0){
|
//非 第一代 且 有子代, 节点宽度 = view宽度 + 前后路径长度 + 展开按钮宽度
|
width = pathLength * 2 + getItemViewWidth() + pathLength * 2 + getExpandIconWidth();
|
}else if (member.getIdentity() > 1 && (member.getChildList() == null || member.getChildList().size() == 0)) {
|
//非 第一代 且 无子代, 节点宽度 = view宽度 + 前路径长度
|
width = getItemViewWidth() + pathLength * 2;
|
}else if (member.getIdentity() == 1 && member.getChildList() != null && member.getChildList().size() > 0) {
|
//第一代 且 有子代, 节点宽度 = view宽度 + 后路径长度 + 展开按钮宽度
|
width = getItemViewWidth() + pathLength * 2+ getExpandIconWidth();
|
}else if (member.getIdentity() == 1 && (member.getChildList() == null || member.getChildList().size() == 0)) {
|
//第一代 且 无子代, 节点宽度 = view宽度
|
width = getItemViewWidth();
|
}
|
//双亲节点 高度 = view高度 + 配偶view高度 + 配偶view上下间距
|
height = getItemViewHeight() * 2 + spouseMargin;
|
initView();
|
}
|
|
private void initView() {
|
memberItemView = createItemView(member, true);
|
spouseView = createItemView(member.getSpouse(),false);
|
expandIconView = createExpandIconView();
|
viewList.add(memberItemView);
|
viewList.add(spouseView);
|
viewList.add(expandIconView);
|
|
if (isExpand){
|
expandIconView.setBackgroundResource(R.drawable.ic_collapse);
|
}else {
|
expandIconView.setBackgroundResource(R.drawable.ic_expand);
|
}
|
expandIconView.setOnClickListener(v -> {
|
if (isExpand){
|
expandIconView.setBackgroundResource(R.drawable.ic_expand);
|
for (Node child : children) {
|
child.setVisible(false);
|
}
|
isExpand = false;
|
}else {
|
expandIconView.setBackgroundResource(R.drawable.ic_collapse);
|
for (Node child : children) {
|
child.setVisible(true);
|
}
|
isExpand = true;
|
}
|
memberItemView.requestLayout();
|
spouseView.requestLayout();
|
});
|
}
|
|
@Override
|
protected void setViewPosition(int x, int centerY) {
|
left = x;
|
right = left + width;
|
this.centerY = centerY;
|
top = centerY - height/2;
|
bottom = top + height;
|
|
if (member.getIdentity() > 1) {//非 第一代 才有前置连线
|
viewLeft = left + 2 * pathLength;
|
} else {
|
viewLeft = left;
|
}
|
memberItemView.setX(viewLeft);
|
memberItemView.setY(centerY - memberItemView.getMeasuredHeight() - spouseMargin/2f);
|
viewRight = viewLeft + memberItemView.getMeasuredWidth();
|
|
spouseView.setX(viewLeft);
|
spouseView.setY(centerY + spouseMargin/2f);
|
|
viewTop = (int) memberItemView.getY();
|
viewBottom = (int) (spouseView.getY() + spouseView.getMeasuredHeight());
|
|
expandIconView.setX(viewRight + pathLength * 2);
|
expandIconView.setY(centerY - expandIconView.getMeasuredHeight()/2f);
|
|
setPath();
|
}
|
|
private void setPath() {
|
//setPath 之前,先清空
|
prePathList.clear();
|
nextPathList.clear();
|
|
if (member.getChildList() != null && member.getChildList().size() > 0){//有子节点,才有后置连线,才有展开按钮
|
expandIconView.setVisibility(View.VISIBLE);
|
float rLeft = viewRight;
|
float rRight = viewRight + pathLength;
|
float rTop = memberItemView.getY()+memberItemView.getMeasuredHeight()/2f;
|
float rBottom = spouseView.getY()+spouseView.getMeasuredHeight()/2f;
|
Path path = new Path();
|
//左上角
|
path.moveTo(rLeft, rTop);
|
// ---
|
path.lineTo(rRight - cornerRadius, rTop);
|
// 添加圆弧路径,右上角的圆角
|
path.arcTo(new RectF(rRight-2*cornerRadius, rTop, rRight, rTop+2*cornerRadius), 270, 90, false);
|
// ----
|
// |
|
// |
|
path.lineTo(rRight, rBottom - cornerRadius);
|
// 添加圆弧路径,右下角的圆角
|
path.arcTo(new RectF(rRight - 2 * cornerRadius, rBottom - 2 * cornerRadius, rRight, rBottom), 0, 90, false);
|
// ----
|
// |
|
// |
|
// ----
|
path.lineTo(rLeft, rBottom);
|
//移到右中间
|
path.moveTo(rRight, centerY);
|
// ----
|
// |____
|
// |
|
// ----
|
path.lineTo(rRight + pathLength, centerY);
|
nextPathList.add(path);
|
|
}else {
|
expandIconView.setVisibility(View.GONE);
|
viewList.remove(expandIconView);
|
}
|
if (member.getIdentity() > 1){//非 第一代 才有前置连线
|
float rLeft = viewLeft - pathLength;
|
float rRight = viewLeft;
|
float rTop = memberItemView.getY()+memberItemView.getMeasuredHeight()/2f;
|
float rBottom = spouseView.getY()+spouseView.getMeasuredHeight()/2f;
|
Path path = new Path();
|
//右上角
|
path.moveTo(rRight, rTop);
|
// ---
|
path.lineTo(rLeft + cornerRadius, rTop);
|
// 添加圆弧路径,左上角的圆角
|
path.arcTo(new RectF(rLeft, rTop, rLeft+2*cornerRadius, rTop+2*cornerRadius), 270, -90, false);
|
// ----
|
// |
|
// |
|
path.lineTo(rLeft, rBottom - cornerRadius);
|
// 添加圆弧路径,左下角的圆角
|
path.arcTo(new RectF(rLeft, rBottom - 2 * cornerRadius, rLeft + 2 * cornerRadius, rBottom), 180, -90, false);
|
// ----
|
// |
|
// |
|
// ----
|
path.lineTo(rRight, rBottom);
|
//移到左中间
|
path.moveTo(rLeft, centerY);
|
// ----
|
// ___|
|
// |
|
// ----
|
path.lineTo(rLeft - pathLength, centerY);
|
prePathList.add(path);
|
}
|
}
|
|
//设置分叉点Y坐标集合
|
public void setForkYList(List<Integer> yList){
|
if (yList == null || yList.size() < 2){
|
return;
|
}
|
forkPathList.clear();
|
|
//取出最大和最小
|
int rBottom = 0;
|
int rTop = 0;
|
for (int i = 0; i < yList.size(); i++) {
|
if (i == 0){
|
rTop = yList.get(i);
|
rBottom = yList.get(i);
|
}else {
|
if (yList.get(i) > rBottom){
|
rBottom = yList.get(i);
|
}
|
if (yList.get(i) < rTop){
|
rTop = yList.get(i);
|
}
|
}
|
}
|
yList.remove((Integer) rTop);
|
yList.remove((Integer) rBottom);
|
|
float rLeft = right + pathLength;
|
float rRight = rLeft + pathLength;
|
Path path = new Path();
|
//右上角
|
path.moveTo(rRight, rTop);
|
// ---
|
path.lineTo(rLeft + cornerRadius, rTop);
|
// 添加圆弧路径,左上角的圆角
|
path.arcTo(new RectF(rLeft, rTop, rLeft+2*cornerRadius, rTop+2*cornerRadius), 270, -90, false);
|
// ----
|
// |
|
// |
|
path.lineTo(rLeft, rBottom - cornerRadius);
|
// 添加圆弧路径,左下角的圆角
|
path.arcTo(new RectF(rLeft, rBottom - 2 * cornerRadius, rLeft + 2 * cornerRadius, rBottom), 180, -90, false);
|
// ----
|
// |
|
// |
|
// ----
|
path.lineTo(rRight, rBottom);
|
//移到左中间
|
path.moveTo(rLeft, centerY);
|
// ----
|
// ___|
|
// |
|
// ----
|
path.lineTo(rLeft - pathLength, centerY);
|
for (Integer y : yList) {
|
path.moveTo(rLeft, y);
|
path.lineTo(rRight, y);
|
}
|
forkPathList.add(path);
|
}
|
|
}
|