using System;
|
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// 个人中心的共通基层画面,继承于此共通的画面,请使用AddForm()函数,
|
/// 或者AddFromAndRemoveNowForm()函数实现添加画面,然后在各自的画面中,
|
/// 实现一个ShowForm()的函数(参数由添加画面时,使用的函数的参数指定)
|
/// </summary>
|
public class UserCenterCommonForm : FrameLayout
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// TopMenuFrameLayout
|
/// </summary>
|
public FrameLayout topMenuFrameLayout = null;
|
/// <summary>
|
/// TopFrameLayout
|
/// </summary>
|
public FrameLayout topFrameLayout = null;
|
/// <summary>
|
/// bodyFrameLayout
|
/// </summary>
|
public FrameLayout bodyFrameLayout = null;
|
/// <summary>
|
/// 画面的ID(自动编号,唯一主键,和各页面并无任何逻辑关系,但是它的用处大着呢)
|
/// </summary>
|
public string FormID = string.Empty;
|
/// <summary>
|
/// 缓存启动参数
|
/// </summary>
|
private object[] m_parameter = null;
|
|
#endregion
|
|
#region ■ 可重载的方法_______________________
|
|
/// <summary>
|
/// 初始化界面框架
|
/// </summary>
|
public void InitForm()
|
{
|
//将当前的画面保存到内存当中
|
UserCenterLogic.AddActionForm(this);
|
|
//初始化头部控件
|
this.InitTopFrameLayout();
|
|
//初始化中部控件
|
this.InitBodyFrameLayout();
|
}
|
|
/// <summary>
|
/// 执行ShowForm()方法
|
/// </summary>
|
/// <param name="parameter">启动参数</param>
|
public void LoadShowFormMethod(params object[] parameter)
|
{
|
this.m_parameter = parameter;
|
this.LoadFormMethodByName(this, "ShowForm", parameter);
|
}
|
|
/// <summary>
|
/// 画面关闭
|
/// </summary>
|
/// <param name="isCloseForm">是否关闭界面,false的时候,只会调用关闭函数里面的附加功能</param>
|
public virtual void CloseForm(bool isCloseForm = true)
|
{
|
//移除接受在线状态推送
|
this.RemoveGatewayOnlinePush();
|
|
if (isCloseForm == false)
|
{
|
//不关闭界面
|
return;
|
}
|
|
this.bodyFrameLayout.RemoveAll();
|
|
//从列表中移除(防止画面二重添加)
|
UserCenterLogic.RemoveActionForm(this);
|
|
//调用的是Base的移除控件函数
|
//而不是调用this的移除控件函
|
base.RemoveFromParent();
|
}
|
|
/// <summary>
|
/// 画面关闭(在画面里面,请不要调用此方法,请使用CloseForm()方法)
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
//画面右滑时,关闭画面,调用自定义的CloseForm()方法
|
this.CloseForm();
|
}
|
|
#endregion
|
|
#region ■ 添加界面___________________________
|
|
/// <summary>
|
/// 添加画面,启动参数由指定画面的ShowForm函数所指定
|
/// </summary>
|
/// <param name="newform">对象画面</param>
|
/// <param name="parameter">启动参数:参数由指定画面的ShowForm函数所指定</param>
|
public void AddForm(UserCenterCommonForm newform, params object[] parameter)
|
{
|
//检测能否追加画面(防止画面二重添加),当点击过快时,会有几率二重添加
|
if (UserCenterLogic.CheckCanAddForm(newform) == false)
|
{
|
return;
|
}
|
|
UserView.HomePage.Instance.AddChidren(newform);
|
UserView.HomePage.Instance.PageIndex += 1;
|
|
//初始化界面框架
|
newform.InitForm();
|
//执行ShowForm()方法
|
newform.LoadShowFormMethod(parameter);
|
}
|
|
/// <summary>
|
/// 添加指定画面,并移除当前画面,启动参数由指定画面的ShowForm函数所指定
|
/// </summary>
|
/// <param name="newform">对象画面</param>
|
/// <param name="parameter">启动参数:参数由指定画面的ShowForm函数所指定</param>
|
public void AddFromAndRemoveNowForm(UserCenterCommonForm newform, params object[] parameter)
|
{
|
//移除当前画面
|
this.CloseForm();
|
//添加画面
|
this.AddForm(newform, parameter);
|
}
|
|
#endregion
|
|
#region ■ 初始化界面_________________________
|
|
#region ■ Top________________________________
|
|
/// <summary>
|
/// 初始化头部控件
|
/// </summary>
|
public void InitTopFrameLayout()
|
{
|
//初始化头部FrameLayout
|
this.InitTopFrameLayout(this, ref topFrameLayout);
|
//返回键
|
BackViewControl back = (BackViewControl)topFrameLayout.GetTagByKey("btnBack");
|
back.MouseUpEventHandler += (sender, e) =>
|
{
|
//this.Animate = Animate.LeftToRight;
|
//画面关闭
|
this.CloseForm();
|
};
|
}
|
|
/// <summary>
|
/// Top标准化
|
/// </summary>
|
private void InitTopFrameLayout(FrameLayout FormframeLayout, ref FrameLayout TopframeLayout)
|
{
|
//头部做成
|
MakeTopLayout(FormframeLayout, ref TopframeLayout);
|
}
|
|
/// <summary>
|
/// 头部做成
|
/// </summary>
|
/// <param name="form">Form.</param>
|
/// <param name="topframe">Topframe.</param>
|
private void MakeTopLayout(FrameLayout form, ref FrameLayout topframe)
|
{
|
if (topframe != null)
|
{
|
topframe.RemoveAll();
|
}
|
|
//TopMenuFrameLayout做成
|
topMenuFrameLayout = this.MakeTopMenuLayout();
|
topMenuFrameLayout.Name = "topMenuFrameLayout";
|
form.AddChidren(topMenuFrameLayout);
|
|
//TopFrameLayout做成
|
topframe = this.MakeTopLayout();
|
topframe.Y = topMenuFrameLayout.Bottom;
|
topframe.Name = "topFrameLayout";
|
form.AddChidren(topframe);
|
|
//返回键
|
BackViewControl btnBack = this.MakeBackButton(topframe);
|
|
//标题
|
this.MakeTitleButton(topframe);
|
}
|
|
/// <summary>
|
/// TopFrameLayout做成
|
/// </summary>
|
/// <returns>The top layout.</returns>
|
private FrameLayout MakeTopLayout()
|
{
|
FrameLayout topframeLayout = new FrameLayout();
|
|
topframeLayout.Width = LayoutParams.MatchParent;
|
topframeLayout.Height = ControlCommonResourse.TopFrameHeight;
|
topframeLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
|
|
return topframeLayout;
|
}
|
|
/// <summary>
|
/// TopMenuFrameLayout做成
|
/// </summary>
|
/// <returns>The top layout.</returns>
|
private FrameLayout MakeTopMenuLayout()
|
{
|
FrameLayout topMenuframeLayout = new FrameLayout();
|
|
topMenuframeLayout.Width = LayoutParams.MatchParent;
|
topMenuframeLayout.Height = ControlCommonResourse.TopMenuFrameHeight;
|
topMenuframeLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
|
|
return topMenuframeLayout;
|
}
|
|
|
/// <summary>
|
/// 返回键做成
|
/// </summary>
|
/// <returns>The back button.</returns>
|
private BackViewControl MakeBackButton(FrameLayout topframeLayout)
|
{
|
var btnBack = new BackViewControl();
|
|
topframeLayout.AddChidren(btnBack);
|
topframeLayout.AddTag("btnBack", btnBack);
|
|
return btnBack;
|
}
|
|
/// <summary>
|
/// 标题控件做成
|
/// </summary>
|
/// <returns>The title button.</returns>
|
private TopLayoutTitleView MakeTitleButton(FrameLayout topframeLayout)
|
{
|
var txttitle = new TopLayoutTitleView();
|
|
topframeLayout.AddChidren(txttitle);
|
topframeLayout.AddTag("txtTitle", txttitle);
|
|
return txttitle;
|
}
|
|
#endregion
|
|
#region ■ Middle_____________________________
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
public void InitBodyFrameLayout()
|
{
|
//初始化中部FrameLayout
|
this.InitBodyFrameLayout(this, ref bodyFrameLayout, topFrameLayout.Bottom);
|
}
|
|
/// <summary>
|
/// Middle标准化
|
/// </summary>
|
private void InitBodyFrameLayout(FrameLayout FormframeLayout, ref FrameLayout MidframeLayout, int YY)
|
{
|
if (MidframeLayout != null)
|
{
|
MidframeLayout.RemoveAll();
|
}
|
|
//中部FrameLayout做成
|
MidframeLayout = this.MakeMiddleLayout(YY);
|
MidframeLayout.Name = "bodyFrameLayout";
|
FormframeLayout.AddChidren(MidframeLayout);
|
}
|
|
/// <summary>
|
/// 中部FrameLayout做成
|
/// </summary>
|
/// <returns>The middle layout.</returns>
|
/// <param name="YY">Yy.</param>
|
private FrameLayout MakeMiddleLayout(int YY)
|
{
|
FrameLayout MidframeLayout = new FrameLayout();
|
MidframeLayout.Width = LayoutParams.MatchParent;
|
MidframeLayout.Height = ControlCommonResourse.BodyFrameHeight;
|
MidframeLayout.Y = YY;
|
MidframeLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
|
|
return MidframeLayout;
|
}
|
|
#endregion
|
|
#endregion
|
|
#region ■ 网关在线状态推送___________________
|
|
/// <summary>
|
/// 设置网关接受在线状态推送
|
/// </summary>
|
public void AddGatewayOnlinePush()
|
{
|
UserCenterResourse.listGatewayOnlinePushForm.Add(this);
|
}
|
|
/// <summary>
|
/// 移除网关接受在线状态推送
|
/// </summary>
|
public void RemoveGatewayOnlinePush()
|
{
|
UserCenterResourse.listGatewayOnlinePushForm.RemoveAll((obj) => { return obj.FormID == this.FormID; });
|
}
|
|
/// <summary>
|
/// 网关在线状态变更推送(只有在变更的时候才会推送)
|
/// </summary>
|
/// <param name="gateWay">网关对象</param>
|
/// <param name="online">在线状态变更后的状态</param>
|
public virtual void GatewayOnlinePush(ZigBee.Device.ZbGateway gateWay, bool online)
|
{
|
}
|
|
#endregion
|
|
#region ■ 圆形进度条_________________________
|
|
/// <summary>
|
/// 进度条启动
|
/// </summary>
|
/// <param name="text">初始文本</param>
|
public void ShowProgressBar(string text = "")
|
{
|
ProgressBar.Show(text);
|
}
|
|
/// <summary>
|
/// 设置进度条的信息值(会自动计算百分比,值累加模式)
|
/// </summary>
|
/// <param name="value">值</param>
|
public void SetProgressValue(decimal value)
|
{
|
ProgressBar.SetValue(value);
|
}
|
|
/// <summary>
|
/// 设置进度条的信息值
|
/// </summary>
|
/// <param name="value">值</param>
|
public void SetProgressValue(string value)
|
{
|
ProgressBar.SetValue(value);
|
}
|
|
/// <summary>
|
/// 设置进度条的信息值
|
/// </summary>
|
/// <param name="value">值</param>
|
public void SetProgressMax(decimal value)
|
{
|
if (value == 0)
|
{
|
value = 100;
|
}
|
ProgressBar.SetMaxValue(value);
|
}
|
|
/// <summary>
|
/// 关闭进度条
|
/// </summary>
|
/// <param name="mode">是否显示重新加载的界面</param>
|
public void CloseProgressBar(ShowReLoadMode mode = ShowReLoadMode.NO)
|
{
|
ProgressBar.Close();
|
if (mode == ShowReLoadMode.YES)
|
{
|
//显示重新加载的界面(主要是用在界面加载错误时,再次加载)
|
this.ShowReLoadView();
|
}
|
}
|
|
#endregion
|
|
#region ■ 一般的方法_________________________
|
|
/// <summary>
|
/// 设置标题信息
|
/// </summary>
|
/// <param name="title">Title.</param>
|
public void SetTitleText(string title)
|
{
|
//设置头部信息
|
Button btntitle = (Button)topFrameLayout.GetTagByKey("txtTitle");
|
btntitle.Text = title;
|
}
|
|
/// <summary>
|
/// 移除返回键
|
/// </summary>
|
public void RemoveBackButton()
|
{
|
//移除返回键
|
Button back = (Button)topFrameLayout.GetTagByKey("btnBack");
|
topFrameLayout.Remove(back);
|
}
|
|
/// <summary>
|
/// 显示错误信息(只针对错误信息)
|
/// </summary>
|
/// <param name="msg">信息</param>
|
/// <param name="methodName">单击确认后的函数(请确认这是一个共有方法)</param>
|
/// <param name="obj">回调函数的启动参数</param>
|
public void ShowErrorMsg(string msg, string methodName = null, params object[] obj)
|
{
|
//空对象时,不显示
|
if (string.IsNullOrEmpty(msg))
|
{
|
return;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
var alert = new ErrorMsgControl(msg);
|
alert.Show();
|
|
if (string.IsNullOrEmpty(methodName) == false)
|
{
|
alert.ResultEventHandler += (sender, result) =>
|
{
|
this.LoadFormMethodByName(this, methodName, obj);
|
};
|
}
|
});
|
}
|
|
/// <summary>
|
/// 显示普通信息(只针对普通信息)
|
/// </summary>
|
/// <param name="msg">信息</param>
|
/// <param name="methodName">单击确认后的函数(请确认这是一个共有方法)</param>
|
/// <param name="obj">回调函数的启动参数</param>
|
public void ShowNormalMsg(string msg, string methodName = null, params object[] obj)
|
{
|
//空对象时,不显示
|
if (string.IsNullOrEmpty(msg))
|
{
|
return;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
var alert = new NormalMsgControl(msg);
|
alert.Show();
|
|
if (methodName != null)
|
{
|
alert.ResultEventHandler += (sender, result) =>
|
{
|
this.LoadFormMethodByName(this, methodName, obj);
|
};
|
}
|
});
|
}
|
|
/// <summary>
|
/// 显示一个需要确认的信息框
|
/// </summary>
|
/// <param name="msg">信息</param>
|
/// <param name="methodName">方法名(请确认这是一个共有方法)</param>
|
/// <param name="obj">回调函数的启动参数</param>
|
public void ShowConfirmMsg(string msg, string methodName = null, params object[] obj)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
var alert = new ConfirmMsgControl(msg);
|
alert.Show();
|
|
if (methodName != null)
|
{
|
alert.ResultEventHandler += (sender, result) =>
|
{
|
if (result == true)
|
{
|
this.LoadFormMethodByName(this, methodName, obj);
|
}
|
};
|
}
|
});
|
}
|
|
/// <summary>
|
/// 显示Tip信息框
|
/// </summary>
|
/// <param name="text">Text.</param>
|
/// <param name="closeTime">Close time.</param>
|
public void ShowTip(string text, int closeTime = 2)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
var tip = new TipViewControl(text, closeTime);
|
tip.ShowView();
|
});
|
}
|
|
/// <summary>
|
/// 判断当前正在活动的界面是否是当前这个界面
|
/// </summary>
|
/// <returns></returns>
|
public bool NowFormIsAction()
|
{
|
return UserCenterResourse.NowActionFormID == this.FormID;
|
}
|
|
#endregion
|
|
#region ■ 反射方法___________________________
|
|
/// <summary>
|
/// 关闭指定的画面
|
/// </summary>
|
/// <param name="formName">指定要关闭的画面英文名字</param>
|
public void CloseFormByFormName(string formName)
|
{
|
if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
|
{
|
return;
|
}
|
//关闭指定画面
|
UserCenterResourse.DicActionForm[formName].CloseForm();
|
}
|
|
/// <summary>
|
/// 执行指定画面的方法
|
/// </summary>
|
/// <param name="formName">指定画面的英文名</param>
|
/// <param name="method">指定要加载的方法名</param>
|
/// <param name="parameter">启动参数</param>
|
public object LoadFormMethodByName(string formName, string method, params object[] parameter)
|
{
|
if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
|
{
|
return null;
|
}
|
UserCenterCommonForm form = UserCenterResourse.DicActionForm[formName];
|
return this.LoadFormMethodByName(form, method, parameter);
|
}
|
|
/// <summary>
|
/// 执行指定画面的方法(注意:这个是专门调用异步,并且等待异步完成的高科技函数,不调用异步的情况,别使用此函数)
|
/// </summary>
|
/// <param name="formName">指定画面的英文名</param>
|
/// <param name="method">指定要加载的方法名</param>
|
/// <param name="parameter">启动参数</param>
|
public async Task<object> LoadFormMethodByNameAsync(string formName, string method, params object[] parameter)
|
{
|
if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
|
{
|
return null;
|
}
|
var form = UserCenterResourse.DicActionForm[formName];
|
var task = this.LoadFormMethodByName(form, method, parameter) as Task;
|
await task;
|
|
var result = task.GetType().GetProperty("Result").GetValue(task, null);
|
return result;
|
}
|
|
/// <summary>
|
/// 执行指定画面的方法
|
/// </summary>
|
/// <param name="form">指定画面的英文名</param>
|
/// <param name="method">指定要加载的方法名</param>
|
/// <param name="parameter">启动参数</param>
|
public object LoadFormMethodByName(UserCenterCommonForm form, string method, params object[] parameter)
|
{
|
try
|
{
|
return form.GetType().InvokeMember(method, System.Reflection.BindingFlags.InvokeMethod, null, form, parameter);
|
}
|
catch (Exception ex)
|
{
|
string msg = ex.Message + "\r\n";
|
msg += ex.TargetSite.ToString();
|
this.ShowErrorMsg(msg);
|
|
return null;
|
}
|
}
|
|
/// <summary>
|
/// 使用反射方法,打开指定的画面(只支持继承于UserCenterCommonForm的画面)
|
/// </summary>
|
/// <param name="fullName">画面的命名空间+画面的英文名</param>
|
/// <param name="parameter">启动参数</param>
|
public void LoadFormByFullName(string fullName, params object[] parameter)
|
{
|
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
|
UserCenterCommonForm form = (UserCenterCommonForm)assembly.CreateInstance(fullName);
|
this.AddForm(form, parameter);
|
}
|
|
#endregion
|
|
#region ■ 显示重新加载_______________________
|
|
/// <summary>
|
/// 显示重新加载的界面(主要是用在界面加载错误时,再次加载)
|
/// </summary>
|
public void ShowReLoadView()
|
{
|
Application.RunOnMainThread(() =>
|
{
|
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.MouseUpEvent += (sender, e) =>
|
{
|
//调用关闭函数的附加函数,但是不关闭界面
|
this.CloseForm(false);
|
//清除全部控件
|
bodyFrameLayout.RemoveAll();
|
|
//执行ShowForm()方法实现重新加载
|
this.LoadShowFormMethod(this.m_parameter);
|
};
|
|
//清除topFrameLayout的非默认的控件
|
var list = new List<View>();
|
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();
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 界面重新激活事件___________________
|
|
/// <summary>
|
/// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
|
/// </summary>
|
public virtual void FormActionAgainEvent()
|
{
|
return;
|
}
|
|
#endregion
|
}
|
}
|