using HDL_ON.Stan;
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
namespace HDL_ON.UI
{
///
/// 行条类型的进度条控件
///
public class ProgressRowBar : FrameLayout
{
#region ■ 变量声明___________________________
///
/// 进度条能否往回走(默认不可以)
///
public bool ProgressBarGoback = false;
///
/// 会移动的进度条
///
private FrameLayout btnProgressBar = null;
///
/// 显示数值百分比的控件
///
private NormalViewControl btnProgressTextView = null;
///
/// 线程是否运行
///
private bool isThreadAction = false;
///
/// 模式区分
///
private int m_ModeDiv = -1;
///
/// 进度条是否可视
///
public new bool Visible
{
get { return base.Visible; }
set
{
if (this.btnProgressTextView != null)
{
this.btnProgressTextView.Visible = value;
}
base.Visible = value;
}
}
#endregion
#region ■ 初始化_____________________________
///
/// 行条类型的进度条控件
///
///
/// 模式1:会动的那个进度条的宽度(非真实值)
/// 模式2:进度条在持续无限的来回移动的区域宽度(非真实值)
///
///
/// 模式1:会动的那个进度条的高度(非真实值)
/// 模式2:进度条在持续无限的来回移动的高度(非真实值)
///
public ProgressRowBar(int width, int height)
{
this.Height = Application.GetRealHeight(height);
this.Width = Application.GetRealWidth(width);
this.BackgroundColor = UI.CSS.CSS_Color.BackgroundColor;
this.Radius = (uint)Application.GetRealHeight(height) / 2;
}
#endregion
#region ■ 模式1______________________________
///
/// 模式1 该模式为:手动填写进度值
///
///
/// 是否在进度条上方显示数值百分比
/// 请确保控件的上方有足够的区域(注:请不要扩大此控件的高度)
///
public void StartMode1(bool showText = false)
{
if (m_ModeDiv != -1) { return; }
this.m_ModeDiv = 1;
//会移动的进度条
this.btnProgressBar = new FrameLayout();
btnProgressBar.Width = 0;
btnProgressBar.Height = this.Height;
btnProgressBar.BackgroundColor = UI.CSS.CSS_Color.MainColor;
btnProgressBar.Radius = (uint)this.Height / 2;
this.AddChidren(btnProgressBar);
if (showText == true)
{
//进度值文本
this.btnProgressTextView = new NormalViewControl(32, 22, true);
btnProgressTextView.Y = this.Y - Application.GetRealHeight(22 + 10);//10:它与进度条的间距
btnProgressTextView.X = this.X - Application.GetRealWidth(32) / 2;
btnProgressTextView.UnSelectedImagePath = "Public/ProgressMsg.png";
btnProgressTextView.TextSize = CSS.CSS_FontSize.PromptFontSize_SecondaryLevel;
btnProgressTextView.TextColor= CSS.CSS_Color.FirstLevelTitleColor;
btnProgressTextView.TextAlignment = TextAlignment.Center;
btnProgressTextView.Text = "0%";
this.Parent.AddChidren(btnProgressTextView);
}
}
///
/// 重置进度条(只对模式1有效)
///
public void ResetProgressBar()
{
if (this.m_ModeDiv == 1 && this.btnProgressBar != null)
{
this.btnProgressBar.Width = 0;
}
}
///
/// 设置进度值
///
/// 此值为百分比值(也就是小于或者等于1的)
public void SetValue(decimal value)
{
this.SetValueEx(value);
}
///
/// 设置进度值
///
/// 进度值,内部会除以maxValue
/// 最大值
public void SetValue(decimal value, decimal maxValue)
{
decimal result = value / maxValue;
this.SetValueEx(result);
}
///
/// 设置进度值
///
///
private void SetValueEx(decimal value)
{
if (btnProgressBar == null || this.m_ModeDiv != 1)
{
return;
}
if (value > 1) { value = 1; }
HdlThreadLogic.Current.RunMain(() =>
{
int width = (int)(value * this.Width);
if (this.ProgressBarGoback == false && btnProgressBar.Width >= width)
{
//不能让进度条往回走
return;
}
btnProgressBar.Width = width;
if (this.btnProgressTextView != null)
{
//文本显示
btnProgressTextView.Text = ((int)(value * 100)) + "%";
//文本显示的那个图片框移动
this.btnProgressTextView.X = this.X + btnProgressBar.Right - btnProgressTextView.Width / 2;
}
});
}
#endregion
#region ■ 模式2______________________________
///
/// 模式2 该模式为:不能手动指定进度值,由内部线程处理,进度条在持续无限的来回移动
///
/// 持续无限的来回移动的进度条的宽度(非真实值)
public void StartMode2(int proWidth = 100)
{
if (m_ModeDiv != -1) { return; }
this.m_ModeDiv = 2;
//会移动的进度条
this.btnProgressBar = new FrameLayout();
btnProgressBar.Width = Application.GetRealWidth(proWidth);
btnProgressBar.Height = this.Height;
btnProgressBar.BackgroundColor = 0xfffb744a;
btnProgressBar.Radius = (uint)this.Height / 2;
this.AddChidren(btnProgressBar);
//开启模式2的线程
this.StartMode2Thread();
}
///
/// 重新开启模式2
///
public void ReStartMode2()
{
//开启模式2的线程
this.StartMode2Thread();
}
///
/// 暂停模式2
///
public void StopMode2()
{
this.isThreadAction = false;
}
///
/// 开启模式2的线程
///
private void StartMode2Thread()
{
if (this.isThreadAction == true)
{
return;
}
this.isThreadAction = true;
int moveLength = Application.GetRealWidth(30);
HdlThreadLogic.Current.RunThread(() =>
{
while (this.Parent != null && isThreadAction == true)
{
HdlThreadLogic.Current.RunMain(() =>
{
if (this.btnProgressBar.X >= this.Width)
{
//超出右边之后,再次从左边循环
this.btnProgressBar.X = -this.btnProgressBar.Width;
return;
}
this.btnProgressBar.X += moveLength;
}, ShowErrorMode.NO);
System.Threading.Thread.Sleep(150);
}
});
}
#endregion
}
}