using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter { /// /// 行条类型的进度条控件 /// public class ProgressRowBar : FrameLayout { #region ■ 变量声明___________________________ /// /// 会移动的进度条 /// private FrameLayout btnProgressBar = null; /// /// 数值百分比文本的容器 /// private FrameLayout frameProgressBack = null; /// /// 显示数值百分比的控件 /// private NormalViewControl btnProgressTextView = null; /// /// 线程是否运行 /// private bool isThreadAction = false; /// /// 模式区分 /// private int m_ModeDiv = -1; #endregion #region ■ 初始化_____________________________ /// /// 行条类型的进度条控件 /// /// 非真实值 /// 非真实值 public ProgressRowBar(int width, int height) { this.Height = Application.GetRealHeight(height); this.Width = Application.GetRealWidth(width); this.BackgroundColor = 0xffe6e6e6; 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 = 0xfffb744a; btnProgressBar.Radius = (uint)this.Height / 2; this.AddChidren(btnProgressBar); if (showText == true) { //进度值文本 this.frameProgressBack = new FrameLayout(); frameProgressBack.Width = Application.GetRealWidth(84); frameProgressBack.Height = Application.GetRealHeight(60); frameProgressBack.Y = this.Y - Application.GetRealHeight(60); frameProgressBack.X = this.X - Application.GetRealWidth(84) / 2; this.Parent.AddChidren(frameProgressBack); var btnProgressPic = new PicViewControl(84, 60); btnProgressPic.UnSelectedImagePath = "Item/ProgressMsg.png"; frameProgressBack.AddChidren(btnProgressPic); this.btnProgressTextView = new NormalViewControl(84, 45, true); btnProgressTextView.TextSize = 10; btnProgressTextView.TextAlignment = TextAlignment.Center; btnProgressTextView.Text = "0%"; frameProgressBack.AddChidren(btnProgressTextView); } } /// /// 设置进度值 /// /// 此值为百分比值(也就是小于或者等于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 || value > 1) { return; } HdlThreadLogic.Current.RunMain(() => { int width = (int)(value * this.Width); btnProgressBar.Width = width; if (this.btnProgressTextView != null) { //文本显示 btnProgressTextView.Text = ((int)(value * 100)) + "%"; //文本显示的那个图片框移动 this.frameProgressBack.X = ControlCommonResourse.XXLeft + btnProgressBar.Right - frameProgressBack.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 } }