| | |
| | | package com.application.zhangshi_app_android.widget; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.Color; |
| | | import android.graphics.Path; |
| | | import android.graphics.drawable.ColorDrawable; |
| | | import android.view.Gravity; |
| | | import android.graphics.Typeface; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.FrameLayout; |
| | | import android.widget.ImageView; |
| | | import android.widget.PopupWindow; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.constraintlayout.utils.widget.ImageFilterView; |
| | | import androidx.databinding.DataBindingUtil; |
| | | |
| | | import com.android.app_base.manager.AppManager; |
| | | import com.android.app_base.utils.GlideUtil; |
| | | import com.android.app_base.utils.ScreenSizeUtils; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.bean.HomeRootBean; |
| | | import com.application.zhangshi_app_android.databinding.PopBasicInformationBinding; |
| | | import com.otaliastudios.zoom.ZoomLayout; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedList; |
| | |
| | | protected HomeRootBean member;//成员 |
| | | protected Node parent;//父节点 |
| | | protected final List<Node> children = new ArrayList<>(); //子节点 |
| | | |
| | | protected HomeMindMapLayout.OnItemClickListener onItemClickListener; |
| | | protected static final int pathLength = ScreenSizeUtils.dip2px(20);// 连线的一般长度 |
| | | protected static final int cornerRadius = ScreenSizeUtils.dip2px(5); // 连线拐角 圆角半径 |
| | | |
| | |
| | | if (member != null) { |
| | | // 递归创建子节点 |
| | | if (member.getChildList() != null && member.getChildList().size() > 0) { |
| | | // 所有可见的子节点需要的宽高总和 |
| | | for (HomeRootBean child : member.getChildList()) { |
| | | // 根据是否有配偶创建不同的节点 |
| | | if (child != null) { |
| | |
| | | protected abstract void setViewPosition(int x, int centerY); |
| | | protected abstract void setForkYList(List<Integer> yList); |
| | | |
| | | protected View createItemView(HomeRootBean bean) { |
| | | /** |
| | | * 创建节点item视图 |
| | | * @param bean 节点数据 |
| | | * @param isFamily 是否是本家成员 |
| | | * @return 节点item视图 |
| | | */ |
| | | protected View createItemView(HomeRootBean bean,boolean isFamily){ |
| | | // 使用布局填充器加载节点布局 |
| | | LayoutInflater inflater = LayoutInflater.from(context); |
| | | View familyMemberView = inflater.inflate(R.layout.item_family_member, null, false); |
| | |
| | | ImageFilterView iv_avatar = familyMemberView.findViewById(R.id.iv_avatar); |
| | | TextView tv_name = familyMemberView.findViewById(R.id.tv_name); |
| | | |
| | | if (!isFamily){ |
| | | tv_name.setTextColor(Color.parseColor("#FF8296C5")); |
| | | tv_name.setTypeface(Typeface.DEFAULT); |
| | | } |
| | | // 设置节点内容 |
| | | tv_generation.setText(String.valueOf(bean.getIdentity())); |
| | | if (bean.getImg() != null) { |
| | |
| | | familyMemberView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | PopBasicInformationBinding mBinding= DataBindingUtil.inflate(inflater,R.layout.pop_basic_information,null,false); |
| | | PopupWindow popupWindow = new PopupWindow(); |
| | | // 设置布局文件 |
| | | popupWindow.setContentView(mBinding.getRoot()); |
| | | // 为了避免部分机型不显示,需要重新设置一下宽高 |
| | | popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); |
| | | popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); |
| | | // 设置pop透明效果 |
| | | popupWindow.setBackgroundDrawable(new ColorDrawable(0x0000)); |
| | | // 设置pop出入动画 |
| | | popupWindow.setAnimationStyle(com.android.app_base.R.style.pop_operate); |
| | | // 设置pop获取焦点,如果为false点击返回按钮会退出当前Activity,如果pop中有Editor的话,focusable必须要为true |
| | | popupWindow.setFocusable(true); |
| | | // 设置pop可点击,为false点击事件无效,默认为true |
| | | popupWindow.setTouchable(true); |
| | | // 设置点击pop外侧消失,默认为false;在focusable为true时点击外侧始终消失 |
| | | popupWindow.setOutsideTouchable(false); |
| | | |
| | | mBinding.setSelfBean(bean); |
| | | mBinding.setSpouseBean(bean.getSpouse()); |
| | | ZoomLayout zoomLayout = (ZoomLayout) familyMemberView.getParent().getParent(); |
| | | popupWindow.setHeight(zoomLayout.getHeight()); |
| | | popupWindow.setWidth(zoomLayout.getWidth()); |
| | | popupWindow.showAtLocation((View) familyMemberView.getParent().getParent(), Gravity.BOTTOM,0,0); |
| | | if (onItemClickListener != null){ |
| | | onItemClickListener.onItemClick(familyMemberView,bean); |
| | | } |
| | | } |
| | | }); |
| | | return familyMemberView; |
| | |
| | | |
| | | // 获取 每个 itemView 的宽度 |
| | | public int getItemViewWidth(){ |
| | | View itemView = createItemView(null); |
| | | View itemView = createItemView(null,false); |
| | | return itemView.getMeasuredWidth(); |
| | | } |
| | | // 获取 每个 itemView 的高度 |
| | | public int getItemViewHeight(){ |
| | | View itemView = createItemView(null); |
| | | View itemView = createItemView(null,false); |
| | | return itemView.getMeasuredHeight(); |
| | | } |
| | | //获取展开按钮的宽度 |
| | |
| | | public int getViewWidth(){ |
| | | return viewBottom - viewTop; |
| | | } |
| | | |
| | | public void setOnItemClickListener(HomeMindMapLayout.OnItemClickListener onItemClickListener) { |
| | | this.onItemClickListener = onItemClickListener; |
| | | //所有的子节点也设置 |
| | | for (Node child : children) { |
| | | child.setOnItemClickListener(onItemClickListener); |
| | | } |
| | | } |
| | | } |