黄学彪
2020-09-18 c7df85937f73fb347ee0b19e9c052d2d00a6df6c
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/CompoundControls/InformationEditorControl.cs
@@ -9,70 +9,153 @@
    /// </summary>
    public class InformationEditorControl
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 明细列表的桌布,白色背景
        /// </summary>
        private FrameLayout detailBackFrame = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private FrameListControl listview = null;
        /// <summary>
        /// 最小高度
        /// </summary>
        private int minHeight = -1;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 初始化控件(返回的是信息容器控件)
        /// </summary>
        /// <param name="bodyFrameLayout">bodyFrameLayout</param>
        /// <param name="bodyFrameLayout">父控件</param>
        /// <param name="title">标题文本</param>
        /// <param name="Y">bodyFrameLayout里面的Y轴坐标</param>
        /// <param name="Height">蓝湖UI里面它的高度</param>
        /// <param name="real">是否计算Height的真实值</param>
        /// <returns>信息容器控件</returns>
        public VerticalListControl InitControl(FrameLayout bodyFrameLayout, string title, int Y, int Height)
        public FrameListControl InitControl(FrameLayout bodyFrameLayout, string title, int Height, bool real = true)
        {
            //弧度的圆的一半的高度(固定)
            int halfRoundHeigth = Application.GetRealHeight(116) / 2;
            //弧度的圆
            var btnRound = new NormalViewControl(bodyFrameLayout.Width, halfRoundHeigth * 2, false);
            btnRound.Y = Application.GetRealHeight(Y);
            btnRound.BackgroundColor = UserCenterColor.Current.White;
            btnRound.Radius = (uint)halfRoundHeigth;
            bodyFrameLayout.AddChidren(btnRound);
            //明细列表的桌布,白色背景(覆盖弧度的圆的半边)
            var detailBackFrame = new FrameLayout();
            detailBackFrame.Y = btnRound.Bottom - btnRound.Height / 2;
            detailBackFrame.Height = Application.GetRealHeight(Height);//高度就是要它超过
            if (real == true) { Height = Application.GetRealHeight(Height); }
            //明细列表的桌布,白色背景
            this.detailBackFrame = new FrameLayout();
            detailBackFrame.Height = Height;
            detailBackFrame.BackgroundColor = UserCenterColor.Current.White;
            detailBackFrame.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            detailBackFrame.Gravity = Gravity.BottomCenter;
            bodyFrameLayout.AddChidren(detailBackFrame);
            this.minHeight = detailBackFrame.Height;
            //信息编辑
            var btnTile = new NormalViewControl(800, 60, true);
            btnTile.X = ControlCommonResourse.XXLeft;
            btnTile.Y = Application.GetRealHeight(81);
            btnTile.TextSize = 15;
            btnTile.TextColor = UserCenterColor.Current.TextColor2;
            btnTile.Text = title;
            detailBackFrame.AddChidren(btnTile);
            var listview = new VerticalListControl(12);
            //列表控件
            this.listview = new FrameListControl(12);
            listview.Y = btnTile.Bottom + Application.GetRealHeight(17);
            listview.Height = Application.GetRealHeight(Height) - halfRoundHeigth - btnTile.Bottom - Application.GetRealHeight(17);
            listview.Height = Application.GetRealHeight(Height) - btnTile.Bottom - Application.GetRealHeight(17);
            detailBackFrame.AddChidren(listview);
            return listview;
        }
        /// <summary>
        /// 完成初始化(当行数多的时候,这个函数很有用。行数不超过容器时,调不调用这个函数都没事)
        /// 完成初始化
        /// </summary>
        /// <param name="bodyFrameLayout">bodyFrameLayout</param>
        /// <param name="listview">容器控件</param>
        public void FinishInitControl(FrameLayout bodyFrameLayout, VerticalListControl listview)
        /// <param name="HadBottomButton">这个控件所在的界面,底部有没有保存按钮</param>
        /// <param name="mandatoryAdjustment">强制调整高度</param>
        public void FinishInitControl(bool HadBottomButton = true, bool mandatoryAdjustment = false)
        {
            var btnFinish = new BottomClickButton();
            //借用Y轴坐标(让这个区域不能点击菜单)
            var frameBack = new FrameLayout();
            frameBack.Y = btnFinish.Yaxis;
            frameBack.Height = bodyFrameLayout.Height - btnFinish.Yaxis;
            bodyFrameLayout.AddChidren(frameBack);
            var realHeight = listview.GetChildren(0).Height * listview.ChildrenCount;
            if (bodyFrameLayout.Height - btnFinish.Yaxis + realHeight > listview.Height)
            if (HadBottomButton == true)
            {
                var btnFinish = new BottomClickButton();
                //让它别改变坐标
                int tempSpace = listview.rowSpace;
                listview.rowSpace = 0;
                //促使被挡住的菜单能够向上滑动
                var frameTemp = new FrameLayout();
                frameTemp.Height = frameBack.Height + Application.GetRealHeight(115);
                frameTemp.Height = ControlCommonResourse.BodyFrameHeight - btnFinish.Yaxis + Application.GetRealHeight(23);
                listview.AddChidren(frameTemp);
                listview.rowSpace = tempSpace;
            }
            btnFinish = null;
            //调整容器高度大小
            int value = this.GetLocationMostLastViewBottom();
            if (mandatoryAdjustment == false)
            {
                if (value + Application.GetRealHeight(23) < listview.Height)
                {
                    //不需要调整
                    return;
                }
            }
            //调整大小
            listview.Height = value + Application.GetRealHeight(23);
            int backHeigth = listview.Bottom;
            if (minHeight > backHeigth)
            {
                //它有个最小高度
                backHeigth = minHeight;
            }
            this.detailBackFrame.Height = backHeigth;
            //获取listview所在的全局容器控件
            var contrFather = GetVerticalFrameControl(listview);
            //调整桌布大小
            contrFather?.AdjustTableHeight();
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 获取listview所在的全局容器控件
        /// </summary>
        /// <param name="listview"></param>
        /// <returns></returns>
        private VerticalFrameControl GetVerticalFrameControl(FrameListControl listview)
        {
            var myContr = listview.Parent;
            while (myContr != null)
            {
                if (myContr is VerticalFrameControl)
                {
                    return (VerticalFrameControl)myContr;
                }
                myContr = myContr.Parent;
            }
            return null;
        }
        /// <summary>
        /// 获取坐标底部最下面的那个控件的底部坐标
        /// </summary>
        /// <returns></returns>
        private int GetLocationMostLastViewBottom()
        {
            int bottomHeight = -1;
            for (int i = 0; i < this.listview.ChildrenCount; i++)
            {
                var child = this.listview.GetChildren(i);
                if (child.Bottom > bottomHeight)
                {
                    bottomHeight = child.Bottom;
                }
            }
            return bottomHeight;
        }
        #endregion
    }
}