using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Shared.Phone.UserCenter
{
///
/// 个人中心的共通基层画面,继承于此共通的画面,请使用AddForm()函数,
/// 或者AddFromAndRemoveNowForm()函数实现添加画面,然后在各自的画面中,
/// 实现一个ShowForm()的函数(参数由添加画面时,使用的函数的参数指定)
///
public class EditorCommonForm : CommonFormBase
{
#region ■ 变量声明___________________________
///
/// TopMenuFrameLayout
///
public FrameLayout topMenuFrameLayout = null;
///
/// TopFrameLayout
///
public FrameLayout topFrameLayout = null;
///
/// bodyFrameLayout
///
public FrameLayout bodyFrameLayout = null;
///
/// 缓存启动参数
///
private object[] m_parameter = null;
#endregion
#region ■ 初始化_____________________________
///
/// 初始化界面框架
///
public override void InitForm()
{
base.InitForm();
//初始化头部控件
this.InitTopFrameLayout();
//初始化中部控件
this.InitBodyFrameLayout();
}
///
/// 执行ShowForm()方法
///
/// 启动参数
public override void LoadShowFormMethod(params object[] parameter)
{
this.m_parameter = parameter;
base.LoadShowFormMethod(parameter);
}
#endregion
#region ■ 初始化界面_________________________
#region ■ Top________________________________
///
/// 初始化头部控件
///
public void InitTopFrameLayout()
{
if (topFrameLayout != null)
{
topFrameLayout.RemoveAll();
}
//TopMenuFrameLayout做成
topMenuFrameLayout = new FrameLayout();
topMenuFrameLayout.Height = ControlCommonResourse.TopMenuFrameHeight;
topMenuFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
topMenuFrameLayout.Name = "topMenuFrameLayout";
this.AddChidren(topMenuFrameLayout);
//TopFrameLayout做成
topFrameLayout = new FrameLayout();
topFrameLayout.Height = ControlCommonResourse.TopFrameHeight;
topFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
topFrameLayout.Y = topMenuFrameLayout.Bottom;
topFrameLayout.Name = "topFrameLayout";
this.AddChidren(topFrameLayout);
//线
var btnLine = new NormalViewControl(topFrameLayout.Width, 1, false);
btnLine.BackgroundColor = 0x40000000;
btnLine.Y = topFrameLayout.Height - 1;
topFrameLayout.AddChidren(btnLine);
//返回键
var btnBack = new BackViewControl();
topFrameLayout.AddChidren(btnBack);
btnBack.InitControl();
btnBack.ButtonClickEvent += (sender, e) =>
{
//画面关闭
this.CloseForm();
};
topFrameLayout.AddTag("btnBack", btnBack);
//标题
var txttitle = new TopLayoutTitleControl();
topFrameLayout.AddChidren(txttitle);
//粗体
txttitle.IsBold = true;
topFrameLayout.AddTag("txtTitle", txttitle);
}
#endregion
#region ■ Middle_____________________________
///
/// 初始化中部控件
///
public void InitBodyFrameLayout()
{
if (bodyFrameLayout != null)
{
bodyFrameLayout.RemoveAll();
}
bodyFrameLayout = new FrameLayout();
bodyFrameLayout.Height = ControlCommonResourse.BodyFrameHeight;
bodyFrameLayout.Y = topFrameLayout.Bottom;
bodyFrameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
bodyFrameLayout.Name = "bodyFrameLayout";
this.AddChidren(bodyFrameLayout);
}
#endregion
#endregion
#region ■ 添加界面___________________________
///
/// 添加画面,启动参数由指定画面的ShowForm函数所指定
///
/// 启动参数:参数由指定画面的ShowForm函数所指定
public override void AddForm(params object[] parameter)
{
//检测能否追加画面
if (UserCenterLogic.CheckCanAddForm(this) == false)
{
return;
}
UserView.HomePage.Instance.AddChidren(this);
UserView.HomePage.Instance.PageIndex += 1;
//初始化界面框架
this.InitForm();
//执行ShowForm()方法
this.LoadShowFormMethod(parameter);
}
#endregion
#region ■ 关闭界面___________________________
///
/// 画面关闭
///
public override void CloseFormBefore()
{
this.m_parameter = null;
//清空bodyFrame
this.ClearBodyFrame();
base.CloseFormBefore();
}
#endregion
#region ■ 显示重新加载_______________________
///
/// 显示重新加载的界面(主要是用在界面加载错误时,再次加载)
///
public override void ShowReLoadView()
{
Application.RunOnMainThread(() =>
{
if (bodyFrameLayout == null || bodyFrameLayout.Parent == null)
{
return;
}
//切换为重新加载模式时的事件
this.ReLoadModelEventMethod();
var frame = new FrameLayout();
frame.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frame);
//重新加载
var btnReLoad = new BottomClickButton();
btnReLoad.Gravity = Gravity.Center;
btnReLoad.TextID = R.MyInternationalizationString.uDoReload;
frame.AddChidren(btnReLoad);
btnReLoad.ButtonClickEvent += (sender, e) =>
{
//清除全部控件
this.ClearBodyFrame();
//执行ShowForm()方法实现重新加载
this.LoadShowFormMethod(this.m_parameter);
};
//清除topFrameLayout的非默认的控件
var list = new List();
for (int i = 0; i < topFrameLayout.ChildrenCount; i++)
{
var view = topFrameLayout.GetChildren(i);
if (view.Name == "btnBack" || view.Name == "txtTitle")
{
//这里是默认的底层控件
continue;
}
list.Add(view);
}
foreach (var view in list)
{
view?.RemoveFromParent();
}
});
}
///
/// 切换为【重新加载模式】时的事件函数,旨在关闭所有线程信息
///
public virtual void ReLoadModelEventMethod()
{
}
#endregion
#region ■ 添加帮助控件_______________________
///
/// 添加查看帮助控件
///
///
public NormalViewControl AddHelpControl()
{
//查看帮助
var btnHelp = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false);
btnHelp.Y = Application.GetRealHeight(1388);
btnHelp.TextSize = 12;
btnHelp.TextAlignment = TextAlignment.Center;
btnHelp.TextColor = UserCenterColor.Current.TextOrangeColor;
btnHelp.Text = Language.StringByID(R.MyInternationalizationString.uSearchHelp);
bodyFrameLayout.AddChidren(btnHelp);
//底线
int lineWidth = btnHelp.GetRealWidthByText();
var btnLine = new NormalViewControl(lineWidth, ControlCommonResourse.BottomLineHeight, false);
btnLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
btnLine.Gravity = Gravity.CenterHorizontal;
btnLine.Y = btnHelp.Bottom - Application.GetRealHeight(8);
bodyFrameLayout.AddChidren(btnLine);
return btnHelp;
}
#endregion
#region ■ 显示没有数据的图像显示特效_________
///
/// 显示没有数据的图像显示特效
///
/// 容器
/// 显示文字
/// 图像地址
/// 图像宽度(非真实值)
/// 图像高度(非真实值)
public void ShowNotDataImage(FrameLayout frameTable, string i_Text, string Imagepath = "Item/NoFunction.png", int imageWith = 683, int imageHeight = 392)
{
this.ShowNotDataImage(frameTable, new string[] { i_Text }, Imagepath, imageWith, imageHeight);
}
///
/// 显示没有数据的图像显示特效
///
/// 容器
/// 显示文字
/// 图像地址
/// 图像宽度(非真实值)
/// 图像高度(非真实值)
public void ShowNotDataImage(FrameLayout frameTable, string[] listText, string Imagepath = "Item/NoFunction.png", int imageWith = 683, int imageHeight = 392)
{
var btnPic = new PicViewControl(imageWith, imageHeight);
btnPic.UnSelectedImagePath = Imagepath;
btnPic.Y = (int)(frameTable.Height * 0.382) - Application.GetRealHeight(imageHeight / 2);
btnPic.Gravity = Gravity.CenterHorizontal;
frameTable.AddChidren(btnPic);
int yy = btnPic.Bottom + Application.GetRealHeight(32);
for (int i = 0; i < listText.Length; i++)
{
var btnView = new NormalViewControl(frameTable.Width, Application.GetRealHeight(50), false);
btnView.Y = yy;
btnView.Text = listText[i];
btnView.TextAlignment = TextAlignment.Center;
btnView.TextSize = 12;
btnView.TextColor = UserCenterColor.Current.TextGrayColor1;
frameTable.AddChidren(btnView);
yy = btnView.Bottom;
}
}
#endregion
#region ■ 界面重新激活事件___________________
///
/// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
/// 重写的时候返回值请返回1(返回值是给底层使用的)
///
public virtual int FormActionAgainEvent()
{
return -1;
}
#endregion
#region ■ 清空BodyFrame______________________
///
/// 清空BodyFrame
///
public void ClearBodyFrame()
{
if (this.Parent == null)
{
return;
}
bodyFrameLayout?.RemoveAll();
}
#endregion
#region ■ 一般的方法_________________________
///
/// 设置标题信息
///
/// Title.
public void SetTitleText(string title)
{
//设置头部信息
var btntitle = (Button)topFrameLayout.GetTagByKey("txtTitle");
btntitle.Text = title;
}
///
/// 移除返回键
///
public void RemoveBackButton()
{
//移除返回键
var back = (BackViewControl)topFrameLayout.GetTagByKey("btnBack");
back?.RemoveFromParent();
}
#endregion
}
}